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);
}
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);
}
Aggregations