Search in sources :

Example 1 with SimpleRequest

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

Example 2 with SimpleRequest

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");
}
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 3 with SimpleRequest

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);
}
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 4 with SimpleRequest

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));
}
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 5 with SimpleRequest

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

Aggregations

SimpleRequest (io.grpc.testing.protobuf.SimpleRequest)8 SimpleResponse (io.grpc.testing.protobuf.SimpleResponse)6 SimpleServiceGrpc (io.grpc.testing.protobuf.SimpleServiceGrpc)5 Test (org.junit.Test)4 ManagedChannel (io.grpc.ManagedChannel)3 StreamObserver (io.grpc.stub.StreamObserver)3 ServerInterceptor (io.grpc.ServerInterceptor)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