Search in sources :

Example 31 with Buffer

use of com.navercorp.pinpoint.common.buffer.Buffer in project pinpoint by naver.

the class AgentStatCodecTestBase method runTest.

private void runTest() {
    // Given
    final long initialTimestamp = System.currentTimeMillis();
    final long baseTimestamp = AgentStatUtils.getBaseTimestamp(initialTimestamp);
    final long timestampDelta = initialTimestamp - baseTimestamp;
    final List<T> expectedAgentStats = createAgentStats(AGENT_ID, AGENT_START_TIMESTAMP, initialTimestamp);
    // When
    Buffer encodedValueBuffer = new AutomaticBuffer();
    getCodec().encodeValues(encodedValueBuffer, expectedAgentStats);
    // Then
    AgentStatDecodingContext decodingContext = new AgentStatDecodingContext();
    decodingContext.setAgentId(AGENT_ID);
    decodingContext.setBaseTimestamp(baseTimestamp);
    decodingContext.setTimestampDelta(timestampDelta);
    Buffer valueBuffer = new FixedBuffer(encodedValueBuffer.getBuffer());
    List<T> actualAgentStats = getCodec().decodeValues(valueBuffer, decodingContext);
    Assert.assertEquals(expectedAgentStats.size(), actualAgentStats.size());
    for (int i = 0; i < expectedAgentStats.size(); i++) {
        T expectedAgentStat = expectedAgentStats.get(i);
        T actualAgentStat = actualAgentStats.get(i);
        verify(expectedAgentStat, actualAgentStat);
    }
}
Also used : FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) Buffer(com.navercorp.pinpoint.common.buffer.Buffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) AgentStatDecodingContext(com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext) FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) AgentStatDataPoint(com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint)

Example 32 with Buffer

use of com.navercorp.pinpoint.common.buffer.Buffer in project pinpoint by naver.

the class AgentStatEncoderTest method stats_should_be_encoded_and_decoded_into_same_value.

@Test
public void stats_should_be_encoded_and_decoded_into_same_value() {
    long initialTimestamp = System.currentTimeMillis();
    int numStats = RandomUtils.nextInt(1, 21);
    List<TestAgentStat> expectedAgentStats = this.createTestAgentStats(initialTimestamp, numStats);
    long baseTimestamp = AgentStatUtils.getBaseTimestamp(initialTimestamp);
    long timestampDelta = initialTimestamp - baseTimestamp;
    ByteBuffer qualifierBuffer = encoder.encodeQualifier(timestampDelta);
    ByteBuffer valueBuffer = encoder.encodeValue(expectedAgentStats);
    Buffer encodedQualifierBuffer = new FixedBuffer(qualifierBuffer.array());
    Buffer encodedValueBuffer = new FixedBuffer(valueBuffer.array());
    AgentStatDecodingContext context = new AgentStatDecodingContext();
    context.setAgentId(AGENT_ID);
    context.setBaseTimestamp(baseTimestamp);
    List<TestAgentStat> decodedAgentStats = decode(encodedQualifierBuffer, encodedValueBuffer, context);
    verify(expectedAgentStats, decodedAgentStats);
}
Also used : FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) Buffer(com.navercorp.pinpoint.common.buffer.Buffer) ByteBuffer(java.nio.ByteBuffer) AgentStatDecodingContext(com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext) FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) ByteBuffer(java.nio.ByteBuffer) AgentStatDataPoint(com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint) Test(org.junit.Test)

Example 33 with Buffer

use of com.navercorp.pinpoint.common.buffer.Buffer in project pinpoint by naver.

the class AgentStatDataPointCodecTest method test_timestamps.

@Test
public void test_timestamps() {
    // Given
    final long initialTimestamp = System.currentTimeMillis();
    final long intervalMs = 5000L;
    final long randomDelta = 10L;
    final int numValues = (int) (Math.random() * 100) + 1;
    final List<Long> expectedTimestamps = createTimestamps(initialTimestamp, intervalMs, randomDelta, numValues);
    final Buffer timestampBuffer = new AutomaticBuffer();
    // When
    codec.encodeTimestamps(timestampBuffer, expectedTimestamps);
    // Then
    List<Long> decodedTimestamps = codec.decodeTimestamps(initialTimestamp, new FixedBuffer(timestampBuffer.getBuffer()), numValues);
    Assert.assertEquals(expectedTimestamps, decodedTimestamps);
}
Also used : FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) Buffer(com.navercorp.pinpoint.common.buffer.Buffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) Test(org.junit.Test)

Example 34 with Buffer

use of com.navercorp.pinpoint.common.buffer.Buffer in project pinpoint by naver.

the class AgentEventMessageSerializerV1 method serializeDeadlockBo.

private byte[] serializeDeadlockBo(final DeadlockBo deadlockBo) {
    final Buffer buffer = new AutomaticBuffer();
    buffer.putInt(deadlockBo.getDeadlockedThreadCount());
    // Put ThreadDumpBoList
    final int threadDumpBoListSize = deadlockBo.getThreadDumpBoList() == null ? 0 : deadlockBo.getThreadDumpBoList().size();
    buffer.putVInt(threadDumpBoListSize);
    if (threadDumpBoListSize > 0) {
        for (ThreadDumpBo threadDumpBo : deadlockBo.getThreadDumpBoList()) {
            putThreadDumpBo(buffer, threadDumpBo);
        }
    }
    return buffer.getBuffer();
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) ThreadDumpBo(com.navercorp.pinpoint.common.server.bo.event.ThreadDumpBo)

Example 35 with Buffer

use of com.navercorp.pinpoint.common.buffer.Buffer in project pinpoint by naver.

the class SpanEncoderV0 method encodeSpanChunkColumnValue.

@Override
public ByteBuffer encodeSpanChunkColumnValue(SpanEncodingContext<SpanChunkBo> encodingContext) {
    final SpanChunkBo spanChunkBo = encodingContext.getValue();
    final Buffer buffer = new AutomaticBuffer(256);
    final byte version = (byte) spanChunkBo.getVersion();
    buffer.putByte(version);
    if (version == SpanVersion.TRACE_V2) {
        long keyTime = spanChunkBo.getKeyTime();
        buffer.putVLong(keyTime);
    }
    final List<SpanEventBo> spanEventBoList = spanChunkBo.getSpanEventBoList();
    writeSpanEventList(buffer, spanEventBoList, encodingContext);
    return buffer.wrapByteBuffer();
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) ByteBuffer(java.nio.ByteBuffer) SpanChunkBo(com.navercorp.pinpoint.common.server.bo.SpanChunkBo) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) SpanEventBo(com.navercorp.pinpoint.common.server.bo.SpanEventBo)

Aggregations

Buffer (com.navercorp.pinpoint.common.buffer.Buffer)107 AutomaticBuffer (com.navercorp.pinpoint.common.buffer.AutomaticBuffer)76 FixedBuffer (com.navercorp.pinpoint.common.buffer.FixedBuffer)57 ByteBuffer (java.nio.ByteBuffer)27 Test (org.junit.Test)24 OffsetFixedBuffer (com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer)15 ApplicationStatDecodingContext (com.navercorp.pinpoint.common.server.bo.serializer.stat.ApplicationStatDecodingContext)11 JoinStatBo (com.navercorp.pinpoint.common.server.bo.stat.join.JoinStatBo)11 AgentStatDataPointCodec (com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec)10 Date (java.util.Date)10 SpanEventBo (com.navercorp.pinpoint.common.server.bo.SpanEventBo)9 Cell (org.apache.hadoop.hbase.Cell)9 SpanBo (com.navercorp.pinpoint.common.server.bo.SpanBo)8 ArrayList (java.util.ArrayList)6 AnnotationBo (com.navercorp.pinpoint.common.server.bo.AnnotationBo)5 TransactionId (com.navercorp.pinpoint.common.profiler.util.TransactionId)4 IntStringStringValue (com.navercorp.pinpoint.common.util.IntStringStringValue)4 TransactionId (com.navercorp.pinpoint.common.util.TransactionId)4 Put (org.apache.hadoop.hbase.client.Put)4 SpanChunkBo (com.navercorp.pinpoint.common.server.bo.SpanChunkBo)3