@@ -195,21 +195,12 @@ public void testCancel() throws Exception {
195195 assertThat (System .currentTimeMillis () - start ).isLessThan (2 * DELAY_MILLIS );
196196 }
197197
198- // write terminated
198+ // after cancel tests
199199 biDiStream = ClientCalls .blockingBidiStreamingCall (channel , BIDI_STREAMING_METHOD ,
200200 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" ));
211202
212- // Write after cancel
203+ // Write after cancel should throw an exception
213204 try {
214205 start = System .currentTimeMillis ();
215206 biDiStream .write (30 );
@@ -357,31 +348,19 @@ public void testReadsAndWritesInterleaved_BlockingWrites() throws Exception {
357348 }
358349
359350 @ Test
360- public void testWriteCompleted () throws Exception {
351+ public void testWriteAfterCloseThrows () throws Exception {
361352 testMethod .disableAutoRequest ();
362353 biDiStream = ClientCalls .blockingBidiStreamingCall (channel , BIDI_STREAMING_METHOD ,
363354 CallOptions .DEFAULT );
364355
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-
372356 // verify new writes throw an illegalStateException
357+ biDiStream .halfClose ();
373358 try {
374359 assertFalse (biDiStream .write (2 ));
375360 fail ("write did not throw an exception when called after halfClose" );
376361 } catch (IllegalStateException e ) {
377362 assertThat (e .getMessage ()).containsMatch ("after.*halfClose.*cancel" );
378363 }
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 ));
385364 }
386365
387366 @ Test
0 commit comments