use of fish.payara.notification.requesttracing.RequestTraceSpan in project Payara by payara.
the class RequestEventStoreTest method testStoreEventMultipleThreads.
/**
* Test of storeEvent method utilising multiple threads ensuring traces are separate
*/
@Test
public void testStoreEventMultipleThreads() throws InterruptedException {
Thread thread1 = new Thread(new Runnable() {
@Override
public void run() {
long threadID = Thread.currentThread().getId();
RequestTraceSpan re = new RequestTraceSpan(EventType.TRACE_START, "Start" + threadID);
eventStore.storeEvent(re);
for (int i = 0; i < 100; i++) {
re = new RequestTraceSpan("Event-" + i + "-" + threadID);
eventStore.storeEvent(re);
}
eventStore.endTrace();
tracesbyThreadId.put(threadID, eventStore.getTrace());
}
});
Thread thread2 = new Thread(new Runnable() {
@Override
public void run() {
long threadID = Thread.currentThread().getId();
RequestTraceSpan re = new RequestTraceSpan(EventType.TRACE_START, "Start" + threadID);
eventStore.storeEvent(re);
for (int i = 0; i < 200; i++) {
re = new RequestTraceSpan("Event-" + i + "-" + threadID);
eventStore.storeEvent(re);
}
eventStore.endTrace();
tracesbyThreadId.put(threadID, eventStore.getTrace());
}
});
thread1.start();
thread2.start();
thread1.join();
thread2.join();
RequestTrace trace1 = tracesbyThreadId.get(thread1.getId());
RequestTrace trace2 = tracesbyThreadId.get(thread2.getId());
// make sure we have something of the correct length in each trace
assertNotNull(trace2);
assertNotNull(trace1);
assertEquals(201, trace2.getTraceSpans().size());
assertEquals(101, trace1.getTraceSpans().size());
// ensure they are different classes
assertNotSame(trace2, trace1);
// assert last names are correct
assertEquals("Event-99-" + thread1.getId(), trace1.getTraceSpans().getLast().getEventName());
assertEquals("Event-199-" + thread2.getId(), trace2.getTraceSpans().getLast().getEventName());
// assert start names are correct
assertEquals("Start" + thread1.getId(), trace1.getTraceSpans().getFirst().getEventName());
assertEquals("Start" + thread2.getId(), trace2.getTraceSpans().getFirst().getEventName());
// assert all conversation IDs are correct trace 1
UUID convID = trace1.getTraceSpans().getFirst().getTraceId();
for (RequestTraceSpan re : trace1.getTraceSpans()) {
assertEquals(convID, re.getTraceId());
}
// assert all conversation IDs are correct trace 2
UUID convID2 = trace2.getTraceSpans().getFirst().getTraceId();
for (RequestTraceSpan re : trace2.getTraceSpans()) {
assertEquals(convID2, re.getTraceId());
}
}
use of fish.payara.notification.requesttracing.RequestTraceSpan in project Payara by payara.
the class RequestEventStoreTest method testGetElapsedTime.
/**
* Test of getElapsedTime method, of class RequestEventStore.
* @throws java.lang.InterruptedException
*/
@Test
public void testGetElapsedTime() throws InterruptedException {
RequestTraceSpan re = new RequestTraceSpan(EventType.TRACE_START, "Start");
eventStore.storeEvent(re);
Thread.sleep(100);
eventStore.storeEvent(new RequestTraceSpan("Test"));
eventStore.endTrace();
assertEquals(2, eventStore.getTrace().getTraceSpans().size());
assertTrue(eventStore.getElapsedTime() >= 90);
}
use of fish.payara.notification.requesttracing.RequestTraceSpan in project Payara by payara.
the class RequestEventStoreTest method testResettingConversationID.
@Test
public void testResettingConversationID() {
RequestTraceSpan re = new RequestTraceSpan(EventType.TRACE_START, "Start");
eventStore.storeEvent(re);
for (int i = 0; i < 10; i++) {
re = new RequestTraceSpan("Event-" + i);
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
Logger.getLogger(RequestEventStoreTest.class.getName()).log(Level.SEVERE, null, ex);
}
eventStore.storeEvent(re);
}
// eventStore.storeEvent(new RequesTraceSpan(EventType.TRACE_END, "End"));
eventStore.endTrace();
UUID oldID = eventStore.getTrace().getTraceSpans().getFirst().getTraceId();
UUID newID = UUID.randomUUID();
eventStore.setTraceId(newID);
for (RequestTraceSpan event : eventStore.getTrace().getTraceSpans()) {
assertEquals(newID, event.getTraceId());
}
}
use of fish.payara.notification.requesttracing.RequestTraceSpan in project Payara by payara.
the class RequestTraceTest method testJSONParse.
@Test
public void testJSONParse() {
RequestTraceSpan re = new RequestTraceSpan(EventType.TRACE_START, "Start");
trace.addEvent(re);
for (int i = 0; i < 1000; i++) {
re = new RequestTraceSpan("Event" + i);
trace.addEvent(re);
}
trace.endTrace();
String jsonString = trace.toString();
JsonReader jsonReader = Json.createReader(new StringReader(jsonString));
jsonReader.readObject();
}
use of fish.payara.notification.requesttracing.RequestTraceSpan in project Payara by payara.
the class RequestTraceTest method testMultipleStartEvents.
@Test
public void testMultipleStartEvents() {
RequestTraceSpan re = new RequestTraceSpan(EventType.TRACE_START, "Start");
trace.addEvent(re);
re = new RequestTraceSpan("Event1");
trace.addEvent(re);
trace.endTrace();
assertEquals(2, trace.getTraceSpans().size());
re = new RequestTraceSpan(EventType.TRACE_START, "Start2");
trace.addEvent(re);
assertEquals(1, trace.getTraceSpans().size());
assertEquals("Start2", trace.getTraceSpans().getFirst().getEventName());
}
Aggregations