use of io.grpc.testing.integration.Messages.SimpleResponse in project grpc-java by grpc.
the class AbstractInteropTest method googleDefaultCredentials.
/**
* Sends an unary rpc with "google default credentials".
*/
public void googleDefaultCredentials(String defaultServiceAccount, TestServiceGrpc.TestServiceBlockingStub googleDefaultStub) throws Exception {
final SimpleRequest request = SimpleRequest.newBuilder().setFillUsername(true).setResponseSize(314159).setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[271828]))).build();
final SimpleResponse response = googleDefaultStub.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);
}
use of io.grpc.testing.integration.Messages.SimpleResponse in project grpc-java by grpc.
the class AbstractInteropTest method pickFirstUnary.
/**
* Assuming "pick_first" policy is used, tests that all requests are sent to the same server.
*/
public void pickFirstUnary() throws Exception {
SimpleRequest request = SimpleRequest.newBuilder().setResponseSize(1).setFillServerId(true).setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[1]))).build();
SimpleResponse firstResponse = blockingStub.unaryCall(request);
// Increase the chance of all servers are connected, in case the channel should be doing
// round_robin instead.
Thread.sleep(5000);
for (int i = 0; i < 100; i++) {
SimpleResponse response = blockingStub.unaryCall(request);
assertThat(response.getServerId()).isEqualTo(firstResponse.getServerId());
}
}
use of io.grpc.testing.integration.Messages.SimpleResponse in project grpc-java by grpc.
the class AbstractInteropTest method cacheableUnary.
/**
* Sends a cacheable unary rpc using GET. Requires that the server is behind a caching proxy.
*/
public void cacheableUnary() {
// THIS TEST IS BROKEN. Enabling safe just on the MethodDescriptor does nothing by itself. This
// test would need to enable GET on the channel.
// Set safe to true.
MethodDescriptor<SimpleRequest, SimpleResponse> safeCacheableUnaryCallMethod = TestServiceGrpc.getCacheableUnaryCallMethod().toBuilder().setSafe(true).build();
// Set fake user IP since some proxies (GFE) won't cache requests from localhost.
Metadata.Key<String> userIpKey = Metadata.Key.of("x-user-ip", Metadata.ASCII_STRING_MARSHALLER);
Metadata metadata = new Metadata();
metadata.put(userIpKey, "1.2.3.4");
Channel channelWithUserIpKey = ClientInterceptors.intercept(channel, MetadataUtils.newAttachHeadersInterceptor(metadata));
SimpleRequest requests1And2 = SimpleRequest.newBuilder().setPayload(Payload.newBuilder().setBody(ByteString.copyFromUtf8(String.valueOf(System.nanoTime())))).build();
SimpleRequest request3 = SimpleRequest.newBuilder().setPayload(Payload.newBuilder().setBody(ByteString.copyFromUtf8(String.valueOf(System.nanoTime())))).build();
SimpleResponse response1 = ClientCalls.blockingUnaryCall(channelWithUserIpKey, safeCacheableUnaryCallMethod, CallOptions.DEFAULT, requests1And2);
SimpleResponse response2 = ClientCalls.blockingUnaryCall(channelWithUserIpKey, safeCacheableUnaryCallMethod, CallOptions.DEFAULT, requests1And2);
SimpleResponse response3 = ClientCalls.blockingUnaryCall(channelWithUserIpKey, safeCacheableUnaryCallMethod, CallOptions.DEFAULT, request3);
assertEquals(response1, response2);
assertNotEquals(response1, response3);
// THIS TEST IS BROKEN. See comment at start of method.
}
use of io.grpc.testing.integration.Messages.SimpleResponse in project grpc-java by grpc.
the class AbstractInteropTest method veryLargeResponse.
@Test
public void veryLargeResponse() throws Exception {
assumeEnoughMemory();
final SimpleRequest request = SimpleRequest.newBuilder().setResponseSize(unaryPayloadLength()).build();
final SimpleResponse goldenResponse = SimpleResponse.newBuilder().setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[unaryPayloadLength()]))).build();
assertResponse(goldenResponse, blockingStub.unaryCall(request));
}
use of io.grpc.testing.integration.Messages.SimpleResponse in project grpc-java by grpc.
the class AbstractInteropTest method veryLargeRequest.
@Test
public void veryLargeRequest() throws Exception {
assumeEnoughMemory();
final SimpleRequest request = SimpleRequest.newBuilder().setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[unaryPayloadLength()]))).setResponseSize(10).build();
final SimpleResponse goldenResponse = SimpleResponse.newBuilder().setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[10]))).build();
assertResponse(goldenResponse, blockingStub.unaryCall(request));
}
Aggregations