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