Search in sources :

Example 1 with EnvironmentHolder

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();
    }
}
Also used : EnvironmentHolderSettingsGenerator(test.newrelic.EnvironmentHolderSettingsGenerator) EnvironmentHolder(test.newrelic.test.agent.EnvironmentHolder) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) SpanEvent(com.newrelic.agent.model.SpanEvent) Test(org.junit.Test)

Example 2 with EnvironmentHolder

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;
}
Also used : EnvironmentHolderSettingsGenerator(test.newrelic.EnvironmentHolderSettingsGenerator) EnvironmentHolder(test.newrelic.test.agent.EnvironmentHolder)

Example 3 with 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();
    }
}
Also used : Transaction(com.newrelic.agent.Transaction) EnvironmentHolder(test.newrelic.test.agent.EnvironmentHolder) Segment(com.newrelic.api.agent.Segment) NoOpSegment(com.newrelic.agent.bridge.NoOpSegment) Test(org.junit.Test)

Example 4 with EnvironmentHolder

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();
    }
}
Also used : EnvironmentHolder(test.newrelic.test.agent.EnvironmentHolder) ExternalAsyncTest(com.newrelic.agent.async.ExternalAsyncTest) Test(org.junit.Test)

Example 5 with EnvironmentHolder

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();
    }
}
Also used : EnvironmentHolder(test.newrelic.test.agent.EnvironmentHolder) ExternalAsyncTest(com.newrelic.agent.async.ExternalAsyncTest) Test(org.junit.Test)

Aggregations

EnvironmentHolder (test.newrelic.test.agent.EnvironmentHolder)23 Test (org.junit.Test)15 EnvironmentHolderSettingsGenerator (test.newrelic.EnvironmentHolderSettingsGenerator)10 ExternalAsyncTest (com.newrelic.agent.async.ExternalAsyncTest)6 Tracer (com.newrelic.agent.tracers.Tracer)5 TransactionDataList (com.newrelic.agent.TransactionDataList)4 Before (org.junit.Before)4 TransactionData (com.newrelic.agent.TransactionData)3 SpanEvent (com.newrelic.agent.model.SpanEvent)3 SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)3 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)2 IOException (java.io.IOException)2 Header (org.apache.http.Header)2 TracerList (com.newrelic.agent.TracerList)1 Transaction (com.newrelic.agent.Transaction)1 TransactionListener (com.newrelic.agent.TransactionListener)1 NoOpSegment (com.newrelic.agent.bridge.NoOpSegment)1 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)1 TracedError (com.newrelic.agent.errors.TracedError)1 TransactionEvent (com.newrelic.agent.service.analytics.TransactionEvent)1