Search in sources :

Example 11 with SimpleResponse

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

the class AbstractInteropTest method largeUnary.

@Test
public void largeUnary() throws Exception {
    assumeEnoughMemory();
    final SimpleRequest request = SimpleRequest.newBuilder().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(request));
    assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.OK, Collections.singleton(request), Collections.singleton(goldenResponse));
}
Also used : SimpleResponse(io.grpc.testing.integration.Messages.SimpleResponse) SimpleRequest(io.grpc.testing.integration.Messages.SimpleRequest) Test(org.junit.Test)

Example 12 with SimpleResponse

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

the class AbstractInteropTest method clientCompressedUnary.

/**
 * Tests client per-message compression for unary calls. The Java API does not support inspecting
 * a message's compression level, so this is primarily intended to run against a gRPC C++ server.
 */
public void clientCompressedUnary(boolean probe) throws Exception {
    assumeEnoughMemory();
    final SimpleRequest expectCompressedRequest = SimpleRequest.newBuilder().setExpectCompressed(BoolValue.newBuilder().setValue(true)).setResponseSize(314159).setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[271828]))).build();
    final SimpleRequest expectUncompressedRequest = SimpleRequest.newBuilder().setExpectCompressed(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();
    if (probe) {
        // should return INVALID_ARGUMENT.
        try {
            blockingStub.unaryCall(expectCompressedRequest);
            fail("expected INVALID_ARGUMENT");
        } catch (StatusRuntimeException e) {
            assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatus().getCode());
        }
        assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.INVALID_ARGUMENT);
    }
    assertResponse(goldenResponse, blockingStub.withCompression("gzip").unaryCall(expectCompressedRequest));
    assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.OK, Collections.singleton(expectCompressedRequest), Collections.singleton(goldenResponse));
    assertResponse(goldenResponse, blockingStub.unaryCall(expectUncompressedRequest));
    assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.OK, Collections.singleton(expectUncompressedRequest), Collections.singleton(goldenResponse));
}
Also used : SimpleResponse(io.grpc.testing.integration.Messages.SimpleResponse) StatusRuntimeException(io.grpc.StatusRuntimeException) SimpleRequest(io.grpc.testing.integration.Messages.SimpleRequest)

Example 13 with SimpleResponse

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

the class AbstractInteropTest method oauth2AuthToken.

/**
 * Sends a unary rpc with raw oauth2 access token credentials.
 */
public void oauth2AuthToken(String jsonKey, InputStream credentialsStream, String authScope) throws Exception {
    GoogleCredentials utilCredentials = GoogleCredentials.fromStream(credentialsStream);
    utilCredentials = utilCredentials.createScoped(Arrays.asList(authScope));
    AccessToken accessToken = utilCredentials.refreshAccessToken();
    OAuth2Credentials credentials = OAuth2Credentials.create(accessToken);
    TestServiceGrpc.TestServiceBlockingStub stub = blockingStub.withCallCredentials(MoreCallCredentials.from(credentials));
    final SimpleRequest request = SimpleRequest.newBuilder().setFillUsername(true).setFillOauthScope(true).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()));
}
Also used : AccessToken(com.google.auth.oauth2.AccessToken) SimpleResponse(io.grpc.testing.integration.Messages.SimpleResponse) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) OAuth2Credentials(com.google.auth.oauth2.OAuth2Credentials) SimpleRequest(io.grpc.testing.integration.Messages.SimpleRequest)

Example 14 with SimpleResponse

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

the class GrpclbLongLivedAffinityTestClient method run.

private void run() throws Exception {
    final long startTimeMillis = System.currentTimeMillis();
    final long endTimeMillis = startTimeMillis + TimeUnit.SECONDS.toMillis(totalTestSeconds);
    final long rpcIntermissionMillis = TimeUnit.SECONDS.toMillis(rpcIntermissionSeconds);
    final long rpcErrorBudgetIncreasePeriodMillis = TimeUnit.MINUTES.toMillis(rpcErrorBudgetIncreaseMinutes);
    final long affinityBreakageBudgetIncreasePeriodMillis = TimeUnit.MINUTES.toMillis(affinityBreakageBudgetIncreaseMinutes);
    final SimpleRequest request = SimpleRequest.newBuilder().setResponseSize(314159).setFillServerId(true).setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[271828]))).build();
    String lastServerId = null;
    long rpcErrorBudget = 1;
    long affinityBreakageBudget = 1;
    long lastRpcErrorBudgetIncreaseTimeMillis = startTimeMillis;
    long lastAffinityBreakageBudgetIncreaseTimeMillis = startTimeMillis;
    logger.info("Test started");
    while (true) {
        try {
            logger.info("Sending request");
            SimpleResponse response = blockingStub.withDeadlineAfter(1, TimeUnit.MINUTES).unaryCall(request);
            logger.info("Received response");
            String serverId = response.getServerId();
            if (lastServerId != null && !lastServerId.equals(serverId)) {
                String msg = "Expected serverId " + lastServerId + ", but got " + serverId;
                logger.warning(msg + ". affinityBreakageBudget=" + affinityBreakageBudget);
                affinityBreakageBudget--;
                if (affinityBreakageBudget < 0) {
                    throw new AssertionError(msg);
                }
            }
        } catch (StatusRuntimeException e) {
            logger.log(Level.WARNING, "RPC error. rpcErrorBudget=" + rpcErrorBudget, e);
            rpcErrorBudget--;
            if (rpcErrorBudget < 0) {
                throw e;
            }
        }
        Thread.sleep(rpcIntermissionMillis);
        long nowMillis = System.currentTimeMillis();
        if (nowMillis > endTimeMillis) {
            logger.info("Time is up");
            break;
        }
        if (nowMillis > lastRpcErrorBudgetIncreaseTimeMillis + rpcErrorBudgetIncreasePeriodMillis) {
            lastRpcErrorBudgetIncreaseTimeMillis = nowMillis;
            rpcErrorBudget = Math.min(20, rpcErrorBudget + 1);
            logger.info("rpcErrorBudget after refresh: " + rpcErrorBudget);
        }
        if (nowMillis > lastAffinityBreakageBudgetIncreaseTimeMillis + affinityBreakageBudgetIncreasePeriodMillis) {
            lastAffinityBreakageBudgetIncreaseTimeMillis = nowMillis;
            affinityBreakageBudget = Math.min(3, affinityBreakageBudget + 1);
            logger.info("affinityBreakageBudget after refresh: " + affinityBreakageBudget);
        }
    }
    logger.info("Test passed.");
}
Also used : SimpleResponse(io.grpc.testing.integration.Messages.SimpleResponse) StatusRuntimeException(io.grpc.StatusRuntimeException) SimpleRequest(io.grpc.testing.integration.Messages.SimpleRequest) ByteString(com.google.protobuf.ByteString)

Example 15 with SimpleResponse

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

the class AltsHandshakerTest method startAltsServer.

private void startAltsServer() throws Exception {
    ServerCredentials serverCredentials = AltsServerCredentials.newBuilder().enableUntrustedAltsForTesting().setHandshakerAddressForTesting("localhost:" + handshakerServer.getPort()).build();
    testServer = grpcCleanup.register(Grpc.newServerBuilderForPort(0, serverCredentials).addService(new TestServiceGrpc.TestServiceImplBase() {

        @Override
        public void unaryCall(SimpleRequest request, StreamObserver<SimpleResponse> so) {
            so.onNext(SimpleResponse.getDefaultInstance());
            so.onCompleted();
        }
    }).build()).start();
}
Also used : ServerCredentials(io.grpc.ServerCredentials) AltsServerCredentials(io.grpc.alts.AltsServerCredentials) SimpleResponse(io.grpc.testing.integration.Messages.SimpleResponse) SimpleRequest(io.grpc.testing.integration.Messages.SimpleRequest)

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