Search in sources :

Example 16 with SimpleResponse

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);
}
Also used : SimpleResponse(io.grpc.testing.integration.Messages.SimpleResponse) SimpleRequest(io.grpc.testing.integration.Messages.SimpleRequest)

Example 17 with SimpleResponse

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());
    }
}
Also used : SimpleResponse(io.grpc.testing.integration.Messages.SimpleResponse) SimpleRequest(io.grpc.testing.integration.Messages.SimpleRequest)

Example 18 with SimpleResponse

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.
}
Also used : SimpleResponse(io.grpc.testing.integration.Messages.SimpleResponse) ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) Metadata(io.grpc.Metadata) SimpleRequest(io.grpc.testing.integration.Messages.SimpleRequest) ByteString(com.google.protobuf.ByteString)

Example 19 with SimpleResponse

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));
}
Also used : SimpleResponse(io.grpc.testing.integration.Messages.SimpleResponse) SimpleRequest(io.grpc.testing.integration.Messages.SimpleRequest) Test(org.junit.Test)

Example 20 with SimpleResponse

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));
}
Also used : SimpleResponse(io.grpc.testing.integration.Messages.SimpleResponse) SimpleRequest(io.grpc.testing.integration.Messages.SimpleRequest) Test(org.junit.Test)

Aggregations

SimpleResponse (io.grpc.testing.integration.Messages.SimpleResponse)24 SimpleRequest (io.grpc.testing.integration.Messages.SimpleRequest)21 Test (org.junit.Test)8 StatusRuntimeException (io.grpc.StatusRuntimeException)4 ByteString (com.google.protobuf.ByteString)3 ManagedChannel (io.grpc.ManagedChannel)3 Metadata (io.grpc.Metadata)3 Status (io.grpc.Status)3 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)2 Channel (io.grpc.Channel)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)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 ClientCall (io.grpc.ClientCall)1 ClientInterceptor (io.grpc.ClientInterceptor)1 Context (io.grpc.Context)1