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);
}
}
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));
}
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);
}
Aggregations