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);
}
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();
}
Aggregations