@@ -195,21 +195,12 @@ public void testCancel() throws Exception {
195
195
assertThat (System .currentTimeMillis () - start ).isLessThan (2 * DELAY_MILLIS );
196
196
}
197
197
198
- // write terminated
198
+ // after cancel tests
199
199
biDiStream = ClientCalls .blockingBidiStreamingCall (channel , BIDI_STREAMING_METHOD ,
200
200
CallOptions .DEFAULT );
201
- start = System .currentTimeMillis ();
202
- delayedCancel (biDiStream , "cancel write" );
203
-
204
- // Write interrupted by cancel
205
- try {
206
- assertFalse (biDiStream .write (30 )); // this is interrupted by cancel
207
- fail ("No exception thrown when write was interrupted by cancel" );
208
- } catch (StatusException e ) {
209
- assertEquals (Status .CANCELLED .getCode (), e .getStatus ().getCode ());
210
- }
201
+ biDiStream .cancel ("cancel write" , new RuntimeException ("Test requested close" ));
211
202
212
- // Write after cancel
203
+ // Write after cancel should throw an exception
213
204
try {
214
205
start = System .currentTimeMillis ();
215
206
biDiStream .write (30 );
@@ -357,31 +348,19 @@ public void testReadsAndWritesInterleaved_BlockingWrites() throws Exception {
357
348
}
358
349
359
350
@ Test
360
- public void testWriteCompleted () throws Exception {
351
+ public void testWriteAfterCloseThrows () throws Exception {
361
352
testMethod .disableAutoRequest ();
362
353
biDiStream = ClientCalls .blockingBidiStreamingCall (channel , BIDI_STREAMING_METHOD ,
363
354
CallOptions .DEFAULT );
364
355
365
- // Verify pending write released
366
- long start = System .currentTimeMillis ();
367
- delayedVoidMethod (DELAY_MILLIS , biDiStream ::halfClose );
368
- assertFalse (biDiStream .write (1 )); // should block until writeComplete is triggered
369
- long end = System .currentTimeMillis ();
370
- assertThat (end - start ).isAtLeast (DELAY_MILLIS );
371
-
372
356
// verify new writes throw an illegalStateException
357
+ biDiStream .halfClose ();
373
358
try {
374
359
assertFalse (biDiStream .write (2 ));
375
360
fail ("write did not throw an exception when called after halfClose" );
376
361
} catch (IllegalStateException e ) {
377
362
assertThat (e .getMessage ()).containsMatch ("after.*halfClose.*cancel" );
378
363
}
379
-
380
- // verify pending write with timeout released
381
- biDiStream = ClientCalls .blockingBidiStreamingCall (channel , BIDI_STREAMING_METHOD ,
382
- CallOptions .DEFAULT );
383
- delayedVoidMethod (DELAY_MILLIS , biDiStream ::halfClose );
384
- assertFalse (biDiStream .write (3 , 2 * DELAY_MILLIS , TimeUnit .MILLISECONDS ));
385
364
}
386
365
387
366
@ Test
0 commit comments