Search in sources :

Example 1 with TransactionTimer

use of com.newrelic.agent.transaction.TransactionTimer in project newrelic-java-agent by newrelic.

the class TransactionDataTest method getEndTimeInNanos.

@Test
public void getEndTimeInNanos() {
    long expected = System.nanoTime();
    TransactionTimer mock = Mockito.mock(TransactionTimer.class);
    Mockito.when(mock.getEndTimeInNanos()).thenReturn(expected);
    Mockito.when(tx.getTransactionTimer()).thenReturn(mock);
    TransactionData txd = getTxData(tx);
    long result = txd.getEndTimeInNanos();
    Assert.assertEquals(expected, result);
}
Also used : TransactionTimer(com.newrelic.agent.transaction.TransactionTimer) Test(org.junit.Test)

Example 2 with TransactionTimer

use of com.newrelic.agent.transaction.TransactionTimer in project newrelic-java-agent by newrelic.

the class TransactionDataTest method getStartTimeInNanos.

@Test
public void getStartTimeInNanos() {
    long expected = System.nanoTime();
    TransactionTimer mock = Mockito.mock(TransactionTimer.class);
    Mockito.when(mock.getStartTimeInNanos()).thenReturn(expected);
    Mockito.when(tx.getTransactionTimer()).thenReturn(mock);
    TransactionData txd = getTxData(tx);
    long result = txd.getStartTimeInNanos();
    Assert.assertEquals(expected, result);
}
Also used : TransactionTimer(com.newrelic.agent.transaction.TransactionTimer) Test(org.junit.Test)

Example 3 with TransactionTimer

use of com.newrelic.agent.transaction.TransactionTimer in project newrelic-java-agent by newrelic.

the class TransactionDataTestBuilder method build.

public TransactionData build() {
    when(tx.getRootTracer()).thenReturn(tracer);
    if (synJobId == null || synMonitorId == null || synResourceId == null) {
        when(tx.isSynthetic()).thenReturn(false);
    } else {
        when(tx.isSynthetic()).thenReturn(true);
    }
    when(tx.getGuid()).thenReturn("guid");
    Dispatcher mockDispatcher = mock(Dispatcher.class);
    when(mockDispatcher.getUri()).thenReturn(requestUri);
    when(mockDispatcher.isWebTransaction()).thenReturn(dispatcher == null ? true : dispatcher.isWebTransaction());
    when(tx.getDispatcher()).thenReturn(mockDispatcher);
    if (throwable != null) {
        when(tx.getThrowable()).thenReturn(new TransactionThrowable(throwable, expectedError, null));
    }
    PriorityTransactionName priorityTransactionName = mock(PriorityTransactionName.class);
    when(priorityTransactionName.getName()).thenReturn(frontendMetricName);
    when(tx.getPriorityTransactionName()).thenReturn(priorityTransactionName);
    Map<String, Map<String, String>> prefixed = new HashMap<>();
    prefixed.put("request.parameters.", requestParams);
    when(tx.getPrefixedAgentAttributes()).thenReturn(prefixed);
    when(tx.getUserAttributes()).thenReturn(userParams);
    when(tx.getAgentAttributes()).thenReturn(agentParams);
    when(tx.getErrorAttributes()).thenReturn(errorParams);
    when(tx.getIntrinsicAttributes()).thenReturn(intrinsics);
    when(tx.isIgnore()).thenReturn(false);
    when(tx.getStatus()).thenReturn(responseStatus);
    when(tx.getStatusMessage()).thenReturn(statusMessage);
    when(tx.isErrorReportableAndNotIgnored()).thenReturn(true);
    when(tx.getSpanProxy()).thenReturn(new SpanProxy());
    ErrorServiceImpl errorService = mock(ErrorServiceImpl.class);
    IRPMService rpmService = mock(IRPMService.class);
    when(rpmService.getApplicationName()).thenReturn(appName);
    when(rpmService.getErrorService()).thenReturn(errorService);
    when(tx.getRPMService()).thenReturn(rpmService);
    when(tx.getAgentConfig()).thenReturn(agentConfig);
    when(tx.getWallClockStartTimeMs()).thenReturn(startTime);
    if (slowQueryListener != null) {
        when(tx.getSlowQueryListener(anyBoolean())).thenReturn(slowQueryListener);
    }
    when(tx.getTracers()).thenReturn(tracers);
    CrossProcessTransactionState crossProcessTransactionState = mock(CrossProcessTransactionState.class);
    when(tx.getCrossProcessTransactionState()).thenReturn(crossProcessTransactionState);
    when(crossProcessTransactionState.getTripId()).thenReturn("tripId");
    InboundHeaderState ihs = mock(InboundHeaderState.class);
    when(ihs.getSyntheticsJobId()).thenReturn(synJobId);
    when(ihs.getSyntheticsMonitorId()).thenReturn(synMonitorId);
    when(ihs.getSyntheticsResourceId()).thenReturn(synResourceId);
    when(ihs.getSyntheticsVersion()).thenReturn(HeadersUtil.SYNTHETICS_MIN_VERSION);
    when(tx.getInboundHeaderState()).thenReturn(ihs);
    TransactionTimer timer = new TransactionTimer(tracer.getStartTime());
    timer.markTransactionActivityAsDone(tracer.getEndTime(), tracer.getDuration());
    timer.markTransactionAsDone();
    when(tx.getTransactionTimer()).thenReturn(timer);
    // when(tx.getApplicationName()).thenReturn(appName);
    Set<TransactionActivity> activities = new HashSet<>();
    for (Map.Entry<Long, Collection<Duration>> entry : threadIdToDuration.asMap().entrySet()) {
        for (Duration duration : entry.getValue()) {
            TransactionActivity activity = mock(TransactionActivity.class);
            when(activity.getThreadId()).thenReturn(entry.getKey());
            Tracer rootTracer = mock(Tracer.class);
            when(rootTracer.getStartTime()).thenReturn(duration.startTime);
            when(rootTracer.getEndTime()).thenReturn(duration.endTime);
            when(activity.getRootTracer()).thenReturn(rootTracer);
            activities.add(activity);
        }
    }
    when(tx.getFinishedChildren()).thenReturn(activities);
    if (includeDistributedTracePayload) {
        SpanProxy spanProxy = mock(SpanProxy.class);
        DistributedTracePayloadImpl payload = DistributedTracePayloadImpl.createDistributedTracePayload("abc", "def", "def", new Random().nextFloat());
        when(spanProxy.getInboundDistributedTracePayload()).thenReturn(payload);
        when(tx.getSpanProxy()).thenReturn(spanProxy);
    }
    return new TransactionData(tx, 0);
}
Also used : ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) HashMap(java.util.HashMap) SpanProxy(com.newrelic.agent.tracing.SpanProxy) Tracer(com.newrelic.agent.tracers.Tracer) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl) Random(java.util.Random) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) Collection(java.util.Collection) TransactionTimer(com.newrelic.agent.transaction.TransactionTimer) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 4 with TransactionTimer

use of com.newrelic.agent.transaction.TransactionTimer in project newrelic-java-agent by newrelic.

the class TransactionDataTest method getDuration.

@Test
public void getDuration() {
    long expected = System.nanoTime();
    TransactionTimer mock = Mockito.mock(TransactionTimer.class);
    Mockito.when(mock.getResponseTimeInNanos()).thenReturn(expected);
    Mockito.when(tx.getTransactionTimer()).thenReturn(mock);
    TransactionData txd = getTxData(tx);
    long result = txd.getLegacyDuration();
    Assert.assertEquals(expected, result, 0);
}
Also used : TransactionTimer(com.newrelic.agent.transaction.TransactionTimer) Test(org.junit.Test)

Example 5 with TransactionTimer

use of com.newrelic.agent.transaction.TransactionTimer in project newrelic-java-agent by newrelic.

the class TransactionDataTest method toString2.

@Test
public void toString2() {
    Tracer dispatcherMock = Mockito.mock(Tracer.class);
    Mockito.when(tx.getRootTracer()).thenReturn(dispatcherMock);
    long expected = System.nanoTime();
    TransactionTimer mockTime = Mockito.mock(TransactionTimer.class);
    Mockito.when(mockTime.getResponseTimeInMilliseconds()).thenReturn(expected);
    Mockito.when(tx.getTransactionTimer()).thenReturn(mockTime);
    Tracer mock = Mockito.mock(Tracer.class);
    Mockito.when(tx.getRootTracer()).thenReturn(mock);
    Throwable ex = new Exception();
    Mockito.when(tx.getThrowable()).thenReturn(new TransactionThrowable(ex, false, null));
    TransactionData txd = getTxData(tx);
    String result = txd.toString();
    Assert.assertEquals(MessageFormat.format(" {0}ms {1}", String.valueOf(expected), ex), result);
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) TransactionTimer(com.newrelic.agent.transaction.TransactionTimer) Test(org.junit.Test)

Aggregations

TransactionTimer (com.newrelic.agent.transaction.TransactionTimer)10 Test (org.junit.Test)6 Tracer (com.newrelic.agent.tracers.Tracer)4 Transaction (com.newrelic.agent.Transaction)2 TransactionData (com.newrelic.agent.TransactionData)2 Dispatcher (com.newrelic.agent.dispatchers.Dispatcher)2 TransactionThrowable (com.newrelic.agent.transaction.TransactionThrowable)2 HashMap (java.util.HashMap)2 CrossProcessTransactionState (com.newrelic.agent.CrossProcessTransactionState)1 MockDispatcher (com.newrelic.agent.MockDispatcher)1 AgentConfig (com.newrelic.agent.config.AgentConfig)1 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)1 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)1 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)1 MethodExitTracer (com.newrelic.agent.tracers.MethodExitTracer)1 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)1 TransactionActivityInitiator (com.newrelic.agent.tracers.TransactionActivityInitiator)1 DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)1 SpanProxy (com.newrelic.agent.tracing.SpanProxy)1 PriorityTransactionName (com.newrelic.agent.transaction.PriorityTransactionName)1