InterruptibleHttpClient { public <IWC extends InterruptibleChannel & WritableByteChannel> HttpResponse interruptibleGet(String url, final IWC output) throws IOException, InterruptedException { return interruptibleRequest(new HttpGet(url), output, null); } InterruptibleHttpClient();  InterruptibleHttpClient(HttpAsyncClientProducer clientProducer); HttpResponse interruptibleRequest(HttpUriRequest request, final IWC output, final ResponseValidator val); HttpResponse interruptibleGet(String url, final IWC output); HttpResponse interruptibleGetRange(String url, final IWC output, String etag, long range_start, long range_end); HttpResponse interruptibleDelete(String url, final IWC output); HttpResponse interruptibleHead(String url);  }
@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 (); }