use of io.grpc.testing.protobuf.SimpleResponse 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.SimpleResponse 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.SimpleResponse 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.SimpleResponse in project grpc-java by grpc.
the class LoggingServerProviderTest method unaryRpc.
private static String unaryRpc(String requestMessage, SimpleServiceGrpc.SimpleServiceBlockingStub blockingStub) {
SimpleRequest request = SimpleRequest.newBuilder().setRequestMessage(requestMessage).build();
SimpleResponse response = blockingStub.unaryRpc(request);
return response.getResponseMessage();
}
use of io.grpc.testing.protobuf.SimpleResponse in project grpc-java by grpc.
the class FakeControlPlaneXdsIntegrationTest method pingPong.
@Test
public void pingPong() throws Exception {
String tcpListenerName = SERVER_LISTENER_TEMPLATE_NO_REPLACEMENT;
String serverHostName = "test-server";
controlPlaneService.setXdsConfig(ADS_TYPE_URL_LDS, ImmutableMap.<String, Listener>of(tcpListenerName, serverListener(tcpListenerName), serverHostName, clientListener(serverHostName)));
startServer(defaultBootstrapOverride());
controlPlaneService.setXdsConfig(ADS_TYPE_URL_RDS, ImmutableMap.of(rdsName, rds(serverHostName)));
controlPlaneService.setXdsConfig(ADS_TYPE_URL_CDS, ImmutableMap.<String, Message>of(clusterName, cds()));
InetSocketAddress edsInetSocketAddress = (InetSocketAddress) server.getListenSockets().get(0);
controlPlaneService.setXdsConfig(ADS_TYPE_URL_EDS, ImmutableMap.<String, Message>of(edsName, eds(edsInetSocketAddress.getHostName(), edsInetSocketAddress.getPort())));
ManagedChannel channel = Grpc.newChannelBuilder(scheme + ":///" + serverHostName, InsecureChannelCredentials.create()).build();
blockingStub = SimpleServiceGrpc.newBlockingStub(channel);
SimpleRequest request = SimpleRequest.newBuilder().build();
SimpleResponse goldenResponse = SimpleResponse.newBuilder().setResponseMessage("Hi, xDS!").build();
assertEquals(goldenResponse, blockingStub.unaryRpc(request));
}
Aggregations