use of io.grpc.channelz.v1.GetServerResponse in project grpc-java by grpc.
the class ChannelzServiceTest method assertServerNotFound.
private void assertServerNotFound(long id) {
@SuppressWarnings("unchecked") StreamObserver<GetServerResponse> observer = mock(StreamObserver.class);
ArgumentCaptor<Exception> exceptionCaptor = ArgumentCaptor.forClass(Exception.class);
service.getServer(GetServerRequest.newBuilder().setServerId(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.GetServerResponse in project grpc-java by grpc.
the class ChannelzService method getServer.
/**
* Returns a server.
*/
@Override
public void getServer(GetServerRequest request, StreamObserver<GetServerResponse> responseObserver) {
InternalInstrumented<ServerStats> s = channelz.getServer(request.getServerId());
if (s == null) {
responseObserver.onError(Status.NOT_FOUND.withDescription("Can't find server " + request.getServerId()).asRuntimeException());
return;
}
GetServerResponse resp;
try {
resp = GetServerResponse.newBuilder().setServer(ChannelzProtoUtil.toServer(s)).build();
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
return;
}
responseObserver.onNext(resp);
responseObserver.onCompleted();
}
Aggregations