use of com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer in project pinpoint by naver.
the class SpanStreamSendDataPlanerTest method deserialize.
private List<TSpanEvent> deserialize(byte[] data) throws TException {
ByteBuffer bb = ByteBuffer.wrap(data);
bb.get();
bb.get();
int chunkSize = bb.get();
List<TSpanEvent> eventList = new ArrayList<TSpanEvent>();
for (int i = 0; i < chunkSize; i++) {
short componentSize = bb.getShort();
byte[] component = new byte[componentSize];
bb.get(component);
HeaderTBaseDeserializer deserialize = new HeaderTBaseDeserializerFactory().createDeserializer();
List<TBase<?, ?>> value = deserialize.deserializeList(component);
for (int j = 0; j < value.size(); j++) {
TBase tbase = value.get(j);
if (tbase instanceof TSpanEvent) {
eventList.add((TSpanEvent) tbase);
} else {
}
}
}
return eventList;
}
use of com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer in project pinpoint by naver.
the class AgentEventHandlerTest method handler_should_handle_serialization_of_request_events.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void handler_should_handle_serialization_of_request_events() throws Exception {
// given
final AgentEventType expectedEventType = AgentEventType.USER_THREAD_DUMP;
final TCommandThreadDumpResponse expectedThreadDumpResponse = new TCommandThreadDumpResponse();
final byte[] expectedThreadDumpResponseBody = 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(expectedThreadDumpResponseBody);
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(expectedThreadDumpResponseBody)).thenReturn((TBase) expectedThreadDumpResponse);
// when
this.agentEventHandler.handleResponseEvent(responseEvent, TEST_EVENT_TIMESTAMP);
// then
verify(this.agentEventDao, atLeast(1)).insert(argCaptor.capture());
AgentEventBo actualAgentEventBo = argCaptor.getValue();
assertEquals(TEST_AGENT_ID, actualAgentEventBo.getAgentId());
assertEquals(TEST_START_TIMESTAMP, actualAgentEventBo.getStartTimestamp());
assertEquals(TEST_EVENT_TIMESTAMP, actualAgentEventBo.getEventTimestamp());
assertEquals(expectedEventType, actualAgentEventBo.getEventType());
assertArrayEquals(expectedThreadDumpResponseBody, actualAgentEventBo.getEventBody());
}
use of com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer 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.io.HeaderTBaseDeserializer in project pinpoint by naver.
the class SpanStreamSendDataSerializerTest method spanStreamSendDataSerializerTest1.
@Test
public void spanStreamSendDataSerializerTest1() throws InterruptedException, TException {
int spanEventSize = 10;
SpanStreamSendDataSerializer serializer = new SpanStreamSendDataSerializer();
HeaderTBaseSerializerFactory factory = new HeaderTBaseSerializerFactory();
SpanChunk spanChunk = spanChunkFactory.create(createSpanEventList(spanEventSize));
PartitionedByteBufferLocator partitionedByteBufferLocator = serializer.serializeSpanChunkStream(factory.createSerializer(), spanChunk);
Assert.assertEquals(spanEventSize + 1, partitionedByteBufferLocator.getPartitionedCount());
HeaderTBaseDeserializer deserializer = new HeaderTBaseDeserializerFactory().createDeserializer();
for (int i = 0; i < partitionedByteBufferLocator.getPartitionedCount(); i++) {
ByteBuffer byteBuffer = partitionedByteBufferLocator.getByteBuffer(i);
byte[] readBuffer = new byte[byteBuffer.remaining()];
byteBuffer.get(readBuffer);
Object o = deserializer.deserialize(readBuffer);
if (o == null) {
Assert.fail();
}
if (i < spanEventSize) {
Assert.assertTrue(o instanceof TSpanEvent);
} else {
Assert.assertTrue(o instanceof TSpanChunk);
}
}
}
use of com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer in project pinpoint by naver.
the class SpanStreamSendDataSerializerTest method spanStreamSendDataSerializerTest2.
@Test
public void spanStreamSendDataSerializerTest2() throws InterruptedException, TException {
int spanEventSize = 10;
SpanStreamSendDataSerializer serializer = new SpanStreamSendDataSerializer();
HeaderTBaseSerializerFactory factory = new HeaderTBaseSerializerFactory();
Span span = createSpan(createSpanEventList(spanEventSize));
PartitionedByteBufferLocator partitionedByteBufferLocator = serializer.serializeSpanStream(factory.createSerializer(), span);
Assert.assertEquals(spanEventSize + 1, partitionedByteBufferLocator.getPartitionedCount());
HeaderTBaseDeserializer deserializer = new HeaderTBaseDeserializerFactory().createDeserializer();
for (int i = 0; i < partitionedByteBufferLocator.getPartitionedCount(); i++) {
ByteBuffer byteBuffer = partitionedByteBufferLocator.getByteBuffer(i);
byte[] readBuffer = new byte[byteBuffer.remaining()];
byteBuffer.get(readBuffer);
Object o = deserializer.deserialize(readBuffer);
if (o == null) {
Assert.fail();
}
if (i < spanEventSize) {
Assert.assertTrue(o instanceof TSpanEvent);
} else {
Assert.assertTrue(o instanceof TSpan);
}
}
}
Aggregations