use of com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer in project pinpoint by naver.
the class AgentEventHandlerTest method handler_should_ignore_request_events_with_unsupported_message_types.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void handler_should_ignore_request_events_with_unsupported_message_types() throws Exception {
// given
final TCommandEcho mismatchingResponse = new TCommandEcho();
final byte[] mismatchingResponseBody = new byte[0];
final TCommandTransfer tCommandTransfer = new TCommandTransfer();
tCommandTransfer.setAgentId(TEST_AGENT_ID);
tCommandTransfer.setStartTime(TEST_START_TIMESTAMP);
final TCommandTransferResponse tCommandTransferResponse = new TCommandTransferResponse();
tCommandTransferResponse.setRouteResult(TRouteResult.OK);
tCommandTransferResponse.setPayload(mismatchingResponseBody);
final ResponseEvent responseEvent = new ResponseEvent(tCommandTransfer, null, 0, tCommandTransferResponse);
ArgumentCaptor<AgentEventBo> argCaptor = ArgumentCaptor.forClass(AgentEventBo.class);
HeaderTBaseDeserializer deserializer = mock(HeaderTBaseDeserializer.class);
when(this.deserializerFactory.createDeserializer()).thenReturn(deserializer);
when(deserializer.deserialize(mismatchingResponseBody)).thenReturn((TBase) mismatchingResponse);
// when
this.agentEventHandler.handleResponseEvent(responseEvent, TEST_EVENT_TIMESTAMP);
// then
verify(this.agentEventDao, never()).insert(argCaptor.capture());
}
use of com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer in project pinpoint by pinpoint-apm.
the class AgentEventHandlingFilterTest method handler_should_ignore_request_events_with_unsupported_message_types.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void handler_should_ignore_request_events_with_unsupported_message_types() throws Exception {
// given
final TCommandEcho mismatchingResponse = new TCommandEcho();
final byte[] mismatchingResponseBody = new byte[0];
final TCommandTransfer tCommandTransfer = new TCommandTransfer();
tCommandTransfer.setAgentId(TEST_AGENT_ID);
tCommandTransfer.setStartTime(TEST_START_TIMESTAMP);
final TCommandTransferResponse tCommandTransferResponse = new TCommandTransferResponse();
tCommandTransferResponse.setRouteResult(TRouteResult.OK);
tCommandTransferResponse.setPayload(mismatchingResponseBody);
final ResponseEvent responseEvent = new ResponseEvent(tCommandTransfer, null, 0, tCommandTransferResponse);
ArgumentCaptor<AgentEventBo> argCaptor = ArgumentCaptor.forClass(AgentEventBo.class);
HeaderTBaseDeserializer deserializer = mock(HeaderTBaseDeserializer.class);
when(this.deserializerFactory.createDeserializer()).thenReturn(deserializer);
Message<TBase<?, ?>> message = new DefaultMessage<>(new HeaderV1((short) 1000), HeaderEntity.EMPTY_HEADER_ENTITY, mismatchingResponse);
when(deserializer.deserialize(mismatchingResponseBody)).thenReturn(message);
// when
this.agentEventHandlingFilter.handleResponseEvent(responseEvent, TEST_EVENT_TIMESTAMP);
// then
verify(this.agentEventDao, never()).insert(argCaptor.capture());
}
use of com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer in project pinpoint by naver.
the class AgentServiceImpl method openStreamAndAwait.
@Override
public ClientStreamChannel openStreamAndAwait(AgentInfo agentInfo, byte[] payload, ClientStreamChannelEventHandler streamChannelEventHandler, long timeout) throws TException, StreamException {
assertClusterEnabled();
TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload);
List<PinpointSocket> socketList = clusterManager.getSocket(agentInfo);
if (CollectionUtils.nullSafeSize(socketList) == 1) {
PinpointSocket socket = socketList.get(0);
return socket.openStreamAndAwait(serializeRequest(transferObject), streamChannelEventHandler, timeout);
} else if (CollectionUtils.isEmpty(socketList)) {
throw new StreamException(StreamCode.CONNECTION_NOT_FOUND);
} else {
throw new StreamException(StreamCode.CONNECTION_DUPLICATED);
}
}
use of com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer in project pinpoint by naver.
the class AgentServiceImpl method invoke.
@Override
public Map<AgentInfo, PinpointRouteResponse> invoke(List<AgentInfo> agentInfoList, byte[] payload, long timeout) throws TException {
Map<AgentInfo, Future<ResponseMessage>> futureMap = new HashMap<>();
for (AgentInfo agentInfo : agentInfoList) {
TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload);
List<PinpointSocket> socketList = clusterManager.getSocket(agentInfo);
if (CollectionUtils.nullSafeSize(socketList) == 1) {
PinpointSocket socket = socketList.get(0);
Future<ResponseMessage> future = socket.request(serializeRequest(transferObject));
futureMap.put(agentInfo, future);
} else {
futureMap.put(agentInfo, null);
}
}
long startTime = System.currentTimeMillis();
Map<AgentInfo, PinpointRouteResponse> result = new HashMap<>();
for (Map.Entry<AgentInfo, Future<ResponseMessage>> futureEntry : futureMap.entrySet()) {
AgentInfo agentInfo = futureEntry.getKey();
Future<ResponseMessage> future = futureEntry.getValue();
PinpointRouteResponse response = getResponse(future, getTimeoutMillis(startTime, timeout));
result.put(agentInfo, response);
}
return result;
}
use of com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer in project pinpoint by naver.
the class AgentServiceImpl method openStream.
@Override
public ClientStreamChannel openStream(AgentInfo agentInfo, byte[] payload, ClientStreamChannelEventHandler streamChannelEventHandler) throws TException, StreamException {
assertClusterEnabled();
TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload);
List<PinpointSocket> socketList = clusterManager.getSocket(agentInfo);
if (CollectionUtils.nullSafeSize(socketList) == 1) {
PinpointSocket socket = socketList.get(0);
return socket.openStream(serializeRequest(transferObject), streamChannelEventHandler);
} else if (CollectionUtils.isEmpty(socketList)) {
throw new StreamException(StreamCode.CONNECTION_NOT_FOUND);
} else {
throw new StreamException(StreamCode.CONNECTION_DUPLICATED);
}
}
Aggregations