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