use of com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext 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.server.bo.serializer.stat.AgentStatDecodingContext 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 = RANDOM.nextInt(20) + 1;
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.server.bo.serializer.stat.AgentStatDecodingContext in project pinpoint by naver.
the class AgentStatMapperV2 method mapRow.
@Override
public List<T> mapRow(Result result, int rowNum) throws Exception {
if (result.isEmpty()) {
return Collections.emptyList();
}
final byte[] distributedRowKey = result.getRow();
final String agentId = this.hbaseOperationFactory.getAgentId(distributedRowKey);
final long baseTimestamp = this.hbaseOperationFactory.getBaseTimestamp(distributedRowKey);
List<T> dataPoints = new ArrayList<>();
for (Cell cell : result.rawCells()) {
if (CellUtil.matchingFamily(cell, HBaseTables.AGENT_STAT_CF_STATISTICS)) {
Buffer qualifierBuffer = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
Buffer valueBuffer = new OffsetFixedBuffer(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
long timestampDelta = this.decoder.decodeQualifier(qualifierBuffer);
AgentStatDecodingContext decodingContext = new AgentStatDecodingContext();
decodingContext.setAgentId(agentId);
decodingContext.setBaseTimestamp(baseTimestamp);
decodingContext.setTimestampDelta(timestampDelta);
List<T> candidates = this.decoder.decodeValue(valueBuffer, decodingContext);
for (T candidate : candidates) {
if (filter(candidate)) {
continue;
}
dataPoints.add(candidate);
}
}
}
// Reverse sort as timestamp is stored in a reversed order.
Collections.sort(dataPoints, REVERSE_TIMESTAMP_COMPARATOR);
return dataPoints;
}
Aggregations