use of com.navercorp.pinpoint.profiler.context.id.TransactionCounter in project pinpoint by naver.
the class DefaultTraceContextTest method transactionCountTest.
@Test
public void transactionCountTest() {
final int samplingRate = 5;
final ProfilerConfig profilerConfig = getProfilerConfig();
Mockito.when((profilerConfig.readInt(CountingSamplerFactory.LEGACY_SAMPLING_RATE_NAME, -1))).thenReturn(samplingRate);
Mockito.when((profilerConfig.readBoolean(SamplerConfig.SAMPLER_ENABLE_NAME, true))).thenReturn(true);
DefaultApplicationContext customContext = MockTraceContextFactory.newMockApplicationContext(profilerConfig);
customContext.start();
final TraceContext traceContext = customContext.getTraceContext();
IdGenerator idGenerator = customContext.getInjector().getInstance(IdGenerator.class);
final TransactionCounter transactionCounter = new DefaultTransactionCounter(idGenerator);
final long newTransactionCount = 22L;
@SuppressWarnings("unused") final long expectedSampledNewCount = newTransactionCount / samplingRate + (newTransactionCount % samplingRate > 0 ? 1 : 0);
final long expectedUnsampledNewCount = newTransactionCount - expectedSampledNewCount;
for (int i = 0; i < newTransactionCount; i++) {
traceContext.newTraceObject();
traceContext.removeTraceObject();
}
final long expectedSampledContinuationCount = 5L;
for (int i = 0; i < expectedSampledContinuationCount; i++) {
traceContext.continueTraceObject(new DefaultTraceId("agentId", 0L, i));
traceContext.removeTraceObject();
}
final long expectedUnsampledContinuationCount = 10L;
for (int i = 0; i < expectedUnsampledContinuationCount; i++) {
traceContext.disableSampling();
traceContext.removeTraceObject();
}
customContext.close();
final long expectedTotalTransactionCount = expectedSampledNewCount + expectedUnsampledNewCount + expectedSampledContinuationCount + expectedUnsampledContinuationCount;
Assert.assertEquals(expectedSampledNewCount, transactionCounter.getSampledNewCount());
Assert.assertEquals(expectedUnsampledNewCount, transactionCounter.getUnSampledNewCount());
Assert.assertEquals(expectedSampledContinuationCount, transactionCounter.getSampledContinuationCount());
Assert.assertEquals(expectedUnsampledContinuationCount, transactionCounter.getUnSampledContinuationCount());
Assert.assertEquals(expectedTotalTransactionCount, transactionCounter.getTotalTransactionCount());
}
Aggregations