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());
}
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());
}
Aggregations