use of com.navercorp.pinpoint.profiler.context.id.DefaultTraceId in project pinpoint by naver.
the class SpanStreamSendDataPlanerTest method createSpan.
private Span createSpan(List<SpanEvent> spanEventList) {
DefaultTraceId traceId = new DefaultTraceId("test", 0, 1);
Span span = new Span();
for (SpanEvent spanEvent : spanEventList) {
span.addToSpanEventList(spanEvent);
}
span.setAgentId("agentId");
span.recordTraceId(traceId);
return span;
}
use of com.navercorp.pinpoint.profiler.context.id.DefaultTraceId in project pinpoint by naver.
the class InvokeMethodInterceptorTest method testValidHeaderExists.
/**
* Test valid header exists.
*/
@SuppressWarnings("unchecked")
@Test
public void testValidHeaderExists() {
when(request.getRequestURI()).thenReturn("/hellotest.nhn");
when(request.getRemoteAddr()).thenReturn("10.0.0.1");
TraceId traceId = new DefaultTraceId("agentTest", System.currentTimeMillis(), 1);
when(request.getHeader(Header.HTTP_TRACE_ID.toString())).thenReturn(traceId.getTransactionId());
when(request.getHeader(Header.HTTP_PARENT_SPAN_ID.toString())).thenReturn("PARENTSPANID");
when(request.getHeader(Header.HTTP_SPAN_ID.toString())).thenReturn("SPANID");
when(request.getHeader(Header.HTTP_SAMPLED.toString())).thenReturn("false");
when(request.getHeader(Header.HTTP_FLAGS.toString())).thenReturn("0");
final Enumeration<?> enumeration = mock(Enumeration.class);
when(request.getParameterNames()).thenReturn((Enumeration<String>) enumeration);
TraceContext traceContext = spyTraceContext();
final StandardHostValveInvokeInterceptor interceptor = new StandardHostValveInvokeInterceptor(traceContext, descriptor);
interceptor.before("target", new Object[] { request, response });
interceptor.after("target", new Object[] { request, response }, new Object(), null);
verify(traceContext, times(1)).continueTraceObject(any(TraceId.class));
interceptor.before("target", new Object[] { request, response });
interceptor.after("target", new Object[] { request, response }, new Object(), null);
verify(traceContext, times(2)).continueTraceObject(any(TraceId.class));
}
use of com.navercorp.pinpoint.profiler.context.id.DefaultTraceId in project pinpoint by naver.
the class DefaultTraceContextTest method parseTest.
@Test
public void parseTest() {
String agent = "test";
long agentStartTime = System.currentTimeMillis();
long agentTransactionCount = 10;
TraceId traceId = new DefaultTraceId(agent, agentStartTime, agentTransactionCount);
String id = traceId.getTransactionId();
logger.debug("id={}", id);
TransactionId transactionid = TransactionIdUtils.parseTransactionId(id);
Assert.assertEquals(transactionid.getAgentId(), agent);
Assert.assertEquals(transactionid.getAgentStartTime(), agentStartTime);
Assert.assertEquals(transactionid.getTransactionSequence(), agentTransactionCount);
}
use of com.navercorp.pinpoint.profiler.context.id.DefaultTraceId in project pinpoint by naver.
the class DefaultTraceContextTest method transactionCountTest.
@Test
public void transactionCountTest() {
final int samplingRate = 5;
final ProfilerConfig profilerConfig = Mockito.mock(ProfilerConfig.class);
Mockito.when(profilerConfig.isTraceAgentActiveThread()).thenReturn(true);
Mockito.when((profilerConfig.getSamplingRate())).thenReturn(samplingRate);
Mockito.when((profilerConfig.isSamplingEnable())).thenReturn(true);
MockTraceContextFactory mockTraceContextFactory = MockTraceContextFactory.newTestTraceContextFactory(profilerConfig);
final TraceContext traceContext = mockTraceContextFactory.getTraceContext();
final TransactionCounter transactionCounter = new DefaultTransactionCounter(mockTraceContextFactory.getIdGenerator());
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();
}
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());
}
use of com.navercorp.pinpoint.profiler.context.id.DefaultTraceId in project pinpoint by naver.
the class DefaultAsyncTraceIdTest method nextAsyncSequence.
@Test
public void nextAsyncSequence() throws Exception {
long agentStartTime = System.currentTimeMillis();
TraceId traceId = new DefaultTraceId("testAgentId", agentStartTime, 0);
AsyncTraceId asyncTraceId = new DefaultAsyncTraceId(traceId, 0, agentStartTime + 10);
Assert.assertEquals(asyncTraceId.nextAsyncSequence(), 1);
Assert.assertEquals(asyncTraceId.nextAsyncSequence(), 2);
Assert.assertEquals(asyncTraceId.nextAsyncSequence(), 3);
}
Aggregations