io.grpc.reflection.v1alpha.ServerReflectionRequest Java Examples

The following examples show how to use io.grpc.reflection.v1alpha.ServerReflectionRequest. 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: ProtoReflectionServiceTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void fileContainingNestedSymbol() throws Exception {
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder()
          .setHost(TEST_HOST)
          .setFileContainingSymbol("grpc.reflection.testing.NestedTypeOuter.Middle.Inner")
          .build();

  ServerReflectionResponse goldenResponse =
      ServerReflectionResponse.newBuilder()
          .setValidHost(TEST_HOST)
          .setOriginalRequest(request)
          .setFileDescriptorResponse(
              FileDescriptorResponse.newBuilder()
                  .addFileDescriptorProto(
                      ReflectionTestDepthThreeProto.getDescriptor().toProto().toByteString())
                  .build())
          .build();

  StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver =
      stub.serverReflectionInfo(responseObserver);
  requestObserver.onNext(request);
  requestObserver.onCompleted();
  assertEquals(goldenResponse, responseObserver.firstValue().get());
}
 
Example #2
Source File: GrpcReflectionTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetrievingFilesContainingNestedSymbol() {
    ServerReflectionRequest request = ServerReflectionRequest.newBuilder()
            .setHost("localhost")
            .setFileContainingSymbol("grpc.reflection.testing.NestedTypeOuter.Middle.Inner")
            .build();
    ServerReflectionResponse expected = ServerReflectionResponse.newBuilder()
            .setValidHost("localhost")
            .setOriginalRequest(request)
            .setFileDescriptorResponse(
                    FileDescriptorResponse.newBuilder()
                            .addFileDescriptorProto(
                                    ReflectionTestDepthThreeProto.getDescriptor().toProto().toByteString())
                            .build())
            .build();
    ServerReflectionResponse resp = invoke(request);
    assertThat(resp).isEqualTo(expected);
}
 
Example #3
Source File: GrpcReflectionTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetrievingFilesContainingExtension() {
    ServerReflectionRequest request = ServerReflectionRequest.newBuilder()
            .setHost("localhost")
            .setFileContainingExtension(
                    ExtensionRequest.newBuilder()
                            .setContainingType("grpc.reflection.testing.ThirdLevelType")
                            .setExtensionNumber(100)
                            .build())
            .build();

    List<ByteString> expected = Arrays.asList(
            ReflectionTestProto.getDescriptor().toProto().toByteString(),
            ReflectionTestDepthTwoProto.getDescriptor().toProto().toByteString(),
            ReflectionTestDepthThreeProto.getDescriptor().toProto().toByteString());

    ServerReflectionResponse response = invoke(request);
    assertThat(response.getFileDescriptorResponse().getFileDescriptorProtoList())
            .containsExactlyInAnyOrderElementsOf(expected);
}
 
Example #4
Source File: GrpcReflectionTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetrievingFilesContainingNestedExtension() {
    ServerReflectionRequest request = ServerReflectionRequest.newBuilder()
            .setHost("localhost")
            .setFileContainingExtension(
                    ExtensionRequest.newBuilder()
                            .setContainingType("grpc.reflection.testing.ThirdLevelType")
                            .setExtensionNumber(101)
                            .build())
            .build();

    ServerReflectionResponse expected = ServerReflectionResponse.newBuilder()
            .setValidHost("localhost")
            .setOriginalRequest(request)
            .setFileDescriptorResponse(
                    FileDescriptorResponse.newBuilder()
                            .addFileDescriptorProto(
                                    ReflectionTestDepthTwoProto.getDescriptor().toProto().toByteString())
                            .addFileDescriptorProto(
                                    ReflectionTestDepthThreeProto.getDescriptor().toProto().toByteString())
                            .build())
            .build();

    ServerReflectionResponse response = invoke(request);
    assertThat(response).isEqualTo(expected);
}
 
Example #5
Source File: ProtoReflectionServiceTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void flowControlOnCompleteWithPendingRequest() throws Exception {
  FlowControlClientResponseObserver clientResponseObserver =
      new FlowControlClientResponseObserver();
  ClientCallStreamObserver<ServerReflectionRequest> requestObserver =
      (ClientCallStreamObserver<ServerReflectionRequest>)
          stub.serverReflectionInfo(clientResponseObserver);

  requestObserver.onNext(flowControlRequest);
  requestObserver.onCompleted();
  assertEquals(0, clientResponseObserver.getResponses().size());
  assertFalse(clientResponseObserver.onCompleteCalled());

  requestObserver.request(1);
  assertTrue(clientResponseObserver.onCompleteCalled());
  assertEquals(1, clientResponseObserver.getResponses().size());
  assertEquals(flowControlGoldenResponse, clientResponseObserver.getResponses().get(0));
}
 
Example #6
Source File: ProtoReflectionServiceTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void flowControl() throws Exception {
  FlowControlClientResponseObserver clientResponseObserver =
      new FlowControlClientResponseObserver();
  ClientCallStreamObserver<ServerReflectionRequest> requestObserver =
      (ClientCallStreamObserver<ServerReflectionRequest>)
          stub.serverReflectionInfo(clientResponseObserver);

  // ClientCalls.startCall() calls request(1) initially, so we should get an immediate response.
  requestObserver.onNext(flowControlRequest);
  assertEquals(1, clientResponseObserver.getResponses().size());
  assertEquals(flowControlGoldenResponse, clientResponseObserver.getResponses().get(0));

  // Verify we don't receive an additional response until we request it.
  requestObserver.onNext(flowControlRequest);
  assertEquals(1, clientResponseObserver.getResponses().size());

  requestObserver.request(1);
  assertEquals(2, clientResponseObserver.getResponses().size());
  assertEquals(flowControlGoldenResponse, clientResponseObserver.getResponses().get(1));

  requestObserver.onCompleted();
  assertTrue(clientResponseObserver.onCompleteCalled());
}
 
Example #7
Source File: ReflectionService.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public Multi<ServerReflectionResponse> serverReflectionInfo(Multi<ServerReflectionRequest> request) {
    return request
            .onItem().apply(new Function<ServerReflectionRequest, ServerReflectionResponse>() {
                @Override
                public ServerReflectionResponse apply(ServerReflectionRequest req) {
                    switch (req.getMessageRequestCase()) {
                        case LIST_SERVICES:
                            return ReflectionService.this.getServiceList(req);
                        case FILE_BY_FILENAME:
                            return ReflectionService.this.getFileByName(req);
                        case FILE_CONTAINING_SYMBOL:
                            return ReflectionService.this.getFileContainingSymbol(req);
                        case FILE_CONTAINING_EXTENSION:
                            return ReflectionService.this.getFileByExtension(req);
                        case ALL_EXTENSION_NUMBERS_OF_TYPE:
                            return ReflectionService.this.getAllExtensions(req);
                        default:
                            return ReflectionService.this.getErrorResponse(req, Status.Code.UNIMPLEMENTED,
                                    "not implemented " + req.getMessageRequestCase());

                    }
                }
            });
}
 
Example #8
Source File: ProtoReflectionServiceTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void allExtensionNumbersOfType() throws Exception {
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder()
          .setHost(TEST_HOST)
          .setAllExtensionNumbersOfType("grpc.reflection.testing.ThirdLevelType")
          .build();

  Set<Integer> goldenResponse = new HashSet<Integer>(Arrays.asList(100, 101));

  StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver =
      stub.serverReflectionInfo(responseObserver);
  requestObserver.onNext(request);
  requestObserver.onCompleted();
  Set<Integer> extensionNumberResponseSet =
      new HashSet<Integer>(
          responseObserver
              .firstValue()
              .get()
              .getAllExtensionNumbersResponse()
              .getExtensionNumberList());
  assertEquals(goldenResponse, extensionNumberResponseSet);
}
 
Example #9
Source File: GrpcReflectionTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetrievingFilesContainingSymbol() {
    ServerReflectionRequest request = ServerReflectionRequest.newBuilder()
            .setHost("localhost")
            .setFileContainingSymbol("grpc.reflection.testing.ReflectableService.Method")
            .build();

    List<ByteString> responses = Arrays.asList(
            ReflectionTestProto.getDescriptor().toProto().toByteString(),
            ReflectionTestDepthTwoProto.getDescriptor().toProto().toByteString(),
            ReflectionTestDepthThreeProto.getDescriptor().toProto().toByteString());

    ServerReflectionResponse response = invoke(request);
    List<ByteString> list = response.getFileDescriptorResponse().getFileDescriptorProtoList();
    assertThat(list).containsExactlyInAnyOrderElementsOf(responses);
}
 
Example #10
Source File: ProtoReflectionServiceTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void fileContainingNestedSymbol() throws Exception {
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder()
          .setHost(TEST_HOST)
          .setFileContainingSymbol("grpc.reflection.testing.NestedTypeOuter.Middle.Inner")
          .build();

  ServerReflectionResponse goldenResponse =
      ServerReflectionResponse.newBuilder()
          .setValidHost(TEST_HOST)
          .setOriginalRequest(request)
          .setFileDescriptorResponse(
              FileDescriptorResponse.newBuilder()
                  .addFileDescriptorProto(
                      ReflectionTestDepthThreeProto.getDescriptor().toProto().toByteString())
                  .build())
          .build();

  StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver =
      stub.serverReflectionInfo(responseObserver);
  requestObserver.onNext(request);
  requestObserver.onCompleted();
  assertEquals(goldenResponse, responseObserver.firstValue().get());
}
 
Example #11
Source File: GrpcReflectionTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetrievingFilesByFileName() {
    ServerReflectionRequest request = ServerReflectionRequest.newBuilder()
            .setHost("localhost")
            .setFileByFilename("reflection/reflection_test_depth_three.proto")
            .build();

    ServerReflectionResponse expected = ServerReflectionResponse.newBuilder()
            .setValidHost("localhost")
            .setOriginalRequest(request)
            .setFileDescriptorResponse(
                    FileDescriptorResponse.newBuilder()
                            .addFileDescriptorProto(
                                    ReflectionTestDepthThreeProto.getDescriptor().toProto().toByteString())
                            .build())
            .build();

    ServerReflectionResponse response = invoke(request);
    assertThat(response).isEqualTo(expected);
}
 
Example #12
Source File: ReflectionService.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private ServerReflectionResponse getAllExtensions(ServerReflectionRequest request) {
    String type = request.getAllExtensionNumbersOfType();
    Set<Integer> extensions = index.getExtensionNumbersOfType(type);
    if (extensions != null) {
        ExtensionNumberResponse.Builder builder = ExtensionNumberResponse.newBuilder()
                .setBaseTypeName(type)
                .addAllExtensionNumber(extensions);
        return ServerReflectionResponse.newBuilder()
                .setValidHost(request.getHost())
                .setOriginalRequest(request)
                .setAllExtensionNumbersResponse(builder)
                .build();
    } else {
        return getErrorResponse(request, Status.Code.NOT_FOUND, "Type not found.");
    }
}
 
Example #13
Source File: ProtoReflectionServiceTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void allExtensionNumbersOfType() throws Exception {
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder()
          .setHost(TEST_HOST)
          .setAllExtensionNumbersOfType("grpc.reflection.testing.ThirdLevelType")
          .build();

  Set<Integer> goldenResponse = new HashSet<>(Arrays.asList(100, 101));

  StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver =
      stub.serverReflectionInfo(responseObserver);
  requestObserver.onNext(request);
  requestObserver.onCompleted();
  Set<Integer> extensionNumberResponseSet =
      new HashSet<>(
          responseObserver
              .firstValue()
              .get()
              .getAllExtensionNumbersResponse()
              .getExtensionNumberList());
  assertEquals(goldenResponse, extensionNumberResponseSet);
}
 
Example #14
Source File: ReflectionService.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private ServerReflectionResponse getServerReflectionResponse(
        ServerReflectionRequest request, FileDescriptor fd) {
    FileDescriptorResponse.Builder fdRBuilder = FileDescriptorResponse.newBuilder();

    // Traverse the descriptors to get the full list of dependencies and add them to the builder
    Set<String> seenFiles = new HashSet<>();
    Queue<FileDescriptor> frontier = new ArrayDeque<>();
    seenFiles.add(fd.getName());
    frontier.add(fd);
    while (!frontier.isEmpty()) {
        FileDescriptor nextFd = frontier.remove();
        fdRBuilder.addFileDescriptorProto(nextFd.toProto().toByteString());
        for (FileDescriptor dependencyFd : nextFd.getDependencies()) {
            if (!seenFiles.contains(dependencyFd.getName())) {
                seenFiles.add(dependencyFd.getName());
                frontier.add(dependencyFd);
            }
        }
    }
    return ServerReflectionResponse.newBuilder()
            .setValidHost(request.getHost())
            .setOriginalRequest(request)
            .setFileDescriptorResponse(fdRBuilder)
            .build();
}
 
Example #15
Source File: ProtoReflectionService.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
private ServerReflectionResponse createServerReflectionResponse(
    ServerReflectionRequest request, FileDescriptor fd) {
  FileDescriptorResponse.Builder fdRBuilder = FileDescriptorResponse.newBuilder();

  Set<String> seenFiles = new HashSet<String>();
  Queue<FileDescriptor> frontier = new ArrayDeque<FileDescriptor>();
  seenFiles.add(fd.getName());
  frontier.add(fd);
  while (!frontier.isEmpty()) {
    FileDescriptor nextFd = frontier.remove();
    fdRBuilder.addFileDescriptorProto(nextFd.toProto().toByteString());
    for (FileDescriptor dependencyFd : nextFd.getDependencies()) {
      if (!seenFiles.contains(dependencyFd.getName())) {
        seenFiles.add(dependencyFd.getName());
        frontier.add(dependencyFd);
      }
    }
  }
  return ServerReflectionResponse.newBuilder()
      .setValidHost(request.getHost())
      .setOriginalRequest(request)
      .setFileDescriptorResponse(fdRBuilder)
      .build();
}
 
Example #16
Source File: ProtoReflectionService.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
private void getAllExtensions(ServerReflectionRequest request) {
  String type = request.getAllExtensionNumbersOfType();
  Set<Integer> extensions = serverReflectionIndex.getExtensionNumbersOfType(type);
  if (extensions != null) {
    ExtensionNumberResponse.Builder builder =
        ExtensionNumberResponse.newBuilder()
            .setBaseTypeName(type)
            .addAllExtensionNumber(extensions);
    serverCallStreamObserver.onNext(
        ServerReflectionResponse.newBuilder()
            .setValidHost(request.getHost())
            .setOriginalRequest(request)
            .setAllExtensionNumbersResponse(builder)
            .build());
  } else {
    sendErrorResponse(request, Status.Code.NOT_FOUND, "Type not found.");
  }
}
 
Example #17
Source File: ProtoReflectionService.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
private ServerReflectionResponse createServerReflectionResponse(
    ServerReflectionRequest request, FileDescriptor fd) {
  FileDescriptorResponse.Builder fdRBuilder = FileDescriptorResponse.newBuilder();

  Set<String> seenFiles = new HashSet<>();
  Queue<FileDescriptor> frontier = new ArrayDeque<>();
  seenFiles.add(fd.getName());
  frontier.add(fd);
  while (!frontier.isEmpty()) {
    FileDescriptor nextFd = frontier.remove();
    fdRBuilder.addFileDescriptorProto(nextFd.toProto().toByteString());
    for (FileDescriptor dependencyFd : nextFd.getDependencies()) {
      if (!seenFiles.contains(dependencyFd.getName())) {
        seenFiles.add(dependencyFd.getName());
        frontier.add(dependencyFd);
      }
    }
  }
  return ServerReflectionResponse.newBuilder()
      .setValidHost(request.getHost())
      .setOriginalRequest(request)
      .setFileDescriptorResponse(fdRBuilder)
      .build();
}
 
Example #18
Source File: ProtoReflectionService.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
private void getAllExtensions(ServerReflectionRequest request) {
  String type = request.getAllExtensionNumbersOfType();
  Set<Integer> extensions = serverReflectionIndex.getExtensionNumbersOfType(type);
  if (extensions != null) {
    ExtensionNumberResponse.Builder builder =
        ExtensionNumberResponse.newBuilder()
            .setBaseTypeName(type)
            .addAllExtensionNumber(extensions);
    serverCallStreamObserver.onNext(
        ServerReflectionResponse.newBuilder()
            .setValidHost(request.getHost())
            .setOriginalRequest(request)
            .setAllExtensionNumbersResponse(builder)
            .build());
  } else {
    sendErrorResponse(request, Status.Code.NOT_FOUND, "Type not found.");
  }
}
 
Example #19
Source File: ProtoReflectionService.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
private void getFileByExtension(ServerReflectionRequest request) {
  ExtensionRequest extensionRequest = request.getFileContainingExtension();
  String type = extensionRequest.getContainingType();
  int extension = extensionRequest.getExtensionNumber();
  FileDescriptor fd =
      serverReflectionIndex.getFileDescriptorByExtensionAndNumber(type, extension);
  if (fd != null) {
    serverCallStreamObserver.onNext(createServerReflectionResponse(request, fd));
  } else {
    sendErrorResponse(request, Status.Code.NOT_FOUND, "Extension not found.");
  }
}
 
Example #20
Source File: ProtoReflectionService.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public StreamObserver<ServerReflectionRequest> serverReflectionInfo(
    final StreamObserver<ServerReflectionResponse> responseObserver) {
  final ServerCallStreamObserver<ServerReflectionResponse> serverCallStreamObserver =
      (ServerCallStreamObserver<ServerReflectionResponse>) responseObserver;
  ProtoReflectionStreamObserver requestObserver =
      new ProtoReflectionStreamObserver(getRefreshedIndex(), serverCallStreamObserver);
  serverCallStreamObserver.setOnReadyHandler(requestObserver);
  serverCallStreamObserver.disableAutoRequest();
  serverCallStreamObserver.request(1);
  return requestObserver;
}
 
Example #21
Source File: DemoAppTest.java    From grpc-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Test
public void testReflection() throws InterruptedException {
    List<String> discoveredServiceNames = new ArrayList<>();
    ServerReflectionRequest request = ServerReflectionRequest.newBuilder().setListServices("services").setHost("localhost").build();
    CountDownLatch latch = new CountDownLatch(1);
    ServerReflectionGrpc.newStub(channel).serverReflectionInfo(new StreamObserver<ServerReflectionResponse>() {
        @Override
        public void onNext(ServerReflectionResponse value) {
            List<ServiceResponse> serviceList = value.getListServicesResponse().getServiceList();
            for (ServiceResponse serviceResponse : serviceList) {
                discoveredServiceNames.add(serviceResponse.getName());
            }
        }

        @Override
        public void onError(Throwable t) {

        }

        @Override
        public void onCompleted() {
            latch.countDown();
        }
    }).onNext(request);

    latch.await(3, TimeUnit.SECONDS);
    assertFalse(discoveredServiceNames.isEmpty());
}
 
Example #22
Source File: GrpcServiceServerTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Test
void reflectionService() throws Exception {
    final ServerReflectionStub stub = ServerReflectionGrpc.newStub(channel);

    final AtomicReference<ServerReflectionResponse> response = new AtomicReference<>();

    final StreamObserver<ServerReflectionRequest> request = stub.serverReflectionInfo(
            new StreamObserver<ServerReflectionResponse>() {
                @Override
                public void onNext(ServerReflectionResponse value) {
                    response.set(value);
                }

                @Override
                public void onError(Throwable t) {}

                @Override
                public void onCompleted() {}
            });
    request.onNext(ServerReflectionRequest.newBuilder()
                                          .setListServices("")
                                          .build());
    request.onCompleted();

    await().untilAsserted(
            () -> {
                assertThat(response).doesNotHaveValue(null);
                // Instead of making this test depend on every other one, just check that there is at
                // least two services returned corresponding to UnitTestService and
                // ProtoReflectionService.
                assertThat(response.get().getListServicesResponse().getServiceList())
                        .hasSizeGreaterThanOrEqualTo(2);
            });
}
 
Example #23
Source File: ReflectionService.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private ServerReflectionResponse getErrorResponse(
        ServerReflectionRequest request, Status.Code code, String message) {
    return ServerReflectionResponse.newBuilder()
            .setValidHost(request.getHost())
            .setOriginalRequest(request)
            .setErrorResponse(
                    ErrorResponse.newBuilder()
                            .setErrorCode(code.value())
                            .setErrorMessage(message))
            .build();

}
 
Example #24
Source File: ProtoReflectionService.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
private void getFileContainingSymbol(ServerReflectionRequest request) {
  String symbol = request.getFileContainingSymbol();
  FileDescriptor fd = serverReflectionIndex.getFileDescriptorBySymbol(symbol);
  if (fd != null) {
    serverCallStreamObserver.onNext(createServerReflectionResponse(request, fd));
  } else {
    sendErrorResponse(request, Status.Code.NOT_FOUND, "Symbol not found.");
  }
}
 
Example #25
Source File: ProtoReflectionService.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
private void listServices(ServerReflectionRequest request) {
  ListServiceResponse.Builder builder = ListServiceResponse.newBuilder();
  for (String serviceName : serverReflectionIndex.getServiceNames()) {
    builder.addService(ServiceResponse.newBuilder().setName(serviceName));
  }
  serverCallStreamObserver.onNext(
      ServerReflectionResponse.newBuilder()
          .setValidHost(request.getHost())
          .setOriginalRequest(request)
          .setListServicesResponse(builder)
          .build());
}
 
Example #26
Source File: GrpcReflectionTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testRetrievingFilesByFileNameWithUnknownFileName() {
    ServerReflectionRequest request = ServerReflectionRequest.newBuilder()
            .setHost("localhost")
            .setFileByFilename("reflection/unknown.proto")
            .build();

    ServerReflectionResponse response = invoke(request);
    assertThat(response.getErrorResponse().getErrorCode()).isEqualTo(Status.Code.NOT_FOUND.value());
}
 
Example #27
Source File: GrpcReflectionTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testRetrievingListOfServices() {
    ServerReflectionRequest request = ServerReflectionRequest.newBuilder().setHost("localhost")
            .setListServices("").build();

    ServerReflectionResponse response = invoke(request);
    List<ServiceResponse> list = response.getListServicesResponse().getServiceList();
    assertThat(list).hasSize(2)
            .anySatisfy(r -> assertThat(r.getName()).isEqualTo("grpc.reflection.testing.ReflectableService"))
            .anySatisfy(r -> assertThat(r.getName()).isEqualTo("grpc.health.v1.Health"));
}
 
Example #28
Source File: ProtoReflectionServiceTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void sharedServiceBetweenServers()
    throws IOException, ExecutionException, InterruptedException {
  Server anotherServer = InProcessServerBuilder.forName("proto-reflection-test-2")
      .directExecutor()
      .addService(reflectionService)
      .addService(new AnotherReflectableServiceGrpc.AnotherReflectableServiceImplBase() {})
      .build()
      .start();
  grpcCleanupRule.register(anotherServer);
  ManagedChannel anotherChannel = grpcCleanupRule.register(
      InProcessChannelBuilder.forName("proto-reflection-test-2").directExecutor().build());
  ServerReflectionGrpc.ServerReflectionStub stub2 = ServerReflectionGrpc.newStub(anotherChannel);

  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder().setHost(TEST_HOST).setListServices("services").build();
  StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver =
      stub2.serverReflectionInfo(responseObserver);
  requestObserver.onNext(request);
  requestObserver.onCompleted();
  List<ServiceResponse> response =
      responseObserver.firstValue().get().getListServicesResponse().getServiceList();
  assertEquals(new HashSet<>(
      Arrays.asList(
          ServiceResponse.newBuilder()
              .setName("grpc.reflection.v1alpha.ServerReflection")
              .build(),
          ServiceResponse.newBuilder()
              .setName("grpc.reflection.testing.AnotherReflectableService")
              .build())),
      new HashSet<>(response));
}
 
Example #29
Source File: ServerReflectionClient.java    From grpc-swagger with MIT License 5 votes vote down vote up
ListenableFuture<FileDescriptorSet> start(
        StreamObserver<ServerReflectionRequest> requestStream) {
    this.requestStream = requestStream;
    requestStream.onNext(requestForSymbol(serviceName));
    ++outstandingRequests;
    return resultFuture;
}
 
Example #30
Source File: ServerReflectionClient.java    From milkman with MIT License 5 votes vote down vote up
ListenableFuture<FileDescriptorSet> start(
    StreamObserver<ServerReflectionRequest> requestStream) {
  this.requestStream = requestStream;
  requestStream.onNext(requestForSymbol(serviceName));
  ++outstandingRequests;
  return resultFuture;
}