use of io.grpc.testing.protobuf.SimpleRequest in project grpc-java by grpc.
the class GrpcServerRuleTest method serverAllowsServicesToBeAddedViaServiceRegistry_withoutDirectExecutor.
@Test
public void serverAllowsServicesToBeAddedViaServiceRegistry_withoutDirectExecutor() {
TestServiceImpl testService = new TestServiceImpl();
grpcServerRule1.getServiceRegistry().addService(testService);
SimpleServiceGrpc.SimpleServiceBlockingStub stub = SimpleServiceGrpc.newBlockingStub(grpcServerRule1.getChannel());
SimpleRequest request1 = SimpleRequest.getDefaultInstance();
SimpleRequest request2 = SimpleRequest.newBuilder().build();
stub.unaryRpc(request1);
stub.unaryRpc(request2);
assertThat(testService.unaryCallRequests).containsExactly(request1, request2);
}
use of io.grpc.testing.protobuf.SimpleRequest in project grpc-java by grpc.
the class FakeControlPlaneXdsIntegrationTest method startServer.
private void startServer(Map<String, ?> bootstrapOverride) throws Exception {
SimpleServiceGrpc.SimpleServiceImplBase simpleServiceImpl = new SimpleServiceGrpc.SimpleServiceImplBase() {
@Override
public void unaryRpc(SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) {
SimpleResponse response = SimpleResponse.newBuilder().setResponseMessage("Hi, xDS!").build();
responseObserver.onNext(response);
responseObserver.onCompleted();
}
};
XdsServerBuilder serverBuilder = XdsServerBuilder.forPort(0, InsecureServerCredentials.create()).addService(simpleServiceImpl).overrideBootstrapForTest(bootstrapOverride);
server = serverBuilder.build().start();
testServerPort = server.getPort();
logger.log(Level.FINE, "server started");
}
use of io.grpc.testing.protobuf.SimpleRequest in project grpc-java by grpc.
the class OrcaMetricReportingServerInterceptorTest method shareCallMetricRecorderInContext.
@Test
public void shareCallMetricRecorderInContext() throws IOException {
final CallMetricRecorder callMetricRecorder = InternalCallMetricRecorder.newCallMetricRecorder();
ServerStreamTracer.Factory callMetricRecorderSharingStreamTracerFactory = new ServerStreamTracer.Factory() {
@Override
public ServerStreamTracer newServerStreamTracer(String fullMethodName, Metadata headers) {
return new ServerStreamTracer() {
@Override
public Context filterContext(Context context) {
return context.withValue(InternalCallMetricRecorder.CONTEXT_KEY, callMetricRecorder);
}
};
}
};
final AtomicReference<CallMetricRecorder> callMetricRecorderCapture = new AtomicReference<>();
SimpleServiceGrpc.SimpleServiceImplBase simpleServiceImpl = new SimpleServiceGrpc.SimpleServiceImplBase() {
@Override
public void unaryRpc(SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) {
callMetricRecorderCapture.set(CallMetricRecorder.getCurrent());
SimpleResponse response = SimpleResponse.newBuilder().setResponseMessage("Simple response").build();
responseObserver.onNext(response);
responseObserver.onCompleted();
}
};
ServerInterceptor metricReportingServerInterceptor = new OrcaMetricReportingServerInterceptor();
String serverName = InProcessServerBuilder.generateName();
grpcCleanupRule.register(InProcessServerBuilder.forName(serverName).directExecutor().addStreamTracerFactory(callMetricRecorderSharingStreamTracerFactory).addService(ServerInterceptors.intercept(simpleServiceImpl, metricReportingServerInterceptor)).build().start());
ManagedChannel channel = grpcCleanupRule.register(InProcessChannelBuilder.forName(serverName).build());
ClientCalls.blockingUnaryCall(channel, SIMPLE_METHOD, CallOptions.DEFAULT, REQUEST);
assertThat(callMetricRecorderCapture.get()).isSameInstanceAs(callMetricRecorder);
}
use of io.grpc.testing.protobuf.SimpleRequest in project grpc-java by grpc.
the class OrcaMetricReportingServerInterceptorTest method setUp.
@Before
public void setUp() throws Exception {
SimpleServiceGrpc.SimpleServiceImplBase simpleServiceImpl = new SimpleServiceGrpc.SimpleServiceImplBase() {
@Override
public void unaryRpc(SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) {
for (Map.Entry<String, Double> entry : applicationMetrics.entrySet()) {
CallMetricRecorder.getCurrent().recordCallMetric(entry.getKey(), entry.getValue());
}
SimpleResponse response = SimpleResponse.newBuilder().setResponseMessage("Simple response").build();
responseObserver.onNext(response);
responseObserver.onCompleted();
}
};
ServerInterceptor metricReportingServerInterceptor = new OrcaMetricReportingServerInterceptor();
String serverName = InProcessServerBuilder.generateName();
grpcCleanupRule.register(InProcessServerBuilder.forName(serverName).directExecutor().addService(ServerInterceptors.intercept(simpleServiceImpl, metricReportingServerInterceptor)).build().start());
ManagedChannel baseChannel = grpcCleanupRule.register(InProcessChannelBuilder.forName(serverName).build());
channelToUse = ClientInterceptors.intercept(baseChannel, new TrailersCapturingClientInterceptor(trailersCapture));
}
use of io.grpc.testing.protobuf.SimpleRequest in project grpc-java by grpc.
the class GrpcServerRuleTest method serverAllowsServicesToBeAddedViaServiceRegistry_withDirectExecutor.
@Test
public void serverAllowsServicesToBeAddedViaServiceRegistry_withDirectExecutor() {
TestServiceImpl testService = new TestServiceImpl();
grpcServerRule2.getServiceRegistry().addService(testService);
SimpleServiceGrpc.SimpleServiceBlockingStub stub = SimpleServiceGrpc.newBlockingStub(grpcServerRule2.getChannel());
SimpleRequest request1 = SimpleRequest.getDefaultInstance();
SimpleRequest request2 = SimpleRequest.newBuilder().build();
stub.unaryRpc(request1);
stub.unaryRpc(request2);
assertThat(testService.unaryCallRequests).containsExactly(request1, request2);
}
Aggregations