Search in sources :

Example 1 with GetSocketResponse

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

the class ChannelzServiceTest method assertSocketNotFound.

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

Example 2 with GetSocketResponse

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

the class ChannelzService method getSocket.

/**
 * Returns a socket.
 */
@Override
public void getSocket(GetSocketRequest request, StreamObserver<GetSocketResponse> responseObserver) {
    InternalInstrumented<SocketStats> s = channelz.getSocket(request.getSocketId());
    if (s == null) {
        responseObserver.onError(Status.NOT_FOUND.withDescription("Can't find socket " + request.getSocketId()).asRuntimeException());
        return;
    }
    GetSocketResponse resp;
    try {
        resp = GetSocketResponse.newBuilder().setSocket(ChannelzProtoUtil.toSocket(s)).build();
    } catch (StatusRuntimeException e) {
        responseObserver.onError(e);
        return;
    }
    responseObserver.onNext(resp);
    responseObserver.onCompleted();
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) SocketStats(io.grpc.InternalChannelz.SocketStats) GetSocketResponse(io.grpc.channelz.v1.GetSocketResponse)

Aggregations

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