use of com.newrelic.agent.stats.ResponseTimeStats in project newrelic-java-agent by newrelic.
the class CrossProcessStateTest method processOutboundResponseHeaders.
@Test
public void processOutboundResponseHeaders() {
String incomingId = "6#66";
String obfuscatedAppData = Obfuscator.obfuscateNameUsingKey("[\"6#66\",\"TestTransaction\\/name\",0.0,0.0,12345,\"5001D\",false]", encodingKey);
cps.processOutboundResponseHeaders(null, 0);
TransactionStats txStats = mock(TransactionStats.class);
TransactionActivity ta = mock(TransactionActivity.class);
when(tx.getTransactionActivity()).thenReturn(ta);
when(ta.getTransactionStats()).thenReturn(txStats);
SimpleStatsEngine statsEngine = mock(SimpleStatsEngine.class);
when(txStats.getUnscopedStats()).thenReturn(statsEngine);
ResponseTimeStats stats = mock(ResponseTimeStats.class);
when(statsEngine.getOrCreateResponseTimeStats(anyString())).thenReturn(stats);
InboundHeaderState ihs = mock(InboundHeaderState.class);
when(ihs.getClientCrossProcessId()).thenReturn(incomingId);
when(ihs.isTrustedCatRequest()).thenReturn(true);
when(tx.getInboundHeaderState()).thenReturn(ihs);
AgentConfig agentConfig = mock(AgentConfig.class);
DistributedTracingConfig distributedTracingConfig = mock(DistributedTracingConfig.class);
when(distributedTracingConfig.isEnabled()).thenReturn(false);
when(agentConfig.getDistributedTracingConfig()).thenReturn(distributedTracingConfig);
when(tx.getAgentConfig()).thenReturn(agentConfig);
PriorityTransactionName txName = mock(PriorityTransactionName.class);
when(tx.getPriorityTransactionName()).thenReturn(txName);
when(txName.getName()).thenReturn("TestTransaction/name");
when(tx.getGuid()).thenReturn("5001D");
when(config.getCrossProcessId()).thenReturn(incomingId);
cps.processOutboundResponseHeaders(outboundHeaders, 12345);
verify(outboundHeaders).setHeader(eq("X-NewRelic-App-Data"), eq(obfuscatedAppData));
cps.processOutboundResponseHeaders(outboundHeaders, 12345);
verify(outboundHeaders, Mockito.times(2)).getHeaderType();
verifyNoMoreInteractions(outboundHeaders);
verify(config, atLeastOnce()).isCrossApplicationTracing();
verify(config, atLeastOnce()).getCrossProcessId();
verify(config, atLeastOnce()).getEncodingKey();
verify(tx, atLeastOnce()).getAgentConfig();
verify(tx, atLeastOnce()).getCrossProcessConfig();
verify(tx, atLeastOnce()).getInboundHeaderState();
verify(tx, atLeastOnce()).isIgnore();
verify(tx, atLeastOnce()).getLock();
verify(tx, atLeastOnce()).getGuid();
verify(tx, atLeastOnce()).freezeTransactionName();
verify(tx, atLeastOnce()).getRunningDurationInNanos();
verify(tx, atLeastOnce()).getExternalTime();
verify(tx, atLeastOnce()).getPriorityTransactionName();
verify(txName, atLeastOnce()).getName();
verify(tx, atLeastOnce()).getTransactionActivity();
verify(ta, atLeastOnce()).getTransactionStats();
verify(txStats, atLeastOnce()).getUnscopedStats();
verify(statsEngine, atLeastOnce()).getOrCreateResponseTimeStats(anyString());
verify(stats, atLeastOnce()).recordResponseTime(anyLong(), any(TimeUnit.class));
verifyNoMoreInteractions(txStats, statsEngine, stats, txName);
}
use of com.newrelic.agent.stats.ResponseTimeStats in project newrelic-java-agent by newrelic.
the class CrossProcessTransactionStateImplTest method testAppDataHeader.
@Test
public void testAppDataHeader() {
String encodingKey = "test";
String incomingId = "1#23";
String txGuid = "5001D";
String obfuscatedAppData = Obfuscator.obfuscateNameUsingKey("[\"6#66\",\"WebTransaction\\/test\\/test\",1.0,0.2,12345,\"" + txGuid + "\",false]", encodingKey);
ExtendedRequest request = createRequestFromStandardHeaders(Obfuscator.obfuscateNameUsingKey(incomingId, encodingKey), null, "12345");
stats = new TransactionStats();
configureTestMocks(encodingKey, txGuid, obfuscatedAppData, request);
CrossProcessTransactionStateImpl crossProcessTransactionState = CrossProcessTransactionStateImpl.create(tx);
crossProcessTransactionState.writeResponseHeaders();
crossProcessTransactionState.writeResponseHeaders();
verifyMocks(obfuscatedAppData);
assertEquals(1, stats.getUnscopedStats().getSize());
ResponseTimeStats clientAppStats = stats.getUnscopedStats().getOrCreateResponseTimeStats("ClientApplication/" + incomingId + "/all");
assertEquals(1, clientAppStats.getCallCount());
assertEquals(incomingId, tx.getInboundHeaderState().getClientCrossProcessId());
assertNull(tx.getInboundHeaderState().getReferrerGuid());
}
use of com.newrelic.agent.stats.ResponseTimeStats in project newrelic-java-agent by newrelic.
the class CrossProcessTransactionStateImplTest method testNoContentLengthNoQueueTime.
@Test
public void testNoContentLengthNoQueueTime() {
String encodingKey = "test";
String incomingId = "1#23";
String txGuid = "5001D";
String obfuscatedAppData = Obfuscator.obfuscateNameUsingKey("[\"6#66\",\"WebTransaction\\/test\\/test\",0.0,0.2,-1,\"" + txGuid + "\",false]", encodingKey);
ExtendedRequest request = createRequestFromStandardHeaders(Obfuscator.obfuscateNameUsingKey(incomingId, encodingKey), null, null);
doNothing().when(response).setHeader("X-NewRelic-App-Data", obfuscatedAppData);
configureCatEnabled(encodingKey, true);
mockDispatcher(request);
mockConfigFromTransaction();
mockBasicTransactionMethods();
InboundHeaderState ihs = mock(InboundHeaderState.class);
when(ihs.getRequestContentLength()).thenReturn(-1L);
when(ihs.getReferrerGuid()).thenReturn(null);
when(ihs.isTrustedCatRequest()).thenReturn(true);
when(ihs.getClientCrossProcessId()).thenReturn(incomingId);
when(tx.getInboundHeaderState()).thenReturn(ihs);
doNothing().when(tx).freezeTransactionName();
when(tx.getExternalTime()).thenReturn(0L);
PriorityTransactionName txName = PriorityTransactionName.create("WebTransaction/test/test", null, TransactionNamePriority.JSP);
when(tx.getPriorityTransactionName()).thenReturn(txName);
when(tx.getTransactionActivity()).thenReturn(ta);
doNothing().when(ta).markAsResponseSender();
when(ta.getTransactionStats()).thenReturn(stats);
long durationInNanos = TimeUnit.NANOSECONDS.convert(200L, TimeUnit.MILLISECONDS);
when(tx.getRunningDurationInNanos()).thenReturn(durationInNanos);
when(tx.getGuid()).thenReturn(txGuid);
CrossProcessTransactionStateImpl crossProcessTransactionState = CrossProcessTransactionStateImpl.create(tx);
crossProcessTransactionState.writeResponseHeaders();
verifyMocks(obfuscatedAppData);
assertEquals(1, stats.getUnscopedStats().getSize());
ResponseTimeStats clientAppStats = stats.getUnscopedStats().getOrCreateResponseTimeStats("ClientApplication/" + incomingId + "/all");
assertEquals(1, clientAppStats.getCallCount());
assertEquals(incomingId, tx.getInboundHeaderState().getClientCrossProcessId());
}
use of com.newrelic.agent.stats.ResponseTimeStats in project newrelic-java-agent by newrelic.
the class TransactionAsyncRootFirstTest method testStartAndThenLinkMultipleDiffTokensExpireAll.
@Test
public void testStartAndThenLinkMultipleDiffTokensExpireAll() throws InterruptedException {
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
tx.getTransactionActivity().tracerStarted(rootTracer);
TokenImpl token1 = (TokenImpl) tx.getToken();
TokenImpl token2 = (TokenImpl) tx.getToken();
rootTracer.finish(Opcodes.RETURN, 0);
StartAndThenLink activity1 = new StartAndThenLink(token1, false, false);
activity1.start();
activity1.join();
StartAndThenLink activity2 = new StartAndThenLink(token2, false, false);
activity2.start();
activity2.join();
tx.expireAllTokensForCurrentTransaction();
waitForTransaction();
TransactionAsyncUtility.basicDataVerify(data, stats, activity1, 3);
Map<String, StatsBase> scoped = stats.getScopedStats().getStatsMap();
ResponseTimeStats data1 = (ResponseTimeStats) scoped.get("RequestDispatcher");
ResponseTimeStats data2 = (ResponseTimeStats) scoped.get("Java/java.lang.Object/root" + token1.toString());
ResponseTimeStats data3 = (ResponseTimeStats) scoped.get("Java/java.lang.Object/root" + token2.toString());
Assert.assertNotNull(data1);
Assert.assertNotNull(data2);
Assert.assertNotNull(data3);
Assert.assertEquals(1, data1.getCallCount());
Assert.assertEquals(1, data2.getCallCount());
Assert.assertEquals(1, data3.getCallCount());
Map<String, StatsBase> unscoped = stats.getUnscopedStats().getStatsMap();
Assert.assertEquals(((ResponseTimeStats) unscoped.get("WebTransactionTotalTime")).getTotal(), data1.getTotal() + data2.getTotal() + data3.getTotal(), .001);
}
use of com.newrelic.agent.stats.ResponseTimeStats in project newrelic-java-agent by newrelic.
the class TransactionAsyncRootFirstTest method testStartAndThenLinkMultipleDiffTokens.
@Test
public void testStartAndThenLinkMultipleDiffTokens() throws InterruptedException {
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
tx.getTransactionActivity().tracerStarted(rootTracer);
TokenImpl token1 = (TokenImpl) tx.getToken();
TokenImpl token2 = (TokenImpl) tx.getToken();
rootTracer.finish(Opcodes.RETURN, 0);
StartAndThenLink activity1 = new StartAndThenLink(token1, true, false);
activity1.start();
activity1.join();
StartAndThenLink activity2 = new StartAndThenLink(token2, false, true);
activity2.start();
activity2.join();
waitForTransaction();
TransactionAsyncUtility.basicDataVerify(data, stats, activity1, 3);
Map<String, StatsBase> scoped = stats.getScopedStats().getStatsMap();
ResponseTimeStats data1 = (ResponseTimeStats) scoped.get("RequestDispatcher");
ResponseTimeStats data2 = (ResponseTimeStats) scoped.get("Java/java.lang.Object/root" + token1.toString());
ResponseTimeStats data3 = (ResponseTimeStats) scoped.get("Java/java.lang.Object/root" + token2.toString());
Assert.assertNotNull(data1);
Assert.assertNotNull(data2);
Assert.assertNotNull(data3);
Assert.assertEquals(1, data1.getCallCount());
Assert.assertEquals(1, data2.getCallCount());
Assert.assertEquals(1, data3.getCallCount());
Map<String, StatsBase> unscoped = stats.getUnscopedStats().getStatsMap();
Assert.assertEquals(((ResponseTimeStats) unscoped.get("WebTransactionTotalTime")).getTotal(), data1.getTotal() + data2.getTotal() + data3.getTotal(), .001);
}
Aggregations