use of com.newrelic.agent.transaction.PriorityTransactionName 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.transaction.PriorityTransactionName in project newrelic-java-agent by newrelic.
the class CrossProcessTransactionStateImplTest method configureTestMocks.
private void configureTestMocks(String encodingKey, String txGuid, String obfuscatedAppData, ExtendedRequest request) {
configureCatEnabled(encodingKey, true);
doNothing().when(response).setHeader("X-NewRelic-App-Data", obfuscatedAppData);
mockDispatcher(request);
mockBasicTransactionMethods();
mockConfigFromTransaction();
when(tx.acceptDistributedTracePayload(anyString())).thenReturn(true);
InboundHeaderState ihs = new InboundHeaderState(tx, new DeobfuscatedInboundHeaders(request, crossProcessConfig.getEncodingKey()));
when(tx.getInboundHeaderState()).thenReturn(ihs);
doNothing().when(tx).freezeTransactionName();
when(tx.getExternalTime()).thenReturn(1000L);
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);
}
use of com.newrelic.agent.transaction.PriorityTransactionName 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.transaction.PriorityTransactionName in project newrelic-java-agent by newrelic.
the class AgentTest method normalRequest.
@Test
public void normalRequest() throws ServletException, Exception {
final String applicationName = APPLICATION_NAME_2;
TestServlet servlet = new TestServlet();
String path = "/my/word";
Transaction tx = AgentHelper.invokeServlet(servlet, "", applicationName, path);
// Assert.assertTrue(Agent.instance().getApplicationNames().toString(),
// Agent.instance().getApplicationNames().contains(applicationName));
Set<String> metrics = AgentHelper.getMetrics();
Assert.assertTrue(metrics.toString(), metrics.contains("Servlet/" + TestServlet.class.getName() + "/service"));
PriorityTransactionName transactionName = tx.getPriorityTransactionName();
Assert.assertEquals("WebTransaction/Servlet/TestServlet", transactionName.getName());
// / Assert.assertTrue(metrics.toString(), metrics.contains(MetricNames.DISPATCHER));
// Assert.assertTrue(metrics.toString(), metrics.contains(MetricNames.FRONTEND + path));
// Assert.assertTrue(metrics.toString(), metrics.contains("ServletInit/" + TestServlet.class.getSimpleName()));
/*
* boolean blameOk = false; for (MetricSpec spec : metricsSpecs) { if (spec.getName().equals("Servlet/" +
* TestServlet.class.getSimpleName() + "/service") && spec.getScope().equals(MetricNames.FRONTEND + path))
* blameOk = true; } Assert.assertTrue(blameOk);
*/
}
use of com.newrelic.agent.transaction.PriorityTransactionName in project newrelic-java-agent by newrelic.
the class ApiTest method testGetBrowserTimingFooter.
@Test
public void testGetBrowserTimingFooter() throws Exception {
ApiTestHelper.mockOutServiceManager();
Transaction tx = Transaction.getTransaction();
TransactionNamePriority expectedPriority = TransactionNamePriority.FILTER_NAME;
PriorityTransactionName ptn = PriorityTransactionName.create("name", null, expectedPriority);
tx.setPriorityTransactionName(ptn);
BasicRequestRootTracer tracer = createDispatcherTracer();
tx.getTransactionActivity().tracerStarted(tracer);
NewRelic.getBrowserTimingHeader();
String browserTimingFooter = NewRelic.getBrowserTimingFooter();
Assert.assertTrue("Incorrect footer. Was " + browserTimingFooter + ", but expected it to start with " + getTimingFooterStart(), browserTimingFooter.startsWith(getTimingFooterStart()));
tx.getTransactionActivity().tracerFinished(tracer, 0);
}
Aggregations