InterruptibleHttpClient { public <IWC extends InterruptibleChannel & WritableByteChannel> HttpResponse interruptibleGet(String url, final IWC output) throws IOException, InterruptedException { return interruptibleRequest(new HttpGet(url), output); } InterruptibleHttpClient();  InterruptibleHttpClient(HttpAsyncClientProducer clientProducer); HttpResponse interruptibleRequest(HttpUriRequest request, final IWC output); HttpResponse interruptibleGet(String url, final IWC output); HttpResponse interruptibleDelete(String url, final IWC output);  }
@Test public void testGet () throws IOException, InterruptedException { InterruptibleHttpClient ihc = new InterruptibleHttpClient (); DummyChannel output = new DummyChannel (); String url = "http: HttpResponse response = ihc.interruptibleGet (url, output); DummyHttpServer.stop (); long contentlength = response.getEntity ().getContentLength (); Assert.assertEquals (contentlength, output.getRead ()); }
@Test (timeOut = 2000L) public void testGetInterrupted () throws IOException, InterruptedException { final InterruptibleHttpClient ihc = new InterruptibleHttpClient (); ServerSocket ss = new ServerSocket (0); final String url = "http: Thread t = new Thread (new Runnable () { @Override public void run () { try { ihc.interruptibleGet (url, new DummyChannel ()); } catch (IOException | InterruptedException ex) { } } }); t.start (); Thread.sleep (1000L); t.interrupt (); ss.close (); t.join (); }