From 3c79c52427dc01541fbe7c5e35cc6ee31a26ba8c Mon Sep 17 00:00:00 2001 From: Xiao Hang Date: Thu, 27 Aug 2015 14:29:32 -0700 Subject: [PATCH] Implement timeout_on_sleeping_server test --- .../integration/AbstractTransportTest.java | 47 ++++++++++++++----- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java index b2d86f8acd..ec9e9f54ab 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java @@ -710,6 +710,40 @@ public abstract class AbstractTransportTest { verifyNoMoreInteractions(responseObserver); } + /** Sends an rpc to an unimplemented method on the server. */ + @Test(timeout = 10000) + public void unimplementedMethod() { + UnimplementedServiceGrpc.UnimplementedServiceBlockingStub stub = + UnimplementedServiceGrpc.newBlockingStub(channel); + try { + stub.unimplementedCall(Empty.getDefaultInstance()); + fail(); + } catch (StatusRuntimeException e) { + assertEquals(Status.UNIMPLEMENTED.getCode(), e.getStatus().getCode()); + } + } + + /** Start a fullDuplexCall which the server will not respond, and verify the deadline expires. */ + @Test(timeout = 10000) + public void timeoutOnSleepingServer() { + TestServiceGrpc.TestService stub = TestServiceGrpc.newStub(channel) + .withDeadlineAfter(1, TimeUnit.MILLISECONDS); + @SuppressWarnings("unchecked") + StreamObserver responseObserver = mock(StreamObserver.class); + StreamObserver requestObserver + = stub.fullDuplexCall(responseObserver); + requestObserver.onNext(StreamingOutputCallRequest.newBuilder() + .setPayload(Payload.newBuilder() + .setBody(ByteString.copyFrom(new byte[27182]))) + .build()); + + ArgumentCaptor captor = ArgumentCaptor.forClass(Throwable.class); + verify(responseObserver, timeout(OPERATION_TIMEOUT)).onError(captor.capture()); + assertEquals(Status.DEADLINE_EXCEEDED.getCode(), + Status.fromThrowable(captor.getValue()).getCode()); + verifyNoMoreInteractions(responseObserver); + } + /** Sends a large unary rpc with service account credentials. */ public void serviceAccountCreds(String jsonKey, InputStream credentialsStream, String authScope) throws Exception { @@ -813,19 +847,6 @@ public abstract class AbstractTransportTest { authScope.contains(response.getOauthScope())); } - /** Sends an rpc to an unimplemented method on the server. */ - @Test(timeout = 10000) - public void unimplementedMethod() { - UnimplementedServiceGrpc.UnimplementedServiceBlockingStub stub = - UnimplementedServiceGrpc.newBlockingStub(channel); - try { - stub.unimplementedCall(Empty.getDefaultInstance()); - fail(); - } catch (StatusRuntimeException e) { - assertEquals(Status.UNIMPLEMENTED.getCode(), e.getStatus().getCode()); - } - } - protected static void assertSuccess(StreamRecorder recorder) { if (recorder.getError() != null) { throw new AssertionError(recorder.getError());