use of test.newrelic.test.agent.EnvironmentHolder in project newrelic-java-agent by newrelic.
the class XmlRpcPointCutTest method externalTest.
@Test
public void externalTest() throws Exception {
EnvironmentHolderSettingsGenerator envHolderSettings = new EnvironmentHolderSettingsGenerator(CONFIG_FILE, "all_enabled_test", CLASS_LOADER);
EnvironmentHolder holder = new EnvironmentHolder(envHolderSettings);
holder.setupEnvironment();
try {
doCall();
SpanEventsService spanEventsService = ServiceFactory.getServiceManager().getSpanEventsService();
String appName = ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName();
SamplingPriorityQueue<SpanEvent> spanEventsPool = spanEventsService.getOrCreateDistributedSamplingReservoir(appName);
assertNotNull(spanEventsPool);
List<SpanEvent> spanEvents = spanEventsPool.asList();
assertNotNull(spanEvents);
assertEquals(2, spanEvents.size());
boolean java = false;
boolean external = false;
for (SpanEvent span : spanEvents) {
String name = (String) span.getIntrinsics().get("name");
if (name.equals("External/newrelic.com/XmlRpc/invoke")) {
external = true;
assertEquals("XmlRpc", span.getIntrinsics().get("component"));
assertEquals("http", span.getIntrinsics().get("category"));
assertEquals("http://newrelic.com", span.getAgentAttributes().get("http.url"));
} else if (name.equals("Java/com.newrelic.agent.instrumentation.pointcuts.javax.xml.rpc.XmlRpcPointCutTest/doCall")) {
java = true;
assertEquals("generic", span.getIntrinsics().get("category"));
}
}
assertTrue("Unexpected span events found", java && external);
} finally {
holder.close();
}
}
use of test.newrelic.test.agent.EnvironmentHolder in project newrelic-java-agent by newrelic.
the class ExternalAsyncTest method setupEnvironmentHolder.
public EnvironmentHolder setupEnvironmentHolder(String environment) throws Exception {
EnvironmentHolderSettingsGenerator envHolderSettings = new EnvironmentHolderSettingsGenerator(CONFIG_FILE, environment, CLASS_LOADER);
EnvironmentHolder environmentHolder = new EnvironmentHolder(envHolderSettings);
environmentHolder.setupEnvironment();
return environmentHolder;
}
use of test.newrelic.test.agent.EnvironmentHolder in project newrelic-java-agent by newrelic.
the class ExternalAsyncTest method testCat.
@Test
public void testCat() throws Exception {
// override default agent config to disabled distributed tracing and use CAT instead
EnvironmentHolder holder = setupEnvironmentHolder("cat_enabled_dt_disabled_test");
try {
final Outbound outbound = new Outbound();
final Inbound inbound = new Inbound();
doInTransaction((Callable<Void>) () -> {
Segment externalEvent = startSegment(outbound);
Transaction transaction = Transaction.getTransaction(false);
String encodingKey = transaction.getCrossProcessConfig().getEncodingKey();
String appData = Obfuscator.obfuscateNameUsingKey("[\"crossProcessId\",\"externalTransactionName\"]", encodingKey);
inbound.headers.put(HeadersUtil.NEWRELIC_APP_DATA_HEADER, appData);
finishExternalEvent(externalEvent, null, inbound, HOST, LIBRARY, URI, OPERATION_NAME);
return null;
});
// assert outbound request headers were populated correctly
Assert.assertTrue(outbound.headers.containsKey(HeadersUtil.NEWRELIC_ID_HEADER));
Assert.assertTrue(outbound.headers.containsKey(HeadersUtil.NEWRELIC_TRANSACTION_HEADER));
// assert inbound response headers were processed correctly by checking for CAT metric name
verifyTimesSet(1);
verifyScopedMetricsPresent("OtherTransaction/Custom/com.newrelic.agent.async.ExternalAsyncTest/doInTransaction", "ExternalTransaction/www.example.com/crossProcessId/externalTransactionName");
verifyUnscopedMetricsPresent("External/www.example.com/all", "External/allOther", "External/all");
verifyScopedMetricsNotPresent("OtherTransaction/Custom/com.newrelic.agent.async.ExternalAsyncTest/doInTransaction", "External/www.host2.com/library");
verifyTransactionSegmentsBreadthFirst("OtherTransaction/Custom/com.newrelic.agent.async.ExternalAsyncTest/doInTransaction", "Java/com.newrelic.agent.async.ExternalAsyncTest/doInTransaction", Thread.currentThread().getName(), "ExternalTransaction/www.example.com/crossProcessId/externalTransactionName", NO_ASYNC_CONTEXT);
verifyNoExceptions();
} finally {
holder.close();
}
}
use of test.newrelic.test.agent.EnvironmentHolder in project newrelic-java-agent by newrelic.
the class APISupportabilityTest method testProcessRequestMetadataDispatcherSupportabilityTracking.
@Test
public void testProcessRequestMetadataDispatcherSupportabilityTracking() throws Exception {
// override default agent config to disabled distributed tracing and use CAT instead
EnvironmentHolder holder = setupEnvironmentHolder("cat_enabled_dt_disabled_test");
try {
String className = APISupportabilityTest.ProcessRequestMetadataDispatcherTestClass.class.getName();
InstrumentTestUtils.createTransformerAndRetransformClass(className, "getProcessRequestMetadata", "()V;");
final String processRequestMetadataMetric = "Supportability/API/ProcessRequestMetadata/API";
new ProcessRequestMetadataDispatcherTestClass().getProcessRequestMetadata();
Map<String, Integer> metricData = InstrumentTestUtils.getAndClearMetricData();
Assert.assertNotNull(metricData.get(processRequestMetadataMetric));
Assert.assertEquals(Integer.valueOf(1), metricData.get(processRequestMetadataMetric));
} finally {
holder.close();
}
}
use of test.newrelic.test.agent.EnvironmentHolder in project newrelic-java-agent by newrelic.
the class APISupportabilityTest method testBridgeProcessRequestMetadataDispatcherSupportabilityTracking.
@Test
public void testBridgeProcessRequestMetadataDispatcherSupportabilityTracking() throws Exception {
// override default agent config to disabled distributed tracing and use CAT instead
EnvironmentHolder holder = setupEnvironmentHolder("cat_enabled_dt_disabled_test");
try {
String className = APISupportabilityTest.ProcessRequestMetadataDispatcherBridgeTestClass.class.getName();
InstrumentTestUtils.createTransformerAndRetransformClass(className, "getProcessRequestMetadata", "()V;");
final String processRequestMetadataMetric = "Supportability/API/ProcessRequestMetadata/API";
new ProcessRequestMetadataDispatcherBridgeTestClass().getProcessRequestMetadata();
Map<String, Integer> metricData = InstrumentTestUtils.getAndClearMetricData();
Assert.assertNotNull(metricData.get(processRequestMetadataMetric));
Assert.assertEquals(Integer.valueOf(1), metricData.get(processRequestMetadataMetric));
} finally {
holder.close();
}
}
Aggregations