use of com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot in project pinpoint by naver.
the class OrderedSpanRecorderTest method testOrderingWithSameEventTime.
@Test
public void testOrderingWithSameEventTime() {
// given
final long startTime = 100;
final long spanId = 1L;
TraceId traceId = new DefaultTraceId(agentId, startTime, 0, -1L, spanId, (short) 0);
final TraceRoot traceRoot = new DefaultTraceRoot(traceId, agentId, startTime, 0);
Span span = createSpan(traceRoot, startTime);
SpanChunk event = wrapSpanChunk(traceRoot, createSpanEvent(traceRoot, 0, 0));
SpanChunk event1 = wrapSpanChunk(traceRoot, createSpanEvent(traceRoot, 0, 1));
SpanChunk event2 = wrapSpanChunk(traceRoot, createSpanEvent(traceRoot, 0, 2));
SpanChunk asyncEvent1_1 = wrapSpanChunk(traceRoot, createAsyncSpanEvent(traceRoot, 0, 0), new DefaultLocalAsyncId(1, (short) 1));
SpanChunk asyncEvent1_2 = wrapSpanChunk(traceRoot, createAsyncSpanEvent(traceRoot, 0, 1), new DefaultLocalAsyncId(1, (short) 1));
SpanChunk asyncEvent2 = wrapSpanChunk(traceRoot, createAsyncSpanEvent(traceRoot, 0, 0), new DefaultLocalAsyncId(2, (short) 1));
final List<SpanType> expectedOrder = Arrays.asList(span, event, event1, event2, asyncEvent1_1, asyncEvent1_2, asyncEvent2);
// when
final List<SpanType> listToBeHandled = Arrays.asList(span, event, event1, event2, asyncEvent1_1, asyncEvent1_2, asyncEvent2);
Collections.shuffle(listToBeHandled);
for (SpanType base : listToBeHandled) {
this.recorder.handleSend(base);
}
// then
ByteArrayOutputStream baos = new ByteArrayOutputStream();
this.recorder.print(new PrintStream(baos));
this.logger.debug(baos.toString());
for (SpanType expectedBase : expectedOrder) {
SpanType actualBase = this.recorder.pop();
assertSame(expectedBase, actualBase);
}
assertNull(this.recorder.pop());
}
use of com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot in project pinpoint by naver.
the class OrderedSpanRecorderTest method testMultipleSpanOrdering.
@Test
public void testMultipleSpanOrdering() {
// given
final long startTime1 = 100;
final long spanId1 = 1L;
final TraceId traceId1 = new DefaultTraceId(agentId, startTime1, 0, -1L, spanId1, (short) 0);
final TraceRoot traceRoot1 = new DefaultTraceRoot(traceId1, agentId, startTime1, 0);
final long startTime2 = startTime1 + 10L;
final long spanId2 = 2L;
final TraceId traceId2 = new DefaultTraceId(agentId, startTime2, 0, -1L, spanId2, (short) 0);
final TraceRoot traceRoot2 = new DefaultTraceRoot(traceId2, agentId, startTime2, 0);
Span span1 = createSpan(traceRoot1, startTime1);
SpanChunk event1_0 = wrapSpanChunk(traceRoot1, createSpanEvent(traceRoot1, 1, 0));
SpanChunk event1_1 = wrapSpanChunk(traceRoot1, createSpanEvent(traceRoot1, 2, 1));
SpanChunk asyncEvent1_0 = wrapSpanChunk(traceRoot1, createAsyncSpanEvent(traceRoot1, 1, 0), new DefaultLocalAsyncId(1, (short) 1));
SpanChunk asyncEvent1_1 = wrapSpanChunk(traceRoot1, createAsyncSpanEvent(traceRoot1, 2, 1), new DefaultLocalAsyncId(1, (short) 1));
Span span2 = createSpan(traceRoot2, startTime2);
SpanChunk event2_0 = wrapSpanChunk(traceRoot2, createSpanEvent(traceRoot2, 0, 0));
SpanChunk event2_1 = wrapSpanChunk(traceRoot2, createSpanEvent(traceRoot2, 1, 1));
SpanChunk asyncEvent2_0 = wrapSpanChunk(traceRoot2, createAsyncSpanEvent(traceRoot2, 0, 0), new DefaultLocalAsyncId(2, (short) 1));
final List<SpanType> expectedOrder = Arrays.asList(span1, event1_0, event1_1, span2, event2_0, event2_1, asyncEvent1_0, asyncEvent1_1, asyncEvent2_0);
// when
final List<SpanType> listToBeHandled = Arrays.asList(span1, event1_0, event1_1, span2, event2_0, event2_1, asyncEvent1_0, asyncEvent1_1, asyncEvent2_0);
Collections.shuffle(listToBeHandled);
for (SpanType base : listToBeHandled) {
this.recorder.handleSend(base);
}
// then
ByteArrayOutputStream baos = new ByteArrayOutputStream();
this.recorder.print(new PrintStream(baos));
this.logger.debug(baos.toString());
for (SpanType expectedBase : expectedOrder) {
SpanType actualBase = this.recorder.pop();
assertSame(expectedBase, actualBase);
}
assertNull(this.recorder.pop());
}
use of com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot in project pinpoint by naver.
the class SpanThriftMessageConverterTest method newSpanChunk.
private SpanChunk newSpanChunk() {
final TraceId traceId = new DefaultTraceId(AGENT_ID, AGENT_START_TIME, 1L);
final TraceRoot traceRoot = new DefaultTraceRoot(traceId, AGENT_ID, AGENT_START_TIME, 100L);
return new DefaultSpanChunk(traceRoot, Arrays.asList(new SpanEvent()));
}
use of com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot in project pinpoint by naver.
the class TraceTest method trace.
@Test
public void trace() {
final TraceId traceId = new DefaultTraceId(agentId, agentStartTime, 1);
final TraceRoot traceRoot = new DefaultTraceRoot(traceId, agentId, traceStartTime, 0);
final CallStack<SpanEvent> callStack = newCallStack();
final Span span = newSpan(traceRoot);
boolean root = span.getTraceRoot().getTraceId().isRoot();
SpanRecorder spanRecorder = new DefaultSpanRecorder(span, root, true, stringMetaDataService, sqlMetaDataService, errorHandler);
WrappedSpanEventRecorder wrappedSpanEventRecorder = new WrappedSpanEventRecorder(traceRoot, asyncContextFactory, stringMetaDataService, sqlMetaDataService, errorHandler);
AsyncContextFactory asyncContextFactory = mock(AsyncContextFactory.class);
Storage storage = mock(Storage.class);
Trace trace = new DefaultTrace(span, callStack, storage, true, spanRecorder, wrappedSpanEventRecorder, ActiveTraceHandle.EMPTY_HANDLE);
trace.traceBlockBegin();
// get data form db
getDataFromDB(trace);
// response to client
trace.traceBlockEnd();
verify(storage, times(2)).store(Mockito.any(SpanEvent.class));
verify(storage, never()).store(Mockito.any(Span.class));
}
use of com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot in project pinpoint by naver.
the class TraceTest method popEventTest.
@Test
public void popEventTest() {
final TraceId traceId = new DefaultTraceId(agentId, agentStartTime, 1);
final TraceRoot traceRoot = new DefaultTraceRoot(traceId, agentId, traceStartTime, 0);
final CallStack<SpanEvent> callStack = newCallStack();
final Span span = newSpan(traceRoot);
final boolean root = span.getTraceRoot().getTraceId().isRoot();
SpanRecorder spanRecorder = new DefaultSpanRecorder(span, root, true, stringMetaDataService, sqlMetaDataService, errorHandler);
WrappedSpanEventRecorder wrappedSpanEventRecorder = new WrappedSpanEventRecorder(traceRoot, asyncContextFactory, stringMetaDataService, sqlMetaDataService, errorHandler);
AsyncContextFactory asyncContextFactory = mock(AsyncContextFactory.class);
Storage storage = mock(Storage.class);
Trace trace = new DefaultTrace(span, callStack, storage, true, spanRecorder, wrappedSpanEventRecorder, ActiveTraceHandle.EMPTY_HANDLE);
trace.close();
verify(storage, never()).store(Mockito.any(SpanEvent.class));
verify(storage).store(Mockito.any(Span.class));
}
Aggregations