io.grpc.testing.protobuf.SimpleResponse Java Examples

The following examples show how to use io.grpc.testing.protobuf.SimpleResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShadingTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void tcnative() throws Exception {
  server = NettyServerBuilder.forPort(0)
      .useTransportSecurity(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key"))
      .addService(new SimpleServiceImpl())
      .build().start();
  channel = NettyChannelBuilder
      .forAddress("localhost", server.getPort())
      .sslContext(
          GrpcSslContexts.configure(SslContextBuilder.forClient(), SslProvider.OPENSSL)
              .trustManager(TestUtils.loadCert("ca.pem")).build())
      .overrideAuthority("foo.test.google.fr")
      .build();
  SimpleServiceBlockingStub stub = SimpleServiceGrpc.newBlockingStub(channel);
  assertThat(SimpleResponse.getDefaultInstance())
      .isEqualTo(stub.unaryRpc(SimpleRequest.getDefaultInstance()));
}
 
Example #2
Source File: ShadingTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void tcnative() throws Exception {
  server = NettyServerBuilder.forPort(0)
      .useTransportSecurity(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key"))
      .addService(new SimpleServiceImpl())
      .build().start();
  channel = NettyChannelBuilder
      .forAddress("localhost", server.getPort())
      .sslContext(
          GrpcSslContexts.configure(SslContextBuilder.forClient(), SslProvider.OPENSSL)
              .trustManager(TestUtils.loadCert("ca.pem")).build())
      .overrideAuthority("foo.test.google.fr")
      .build();
  SimpleServiceBlockingStub stub = SimpleServiceGrpc.newBlockingStub(channel);
  assertThat(SimpleResponse.getDefaultInstance())
      .isEqualTo(stub.unaryRpc(SimpleRequest.getDefaultInstance()));
}
 
Example #3
Source File: XdsSdsClientServerTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public void unaryRpc(SimpleRequest req, StreamObserver<SimpleResponse> responseObserver) {
  SimpleResponse response =
      SimpleResponse.newBuilder()
          .setResponseMessage("Hello " + req.getRequestMessage())
          .build();
  responseObserver.onNext(response);
  responseObserver.onCompleted();
}
 
Example #4
Source File: ShadingTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void basic() throws Exception {
  server = ServerBuilder.forPort(0)
      .addService(new SimpleServiceImpl())
      .build().start();
  channel = ManagedChannelBuilder
      .forAddress("localhost", server.getPort())
      .usePlaintext()
      .build();
  SimpleServiceBlockingStub stub = SimpleServiceGrpc.newBlockingStub(channel);
  assertThat(SimpleResponse.getDefaultInstance())
      .isEqualTo(stub.unaryRpc(SimpleRequest.getDefaultInstance()));
}
 
Example #5
Source File: OrcaMetricReportingServerInterceptorTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #6
Source File: ShadingTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void basic() throws Exception {
  server = ServerBuilder.forPort(0)
      .addService(new SimpleServiceImpl())
      .build().start();
  channel = ManagedChannelBuilder
      .forAddress("localhost", server.getPort())
      .usePlaintext()
      .build();
  SimpleServiceBlockingStub stub = SimpleServiceGrpc.newBlockingStub(channel);
  assertThat(SimpleResponse.getDefaultInstance())
      .isEqualTo(stub.unaryRpc(SimpleRequest.getDefaultInstance()));
}
 
Example #7
Source File: XdsSdsClientServerTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
/** Say hello to server. */
private static String unaryRpc(
    String requestMessage, SimpleServiceGrpc.SimpleServiceBlockingStub blockingStub) {
  SimpleRequest request = SimpleRequest.newBuilder().setRequestMessage(requestMessage).build();
  SimpleResponse response = blockingStub.unaryRpc(request);
  return response.getResponseMessage();
}
 
Example #8
Source File: OrcaMetricReportingServerInterceptorTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example #9
Source File: TlsTest.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Override
public void unaryRpc(SimpleRequest req, StreamObserver<SimpleResponse> respOb) {
  respOb.onNext(SimpleResponse.getDefaultInstance());
  respOb.onCompleted();
}
 
Example #10
Source File: ShadingTest.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Override public void unaryRpc(SimpleRequest req, StreamObserver<SimpleResponse> obs) {
  obs.onNext(SimpleResponse.getDefaultInstance());
  obs.onCompleted();
}
 
Example #11
Source File: ShadingTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override public void unaryRpc(SimpleRequest req, StreamObserver<SimpleResponse> obs) {
  obs.onNext(SimpleResponse.getDefaultInstance());
  obs.onCompleted();
}
 
Example #12
Source File: TlsTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
public void unaryRpc(SimpleRequest req, StreamObserver<SimpleResponse> respOb) {
  respOb.onNext(SimpleResponse.getDefaultInstance());
  respOb.onCompleted();
}
 
Example #13
Source File: HandshakerServiceChannelTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
public void unaryRpc(SimpleRequest request, StreamObserver<SimpleResponse> so) {
  so.onNext(SimpleResponse.getDefaultInstance());
  so.onCompleted();
}
 
Example #14
Source File: NettyGrpcServerRuleTest.java    From grpc-java-contrib with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
@Override
public void unaryRpc(
        SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) {

    unaryCallRequests.add(request);

    responseObserver.onNext(SimpleResponse.getDefaultInstance());

    responseObserver.onCompleted();
}
 
Example #15
Source File: NettyGrpcServerRuleTest.java    From grpc-java-contrib with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
@Override
public void serverStreamingRpc(
        SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) {

    lastServerStreamingRpcThread = Thread.currentThread();

    responseObserver.onNext(SimpleResponse.getDefaultInstance());

    responseObserver.onCompleted();
}
 
Example #16
Source File: GrpcServerRuleTest.java    From grpc-nebula-java with Apache License 2.0 3 votes vote down vote up
@Override
public void unaryRpc(
    SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) {

  unaryCallRequests.add(request);

  responseObserver.onNext(SimpleResponse.getDefaultInstance());

  responseObserver.onCompleted();
}
 
Example #17
Source File: GrpcServerRuleTest.java    From grpc-nebula-java with Apache License 2.0 3 votes vote down vote up
@Override
public void serverStreamingRpc(
    SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) {

  lastServerStreamingRpcThread = Thread.currentThread();

  responseObserver.onNext(SimpleResponse.getDefaultInstance());

  responseObserver.onCompleted();
}
 
Example #18
Source File: GrpcServerRuleTest.java    From grpc-java with Apache License 2.0 3 votes vote down vote up
@Override
public void serverStreamingRpc(
    SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) {

  lastServerStreamingRpcThread = Thread.currentThread();

  responseObserver.onNext(SimpleResponse.getDefaultInstance());

  responseObserver.onCompleted();
}
 
Example #19
Source File: GrpcServerRuleTest.java    From grpc-java with Apache License 2.0 3 votes vote down vote up
@Override
public void unaryRpc(
    SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) {

  unaryCallRequests.add(request);

  responseObserver.onNext(SimpleResponse.getDefaultInstance());

  responseObserver.onCompleted();
}