Java 类io.grpc.reflection.v1alpha.ServerReflectionRequest 实例源码

项目:grpc-java    文件:ProtoReflectionService.java   
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.");
  }
}
项目:grpc-java    文件:ProtoReflectionService.java   
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();
}
项目:grpc-java    文件:ProtoReflectionServiceTest.java   
@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());
}
项目:grpc-java    文件:ProtoReflectionServiceTest.java   
@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);
}
项目:grpc-java    文件:ProtoReflectionServiceTest.java   
@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());
}
项目:grpc-java    文件:ProtoReflectionServiceTest.java   
@Test
public void flowControlOnCompleteWithPendingRequest() throws Exception {
  FlowControlClientResponseObserver clientResponseObserver =
      new FlowControlClientResponseObserver();
  ClientCallStreamObserver<ServerReflectionRequest> requestObserver =
      (ClientCallStreamObserver<ServerReflectionRequest>)
          stub.serverReflectionInfo(clientResponseObserver);

  // ClientCalls.startCall() calls request(1) initially, so make additional request.
  requestObserver.onNext(flowControlRequest);
  requestObserver.onNext(flowControlRequest);
  requestObserver.onCompleted();
  assertEquals(1, clientResponseObserver.getResponses().size());
  assertFalse(clientResponseObserver.onCompleteCalled());

  requestObserver.request(1);
  assertTrue(clientResponseObserver.onCompleteCalled());
  assertEquals(2, clientResponseObserver.getResponses().size());
  assertEquals(flowControlGoldenResponse, clientResponseObserver.getResponses().get(1));
}
项目:polyglot    文件:ServerReflectionClient.java   
/** Asks the remote server to list its services and completes when the server responds. */
public ListenableFuture<ImmutableList<String>> listServices() {
  ListServicesHandler rpcHandler = new ListServicesHandler();
  StreamObserver<ServerReflectionRequest> requestStream = ServerReflectionGrpc.newStub(channel)
      .withDeadlineAfter(LIST_RPC_DEADLINE_MS, TimeUnit.MILLISECONDS)
      .serverReflectionInfo(rpcHandler);
  return rpcHandler.start(requestStream);
}
项目:polyglot    文件:ServerReflectionClient.java   
/**
 * Returns a {@link FileDescriptorSet} containing all the transitive dependencies of the supplied
 * service, as provided by the remote server.
 */
public ListenableFuture<FileDescriptorSet> lookupService(String serviceName) {
  LookupServiceHandler rpcHandler = new LookupServiceHandler(serviceName);
  StreamObserver<ServerReflectionRequest> requestStream = ServerReflectionGrpc.newStub(channel)
      .withDeadlineAfter(LOOKUP_RPC_DEADLINE_MS, TimeUnit.MILLISECONDS)
      .serverReflectionInfo(rpcHandler);
  return rpcHandler.start(requestStream);
}
项目:polyglot    文件:ServerReflectionClient.java   
ListenableFuture<FileDescriptorSet> start(
    StreamObserver<ServerReflectionRequest> requestStream) {
  this.requestStream = requestStream;
  requestStream.onNext(requestForSymbol(serviceName));
  ++outstandingRequests;
  return resultFuture;
}
项目:grpc-java    文件:ProtoReflectionService.java   
@Override
public StreamObserver<ServerReflectionRequest> serverReflectionInfo(
    final StreamObserver<ServerReflectionResponse> responseObserver) {
  final ServerCallStreamObserver<ServerReflectionResponse> serverCallStreamObserver =
      (ServerCallStreamObserver<ServerReflectionResponse>) responseObserver;
  ProtoReflectionStreamObserver requestObserver =
      new ProtoReflectionStreamObserver(updateIndexIfNecessary(), serverCallStreamObserver);
  serverCallStreamObserver.setOnReadyHandler(requestObserver);
  serverCallStreamObserver.disableAutoInboundFlowControl();
  serverCallStreamObserver.request(1);
  return requestObserver;
}
项目:grpc-java    文件:ProtoReflectionService.java   
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.");
  }
}
项目:grpc-java    文件:ProtoReflectionService.java   
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.");
  }
}
项目:grpc-java    文件:ProtoReflectionService.java   
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.");
  }
}
项目:grpc-java    文件:ProtoReflectionService.java   
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());
}
项目:grpc-java    文件:ProtoReflectionService.java   
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);
}
项目:grpc-java    文件:ProtoReflectionServiceTest.java   
@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());
}
项目:grpc-java    文件:ProtoReflectionServiceTest.java   
@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));
}
项目:grpc-java    文件:ProtoReflectionServiceTest.java   
@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));
}
项目:grpc-java    文件:ProtoReflectionServiceTest.java   
@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());
}
项目:grpc-java    文件:ProtoReflectionServiceTest.java   
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));
}
项目:polyglot    文件:ServerReflectionClient.java   
ListenableFuture<ImmutableList<String>> start(
    StreamObserver<ServerReflectionRequest> requestStream) {
  this.requestStream = requestStream;
  requestStream.onNext(LIST_SERVICES_REQUEST);
  return resultFuture;
}
项目:polyglot    文件:ServerReflectionClient.java   
private static ServerReflectionRequest requestForDescriptor(String name) {
  return ServerReflectionRequest.newBuilder()
      .setFileByFilename(name)
      .build();
}
项目:polyglot    文件:ServerReflectionClient.java   
private static ServerReflectionRequest requestForSymbol(String symbol) {
  return ServerReflectionRequest.newBuilder()
      .setFileContainingSymbol(symbol)
      .build();
}
项目:grpc-java    文件:ProtoReflectionService.java   
@Override
public void onNext(ServerReflectionRequest request) {
  checkState(this.request == null);
  this.request = checkNotNull(request);
  handleReflectionRequest();
}
项目:grpc-java    文件:ProtoReflectionServiceTest.java   
@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());
}
项目:grpc-java    文件:ProtoReflectionServiceTest.java   
@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());
}
项目:grpc-java    文件:ProtoReflectionServiceTest.java   
@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());
}
项目:grpc-java    文件:ProtoReflectionServiceTest.java   
@Test
public void allExtensionNumbersOfTypeForMutableServices() throws Exception {
  String type = "grpc.reflection.testing.TypeWithExtensions";
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder()
          .setHost(TEST_HOST)
          .setAllExtensionNumbersOfType(type)
          .build();
  ServerReflectionResponse goldenResponse =
      ServerReflectionResponse.newBuilder()
          .setValidHost(TEST_HOST)
          .setOriginalRequest(request)
          .setAllExtensionNumbersResponse(
              ExtensionNumberResponse.newBuilder()
                  .setBaseTypeName(type)
                  .addExtensionNumber(200)
                  .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());
}
项目:grpc-java    文件:ProtoReflectionServiceTest.java   
@Override
public void beforeStart(final ClientCallStreamObserver<ServerReflectionRequest> requestStream) {
  requestStream.disableAutoInboundFlowControl();
}