Search in sources :

Example 11 with SimpleRequest

use of io.grpc.testing.integration.Messages.SimpleRequest in project grpc-java by grpc.

the class AbstractInteropTest method statusCodeAndMessage.

@Test(timeout = 10000)
public void statusCodeAndMessage() throws Exception {
    int errorCode = 2;
    String errorMessage = "test status message";
    EchoStatus responseStatus = EchoStatus.newBuilder().setCode(errorCode).setMessage(errorMessage).build();
    SimpleRequest simpleRequest = SimpleRequest.newBuilder().setResponseStatus(responseStatus).build();
    StreamingOutputCallRequest streamingRequest = StreamingOutputCallRequest.newBuilder().setResponseStatus(responseStatus).build();
    // Test UnaryCall
    try {
        blockingStub.unaryCall(simpleRequest);
        fail();
    } catch (StatusRuntimeException e) {
        assertEquals(Status.UNKNOWN.getCode(), e.getStatus().getCode());
        assertEquals(errorMessage, e.getStatus().getDescription());
    }
    if (metricsExpected()) {
        assertClientMetrics("grpc.testing.TestService/UnaryCall", Status.Code.UNKNOWN);
    }
    // Test FullDuplexCall
    @SuppressWarnings("unchecked") StreamObserver<StreamingOutputCallResponse> responseObserver = mock(StreamObserver.class);
    StreamObserver<StreamingOutputCallRequest> requestObserver = asyncStub.fullDuplexCall(responseObserver);
    requestObserver.onNext(streamingRequest);
    requestObserver.onCompleted();
    ArgumentCaptor<Throwable> captor = ArgumentCaptor.forClass(Throwable.class);
    verify(responseObserver, timeout(operationTimeoutMillis())).onError(captor.capture());
    assertEquals(Status.UNKNOWN.getCode(), Status.fromThrowable(captor.getValue()).getCode());
    assertEquals(errorMessage, Status.fromThrowable(captor.getValue()).getDescription());
    verifyNoMoreInteractions(responseObserver);
    if (metricsExpected()) {
        assertClientMetrics("grpc.testing.TestService/FullDuplexCall", Status.Code.UNKNOWN);
    }
}
Also used : EchoStatus(io.grpc.testing.integration.Messages.EchoStatus) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) SimpleRequest(io.grpc.testing.integration.Messages.SimpleRequest) StreamingOutputCallRequest(io.grpc.testing.integration.Messages.StreamingOutputCallRequest) StreamingOutputCallResponse(io.grpc.testing.integration.Messages.StreamingOutputCallResponse) Test(org.junit.Test)

Example 12 with SimpleRequest

use of io.grpc.testing.integration.Messages.SimpleRequest in project grpc-java by grpc.

the class AbstractInteropTest method veryLargeRequest.

@Test(timeout = 30000)
public void veryLargeRequest() throws Exception {
    assumeEnoughMemory();
    final SimpleRequest request = SimpleRequest.newBuilder().setPayload(Payload.newBuilder().setType(PayloadType.COMPRESSABLE).setBody(ByteString.copyFrom(new byte[unaryPayloadLength()]))).setResponseSize(10).setResponseType(PayloadType.COMPRESSABLE).build();
    final SimpleResponse goldenResponse = SimpleResponse.newBuilder().setPayload(Payload.newBuilder().setType(PayloadType.COMPRESSABLE).setBody(ByteString.copyFrom(new byte[10]))).build();
    assertEquals(goldenResponse, blockingStub.unaryCall(request));
}
Also used : SimpleResponse(io.grpc.testing.integration.Messages.SimpleResponse) SimpleRequest(io.grpc.testing.integration.Messages.SimpleRequest) Test(org.junit.Test)

Example 13 with SimpleRequest

use of io.grpc.testing.integration.Messages.SimpleRequest in project grpc-java by grpc.

the class AbstractInteropTest method serviceAccountCreds.

/** Sends a large unary rpc with service account credentials. */
public void serviceAccountCreds(String jsonKey, InputStream credentialsStream, String authScope) throws Exception {
    // cast to ServiceAccountCredentials to double-check the right type of object was created.
    GoogleCredentials credentials = ServiceAccountCredentials.class.cast(GoogleCredentials.fromStream(credentialsStream));
    credentials = credentials.createScoped(Arrays.<String>asList(authScope));
    TestServiceGrpc.TestServiceBlockingStub stub = blockingStub.withCallCredentials(MoreCallCredentials.from(credentials));
    final SimpleRequest request = SimpleRequest.newBuilder().setFillUsername(true).setFillOauthScope(true).setResponseSize(314159).setResponseType(PayloadType.COMPRESSABLE).setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[271828]))).build();
    final SimpleResponse response = stub.unaryCall(request);
    assertFalse(response.getUsername().isEmpty());
    assertTrue("Received username: " + response.getUsername(), jsonKey.contains(response.getUsername()));
    assertFalse(response.getOauthScope().isEmpty());
    assertTrue("Received oauth scope: " + response.getOauthScope(), authScope.contains(response.getOauthScope()));
    final SimpleResponse goldenResponse = SimpleResponse.newBuilder().setOauthScope(response.getOauthScope()).setUsername(response.getUsername()).setPayload(Payload.newBuilder().setType(PayloadType.COMPRESSABLE).setBody(ByteString.copyFrom(new byte[314159]))).build();
    assertEquals(goldenResponse, response);
}
Also used : SimpleResponse(io.grpc.testing.integration.Messages.SimpleResponse) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) ByteString(com.google.protobuf.ByteString) SimpleRequest(io.grpc.testing.integration.Messages.SimpleRequest)

Aggregations

SimpleRequest (io.grpc.testing.integration.Messages.SimpleRequest)13 SimpleResponse (io.grpc.testing.integration.Messages.SimpleResponse)9 Test (org.junit.Test)8 ByteString (com.google.protobuf.ByteString)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)2 ServerCallStreamObserver (io.grpc.stub.ServerCallStreamObserver)2 StreamObserver (io.grpc.stub.StreamObserver)2 StreamingOutputCallRequest (io.grpc.testing.integration.Messages.StreamingOutputCallRequest)2 StreamingOutputCallResponse (io.grpc.testing.integration.Messages.StreamingOutputCallResponse)2 IOException (java.io.IOException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AccessToken (com.google.auth.oauth2.AccessToken)1 ComputeEngineCredentials (com.google.auth.oauth2.ComputeEngineCredentials)1 OAuth2Credentials (com.google.auth.oauth2.OAuth2Credentials)1 ServiceAccountCredentials (com.google.auth.oauth2.ServiceAccountCredentials)1 CallOptions (io.grpc.CallOptions)1 Deadline (io.grpc.Deadline)1 Metadata (io.grpc.Metadata)1 Status (io.grpc.Status)1