use of jdk.jfr.consumer.RecordedEvent in project splunk-otel-java by signalfx.
the class SpanContextualizerTest method contextEvent.
private static RecordedEvent contextEvent(String traceId, String spanId, long threadId) {
RecordedEvent event = mock(RecordedEvent.class);
EventType type = mock(EventType.class);
when(type.getName()).thenReturn(ContextAttached.EVENT_NAME);
when(event.getEventType()).thenReturn(type);
when(event.getString("traceId")).thenReturn(traceId);
when(event.getString("spanId")).thenReturn(spanId);
RecordedThread thread = mock(RecordedThread.class);
when(thread.getJavaThreadId()).thenReturn(threadId);
when(event.getThread()).thenReturn(thread);
return event;
}
use of jdk.jfr.consumer.RecordedEvent in project splunk-otel-java by signalfx.
the class EventProcessingChainTest method testLifecycle.
@Test
void testLifecycle() {
EventType contextAttachedType = newEventType(ContextAttached.EVENT_NAME);
EventType threadDumpType = newEventType(ThreadDumpProcessor.EVENT_NAME);
EventType tlabType = newEventType(TLABProcessor.NEW_TLAB_EVENT_NAME);
Instant now = Instant.now();
RecordedEvent tlab1 = newEvent(tlabType, now.minus(100, ChronoUnit.MILLIS));
RecordedEvent tlab2 = newEvent(tlabType, now.plus(100, ChronoUnit.MILLIS));
// context even happens after the thread dump but is seen first
RecordedEvent contextEvent = newEvent(contextAttachedType, now);
RecordedEvent threadDump = newEvent(threadDumpType, now.minus(250, ChronoUnit.MILLIS));
EventProcessingChain chain = new EventProcessingChain(contextualizer, threadDumpProcessor, tlabProcessor);
chain.accept(tlab1);
chain.accept(contextEvent);
chain.accept(tlab2);
chain.accept(threadDump);
verifyNoInteractions(contextualizer, threadDumpProcessor, tlabProcessor);
chain.flushBuffer();
InOrder inOrder = inOrder(contextualizer, threadDumpProcessor, tlabProcessor);
inOrder.verify(threadDumpProcessor).accept(threadDump);
inOrder.verify(tlabProcessor).accept(tlab1);
inOrder.verify(contextualizer).updateContext(contextEvent);
inOrder.verify(tlabProcessor).accept(tlab2);
inOrder.verifyNoMoreInteractions();
}
use of jdk.jfr.consumer.RecordedEvent in project splunk-otel-java by signalfx.
the class EventProcessingChainTest method eventsDispatchedInTimeOrder.
@Test
void eventsDispatchedInTimeOrder() {
EventType contextAttachedType = newEventType(ContextAttached.EVENT_NAME);
EventType threadDumpType = newEventType(ThreadDumpProcessor.EVENT_NAME);
Instant now = Instant.now();
RecordedEvent event1 = newEvent(contextAttachedType, now.plus(1, SECONDS));
RecordedEvent event2 = newEvent(contextAttachedType, now.plus(2, SECONDS));
RecordedEvent event3 = newEvent(threadDumpType, now.plus(3, SECONDS));
RecordedEvent event4 = newEvent(null, null);
// Our events are in time order: context1, context2, threadDump1, threadDump2.
// However, we will send them to the chain out of order: context2, context1, threadDump.
// Expectation is that we see them dispatched in the correct order.
// The "chunk" is finished only after event4, and event4 is part of a new chunk so is not
// dispatched.
EventProcessingChain.ChunkTracker chunkTracker = mock(EventProcessingChain.ChunkTracker.class);
when(chunkTracker.isNewChunk(isA(RecordedEvent.class))).thenReturn(false, false, false, true);
EventProcessingChain chain = new EventProcessingChain(contextualizer, threadDumpProcessor, tlabProcessor, chunkTracker);
// Out of order
chain.accept(event2);
// Out of order
chain.accept(event1);
chain.accept(event3);
chain.accept(event4);
InOrder ordered = inOrder(contextualizer, threadDumpProcessor);
ordered.verify(contextualizer).updateContext(event1);
ordered.verify(contextualizer).updateContext(event2);
ordered.verify(threadDumpProcessor).accept(event3);
ordered.verifyNoMoreInteractions();
}
use of jdk.jfr.consumer.RecordedEvent in project splunk-otel-java by signalfx.
the class JfrPathHandlerTest method testAccept.
@Test
void testAccept() {
Path path = Paths.get("/path/to/something.jfr");
EventProcessingChain chain = mock(EventProcessingChain.class);
Consumer<Path> onFileFinished = mock(Consumer.class);
RecordedEventStream.Factory eventStreamFactory = mock(RecordedEventStream.Factory.class);
RecordedEventStream recordedEventStream = mock(RecordedEventStream.class);
RecordedEvent e1 = mock(RecordedEvent.class);
RecordedEvent e2 = mock(RecordedEvent.class);
RecordedEvent e3 = mock(RecordedEvent.class);
AtomicBoolean closeWasCalled = new AtomicBoolean(false);
Stream<RecordedEvent> stream = Stream.of(e1, e2, e3).onClose(() -> closeWasCalled.set(true));
when(eventStreamFactory.get()).thenReturn(recordedEventStream);
when(recordedEventStream.open(path)).thenReturn(stream);
JfrPathHandler jfrPathHandler = JfrPathHandler.builder().eventProcessingChain(chain).onFileFinished(onFileFinished).recordedEventStreamFactory(eventStreamFactory).build();
jfrPathHandler.accept(path);
verify(chain).accept(e1);
verify(chain).accept(e2);
verify(chain).accept(e3);
verify(chain).flushBuffer();
verify(chain).logEventStats();
verifyNoMoreInteractions(chain);
verify(onFileFinished).accept(path);
assertTrue(closeWasCalled.get());
}
use of jdk.jfr.consumer.RecordedEvent in project splunk-otel-java by signalfx.
the class BasicJfrRecordingFileTest method testCloseException.
@Test
void testCloseException() throws Exception {
RecordedEvent ev = mock(RecordedEvent.class);
when(recordingFile.hasMoreEvents()).thenReturn(true, true, true, false);
when(jfr.openRecordingFile(path)).thenReturn(recordingFile);
when(jfr.readEvent(recordingFile, path)).thenReturn(ev);
doThrow(new IOException("it hurts")).when(recordingFile).close();
BasicJfrRecordingFile basicJfrRecordingFile = new BasicJfrRecordingFile(jfr);
Stream<RecordedEvent> stream = basicJfrRecordingFile.open(path);
stream.collect(Collectors.toList());
verify(recordingFile).close();
// no exception thrown, success
}
Aggregations