Search in sources :

Example 1 with Error

use of com.newrelic.agent.introspec.Error in project newrelic-java-agent by newrelic.

the class IntrospectorImplTest method testErrorOutsideTransaction.

@Test
public void testErrorOutsideTransaction() {
    Throwable throwable = new Throwable("MyTest");
    ServiceFactory.getRPMService().getErrorService().reportException(throwable);
    // data check
    Collection<String> txNames = impl.getTransactionNames();
    Assert.assertEquals(0, txNames.size());
    Collection<Error> errors1 = impl.getErrors();
    Assert.assertEquals(1, errors1.size());
    Error error1 = errors1.iterator().next();
    Assert.assertEquals("MyTest", error1.getErrorMessage());
    Assert.assertEquals(throwable, error1.getThrowable());
    Collection<ErrorEvent> events = impl.getErrorEvents();
    Assert.assertEquals(1, events.size());
    ErrorEvent event = events.iterator().next();
    // well that seems wrong - but that seems to be what we name all errors
    Assert.assertEquals("TransactionError", event.getType());
    Assert.assertEquals("MyTest", event.getErrorMessage());
    Assert.assertEquals("java.lang.Throwable", event.getErrorClass());
    Assert.assertEquals("Unknown", event.getTransactionName());
}
Also used : ErrorEvent(com.newrelic.agent.introspec.ErrorEvent) Error(com.newrelic.agent.introspec.Error) Test(org.junit.Test)

Example 2 with Error

use of com.newrelic.agent.introspec.Error in project newrelic-java-agent by newrelic.

the class IntrospectorImplTest method testErrorInTx.

@Test
public void testErrorInTx() {
    // transaction
    Transaction.getTransaction();
    Tracer rootTracer = createOtherTracer("rootOnly");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(rootTracer);
    Throwable throwable = new Throwable("MyTest");
    Transaction.getTransaction().setThrowable(throwable, TransactionErrorPriority.TRACER, false);
    rootTracer.finish(RETURN_OPCODE, 0);
    // data check
    Collection<String> txNames = impl.getTransactionNames();
    Assert.assertEquals(1, txNames.size());
    Assert.assertEquals("OtherTransaction/rootOnly", txNames.iterator().next());
    Collection<Error> errors1 = impl.getErrors();
    Collection<Error> errors2 = impl.getErrorsForTransaction("OtherTransaction/rootOnly");
    Assert.assertEquals(1, errors1.size());
    Assert.assertEquals(1, errors2.size());
    Error error1 = errors1.iterator().next();
    Assert.assertEquals(error1, errors2.iterator().next());
    Assert.assertEquals("MyTest", error1.getErrorMessage());
    Assert.assertEquals(throwable, error1.getThrowable());
    Assert.assertEquals(1, impl.getTransactionEvents(txNames.iterator().next()).size());
    Collection<ErrorEvent> events = impl.getErrorEvents();
    Assert.assertEquals(1, events.size());
    ErrorEvent event1 = events.iterator().next();
    Assert.assertEquals("TransactionError", event1.getType());
    Assert.assertEquals("MyTest", event1.getErrorMessage());
    Assert.assertEquals("java.lang.Throwable", event1.getErrorClass());
    Assert.assertEquals("OtherTransaction/rootOnly", event1.getTransactionName());
    Collection<ErrorEvent> txEvents = impl.getErrorEventsForTransaction("OtherTransaction/rootOnly");
    Assert.assertEquals(1, txEvents.size());
    Event event2 = events.iterator().next();
    Assert.assertEquals("TransactionError", event2.getType());
    Assert.assertEquals(event1, event2);
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) ErrorEvent(com.newrelic.agent.introspec.ErrorEvent) Error(com.newrelic.agent.introspec.Error) Event(com.newrelic.agent.introspec.Event) ErrorEvent(com.newrelic.agent.introspec.ErrorEvent) Test(org.junit.Test)

Aggregations

Error (com.newrelic.agent.introspec.Error)2 ErrorEvent (com.newrelic.agent.introspec.ErrorEvent)2 Test (org.junit.Test)2 Event (com.newrelic.agent.introspec.Event)1 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)1 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)1 Tracer (com.newrelic.agent.tracers.Tracer)1