Search in sources :

Example 31 with FixedBuffer

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

the class TransactionCodecTest method encodeValuesTest.

@Test
public void encodeValuesTest() {
    final String id = "test_app";
    final long currentTime = new Date().getTime();
    TransactionCodec transactionCodec = new TransactionCodec(new AgentStatDataPointCodec());
    final Buffer encodedValueBuffer = new AutomaticBuffer();
    final List<JoinStatBo> joinTransactionBoList = createJoinTransactionBoList(currentTime);
    encodedValueBuffer.putByte(transactionCodec.getVersion());
    transactionCodec.encodeValues(encodedValueBuffer, joinTransactionBoList);
    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(), transactionCodec.getVersion());
    List<JoinStatBo> decodedJoinTransactionBoList = transactionCodec.decodeValues(valueBuffer, decodingContext);
    for (int i = 0; i < decodedJoinTransactionBoList.size(); i++) {
        assertEquals(decodedJoinTransactionBoList.get(i), joinTransactionBoList.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 32 with FixedBuffer

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

the class BytesUtilsTest method assertVar32.

private void assertVar32(int value) {
    final int computeBufferSize = BytesUtils.computeVar32Size(value);
    final byte[] bytes = new byte[computeBufferSize];
    BytesUtils.writeVar32(value, bytes, 0);
    final Buffer buffer = new FixedBuffer(bytes);
    final int varInt = buffer.readVInt();
    Assert.assertEquals("check value", value, varInt);
    assertEquals("check buffer size", buffer.getOffset(), computeBufferSize);
    final int varInt_ByteUtils1 = BytesUtils.bytesToVar32(buffer.getBuffer(), 0);
    Assert.assertEquals("check value", value, varInt_ByteUtils1);
    final byte[] max_buffer = new byte[BytesUtils.VLONG_MAX_SIZE];
    BytesUtils.writeVar32(value, max_buffer, 0);
    final int varInt_ByteUtils2 = BytesUtils.bytesToVar32(max_buffer, 0);
    Assert.assertEquals("check value", value, varInt_ByteUtils2);
}
Also used : FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) Buffer(com.navercorp.pinpoint.common.buffer.Buffer) ByteBuffer(java.nio.ByteBuffer) FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer)

Example 33 with FixedBuffer

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

the class BytesUtilsTest method assertVar64.

private void assertVar64(long value) {
    final int computeBufferSize = BytesUtils.computeVar64Size(value);
    final byte[] bytes = new byte[computeBufferSize];
    BytesUtils.writeVar64(value, bytes, 0);
    final Buffer buffer = new FixedBuffer(bytes);
    final long varLong = buffer.readVLong();
    Assert.assertEquals("check value", value, varLong);
    assertEquals("check buffer size", buffer.getOffset(), computeBufferSize);
    final long varLong_ByteUtils1 = BytesUtils.bytesToVar64(buffer.getBuffer(), 0);
    Assert.assertEquals("check value", value, varLong_ByteUtils1);
    final byte[] max_buffer = new byte[BytesUtils.VLONG_MAX_SIZE];
    BytesUtils.writeVar64(value, max_buffer, 0);
    final long varLong_ByteUtils2 = BytesUtils.bytesToVar64(max_buffer, 0);
    Assert.assertEquals("check value", value, varLong_ByteUtils2);
}
Also used : FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) Buffer(com.navercorp.pinpoint.common.buffer.Buffer) ByteBuffer(java.nio.ByteBuffer) FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer)

Example 34 with FixedBuffer

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

the class EncodingStrategyTestBase method testStrategy.

public <T> void testStrategy(List<T> expectedValues, EncodingStrategy<T> strategy) {
    Buffer encodeBuffer = new AutomaticBuffer();
    strategy.encodeValues(encodeBuffer, expectedValues);
    Buffer decodeBuffer = new FixedBuffer(encodeBuffer.getBuffer());
    List<T> actualValues = strategy.decodeValues(decodeBuffer, expectedValues.size());
    Assert.assertEquals(expectedValues, actualValues);
}
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)

Example 35 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