Search in sources :

Example 1 with GetChannelResponse

use of io.grpc.channelz.v1.GetChannelResponse in project grpc-java by grpc.

the class ChannelzServiceTest method assertChannelNotFound.

private void assertChannelNotFound(long id) {
    @SuppressWarnings("unchecked") StreamObserver<GetChannelResponse> observer = mock(StreamObserver.class);
    ArgumentCaptor<Exception> exceptionCaptor = ArgumentCaptor.forClass(Exception.class);
    service.getChannel(GetChannelRequest.newBuilder().setChannelId(id).build(), observer);
    verify(observer).onError(exceptionCaptor.capture());
    Status s = Status.fromThrowable(exceptionCaptor.getValue());
    assertWithMessage(s.toString()).that(s.getCode()).isEqualTo(Status.Code.NOT_FOUND);
}
Also used : Status(io.grpc.Status) GetChannelResponse(io.grpc.channelz.v1.GetChannelResponse) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with GetChannelResponse

use of io.grpc.channelz.v1.GetChannelResponse in project grpc-java by grpc.

the class ChannelzService method getChannel.

/**
 * Returns a top level channel aka {@link io.grpc.ManagedChannel}.
 */
@Override
public void getChannel(GetChannelRequest request, StreamObserver<GetChannelResponse> responseObserver) {
    InternalInstrumented<ChannelStats> s = channelz.getRootChannel(request.getChannelId());
    if (s == null) {
        responseObserver.onError(Status.NOT_FOUND.withDescription("Can't find channel " + request.getChannelId()).asRuntimeException());
        return;
    }
    GetChannelResponse resp;
    try {
        resp = GetChannelResponse.newBuilder().setChannel(ChannelzProtoUtil.toChannel(s)).build();
    } catch (StatusRuntimeException e) {
        responseObserver.onError(e);
        return;
    }
    responseObserver.onNext(resp);
    responseObserver.onCompleted();
}
Also used : ChannelStats(io.grpc.InternalChannelz.ChannelStats) StatusRuntimeException(io.grpc.StatusRuntimeException) GetChannelResponse(io.grpc.channelz.v1.GetChannelResponse)

Aggregations

GetChannelResponse (io.grpc.channelz.v1.GetChannelResponse)2 ChannelStats (io.grpc.InternalChannelz.ChannelStats)1 Status (io.grpc.Status)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 ExecutionException (java.util.concurrent.ExecutionException)1