use of com.navercorp.pinpoint.grpc.trace.PCmdMessage in project pinpoint by naver.
the class GrpcCommandServiceTest method oldVersionHandshakeTest.
@Test
public void oldVersionHandshakeTest() throws IOException, PinpointZookeeperException {
ZookeeperProfilerClusterManager manager = creteMemoryClusterManager();
ZookeeperClusterService mockClusterService = Mockito.mock(ZookeeperClusterService.class);
Mockito.when(mockClusterService.getProfilerClusterManager()).thenReturn(manager);
try (GrpcCommandService commandService = new GrpcCommandService(mockClusterService)) {
TransportMetadata transportMetaData = createTransportMetaData(new InetSocketAddress("127.0.0.1", 61613), 10);
attachContext(transportMetaData);
attachContext(new Header("test", "agentId", "agentName", "applicationName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis(), Header.SOCKET_ID_NOT_EXIST, null));
StreamObserver<PCmdMessage> handleMessageObserver = commandService.handleCommand(new TempServerCallStreamObserver<>());
handleMessageObserver.onNext(createHandshakeMessage());
awaitility().await("oldVersionHandshakeTest").until(manager::getClusterData, hasSize(1));
assertHandleMessage(commandService, transportMetaData);
}
}
use of com.navercorp.pinpoint.grpc.trace.PCmdMessage in project pinpoint by naver.
the class GrpcCommandServiceTest method oldVersionHandshakeFailTest.
@Test
public void oldVersionHandshakeFailTest() throws IOException, PinpointZookeeperException {
ZookeeperProfilerClusterManager manager = creteMemoryClusterManager();
ZookeeperClusterService mockClusterService = Mockito.mock(ZookeeperClusterService.class);
Mockito.when(mockClusterService.getProfilerClusterManager()).thenReturn(manager);
try (GrpcCommandService commandService = new GrpcCommandService(mockClusterService)) {
TransportMetadata transportMetaData = createTransportMetaData(new InetSocketAddress("127.0.0.1", 61613), 10);
attachContext(transportMetaData);
attachContext(new Header("test", "agentId", "agentName", "applicationName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis(), Header.SOCKET_ID_NOT_EXIST, getCodeList()));
final TempServerCallStreamObserver<PCmdRequest> requestObserver = new TempServerCallStreamObserver<>();
StreamObserver<PCmdMessage> handleMessageObserver = commandService.handleCommand(requestObserver);
Assert.assertThrows(ConditionTimeoutException.class, () -> {
Awaitility.await("oldVersionHandshakeFailTest").timeout(400, TimeUnit.MILLISECONDS).until(manager::getClusterData, hasSize(1));
});
Assert.assertNotNull(requestObserver.getLatestException());
}
}
use of com.navercorp.pinpoint.grpc.trace.PCmdMessage in project pinpoint by naver.
the class GrpcCommandServiceTest method createHandshakeMessage.
private PCmdMessage createHandshakeMessage() {
PCmdServiceHandshake.Builder handshakeBuilder = PCmdServiceHandshake.newBuilder();
for (TCommandType commandType : TCommandType.values()) {
handshakeBuilder.addSupportCommandServiceKey(commandType.getCode());
}
PCmdMessage.Builder builder = PCmdMessage.newBuilder();
builder.setHandshakeMessage(handshakeBuilder.build());
return builder.build();
}
use of com.navercorp.pinpoint.grpc.trace.PCmdMessage in project pinpoint by naver.
the class GrpcCommandServiceTest method newVersionHandshakeTest.
@Test
public void newVersionHandshakeTest() throws IOException, PinpointZookeeperException {
ZookeeperProfilerClusterManager manager = creteMemoryClusterManager();
ZookeeperClusterService mockClusterService = Mockito.mock(ZookeeperClusterService.class);
Mockito.when(mockClusterService.getProfilerClusterManager()).thenReturn(manager);
try (GrpcCommandService commandService = new GrpcCommandService(mockClusterService)) {
TransportMetadata transportMetaData = createTransportMetaData(new InetSocketAddress("127.0.0.1", 61613), 10);
attachContext(transportMetaData);
attachContext(new Header("test", "agentId", null, "applicationName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis(), Header.SOCKET_ID_NOT_EXIST, getCodeList()));
StreamObserver<PCmdMessage> handleMessageObserver = commandService.handleCommandV2(new TempServerCallStreamObserver<>());
awaitility().until(manager::getClusterData, hasSize(1));
assertHandleMessage(commandService, transportMetaData);
}
}
use of com.navercorp.pinpoint.grpc.trace.PCmdMessage in project pinpoint by naver.
the class GrpcCommandService method handleCommandV2.
@Override
public StreamObserver<PCmdMessage> handleCommandV2(StreamObserver<PCmdRequest> requestObserver) {
final Long transportId = getTransportId();
final AgentInfo agentInfo = getAgentInfo();
final List<Integer> supportCommandCodeList = getSupportCommandCodeList();
logger.info("{} => local. handleCommandV2(). transportId:{}, supportCommandCodeList{}", agentInfo, transportId, supportCommandCodeList);
if (supportCommandCodeList == Header.SUPPORT_COMMAND_CODE_LIST_NOT_EXIST) {
logger.warn("handleCommandV2() not allow empty Header:{}. Connection will be disconnected.", Header.SUPPORT_COMMAND_CODE.name());
requestObserver.onError(new StatusException(Status.INVALID_ARGUMENT));
return DisabledStreamObserver.instance();
}
final PinpointGrpcServer pinpointGrpcServer = registerNewPinpointGrpcServer(requestObserver, agentInfo, transportId);
if (pinpointGrpcServer == null) {
return handleServerRegistrationFailed(requestObserver, agentInfo, transportId);
}
final ServerCallStreamObserver<PCmdRequest> serverCallStreamObserver = (ServerCallStreamObserver<PCmdRequest>) requestObserver;
serverCallStreamObserver.setOnReadyHandler(new Runnable() {
public void run() {
if (serverCallStreamObserver.isReady()) {
logger.info("{} => local. ready() transportId:{}", agentInfo.getAgentKey(), transportId);
pinpointGrpcServer.connected();
registerAgentCommandList(pinpointGrpcServer, supportCommandCodeList);
}
pinpointGrpcServer.setOnCloseHandler(new Runnable() {
@Override
public void run() {
unregisterPinpointGrpcServer(transportId);
}
});
}
});
final StreamObserver<PCmdMessage> responseObserver = new StreamObserver<PCmdMessage>() {
@Override
public void onNext(PCmdMessage value) {
if (value.hasFailMessage()) {
PCmdResponse failMessage = value.getFailMessage();
pinpointGrpcServer.handleFail(failMessage);
}
}
@Override
public void onError(Throwable t) {
handleOnError(t, pinpointGrpcServer, agentInfo);
}
@Override
public void onCompleted() {
handleOnCompleted(pinpointGrpcServer, agentInfo);
}
};
return responseObserver;
}
Aggregations