Search in sources :

Example 1 with RequestManager

use of com.navercorp.pinpoint.rpc.client.RequestManager in project pinpoint by naver.

the class PinpointGrpcServerTest method requestTest.

@Test
public void requestTest() {
    RecordedStreamObserver<PCmdRequest> recordedStreamObserver = new RecordedStreamObserver<PCmdRequest>();
    PinpointGrpcServer pinpointGrpcServer = new PinpointGrpcServer(Mockito.mock(InetSocketAddress.class), agentInfo, new RequestManager(testTimer, 3000), Mockito.mock(ProfilerClusterManager.class), recordedStreamObserver);
    pinpointGrpcServer.connected();
    List<Integer> supportCommandList = Collections.singletonList(Short.toUnsignedInt(TCommandType.ECHO.getCode()));
    pinpointGrpcServer.handleHandshake(supportCommandList);
    Future<ResponseMessage> future = pinpointGrpcServer.request(this.request);
    Assert.assertEquals(1, recordedStreamObserver.getRequestCount());
    // timeout
    awaitAndAssert(future, false);
    future = pinpointGrpcServer.request(this.request);
    Assert.assertEquals(2, recordedStreamObserver.getRequestCount());
    PCmdRequest latestRequest = recordedStreamObserver.getLatestRequest();
    pinpointGrpcServer.handleMessage(latestRequest.getRequestId(), PCmdEchoResponse.newBuilder().setMessage(latestRequest.getCommandEcho().getMessage()).build());
    // success
    awaitAndAssert(future, true);
    future = pinpointGrpcServer.request(this.request);
    Assert.assertEquals(3, recordedStreamObserver.getRequestCount());
    latestRequest = recordedStreamObserver.getLatestRequest();
    PCmdResponse.Builder builder = PCmdResponse.newBuilder();
    PCmdResponse response = builder.setMessage(StringValue.of("fail")).setResponseId(latestRequest.getRequestId()).build();
    pinpointGrpcServer.handleFail(response);
    // fail
    awaitAndAssert(future, false);
    pinpointGrpcServer.close();
    assertCurrentState(SocketStateCode.CLOSED_BY_SERVER, pinpointGrpcServer);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage) RequestManager(com.navercorp.pinpoint.rpc.client.RequestManager) PCmdRequest(com.navercorp.pinpoint.grpc.trace.PCmdRequest) ProfilerClusterManager(com.navercorp.pinpoint.collector.cluster.ProfilerClusterManager) PCmdResponse(com.navercorp.pinpoint.grpc.trace.PCmdResponse) Test(org.junit.Test)

Example 2 with RequestManager

use of com.navercorp.pinpoint.rpc.client.RequestManager in project pinpoint by naver.

the class PinpointGrpcServerTest method stateTest.

@Test
public void stateTest() {
    RecordedStreamObserver recordedStreamObserver = new RecordedStreamObserver();
    PinpointGrpcServer pinpointGrpcServer = new PinpointGrpcServer(Mockito.mock(InetSocketAddress.class), agentInfo, new RequestManager(testTimer, 3000), Mockito.mock(ProfilerClusterManager.class), recordedStreamObserver);
    assertCurrentState(SocketStateCode.NONE, pinpointGrpcServer);
    Future<ResponseMessage> future = pinpointGrpcServer.request(request);
    requestOnInvalidState(future, recordedStreamObserver);
    pinpointGrpcServer.connected();
    assertCurrentState(SocketStateCode.CONNECTED, pinpointGrpcServer);
    future = pinpointGrpcServer.request(request);
    requestOnInvalidState(future, recordedStreamObserver);
    List<Integer> supportCommandList = Collections.singletonList(Short.toUnsignedInt(TCommandType.ECHO.getCode()));
    pinpointGrpcServer.handleHandshake(supportCommandList);
    assertCurrentState(SocketStateCode.RUN_DUPLEX, pinpointGrpcServer);
    pinpointGrpcServer.disconnected();
    assertCurrentState(SocketStateCode.CLOSED_BY_CLIENT, pinpointGrpcServer);
    future = pinpointGrpcServer.request(request);
    requestOnInvalidState(future, recordedStreamObserver);
}
Also used : RequestManager(com.navercorp.pinpoint.rpc.client.RequestManager) InetSocketAddress(java.net.InetSocketAddress) ProfilerClusterManager(com.navercorp.pinpoint.collector.cluster.ProfilerClusterManager) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage) Test(org.junit.Test)

Aggregations

ProfilerClusterManager (com.navercorp.pinpoint.collector.cluster.ProfilerClusterManager)2 ResponseMessage (com.navercorp.pinpoint.rpc.ResponseMessage)2 RequestManager (com.navercorp.pinpoint.rpc.client.RequestManager)2 InetSocketAddress (java.net.InetSocketAddress)2 Test (org.junit.Test)2 PCmdRequest (com.navercorp.pinpoint.grpc.trace.PCmdRequest)1 PCmdResponse (com.navercorp.pinpoint.grpc.trace.PCmdResponse)1