Search in sources :

Example 1 with GetServerResponse

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);
}
Also used : Status(io.grpc.Status) GetServerResponse(io.grpc.channelz.v1.GetServerResponse) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with GetServerResponse

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();
}
Also used : GetServerResponse(io.grpc.channelz.v1.GetServerResponse) ServerStats(io.grpc.InternalChannelz.ServerStats) StatusRuntimeException(io.grpc.StatusRuntimeException)

Aggregations

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