Search in sources :

Example 11 with FixedBuffer

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

the class DirectBufferCodecTest method encodeAndDecodeTest.

@Test
public void encodeAndDecodeTest() {
    final String id = "test_app";
    final long currentTime = new Date().getTime();
    final AgentStatDataPointCodec agentStatDataPointCodec = new AgentStatDataPointCodec();
    final DirectBufferCodec directBufferCodec = new DirectBufferCodec(agentStatDataPointCodec);
    final Buffer encodedValueBuffer = new AutomaticBuffer();
    final List<JoinStatBo> joinDirectBufferBoList = createJoinDirectBufferBoList(currentTime);
    encodedValueBuffer.putByte(directBufferCodec.getVersion());
    directBufferCodec.encodeValues(encodedValueBuffer, joinDirectBufferBoList);
    final Buffer valueBuffer = new FixedBuffer(encodedValueBuffer.getBuffer());
    ;
    final long baseTimestamp = AgentStatUtils.getBaseTimestamp(currentTime);
    final long timestampDelta = currentTime - baseTimestamp;
    final ApplicationStatDecodingContext decodingContext = new ApplicationStatDecodingContext();
    decodingContext.setApplicationId(id);
    decodingContext.setBaseTimestamp(baseTimestamp);
    decodingContext.setTimestampDelta(timestampDelta);
    assertEquals(valueBuffer.readByte(), directBufferCodec.getVersion());
    List<JoinStatBo> decodedJoinDirectBufferBoList = directBufferCodec.decodeValues(valueBuffer, decodingContext);
    for (int i = 0; i < decodedJoinDirectBufferBoList.size(); i++) {
        assertEquals(decodedJoinDirectBufferBoList.get(i), joinDirectBufferBoList.get(i));
    }
}
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) ApplicationStatDecodingContext(com.navercorp.pinpoint.common.server.bo.serializer.stat.ApplicationStatDecodingContext) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) JoinStatBo(com.navercorp.pinpoint.common.server.bo.stat.join.JoinStatBo) Date(java.util.Date) AgentStatDataPointCodec(com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec) Test(org.junit.Test)

Example 12 with FixedBuffer

use of com.navercorp.pinpoint.common.buffer.FixedBuffer 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 13 with FixedBuffer

use of com.navercorp.pinpoint.common.buffer.FixedBuffer 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 14 with FixedBuffer

use of com.navercorp.pinpoint.common.buffer.FixedBuffer 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 15 with FixedBuffer

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

the class AgentInfoMapper method createBuilderFromValue.

private AgentInfoBo.Builder createBuilderFromValue(byte[] serializedAgentInfo) {
    final Buffer buffer = new FixedBuffer(serializedAgentInfo);
    final AgentInfoBo.Builder builder = new AgentInfoBo.Builder();
    builder.setHostName(buffer.readPrefixedString());
    builder.setIp(buffer.readPrefixedString());
    builder.setPorts(buffer.readPrefixedString());
    builder.setApplicationName(buffer.readPrefixedString());
    builder.setServiceTypeCode(buffer.readShort());
    builder.setPid(buffer.readInt());
    builder.setAgentVersion(buffer.readPrefixedString());
    builder.setStartTime(buffer.readLong());
    builder.setEndTimeStamp(buffer.readLong());
    builder.setEndStatus(buffer.readInt());
    // FIXME - 2015.09 v1.5.0 added vmVersion (check for compatibility)
    if (buffer.hasRemaining()) {
        builder.setVmVersion(buffer.readPrefixedString());
    }
    // FIXME - 2018.06 v1.8.0 added container (check for compatibility)
    if (buffer.hasRemaining()) {
        builder.isContainer(buffer.readBoolean());
    }
    // 2021.03.24 added agent name
    if (buffer.hasRemaining()) {
        builder.setAgentName(buffer.readPrefixedString());
    }
    return builder;
}
Also used : FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) Buffer(com.navercorp.pinpoint.common.buffer.Buffer) AgentInfoBo(com.navercorp.pinpoint.common.server.bo.AgentInfoBo) FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer)

Aggregations

Buffer (com.navercorp.pinpoint.common.buffer.Buffer)39 FixedBuffer (com.navercorp.pinpoint.common.buffer.FixedBuffer)39 AutomaticBuffer (com.navercorp.pinpoint.common.buffer.AutomaticBuffer)23 Test (org.junit.Test)16 AgentStatDataPointCodec (com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec)10 ApplicationStatDecodingContext (com.navercorp.pinpoint.common.server.bo.serializer.stat.ApplicationStatDecodingContext)10 JoinStatBo (com.navercorp.pinpoint.common.server.bo.stat.join.JoinStatBo)10 Date (java.util.Date)10 ByteBuffer (java.nio.ByteBuffer)5 Cell (org.apache.hadoop.hbase.Cell)4 ArrayList (java.util.ArrayList)3 AgentInfoBo (com.navercorp.pinpoint.common.server.bo.AgentInfoBo)2 AgentStatDecodingContext (com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext)2 AgentStatDataPoint (com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint)2 IntStringStringValue (com.navercorp.pinpoint.common.util.IntStringStringValue)2 LinkDataMap (com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataMap)2 Application (com.navercorp.pinpoint.web.vo.Application)2 OffsetFixedBuffer (com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer)1 AgentLifeCycleBo (com.navercorp.pinpoint.common.server.bo.AgentLifeCycleBo)1 ApiMetaDataBo (com.navercorp.pinpoint.common.server.bo.ApiMetaDataBo)1