Java Code Examples for io.grpc.reflection.v1alpha.ServerReflectionRequest

The following examples show how to use io.grpc.reflection.v1alpha.ServerReflectionRequest. These examples are extracted from open source projects. 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 Project: grpc-nebula-java   Source File: ProtoReflectionService.java    License: 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 2
Source Project: grpc-nebula-java   Source File: ProtoReflectionService.java    License: 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 3
@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 4
@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 5
@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 6
Source Project: grpc-java   Source File: ProtoReflectionServiceTest.java    License: 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 7
Source Project: quarkus   Source File: GrpcReflectionTest.java    License: 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 8
Source Project: quarkus   Source File: GrpcReflectionTest.java    License: 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 9
Source Project: quarkus   Source File: GrpcReflectionTest.java    License: 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 10
Source Project: quarkus   Source File: GrpcReflectionTest.java    License: 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 11
Source Project: quarkus   Source File: GrpcReflectionTest.java    License: 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 12
Source Project: quarkus   Source File: ReflectionService.java    License: 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 13
Source Project: quarkus   Source File: ReflectionService.java    License: 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 14
Source Project: quarkus   Source File: ReflectionService.java    License: 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 Project: grpc-java   Source File: ProtoReflectionService.java    License: 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 16
Source Project: grpc-java   Source File: ProtoReflectionService.java    License: 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 17
Source Project: grpc-java   Source File: ProtoReflectionServiceTest.java    License: 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 18
Source Project: grpc-java   Source File: ProtoReflectionServiceTest.java    License: 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 19
Source Project: grpc-java   Source File: ProtoReflectionServiceTest.java    License: 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 20
Source Project: grpc-nebula-java   Source File: ProtoReflectionService.java    License: Apache License 2.0 5 votes vote down vote up
private void getFileByName(ServerReflectionRequest request) {
  String name = request.getFileByFilename();
  FileDescriptor fd = serverReflectionIndex.getFileDescriptorByName(name);
  if (fd != null) {
    serverCallStreamObserver.onNext(createServerReflectionResponse(request, fd));
  } else {
    sendErrorResponse(request, Status.Code.NOT_FOUND, "File not found.");
  }
}
 
Example 21
Source Project: grpc-nebula-java   Source File: ProtoReflectionService.java    License: 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 22
Source Project: grpc-nebula-java   Source File: ProtoReflectionService.java    License: 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 23
Source Project: grpc-nebula-java   Source File: ProtoReflectionService.java    License: 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 24
Source Project: grpc-nebula-java   Source File: ProtoReflectionService.java    License: Apache License 2.0 5 votes vote down vote up
private void sendErrorResponse(
    ServerReflectionRequest request, Status.Code code, String message) {
  ServerReflectionResponse response =
      ServerReflectionResponse.newBuilder()
          .setValidHost(request.getHost())
          .setOriginalRequest(request)
          .setErrorResponse(
              ErrorResponse.newBuilder()
                  .setErrorCode(code.value())
                  .setErrorMessage(message))
          .build();
  serverCallStreamObserver.onNext(response);
}
 
Example 25
@Test
public void fileByFilename() throws Exception {
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder()
          .setHost(TEST_HOST)
          .setFileByFilename("io/grpc/reflection/testing/reflection_test_depth_three.proto")
          .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 26
@Test
public void fileContainingSymbol() throws Exception {
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder()
          .setHost(TEST_HOST)
          .setFileContainingSymbol("grpc.reflection.testing.ReflectableService.Method")
          .build();

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

  StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver =
      stub.serverReflectionInfo(responseObserver);
  requestObserver.onNext(request);
  requestObserver.onCompleted();

  List<ByteString> response =
      responseObserver
          .firstValue()
          .get()
          .getFileDescriptorResponse()
          .getFileDescriptorProtoList();
  assertEquals(goldenResponse.size(), response.size());
  assertEquals(new HashSet<ByteString>(goldenResponse), new HashSet<ByteString>(response));
}
 
Example 27
@Test
public void fileContainingExtension() throws Exception {
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder()
          .setHost(TEST_HOST)
          .setFileContainingExtension(
              ExtensionRequest.newBuilder()
                  .setContainingType("grpc.reflection.testing.ThirdLevelType")
                  .setExtensionNumber(100)
                  .build())
          .build();

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

  StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver =
      stub.serverReflectionInfo(responseObserver);
  requestObserver.onNext(request);
  requestObserver.onCompleted();

  List<ByteString> response =
      responseObserver
          .firstValue()
          .get()
          .getFileDescriptorResponse()
          .getFileDescriptorProtoList();
  assertEquals(goldenResponse.size(), response.size());
  assertEquals(new HashSet<ByteString>(goldenResponse), new HashSet<ByteString>(response));
}
 
Example 28
@Test
public void fileContainingNestedExtension() throws Exception {
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder()
          .setHost(TEST_HOST)
          .setFileContainingExtension(
              ExtensionRequest.newBuilder()
                  .setContainingType("grpc.reflection.testing.ThirdLevelType")
                  .setExtensionNumber(101)
                  .build())
          .build();

  ServerReflectionResponse goldenResponse =
      ServerReflectionResponse.newBuilder()
          .setValidHost(TEST_HOST)
          .setOriginalRequest(request)
          .setFileDescriptorResponse(
              FileDescriptorResponse.newBuilder()
                  .addFileDescriptorProto(
                      ReflectionTestDepthTwoProto.getDescriptor().toProto().toByteString())
                  .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 29
Source Project: grpc-java   Source File: ProtoReflectionServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
private void assertServiceResponseEquals(Set<ServiceResponse> goldenResponse) throws Exception {
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder().setHost(TEST_HOST).setListServices("services").build();
  StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver =
      stub.serverReflectionInfo(responseObserver);
  requestObserver.onNext(request);
  requestObserver.onCompleted();
  List<ServiceResponse> response =
      responseObserver.firstValue().get().getListServicesResponse().getServiceList();
  assertEquals(goldenResponse.size(), response.size());
  assertEquals(goldenResponse, new HashSet<>(response));
}
 
Example 30
private void assertServiceResponseEquals(Set<ServiceResponse> goldenResponse) throws Exception {
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder().setHost(TEST_HOST).setListServices("services").build();
  StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver =
      stub.serverReflectionInfo(responseObserver);
  requestObserver.onNext(request);
  requestObserver.onCompleted();
  List<ServiceResponse> response =
      responseObserver.firstValue().get().getListServicesResponse().getServiceList();
  assertEquals(goldenResponse.size(), response.size());
  assertEquals(goldenResponse, new HashSet<ServiceResponse>(response));
}