use of com.navercorp.pinpoint.grpc.trace.PCmdResponse 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.grpc.trace.PCmdResponse in project pinpoint by naver.
the class GrpcActiveThreadDumpService method handle.
@Override
public void handle(PCmdRequest request, ProfilerCommandServiceGrpc.ProfilerCommandServiceStub profilerCommandServiceStub) {
logger.info("simpleCommandService:{}", request);
PCmdActiveThreadDump commandActiveThreadDump = request.getCommandActiveThreadDump();
PCmdActiveThreadDumpRes.Builder builder = PCmdActiveThreadDumpRes.newBuilder();
PCmdResponse commonResponse = PCmdResponse.newBuilder().setResponseId(request.getRequestId()).build();
builder.setCommonResponse(commonResponse);
builder.setType(JAVA);
builder.setSubType(JvmUtils.getType().name());
builder.setVersion(JvmUtils.getVersion().name());
List<PActiveThreadDump> activeThreadDumpList = getActiveThreadDumpList(commandActiveThreadDump);
builder.addAllThreadDump(activeThreadDumpList);
profilerCommandServiceStub.commandActiveThreadDump(builder.build(), EmptyStreamObserver.create());
}
use of com.navercorp.pinpoint.grpc.trace.PCmdResponse in project pinpoint by naver.
the class GrpcActiveThreadLightDumpService method handle.
@Override
public void handle(PCmdRequest request, ProfilerCommandServiceGrpc.ProfilerCommandServiceStub profilerCommandServiceStub) {
logger.info("simpleCommandService:{}", request);
PCmdActiveThreadLightDump commandActiveThreadLightDump = request.getCommandActiveThreadLightDump();
PCmdActiveThreadLightDumpRes.Builder builder = PCmdActiveThreadLightDumpRes.newBuilder();
PCmdResponse commonResponse = PCmdResponse.newBuilder().setResponseId(request.getRequestId()).build();
builder.setCommonResponse(commonResponse);
builder.setType(JAVA);
builder.setSubType(JvmUtils.getType().name());
builder.setVersion(JvmUtils.getVersion().name());
List<PActiveThreadLightDump> activeThreadDumpList = getActiveThreadDumpList(commandActiveThreadLightDump);
builder.addAllThreadDump(activeThreadDumpList);
profilerCommandServiceStub.commandActiveThreadLightDump(builder.build(), EmptyStreamObserver.create());
}
use of com.navercorp.pinpoint.grpc.trace.PCmdResponse in project pinpoint by naver.
the class GrpcCommandDispatcher method handle.
public void handle(PCmdRequest commandRequest, StreamObserver<PCmdMessage> streamObserver) {
int value = commandRequest.getCommandCase().getNumber();
final ProfilerGrpcCommandService grpcCommandService = commandServiceLocator.getGrpcService((short) value);
if (grpcCommandService != null) {
try {
grpcCommandService.handle(commandRequest, profilerCommandServiceStub);
} catch (Exception e) {
logger.warn("Failed to handle commandService. message:{}", e.getMessage(), e);
PCmdResponse failMessage = createFailMessage(commandRequest, e.getMessage());
if (streamObserver != null) {
streamObserver.onNext(PCmdMessage.newBuilder().setFailMessage(failMessage).build());
}
}
} else {
PCmdResponse failMessage = createFailMessage(commandRequest, TRouteResult.NOT_SUPPORTED_REQUEST.name());
if (streamObserver != null) {
streamObserver.onNext(PCmdMessage.newBuilder().setFailMessage(failMessage).build());
}
}
}
use of com.navercorp.pinpoint.grpc.trace.PCmdResponse in project pinpoint by naver.
the class GrpcEchoService method handle.
@Override
public void handle(PCmdRequest request, ProfilerCommandServiceGrpc.ProfilerCommandServiceStub profilerCommandServiceStub) {
logger.info("simpleCommandService:{}", request);
PCmdEcho commandEcho = request.getCommandEcho();
PCmdEchoResponse.Builder responseBuilder = PCmdEchoResponse.newBuilder();
responseBuilder.setMessage(commandEcho.getMessage());
PCmdResponse commonResponse = PCmdResponse.newBuilder().setResponseId(request.getRequestId()).build();
responseBuilder.setCommonResponse(commonResponse);
profilerCommandServiceStub.commandEcho(responseBuilder.build(), EmptyStreamObserver.create());
}
Aggregations