Search in sources :

Example 6 with ServerList

use of io.grpc.InternalChannelz.ServerList in project grpc-java by grpc.

the class ChannelzService method getServers.

/**
 * Returns servers.
 */
@Override
public void getServers(GetServersRequest request, StreamObserver<GetServersResponse> responseObserver) {
    ServerList servers = channelz.getServers(request.getStartServerId(), maxPageSize);
    GetServersResponse resp;
    try {
        resp = ChannelzProtoUtil.toGetServersResponse(servers);
    } catch (StatusRuntimeException e) {
        responseObserver.onError(e);
        return;
    }
    responseObserver.onNext(resp);
    responseObserver.onCompleted();
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) ServerList(io.grpc.InternalChannelz.ServerList) GetServersResponse(io.grpc.channelz.v1.GetServersResponse)

Example 7 with ServerList

use of io.grpc.InternalChannelz.ServerList in project grpc-java by grpc.

the class ChannelzProtoUtilTest method toGetServersResponse.

@Test
public void toGetServersResponse() {
    // empty results
    assertEquals(GetServersResponse.getDefaultInstance(), ChannelzProtoUtil.toGetServersResponse(new ServerList(Collections.<InternalInstrumented<ServerStats>>emptyList(), false)));
    // 1 result, paginated
    assertEquals(GetServersResponse.newBuilder().addServer(serverProto).build(), ChannelzProtoUtil.toGetServersResponse(new ServerList(ImmutableList.<InternalInstrumented<ServerStats>>of(server), false)));
    // 1 result, end
    assertEquals(GetServersResponse.newBuilder().addServer(serverProto).setEnd(true).build(), ChannelzProtoUtil.toGetServersResponse(new ServerList(ImmutableList.<InternalInstrumented<ServerStats>>of(server), true)));
    TestServer server2 = new TestServer();
    // 2 results, end
    assertEquals(GetServersResponse.newBuilder().addServer(serverProto).addServer(ChannelzProtoUtil.toServer(server2)).setEnd(true).build(), ChannelzProtoUtil.toGetServersResponse(new ServerList(ImmutableList.<InternalInstrumented<ServerStats>>of(server, server2), true)));
}
Also used : ServerStats(io.grpc.InternalChannelz.ServerStats) ServerList(io.grpc.InternalChannelz.ServerList) TestServer(io.grpc.protobuf.services.ChannelzTestHelper.TestServer) Test(org.junit.Test)

Aggregations

ServerList (io.grpc.InternalChannelz.ServerList)7 Test (org.junit.Test)6 ServerStats (io.grpc.InternalChannelz.ServerStats)5 StatusRuntimeException (io.grpc.StatusRuntimeException)1 GetServersResponse (io.grpc.channelz.v1.GetServersResponse)1 TestServer (io.grpc.protobuf.services.ChannelzTestHelper.TestServer)1