Search in sources :

Example 6 with HeaderTBaseDeserializer

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;
}
Also used : ArrayList(java.util.ArrayList) TBase(org.apache.thrift.TBase) ByteBuffer(java.nio.ByteBuffer) TSpanEvent(com.navercorp.pinpoint.thrift.dto.TSpanEvent) HeaderTBaseDeserializer(com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer) HeaderTBaseDeserializerFactory(com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializerFactory)

Example 7 with HeaderTBaseDeserializer

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());
}
Also used : TCommandThreadDumpResponse(com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse) AgentEventType(com.navercorp.pinpoint.common.server.util.AgentEventType) TCommandTransfer(com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer) TCommandTransferResponse(com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse) AgentEventBo(com.navercorp.pinpoint.common.server.bo.AgentEventBo) ResponseEvent(com.navercorp.pinpoint.collector.cluster.route.ResponseEvent) HeaderTBaseDeserializer(com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer) Test(org.junit.Test)

Example 8 with HeaderTBaseDeserializer

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());
}
Also used : TCommandTransfer(com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer) TCommandTransferResponse(com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse) AgentEventBo(com.navercorp.pinpoint.common.server.bo.AgentEventBo) TCommandEcho(com.navercorp.pinpoint.thrift.dto.command.TCommandEcho) ResponseEvent(com.navercorp.pinpoint.collector.cluster.route.ResponseEvent) HeaderTBaseDeserializer(com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer) Test(org.junit.Test)

Example 9 with HeaderTBaseDeserializer

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);
        }
    }
}
Also used : TSpanChunk(com.navercorp.pinpoint.thrift.dto.TSpanChunk) HeaderTBaseSerializerFactory(com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializerFactory) SpanChunk(com.navercorp.pinpoint.profiler.context.SpanChunk) TSpanChunk(com.navercorp.pinpoint.thrift.dto.TSpanChunk) HeaderTBaseDeserializer(com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer) HeaderTBaseDeserializerFactory(com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializerFactory) ByteBuffer(java.nio.ByteBuffer) TSpanEvent(com.navercorp.pinpoint.thrift.dto.TSpanEvent) Test(org.junit.Test)

Example 10 with HeaderTBaseDeserializer

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);
        }
    }
}
Also used : HeaderTBaseSerializerFactory(com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializerFactory) TSpan(com.navercorp.pinpoint.thrift.dto.TSpan) TSpan(com.navercorp.pinpoint.thrift.dto.TSpan) Span(com.navercorp.pinpoint.profiler.context.Span) HeaderTBaseDeserializer(com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer) HeaderTBaseDeserializerFactory(com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializerFactory) ByteBuffer(java.nio.ByteBuffer) TSpanEvent(com.navercorp.pinpoint.thrift.dto.TSpanEvent) Test(org.junit.Test)

Aggregations

HeaderTBaseDeserializer (com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer)10 HeaderTBaseDeserializerFactory (com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializerFactory)6 Test (org.junit.Test)6 TSpanEvent (com.navercorp.pinpoint.thrift.dto.TSpanEvent)4 HeaderTBaseSerializerFactory (com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializerFactory)4 ByteBuffer (java.nio.ByteBuffer)4 TBase (org.apache.thrift.TBase)4 ResponseEvent (com.navercorp.pinpoint.collector.cluster.route.ResponseEvent)2 AgentEventBo (com.navercorp.pinpoint.common.server.bo.AgentEventBo)2 FutureListener (com.navercorp.pinpoint.rpc.FutureListener)2 ResponseMessage (com.navercorp.pinpoint.rpc.ResponseMessage)2 TResult (com.navercorp.pinpoint.thrift.dto.TResult)2 TCommandTransfer (com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer)2 TCommandTransferResponse (com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse)2 HeaderTBaseSerializer (com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer)2 ArrayList (java.util.ArrayList)2 AgentEventType (com.navercorp.pinpoint.common.server.util.AgentEventType)1 Span (com.navercorp.pinpoint.profiler.context.Span)1 SpanChunk (com.navercorp.pinpoint.profiler.context.SpanChunk)1 TSpan (com.navercorp.pinpoint.thrift.dto.TSpan)1