@@ -37,7 +37,7 @@ public void whenSetRequestTimeout_thenFail() throws IOException {
3737 response .close ();
3838 }
3939
40- @ Test
40+ @ Test ( expected = IOException . class )
4141 public void whenCancelRequest_thenCorrect () throws IOException {
4242
4343 ScheduledExecutorService executor = Executors .newScheduledThreadPool (1 );
@@ -49,30 +49,22 @@ public void whenCancelRequest_thenCorrect() throws IOException {
4949 .build ();
5050
5151 final int seconds = 1 ;
52-
5352 final long startNanos = System .nanoTime ();
53+
5454 final Call call = client .newCall (request );
5555
5656 // Schedule a job to cancel the call in 1 second.
57- executor .schedule (new Runnable () {
58- public void run () {
59-
60- logger .debug ("Canceling call: " + (System .nanoTime () - startNanos ) / 1e9f );
61- call .cancel ();
62- logger .debug ("Canceled call: " + (System .nanoTime () - startNanos ) / 1e9f );
63- }
64- }, seconds , TimeUnit .SECONDS );
65-
66- try {
57+ executor .schedule (() -> {
6758
68- logger .debug ("Executing call: " + (System .nanoTime () - startNanos ) / 1e9f );
69- Response response = call .execute ();
70- logger .debug ("Call was expected to fail, but completed : " + (System .nanoTime () - startNanos ) / 1e9f , response );
59+ logger .debug ("Canceling call: " + (System .nanoTime () - startNanos ) / 1e9f );
60+ call .cancel ();
61+ logger .debug ("Canceled call : " + (System .nanoTime () - startNanos ) / 1e9f );
7162
72- } catch ( IOException e ) {
63+ }, seconds , TimeUnit . SECONDS );
7364
74- logger .debug ("Call failed as expected: " + (System .nanoTime () - startNanos ) / 1e9f , e );
75- }
65+ logger .debug ("Executing call: " + (System .nanoTime () - startNanos ) / 1e9f );
66+ Response response = call .execute ();
67+ logger .debug ("Call completed: " + (System .nanoTime () - startNanos ) / 1e9f , response );
7668 }
7769
7870 @ Test
0 commit comments