use of io.grpc.testing.integration.Messages.SimpleResponse in project grpc-java by grpc.
the class AbstractInteropTest method serviceAccountCreds.
/**
* Sends a large unary rpc with service account credentials.
*/
public void serviceAccountCreds(String jsonKey, InputStream credentialsStream, String authScope) throws Exception {
// cast to ServiceAccountCredentials to double-check the right type of object was created.
GoogleCredentials credentials = ServiceAccountCredentials.class.cast(GoogleCredentials.fromStream(credentialsStream));
credentials = credentials.createScoped(Arrays.asList(authScope));
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);
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()));
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 performOneSoakIteration.
private SoakIterationResult performOneSoakIteration(boolean resetChannel) throws Exception {
long startNs = System.nanoTime();
Status status = Status.OK;
ManagedChannel soakChannel = channel;
TestServiceGrpc.TestServiceBlockingStub soakStub = blockingStub;
if (resetChannel) {
soakChannel = createChannel();
soakStub = TestServiceGrpc.newBlockingStub(soakChannel);
}
try {
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, soakStub.unaryCall(request));
} catch (StatusRuntimeException e) {
status = e.getStatus();
}
long elapsedNs = System.nanoTime() - startNs;
if (resetChannel) {
soakChannel.shutdownNow();
soakChannel.awaitTermination(10, TimeUnit.SECONDS);
}
return new SoakIterationResult(TimeUnit.NANOSECONDS.toMillis(elapsedNs), status);
}
use of io.grpc.testing.integration.Messages.SimpleResponse in project grpc-java by grpc.
the class TestServiceImpl method unaryCall.
/**
* Immediately responds with a payload of the type and size specified in the request.
*/
@Override
public void unaryCall(SimpleRequest req, StreamObserver<SimpleResponse> responseObserver) {
ServerCallStreamObserver<SimpleResponse> obs = (ServerCallStreamObserver<SimpleResponse>) responseObserver;
SimpleResponse.Builder responseBuilder = SimpleResponse.newBuilder();
try {
if (req.hasResponseCompressed() && req.getResponseCompressed().getValue()) {
obs.setCompression("gzip");
} else {
obs.setCompression("identity");
}
} catch (IllegalArgumentException e) {
obs.onError(Status.UNIMPLEMENTED.withDescription("compression not supported.").withCause(e).asRuntimeException());
return;
}
if (req.getResponseSize() != 0) {
// For consistency with the c++ TestServiceImpl, use a random offset for unary calls.
// TODO(wonderfly): whether or not this is a good approach needs further discussion.
int offset = random.nextInt(compressableBuffer.size());
ByteString payload = generatePayload(compressableBuffer, offset, req.getResponseSize());
responseBuilder.setPayload(Payload.newBuilder().setBody(payload));
}
if (req.hasResponseStatus()) {
obs.onError(Status.fromCodeValue(req.getResponseStatus().getCode()).withDescription(req.getResponseStatus().getMessage()).asRuntimeException());
return;
}
responseObserver.onNext(responseBuilder.build());
responseObserver.onCompleted();
}
use of io.grpc.testing.integration.Messages.SimpleResponse in project grpc-java by grpc.
the class GrpclbFallbackTestClient method doRpcAndGetPath.
private GrpclbRouteType doRpcAndGetPath(Deadline deadline) {
logger.info("doRpcAndGetPath deadline: " + deadline);
final SimpleRequest request = SimpleRequest.newBuilder().setFillGrpclbRouteType(true).build();
GrpclbRouteType result = GrpclbRouteType.GRPCLB_ROUTE_TYPE_UNKNOWN;
try {
SimpleResponse response = blockingStub.withDeadline(deadline).unaryCall(request);
result = response.getGrpclbRouteType();
} catch (StatusRuntimeException ex) {
logger.warning("doRpcAndGetPath failed. Status: " + ex);
return GrpclbRouteType.GRPCLB_ROUTE_TYPE_UNKNOWN;
}
logger.info("doRpcAndGetPath. GrpclbRouteType result: " + result);
if (result != GrpclbRouteType.GRPCLB_ROUTE_TYPE_FALLBACK && result != GrpclbRouteType.GRPCLB_ROUTE_TYPE_BACKEND) {
throw new AssertionError("Received invalid LB route type. This suggests " + "that the server hasn't implemented this test correctly.");
}
return result;
}
Aggregations