Search in sources :

Example 1 with GetSubchannelResponse

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

the class ChannelzService method getSubchannel.

/**
 * Returns a subchannel.
 */
@Override
public void getSubchannel(GetSubchannelRequest request, StreamObserver<GetSubchannelResponse> responseObserver) {
    InternalInstrumented<ChannelStats> s = channelz.getSubchannel(request.getSubchannelId());
    if (s == null) {
        responseObserver.onError(Status.NOT_FOUND.withDescription("Can't find subchannel " + request.getSubchannelId()).asRuntimeException());
        return;
    }
    GetSubchannelResponse resp;
    try {
        resp = GetSubchannelResponse.newBuilder().setSubchannel(ChannelzProtoUtil.toSubchannel(s)).build();
    } catch (StatusRuntimeException e) {
        responseObserver.onError(e);
        return;
    }
    responseObserver.onNext(resp);
    responseObserver.onCompleted();
}
Also used : ChannelStats(io.grpc.InternalChannelz.ChannelStats) GetSubchannelResponse(io.grpc.channelz.v1.GetSubchannelResponse) StatusRuntimeException(io.grpc.StatusRuntimeException)

Example 2 with GetSubchannelResponse

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

the class ChannelzServiceTest method assertSubchannelNotFound.

private void assertSubchannelNotFound(long id) {
    @SuppressWarnings("unchecked") StreamObserver<GetSubchannelResponse> observer = mock(StreamObserver.class);
    ArgumentCaptor<Exception> exceptionCaptor = ArgumentCaptor.forClass(Exception.class);
    service.getSubchannel(GetSubchannelRequest.newBuilder().setSubchannelId(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) GetSubchannelResponse(io.grpc.channelz.v1.GetSubchannelResponse) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

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