Search in sources :

Example 1 with SpanEncoder

use of com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncoder in project pinpoint by naver.

the class SpanMapperV2Test method test.

@Test
public void test() {
    SpanBo span = new SpanBo();
    span.setServiceType((short) 1000);
    span.setExceptionInfo(1, "spanException");
    SpanEventBo firstSpanEventBo = new SpanEventBo();
    firstSpanEventBo.setExceptionInfo(2, "first");
    firstSpanEventBo.setEndElapsed(100);
    AnnotationBo annotationBo = newAnnotation(200, "annotation");
    firstSpanEventBo.setAnnotationBoList(Lists.<AnnotationBo>newArrayList(annotationBo));
    firstSpanEventBo.setServiceType((short) 1003);
    firstSpanEventBo.setSequence((short) 0);
    span.addSpanEvent(firstSpanEventBo);
    //// next
    SpanEventBo nextSpanEventBo = new SpanEventBo();
    nextSpanEventBo.setEndElapsed(200);
    nextSpanEventBo.setServiceType((short) 2003);
    nextSpanEventBo.setSequence((short) 1);
    span.addSpanEvent(nextSpanEventBo);
    SpanEncodingContext<SpanBo> encodingContext = new SpanEncodingContext<>(span);
    SpanEncoder encoder = new SpanEncoderV0();
    ByteBuffer byteBuffer = encoder.encodeSpanColumnValue(encodingContext);
    Buffer buffer = new OffsetFixedBuffer(byteBuffer.array(), byteBuffer.arrayOffset(), byteBuffer.remaining());
    SpanBo readSpan = new SpanBo();
    SpanDecodingContext decodingContext = new SpanDecodingContext();
    decoder.readSpanValue(buffer, readSpan, new SpanEventBo(), decodingContext);
    Assert.assertEquals(readSpan.getSpanEventBoList().size(), 2);
    // span
    Assert.assertEquals(readSpan.getServiceType(), 1000);
    Assert.assertEquals(readSpan.hasException(), true);
    Assert.assertEquals(readSpan.getExceptionId(), 1);
    Assert.assertEquals(readSpan.getExceptionMessage(), "spanException");
    List<SpanEventBo> spanEventBoList = readSpan.getSpanEventBoList();
    SpanEventBo readFirst = spanEventBoList.get(0);
    SpanEventBo readNext = spanEventBoList.get(1);
    Assert.assertEquals(readFirst.getEndElapsed(), 100);
    Assert.assertEquals(readNext.getEndElapsed(), 200);
    Assert.assertEquals(readFirst.getExceptionId(), 2);
    Assert.assertEquals(readNext.hasException(), false);
    Assert.assertEquals(readFirst.getServiceType(), 1003);
    Assert.assertEquals(readNext.getServiceType(), 2003);
    Assert.assertEquals(readFirst.getSequence(), 0);
    Assert.assertEquals(readNext.getSequence(), 1);
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) OffsetFixedBuffer(com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer) ByteBuffer(java.nio.ByteBuffer) AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo) SpanEncodingContext(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncodingContext) SpanDecodingContext(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanDecodingContext) SpanEncoder(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncoder) OffsetFixedBuffer(com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer) SpanEncoderV0(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncoderV0) SpanBo(com.navercorp.pinpoint.common.server.bo.SpanBo) ByteBuffer(java.nio.ByteBuffer) SpanEventBo(com.navercorp.pinpoint.common.server.bo.SpanEventBo) Test(org.junit.Test)

Aggregations

Buffer (com.navercorp.pinpoint.common.buffer.Buffer)1 OffsetFixedBuffer (com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer)1 AnnotationBo (com.navercorp.pinpoint.common.server.bo.AnnotationBo)1 SpanBo (com.navercorp.pinpoint.common.server.bo.SpanBo)1 SpanEventBo (com.navercorp.pinpoint.common.server.bo.SpanEventBo)1 SpanDecodingContext (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanDecodingContext)1 SpanEncoder (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncoder)1 SpanEncoderV0 (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncoderV0)1 SpanEncodingContext (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncodingContext)1 ByteBuffer (java.nio.ByteBuffer)1 Test (org.junit.Test)1