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));
}
}
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);
}
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);
}
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);
}
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;
}
Aggregations