Search in sources :

Example 1 with ServerReflectionResponse

use of io.grpc.reflection.v1alpha.ServerReflectionResponse in project grpc-java by grpc.

the class ProtoReflectionServiceTest method fileByFilenameConsistentForMutableServices.

@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());
}
Also used : ServerReflectionRequest(io.grpc.reflection.v1alpha.ServerReflectionRequest) ServerReflectionResponse(io.grpc.reflection.v1alpha.ServerReflectionResponse) Test(org.junit.Test)

Example 2 with ServerReflectionResponse

use of io.grpc.reflection.v1alpha.ServerReflectionResponse in project grpc-java by grpc.

the class ProtoReflectionServiceTest method fileContainingExtension.

@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));
}
Also used : ByteString(com.google.protobuf.ByteString) ServerReflectionRequest(io.grpc.reflection.v1alpha.ServerReflectionRequest) ServerReflectionResponse(io.grpc.reflection.v1alpha.ServerReflectionResponse) Test(org.junit.Test)

Example 3 with ServerReflectionResponse

use of io.grpc.reflection.v1alpha.ServerReflectionResponse in project grpc-java by grpc.

the class ProtoReflectionServiceTest method allExtensionNumbersOfTypeForMutableServices.

@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());
}
Also used : ServerReflectionRequest(io.grpc.reflection.v1alpha.ServerReflectionRequest) ByteString(com.google.protobuf.ByteString) ServerReflectionResponse(io.grpc.reflection.v1alpha.ServerReflectionResponse) Test(org.junit.Test)

Example 4 with ServerReflectionResponse

use of io.grpc.reflection.v1alpha.ServerReflectionResponse in project grpc-java by grpc.

the class ProtoReflectionServiceTest method fileContainingSymbol.

@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));
}
Also used : ByteString(com.google.protobuf.ByteString) ServerReflectionRequest(io.grpc.reflection.v1alpha.ServerReflectionRequest) ServerReflectionResponse(io.grpc.reflection.v1alpha.ServerReflectionResponse) Test(org.junit.Test)

Example 5 with ServerReflectionResponse

use of io.grpc.reflection.v1alpha.ServerReflectionResponse in project grpc-java by grpc.

the class ProtoReflectionServiceTest method fileContainingNestedExtension.

@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());
}
Also used : ServerReflectionRequest(io.grpc.reflection.v1alpha.ServerReflectionRequest) ServerReflectionResponse(io.grpc.reflection.v1alpha.ServerReflectionResponse) Test(org.junit.Test)

Aggregations

ServerReflectionRequest (io.grpc.reflection.v1alpha.ServerReflectionRequest)11 ServerReflectionResponse (io.grpc.reflection.v1alpha.ServerReflectionResponse)11 Test (org.junit.Test)10 ByteString (com.google.protobuf.ByteString)3 ServiceResponse (io.grpc.reflection.v1alpha.ServiceResponse)1 HashSet (java.util.HashSet)1