Search in sources :

Example 21 with RequestTraceSpan

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());
    }
}
Also used : RequestTraceSpan(fish.payara.notification.requesttracing.RequestTraceSpan) RequestTrace(fish.payara.notification.requesttracing.RequestTrace) UUID(java.util.UUID) Test(org.junit.Test)

Example 22 with RequestTraceSpan

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);
}
Also used : RequestTraceSpan(fish.payara.notification.requesttracing.RequestTraceSpan) Test(org.junit.Test)

Example 23 with RequestTraceSpan

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());
    }
}
Also used : RequestTraceSpan(fish.payara.notification.requesttracing.RequestTraceSpan) UUID(java.util.UUID) Test(org.junit.Test)

Example 24 with RequestTraceSpan

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();
}
Also used : StringReader(java.io.StringReader) RequestTraceSpan(fish.payara.notification.requesttracing.RequestTraceSpan) JsonReader(javax.json.JsonReader) Test(org.junit.Test)

Example 25 with RequestTraceSpan

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());
}
Also used : RequestTraceSpan(fish.payara.notification.requesttracing.RequestTraceSpan) Test(org.junit.Test)

Aggregations

RequestTraceSpan (fish.payara.notification.requesttracing.RequestTraceSpan)30 Test (org.junit.Test)13 FaultToleranceService (fish.payara.microprofile.faulttolerance.FaultToleranceService)3 RequestTrace (fish.payara.notification.requesttracing.RequestTrace)3 UUID (java.util.UUID)3 InvocationManager (org.glassfish.api.invocation.InvocationManager)3 Principal (java.security.Principal)2 ServletException (javax.servlet.ServletException)2 Config (org.eclipse.microprofile.config.Config)2 Endpoint (org.glassfish.webservices.monitoring.Endpoint)2 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)1 WebServiceEndpoint (com.sun.enterprise.deployment.WebServiceEndpoint)1 SecurityContext (com.sun.enterprise.security.SecurityContext)1 WebPrincipal (com.sun.enterprise.security.web.integration.WebPrincipal)1 ServletAdapter (com.sun.xml.ws.transport.http.servlet.ServletAdapter)1 RequestTracingService (fish.payara.nucleus.requesttracing.RequestTracingService)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 ChronoUnit (java.time.temporal.ChronoUnit)1