Search in sources :

Example 1 with SimpleResponse

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");
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) SimpleResponse(io.grpc.testing.protobuf.SimpleResponse) SimpleServiceGrpc(io.grpc.testing.protobuf.SimpleServiceGrpc) SimpleRequest(io.grpc.testing.protobuf.SimpleRequest)

Example 2 with SimpleResponse

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);
}
Also used : Context(io.grpc.Context) StreamObserver(io.grpc.stub.StreamObserver) ServerStreamTracer(io.grpc.ServerStreamTracer) Metadata(io.grpc.Metadata) AtomicReference(java.util.concurrent.atomic.AtomicReference) SimpleServiceGrpc(io.grpc.testing.protobuf.SimpleServiceGrpc) SimpleRequest(io.grpc.testing.protobuf.SimpleRequest) SimpleResponse(io.grpc.testing.protobuf.SimpleResponse) ServerInterceptor(io.grpc.ServerInterceptor) ManagedChannel(io.grpc.ManagedChannel) InternalCallMetricRecorder(io.grpc.services.InternalCallMetricRecorder) CallMetricRecorder(io.grpc.services.CallMetricRecorder) Test(org.junit.Test)

Example 3 with SimpleResponse

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));
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) SimpleServiceGrpc(io.grpc.testing.protobuf.SimpleServiceGrpc) SimpleRequest(io.grpc.testing.protobuf.SimpleRequest) SimpleResponse(io.grpc.testing.protobuf.SimpleResponse) ServerInterceptor(io.grpc.ServerInterceptor) ManagedChannel(io.grpc.ManagedChannel) HashMap(java.util.HashMap) Map(java.util.Map) Before(org.junit.Before)

Example 4 with SimpleResponse

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();
}
Also used : SimpleResponse(io.grpc.testing.protobuf.SimpleResponse) SimpleRequest(io.grpc.testing.protobuf.SimpleRequest)

Example 5 with SimpleResponse

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));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SimpleResponse(io.grpc.testing.protobuf.SimpleResponse) ManagedChannel(io.grpc.ManagedChannel) SimpleRequest(io.grpc.testing.protobuf.SimpleRequest) Test(org.junit.Test)

Aggregations

SimpleRequest (io.grpc.testing.protobuf.SimpleRequest)6 SimpleResponse (io.grpc.testing.protobuf.SimpleResponse)6 ManagedChannel (io.grpc.ManagedChannel)3 StreamObserver (io.grpc.stub.StreamObserver)3 SimpleServiceGrpc (io.grpc.testing.protobuf.SimpleServiceGrpc)3 ServerInterceptor (io.grpc.ServerInterceptor)2 Test (org.junit.Test)2 Context (io.grpc.Context)1 Metadata (io.grpc.Metadata)1 ServerStreamTracer (io.grpc.ServerStreamTracer)1 CallMetricRecorder (io.grpc.services.CallMetricRecorder)1 InternalCallMetricRecorder (io.grpc.services.InternalCallMetricRecorder)1 InetSocketAddress (java.net.InetSocketAddress)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Before (org.junit.Before)1