Search in sources :

Example 6 with ExtendedRequest

use of com.newrelic.api.agent.ExtendedRequest in project newrelic-java-agent by newrelic.

the class ApiTest method runTestWebFrameworkAPI.

@Trace(dispatcher = true)
private void runTestWebFrameworkAPI() {
    NewRelic.setAppServerPort(666);
    NewRelic.setInstanceName("instance");
    NewRelic.setServerInfo("server", "6.6.6");
    com.newrelic.agent.bridge.Transaction txn = AgentBridge.getAgent().getTransaction();
    AgentIdentity env = ServiceFactory.getEnvironmentService().getEnvironment().getAgentIdentity();
    txn.convertToWebTransaction();
    Assert.assertTrue(txn.isWebTransaction());
    ExtendedRequest request = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "mytest", "", "&test=dude"));
    txn.setWebRequest(request);
    Assert.assertTrue(txn.isWebRequestSet());
    ApiTestHelper.DummyResponse dummyResponse = new ApiTestHelper.DummyResponse();
    NewRelic.getAgent().getTransaction().setWebResponse(dummyResponse);
    Assert.assertTrue(txn.isWebResponseSet());
    WebRequestDispatcher webRequestDispatcher = (WebRequestDispatcher) AgentBridge.getAgent().getTransaction().getWebResponse();
    try {
        int status = webRequestDispatcher.getResponse().getStatus();
        String statusMessage = webRequestDispatcher.getResponse().getStatusMessage();
        Assert.assertEquals(200, status);
        Assert.assertEquals("HTTP 200 OK", statusMessage);
    } catch (Exception ex) {
        Assert.fail();
    }
    int port = env.getServerPort();
    String instance = env.getInstanceName();
    String dispatcher = env.getDispatcher();
    String version = env.getDispatcherVersion();
    Assert.assertEquals(666, port);
    Assert.assertEquals("instance", instance);
    Assert.assertEquals("server", dispatcher);
    Assert.assertEquals("6.6.6", version);
    NewRelic.getAgent().getTransaction().markResponseSent();
    Transaction tx = Transaction.getTransaction(false);
    Assert.assertNotEquals(0, tx.getTransactionTimer().getResponseTimeInNanos());
}
Also used : MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) URISyntaxException(java.net.URISyntaxException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) AgentIdentity(com.newrelic.agent.environment.AgentIdentity) Transaction(com.newrelic.agent.Transaction) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) Trace(com.newrelic.api.agent.Trace)

Example 7 with ExtendedRequest

use of com.newrelic.api.agent.ExtendedRequest in project newrelic-java-agent by newrelic.

the class CrossProcessTransactionStateImplTest method testTransactionHeader.

// The following test used to cover the complex logic that tried to decide when to create and
// send GUIDs based on the old "Beacon" logic. Eventually the Browser product replaced this with
// a new and better implementation, so all the Agent support was ripped out sometime after the
// 3.13.0 release of the Agent. This test was modified to suit; so it compiles and executes now,
// and passes, but it's unclear what it's really testing.
@Test
public void testTransactionHeader() {
    String encodingKey = "test";
    String incomingId = "1#23";
    String transactionHeader = "[\"8cd217491c0264d7\",false]";
    String txGuid = "56b0d429ee4730fe";
    String obfuscatedAppData = Obfuscator.obfuscateNameUsingKey("[\"6#66\",\"WebTransaction\\/test\\/test\",1.0,0.2,12345,\"" + txGuid + "\",false]", encodingKey);
    ExtendedRequest request = createRequestFromStandardHeaders(Obfuscator.obfuscateNameUsingKey(incomingId, encodingKey), Obfuscator.obfuscateNameUsingKey(transactionHeader, encodingKey), "12345");
    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());
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

ExtendedRequest (com.newrelic.api.agent.ExtendedRequest)7 Test (org.junit.Test)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)3 Transaction (com.newrelic.agent.Transaction)1 WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)1 AgentIdentity (com.newrelic.agent.environment.AgentIdentity)1 TransactionStats (com.newrelic.agent.stats.TransactionStats)1 PriorityTransactionName (com.newrelic.agent.transaction.PriorityTransactionName)1 Trace (com.newrelic.api.agent.Trace)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URISyntaxException (java.net.URISyntaxException)1 MockHttpServletRequest (org.apache.struts.mock.MockHttpServletRequest)1