use of io.grpc.testing.integration.Messages.SimpleResponse in project grpc-java by grpc.
the class AbstractInteropTest method computeEngineCreds.
/**
* Sends a large unary rpc with compute engine credentials.
*/
public void computeEngineCreds(String serviceAccount, String oauthScope) throws Exception {
ComputeEngineCredentials credentials = ComputeEngineCredentials.create();
TestServiceGrpc.TestServiceBlockingStub stub = blockingStub.withCallCredentials(MoreCallCredentials.from(credentials));
final SimpleRequest request = SimpleRequest.newBuilder().setFillUsername(true).setFillOauthScope(true).setResponseSize(314159).setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[271828]))).build();
final SimpleResponse response = stub.unaryCall(request);
assertEquals(serviceAccount, response.getUsername());
assertFalse(response.getOauthScope().isEmpty());
assertTrue("Received oauth scope: " + response.getOauthScope(), oauthScope.contains(response.getOauthScope()));
final SimpleResponse goldenResponse = SimpleResponse.newBuilder().setOauthScope(response.getOauthScope()).setUsername(response.getUsername()).setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[314159]))).build();
assertResponse(goldenResponse, response);
}
use of io.grpc.testing.integration.Messages.SimpleResponse in project grpc-java by grpc.
the class AbstractInteropTest method customMetadata.
@Test
public void customMetadata() throws Exception {
final int responseSize = 314159;
final int requestSize = 271828;
final SimpleRequest request = SimpleRequest.newBuilder().setResponseSize(responseSize).setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[requestSize]))).build();
final StreamingOutputCallRequest streamingRequest = StreamingOutputCallRequest.newBuilder().addResponseParameters(ResponseParameters.newBuilder().setSize(responseSize)).setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[requestSize]))).build();
final SimpleResponse goldenResponse = SimpleResponse.newBuilder().setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[responseSize]))).build();
final StreamingOutputCallResponse goldenStreamingResponse = StreamingOutputCallResponse.newBuilder().setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[responseSize]))).build();
final byte[] trailingBytes = { (byte) 0xa, (byte) 0xb, (byte) 0xa, (byte) 0xb, (byte) 0xa, (byte) 0xb };
// Test UnaryCall
Metadata metadata = new Metadata();
metadata.put(Util.ECHO_INITIAL_METADATA_KEY, "test_initial_metadata_value");
metadata.put(Util.ECHO_TRAILING_METADATA_KEY, trailingBytes);
AtomicReference<Metadata> headersCapture = new AtomicReference<>();
AtomicReference<Metadata> trailersCapture = new AtomicReference<>();
TestServiceGrpc.TestServiceBlockingStub blockingStub = this.blockingStub.withInterceptors(MetadataUtils.newAttachHeadersInterceptor(metadata), MetadataUtils.newCaptureMetadataInterceptor(headersCapture, trailersCapture));
SimpleResponse response = blockingStub.unaryCall(request);
assertResponse(goldenResponse, response);
assertEquals("test_initial_metadata_value", headersCapture.get().get(Util.ECHO_INITIAL_METADATA_KEY));
assertTrue(Arrays.equals(trailingBytes, trailersCapture.get().get(Util.ECHO_TRAILING_METADATA_KEY)));
assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.OK, Collections.singleton(request), Collections.singleton(goldenResponse));
// Test FullDuplexCall
metadata = new Metadata();
metadata.put(Util.ECHO_INITIAL_METADATA_KEY, "test_initial_metadata_value");
metadata.put(Util.ECHO_TRAILING_METADATA_KEY, trailingBytes);
headersCapture = new AtomicReference<>();
trailersCapture = new AtomicReference<>();
TestServiceGrpc.TestServiceStub stub = asyncStub.withInterceptors(MetadataUtils.newAttachHeadersInterceptor(metadata), MetadataUtils.newCaptureMetadataInterceptor(headersCapture, trailersCapture));
StreamRecorder<Messages.StreamingOutputCallResponse> recorder = StreamRecorder.create();
StreamObserver<Messages.StreamingOutputCallRequest> requestStream = stub.fullDuplexCall(recorder);
requestStream.onNext(streamingRequest);
requestStream.onCompleted();
recorder.awaitCompletion();
assertSuccess(recorder);
assertResponse(goldenStreamingResponse, recorder.firstValue().get());
assertEquals("test_initial_metadata_value", headersCapture.get().get(Util.ECHO_INITIAL_METADATA_KEY));
assertTrue(Arrays.equals(trailingBytes, trailersCapture.get().get(Util.ECHO_TRAILING_METADATA_KEY)));
assertStatsTrace("grpc.testing.TestService/FullDuplexCall", Status.Code.OK, Collections.singleton(streamingRequest), Collections.singleton(goldenStreamingResponse));
}
use of io.grpc.testing.integration.Messages.SimpleResponse in project grpc-java by grpc.
the class AbstractInteropTest method jwtTokenCreds.
/**
* Test JWT-based auth.
*/
public void jwtTokenCreds(InputStream serviceAccountJson) throws Exception {
final SimpleRequest request = SimpleRequest.newBuilder().setResponseSize(314159).setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[271828]))).setFillUsername(true).build();
ServiceAccountCredentials credentials = (ServiceAccountCredentials) GoogleCredentials.fromStream(serviceAccountJson);
TestServiceGrpc.TestServiceBlockingStub stub = blockingStub.withCallCredentials(MoreCallCredentials.from(credentials));
SimpleResponse response = stub.unaryCall(request);
assertEquals(credentials.getClientEmail(), response.getUsername());
assertEquals(314159, response.getPayload().getBody().size());
}
use of io.grpc.testing.integration.Messages.SimpleResponse in project grpc-java by grpc.
the class AbstractInteropTest method serverCompressedUnary.
/**
* Tests if the server can send a compressed unary response. Ideally we would assert that the
* responses have the requested compression, but this is not supported by the API. Given a
* compliant server, this test will exercise the code path for receiving a compressed response but
* cannot itself verify that the response was compressed.
*/
@Test
public void serverCompressedUnary() throws Exception {
assumeEnoughMemory();
final SimpleRequest responseShouldBeCompressed = SimpleRequest.newBuilder().setResponseCompressed(BoolValue.newBuilder().setValue(true)).setResponseSize(314159).setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[271828]))).build();
final SimpleRequest responseShouldBeUncompressed = SimpleRequest.newBuilder().setResponseCompressed(BoolValue.newBuilder().setValue(false)).setResponseSize(314159).setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[271828]))).build();
final SimpleResponse goldenResponse = SimpleResponse.newBuilder().setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[314159]))).build();
assertResponse(goldenResponse, blockingStub.unaryCall(responseShouldBeCompressed));
assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.OK, Collections.singleton(responseShouldBeCompressed), Collections.singleton(goldenResponse));
assertResponse(goldenResponse, blockingStub.unaryCall(responseShouldBeUncompressed));
assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.OK, Collections.singleton(responseShouldBeUncompressed), Collections.singleton(goldenResponse));
}
use of io.grpc.testing.integration.Messages.SimpleResponse in project grpc-java by grpc.
the class AbstractInteropTest method computeEngineChannelCredentials.
/**
* Sends an unary rpc with ComputeEngineChannelBuilder.
*/
public void computeEngineChannelCredentials(String defaultServiceAccount, TestServiceGrpc.TestServiceBlockingStub computeEngineStub) throws Exception {
final SimpleRequest request = SimpleRequest.newBuilder().setFillUsername(true).setResponseSize(314159).setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[271828]))).build();
final SimpleResponse response = computeEngineStub.unaryCall(request);
assertEquals(defaultServiceAccount, response.getUsername());
final SimpleResponse goldenResponse = SimpleResponse.newBuilder().setUsername(defaultServiceAccount).setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[314159]))).build();
assertResponse(goldenResponse, response);
}
Aggregations