io.grpc.reflection.v1alpha.FileDescriptorResponse Java Examples

The following examples show how to use io.grpc.reflection.v1alpha.FileDescriptorResponse. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
Source File: ProtoReflectionServiceTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@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 #10
Source File: ProtoReflectionServiceTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@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 #11
Source File: ProtoReflectionServiceTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@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 #12
Source File: ProtoReflectionServiceTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@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 #13
Source File: ProtoReflectionServiceTest.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Test
public void fileContainingExtensionForMutableServices() throws Exception {
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder()
          .setHost(TEST_HOST)
          .setFileContainingExtension(
              ExtensionRequest.newBuilder()
                  .setContainingType("grpc.reflection.testing.TypeWithExtensions")
                  .setExtensionNumber(200)
                  .build())
          .build();
  ServerReflectionResponse goldenResponse =
      ServerReflectionResponse.newBuilder()
          .setValidHost(TEST_HOST)
          .setOriginalRequest(request)
          .setFileDescriptorResponse(
              FileDescriptorResponse.newBuilder()
                  .addFileDescriptorProto(
                      DynamicReflectionTestDepthTwoProto.getDescriptor().toProto().toByteString())
                  .build())
          .build();

  StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver =
      stub.serverReflectionInfo(responseObserver);
  handlerRegistry.addService(dynamicService);
  requestObserver.onNext(request);
  requestObserver.onCompleted();
  StreamRecorder<ServerReflectionResponse> responseObserver2 = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver2 =
      stub.serverReflectionInfo(responseObserver2);
  handlerRegistry.removeService(dynamicService);
  requestObserver2.onNext(request);
  requestObserver2.onCompleted();
  StreamRecorder<ServerReflectionResponse> responseObserver3 = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver3 =
      stub.serverReflectionInfo(responseObserver3);
  requestObserver3.onNext(request);
  requestObserver3.onCompleted();

  assertEquals(
      ServerReflectionResponse.MessageResponseCase.ERROR_RESPONSE,
      responseObserver.firstValue().get().getMessageResponseCase());
  assertEquals(goldenResponse, responseObserver2.firstValue().get());
  assertEquals(
      ServerReflectionResponse.MessageResponseCase.ERROR_RESPONSE,
      responseObserver3.firstValue().get().getMessageResponseCase());
}
 
Example #14
Source File: ProtoReflectionServiceTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Test
public void fileByFilenameConsistentForMutableServices() throws Exception {
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder()
          .setHost(TEST_HOST)
          .setFileByFilename("io/grpc/reflection/testing/dynamic_reflection_test_depth_two.proto")
          .build();
  ServerReflectionResponse goldenResponse =
      ServerReflectionResponse.newBuilder()
          .setValidHost(TEST_HOST)
          .setOriginalRequest(request)
          .setFileDescriptorResponse(
              FileDescriptorResponse.newBuilder()
                  .addFileDescriptorProto(
                      DynamicReflectionTestDepthTwoProto.getDescriptor().toProto().toByteString())
                  .build())
          .build();

  StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver =
      stub.serverReflectionInfo(responseObserver);
  handlerRegistry.addService(dynamicService);
  requestObserver.onNext(request);
  requestObserver.onCompleted();
  StreamRecorder<ServerReflectionResponse> responseObserver2 = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver2 =
      stub.serverReflectionInfo(responseObserver2);
  handlerRegistry.removeService(dynamicService);
  requestObserver2.onNext(request);
  requestObserver2.onCompleted();
  StreamRecorder<ServerReflectionResponse> responseObserver3 = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver3 =
      stub.serverReflectionInfo(responseObserver3);
  requestObserver3.onNext(request);
  requestObserver3.onCompleted();

  assertEquals(
      ServerReflectionResponse.MessageResponseCase.ERROR_RESPONSE,
      responseObserver.firstValue().get().getMessageResponseCase());
  assertEquals(goldenResponse, responseObserver2.firstValue().get());
  assertEquals(
      ServerReflectionResponse.MessageResponseCase.ERROR_RESPONSE,
      responseObserver3.firstValue().get().getMessageResponseCase());
}
 
Example #15
Source File: ProtoReflectionServiceTest.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Test
public void fileContainingSymbolForMutableServices() throws Exception {
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder()
          .setHost(TEST_HOST)
          .setFileContainingSymbol("grpc.reflection.testing.DynamicRequest")
          .build();
  ServerReflectionResponse goldenResponse =
      ServerReflectionResponse.newBuilder()
          .setValidHost(TEST_HOST)
          .setOriginalRequest(request)
          .setFileDescriptorResponse(
              FileDescriptorResponse.newBuilder()
                  .addFileDescriptorProto(
                      DynamicReflectionTestDepthTwoProto.getDescriptor().toProto().toByteString())
                  .build())
          .build();

  StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver =
      stub.serverReflectionInfo(responseObserver);
  handlerRegistry.addService(dynamicService);
  requestObserver.onNext(request);
  requestObserver.onCompleted();
  StreamRecorder<ServerReflectionResponse> responseObserver2 = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver2 =
      stub.serverReflectionInfo(responseObserver2);
  handlerRegistry.removeService(dynamicService);
  requestObserver2.onNext(request);
  requestObserver2.onCompleted();
  StreamRecorder<ServerReflectionResponse> responseObserver3 = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver3 =
      stub.serverReflectionInfo(responseObserver3);
  requestObserver3.onNext(request);
  requestObserver3.onCompleted();

  assertEquals(
      ServerReflectionResponse.MessageResponseCase.ERROR_RESPONSE,
      responseObserver.firstValue().get().getMessageResponseCase());
  assertEquals(goldenResponse, responseObserver2.firstValue().get());
  assertEquals(
      ServerReflectionResponse.MessageResponseCase.ERROR_RESPONSE,
      responseObserver3.firstValue().get().getMessageResponseCase());
}
 
Example #16
Source File: ProtoReflectionServiceTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Test
public void fileContainingSymbolForMutableServices() throws Exception {
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder()
          .setHost(TEST_HOST)
          .setFileContainingSymbol("grpc.reflection.testing.DynamicRequest")
          .build();
  ServerReflectionResponse goldenResponse =
      ServerReflectionResponse.newBuilder()
          .setValidHost(TEST_HOST)
          .setOriginalRequest(request)
          .setFileDescriptorResponse(
              FileDescriptorResponse.newBuilder()
                  .addFileDescriptorProto(
                      DynamicReflectionTestDepthTwoProto.getDescriptor().toProto().toByteString())
                  .build())
          .build();

  StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver =
      stub.serverReflectionInfo(responseObserver);
  handlerRegistry.addService(dynamicService);
  requestObserver.onNext(request);
  requestObserver.onCompleted();
  StreamRecorder<ServerReflectionResponse> responseObserver2 = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver2 =
      stub.serverReflectionInfo(responseObserver2);
  handlerRegistry.removeService(dynamicService);
  requestObserver2.onNext(request);
  requestObserver2.onCompleted();
  StreamRecorder<ServerReflectionResponse> responseObserver3 = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver3 =
      stub.serverReflectionInfo(responseObserver3);
  requestObserver3.onNext(request);
  requestObserver3.onCompleted();

  assertEquals(
      ServerReflectionResponse.MessageResponseCase.ERROR_RESPONSE,
      responseObserver.firstValue().get().getMessageResponseCase());
  assertEquals(goldenResponse, responseObserver2.firstValue().get());
  assertEquals(
      ServerReflectionResponse.MessageResponseCase.ERROR_RESPONSE,
      responseObserver3.firstValue().get().getMessageResponseCase());
}
 
Example #17
Source File: ProtoReflectionServiceTest.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Test
public void fileByFilenameConsistentForMutableServices() throws Exception {
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder()
          .setHost(TEST_HOST)
          .setFileByFilename("io/grpc/reflection/testing/dynamic_reflection_test_depth_two.proto")
          .build();
  ServerReflectionResponse goldenResponse =
      ServerReflectionResponse.newBuilder()
          .setValidHost(TEST_HOST)
          .setOriginalRequest(request)
          .setFileDescriptorResponse(
              FileDescriptorResponse.newBuilder()
                  .addFileDescriptorProto(
                      DynamicReflectionTestDepthTwoProto.getDescriptor().toProto().toByteString())
                  .build())
          .build();

  StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver =
      stub.serverReflectionInfo(responseObserver);
  handlerRegistry.addService(dynamicService);
  requestObserver.onNext(request);
  requestObserver.onCompleted();
  StreamRecorder<ServerReflectionResponse> responseObserver2 = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver2 =
      stub.serverReflectionInfo(responseObserver2);
  handlerRegistry.removeService(dynamicService);
  requestObserver2.onNext(request);
  requestObserver2.onCompleted();
  StreamRecorder<ServerReflectionResponse> responseObserver3 = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver3 =
      stub.serverReflectionInfo(responseObserver3);
  requestObserver3.onNext(request);
  requestObserver3.onCompleted();

  assertEquals(
      ServerReflectionResponse.MessageResponseCase.ERROR_RESPONSE,
      responseObserver.firstValue().get().getMessageResponseCase());
  assertEquals(goldenResponse, responseObserver2.firstValue().get());
  assertEquals(
      ServerReflectionResponse.MessageResponseCase.ERROR_RESPONSE,
      responseObserver3.firstValue().get().getMessageResponseCase());
}
 
Example #18
Source File: ProtoReflectionServiceTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Test
public void fileContainingExtensionForMutableServices() throws Exception {
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder()
          .setHost(TEST_HOST)
          .setFileContainingExtension(
              ExtensionRequest.newBuilder()
                  .setContainingType("grpc.reflection.testing.TypeWithExtensions")
                  .setExtensionNumber(200)
                  .build())
          .build();
  ServerReflectionResponse goldenResponse =
      ServerReflectionResponse.newBuilder()
          .setValidHost(TEST_HOST)
          .setOriginalRequest(request)
          .setFileDescriptorResponse(
              FileDescriptorResponse.newBuilder()
                  .addFileDescriptorProto(
                      DynamicReflectionTestDepthTwoProto.getDescriptor().toProto().toByteString())
                  .build())
          .build();

  StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver =
      stub.serverReflectionInfo(responseObserver);
  handlerRegistry.addService(dynamicService);
  requestObserver.onNext(request);
  requestObserver.onCompleted();
  StreamRecorder<ServerReflectionResponse> responseObserver2 = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver2 =
      stub.serverReflectionInfo(responseObserver2);
  handlerRegistry.removeService(dynamicService);
  requestObserver2.onNext(request);
  requestObserver2.onCompleted();
  StreamRecorder<ServerReflectionResponse> responseObserver3 = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver3 =
      stub.serverReflectionInfo(responseObserver3);
  requestObserver3.onNext(request);
  requestObserver3.onCompleted();

  assertEquals(
      ServerReflectionResponse.MessageResponseCase.ERROR_RESPONSE,
      responseObserver.firstValue().get().getMessageResponseCase());
  assertEquals(goldenResponse, responseObserver2.firstValue().get());
  assertEquals(
      ServerReflectionResponse.MessageResponseCase.ERROR_RESPONSE,
      responseObserver3.firstValue().get().getMessageResponseCase());
}