Search in sources :

Example 1 with TransactionCounter

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());
}
Also used : DefaultApplicationContext(com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext) DefaultTransactionCounter(com.navercorp.pinpoint.profiler.context.id.DefaultTransactionCounter) DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) ProfilerConfig(com.navercorp.pinpoint.bootstrap.config.ProfilerConfig) DefaultProfilerConfig(com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig) TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) DefaultTransactionCounter(com.navercorp.pinpoint.profiler.context.id.DefaultTransactionCounter) TransactionCounter(com.navercorp.pinpoint.profiler.context.id.TransactionCounter) IdGenerator(com.navercorp.pinpoint.profiler.context.id.IdGenerator) Test(org.junit.Test)

Aggregations

DefaultProfilerConfig (com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig)1 ProfilerConfig (com.navercorp.pinpoint.bootstrap.config.ProfilerConfig)1 TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)1 DefaultTraceId (com.navercorp.pinpoint.profiler.context.id.DefaultTraceId)1 DefaultTransactionCounter (com.navercorp.pinpoint.profiler.context.id.DefaultTransactionCounter)1 IdGenerator (com.navercorp.pinpoint.profiler.context.id.IdGenerator)1 TransactionCounter (com.navercorp.pinpoint.profiler.context.id.TransactionCounter)1 DefaultApplicationContext (com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext)1 Test (org.junit.Test)1