diff --git a/stub/src/test/java/io/grpc/stub/BlockingClientCallTest.java b/stub/src/test/java/io/grpc/stub/BlockingClientCallTest.java index 112b092eaed..e3a4f90e2c2 100644 --- a/stub/src/test/java/io/grpc/stub/BlockingClientCallTest.java +++ b/stub/src/test/java/io/grpc/stub/BlockingClientCallTest.java @@ -195,21 +195,12 @@ public void testCancel() throws Exception { assertThat(System.currentTimeMillis() - start).isLessThan(2 * DELAY_MILLIS); } - // write terminated + // after cancel tests biDiStream = ClientCalls.blockingBidiStreamingCall(channel, BIDI_STREAMING_METHOD, CallOptions.DEFAULT); - start = System.currentTimeMillis(); - delayedCancel(biDiStream, "cancel write"); - - // Write interrupted by cancel - try { - assertFalse(biDiStream.write(30)); // this is interrupted by cancel - fail("No exception thrown when write was interrupted by cancel"); - } catch (StatusException e) { - assertEquals(Status.CANCELLED.getCode(), e.getStatus().getCode()); - } + biDiStream.cancel("cancel write", new RuntimeException("Test requested close")); - // Write after cancel + // Write after cancel should throw an exception try { start = System.currentTimeMillis(); biDiStream.write(30); @@ -357,31 +348,19 @@ public void testReadsAndWritesInterleaved_BlockingWrites() throws Exception { } @Test - public void testWriteCompleted() throws Exception { + public void testWriteAfterCloseThrows() throws Exception { testMethod.disableAutoRequest(); biDiStream = ClientCalls.blockingBidiStreamingCall(channel, BIDI_STREAMING_METHOD, CallOptions.DEFAULT); - // Verify pending write released - long start = System.currentTimeMillis(); - delayedVoidMethod(DELAY_MILLIS, biDiStream::halfClose); - assertFalse(biDiStream.write(1)); // should block until writeComplete is triggered - long end = System.currentTimeMillis(); - assertThat(end - start).isAtLeast(DELAY_MILLIS); - // verify new writes throw an illegalStateException + biDiStream.halfClose(); try { assertFalse(biDiStream.write(2)); fail("write did not throw an exception when called after halfClose"); } catch (IllegalStateException e) { assertThat(e.getMessage()).containsMatch("after.*halfClose.*cancel"); } - - // verify pending write with timeout released - biDiStream = ClientCalls.blockingBidiStreamingCall(channel, BIDI_STREAMING_METHOD, - CallOptions.DEFAULT); - delayedVoidMethod(DELAY_MILLIS, biDiStream::halfClose); - assertFalse(biDiStream.write(3, 2 * DELAY_MILLIS, TimeUnit.MILLISECONDS)); } @Test