Search in sources :

Example 16 with PriorityTransactionName

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);
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) AgentConfig(com.newrelic.agent.config.AgentConfig) DistributedTracingConfig(com.newrelic.agent.config.DistributedTracingConfig) TransactionStats(com.newrelic.agent.stats.TransactionStats) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) TimeUnit(java.util.concurrent.TimeUnit) SimpleStatsEngine(com.newrelic.agent.stats.SimpleStatsEngine) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 17 with PriorityTransactionName

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);
}
Also used : PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName)

Example 18 with PriorityTransactionName

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());
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 19 with PriorityTransactionName

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);
         */
}
Also used : NewRelicIgnoreTransaction(test.newrelic.test.agent.TraceAnnotationTest.NewRelicIgnoreTransaction) Transaction(com.newrelic.agent.Transaction) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) Test(org.junit.Test)

Example 20 with PriorityTransactionName

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);
}
Also used : Transaction(com.newrelic.agent.Transaction) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) TransactionNamePriority(com.newrelic.agent.bridge.TransactionNamePriority) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Aggregations

PriorityTransactionName (com.newrelic.agent.transaction.PriorityTransactionName)26 Test (org.junit.Test)21 Transaction (com.newrelic.agent.Transaction)19 TransactionNamePriority (com.newrelic.agent.bridge.TransactionNamePriority)14 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)14 ArrayList (java.util.ArrayList)7 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)5 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)3 TransactionStats (com.newrelic.agent.stats.TransactionStats)3 AgentConfig (com.newrelic.agent.config.AgentConfig)2 SimpleStatsEngine (com.newrelic.agent.stats.SimpleStatsEngine)2 DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 NewRelicIgnoreTransaction (test.newrelic.test.agent.TraceAnnotationTest.NewRelicIgnoreTransaction)2 TransactionData (com.newrelic.agent.TransactionData)1 TransactionListener (com.newrelic.agent.TransactionListener)1 BrowserMonitoringConfig (com.newrelic.agent.config.BrowserMonitoringConfig)1 DistributedTracingConfig (com.newrelic.agent.config.DistributedTracingConfig)1 Dispatcher (com.newrelic.agent.dispatchers.Dispatcher)1