Search in sources :

Example 21 with ExternalRequest

use of com.newrelic.agent.introspec.ExternalRequest in project newrelic-java-agent by newrelic.

the class HttpServerTest method testCatCallDefaultName.

// this one creates a new path hash at the end
@Test
public void testCatCallDefaultName() throws IOException, URISyntaxException {
    Introspector intro = InstrumentationTestRunner.getIntrospector();
    HttpRequestClass myClass = new HttpRequestClass();
    myClass.performCatHttpNoSetName(server.getEndPoint());
    assertEquals(2, intro.getFinishedTransactionCount());
    Collection<String> names = intro.getTransactionNames();
    assertEquals(2, names.size());
    String txName1 = "OtherTransaction/Custom/com.example.http.HttpRequestClass/performCatHttpNoSetName";
    String txName2 = "WebTransaction/Custom/ExternalHTTPServer";
    assertTrue(names.contains(txName1));
    assertTrue(names.contains(txName2));
    Collection<ExternalRequest> externals = intro.getExternalRequests(txName1);
    assertEquals(1, externals.size());
    ExternalRequest req = externals.iterator().next();
    assertEquals(1, req.getCount());
    assertEquals("localhost", req.getHostname());
    CatHelper.verifyOneSuccessfulCat(intro, txName1);
}
Also used : HttpRequestClass(com.example.http.HttpRequestClass) Introspector(com.newrelic.agent.introspec.Introspector) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) Test(org.junit.Test)

Example 22 with ExternalRequest

use of com.newrelic.agent.introspec.ExternalRequest in project newrelic-java-agent by newrelic.

the class S3MetricAssertions method assertMetrics.

static void assertMetrics(String operation, Integer expectedStatusCode) {
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    assertEquals(1, introspector.getFinishedTransactionCount(2000));
    String txName = introspector.getTransactionNames().iterator().next();
    assertTrue(introspector.getTransactionNames().contains(txName));
    if (operation.equals("listBuckets")) {
        // scoped
        assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "External/amazon/S3/" + operation));
        if (txName.contains("AmazonS3SyncApiTest")) {
            assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "Java/com.agent.instrumentation.awsjavasdks3.AmazonS3SyncApiTest/" + operation));
        } else {
            assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "Java/com.agent.instrumentation.awsjavasdks3.AmazonS3AsyncApiTest/" + operation));
        }
        // unscoped
        assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/amazon/S3/" + operation));
        assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/all"));
        assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/allOther"));
        // events
        Collection<TransactionEvent> transactionEvents = introspector.getTransactionEvents(txName);
        assertEquals(1, transactionEvents.size());
        TransactionEvent transactionEvent = transactionEvents.iterator().next();
        assertEquals(1, transactionEvent.getExternalCallCount());
        assertTrue(transactionEvent.getExternalDurationInSec() > 0);
    } else {
        assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "External/testbucket/S3/" + operation));
        if (txName.contains("AmazonS3SyncApiTest")) {
            assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "Java/com.agent.instrumentation.awsjavasdks3.AmazonS3SyncApiTest/" + operation));
        } else {
            assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "Java/com.agent.instrumentation.awsjavasdks3.AmazonS3AsyncApiTest/" + operation));
        }
        // unscoped
        assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/testbucket/S3/" + operation));
        // events
        Collection<TransactionEvent> transactionEvents = introspector.getTransactionEvents(txName);
        assertEquals(1, transactionEvents.size());
        TransactionEvent transactionEvent = transactionEvents.iterator().next();
        assertEquals(1, transactionEvent.getExternalCallCount());
        assertTrue(transactionEvent.getExternalDurationInSec() > 0);
    }
    Collection<ExternalRequest> externalRequests = introspector.getExternalRequests(txName);
    assertEquals(1, externalRequests.size());
    ExternalRequest externalRequest = externalRequests.iterator().next();
    assertEquals(expectedStatusCode, externalRequest.getStatusCode());
    String expectedStatusText = statusCodeText.get(expectedStatusCode);
    if (!"getObject".equals(operation)) {
        assertEquals(expectedStatusText, externalRequest.getStatusText());
    }
}
Also used : TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) Introspector(com.newrelic.agent.introspec.Introspector) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest)

Example 23 with ExternalRequest

use of com.newrelic.agent.introspec.ExternalRequest in project newrelic-java-agent by newrelic.

the class HttpClient4Test method testExternal.

@Test
public void testExternal() throws Exception {
    URI endpoint = server.getEndPoint();
    String host1 = endpoint.getHost();
    httpClientExternal(endpoint.toString(), false);
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    Assert.assertEquals(2, introspector.getFinishedTransactionCount());
    String txOne = null;
    for (String txName : introspector.getTransactionNames()) {
        if (txName.matches(".*HttpClient4Test.*")) {
            txOne = txName;
        }
    }
    Assert.assertNotNull("Transaction not found", txOne);
    Assert.assertEquals(1, MetricsHelper.getScopedMetricCount(txOne, "External/" + host1 + "/CommonsHttp/execute"));
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host1 + "/CommonsHttp/execute"));
    // external rollups
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host1 + "/all"));
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/allOther"));
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/all"));
    Collection<TransactionEvent> transactionEvents = introspector.getTransactionEvents(txOne);
    Assert.assertEquals(1, transactionEvents.size());
    TransactionEvent transactionEvent = transactionEvents.iterator().next();
    Assert.assertEquals(1, transactionEvent.getExternalCallCount());
    Assert.assertTrue(transactionEvent.getExternalDurationInSec() > 0);
    Collection<ExternalRequest> externalRequests = introspector.getExternalRequests(txOne);
    Assert.assertEquals(1, externalRequests.size());
    ExternalRequest externalRequest = externalRequests.iterator().next();
    Assert.assertEquals(1, externalRequest.getCount());
    Assert.assertEquals(host1, externalRequest.getHostname());
    Assert.assertEquals("CommonsHttp", externalRequest.getLibrary());
    Assert.assertEquals("execute", externalRequest.getOperation());
}
Also used : TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) Introspector(com.newrelic.agent.introspec.Introspector) URI(java.net.URI) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) Test(org.junit.Test)

Example 24 with ExternalRequest

use of com.newrelic.agent.introspec.ExternalRequest in project newrelic-java-agent by newrelic.

the class HttpClient31Test method testExternal.

@Test
public void testExternal() throws Exception {
    httpClientExternal("http://localhost:" + server.getEndPoint().getPort());
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    Assert.assertEquals(2, introspector.getFinishedTransactionCount());
    String txOne = "OtherTransaction/Custom/com.nr.agent.instrumentation.httpclient.HttpClient31Test/httpClientExternal";
    Assert.assertEquals(1, MetricsHelper.getScopedMetricCount(txOne, "External/localhost/CommonsHttp/execute"));
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/localhost/CommonsHttp/execute"));
    // external rollups
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/localhost/all"));
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/allOther"));
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/all"));
    Collection<TransactionEvent> transactionEvents = introspector.getTransactionEvents(txOne);
    Assert.assertEquals(1, transactionEvents.size());
    TransactionEvent transactionEvent = transactionEvents.iterator().next();
    Assert.assertEquals(1, transactionEvent.getExternalCallCount());
    Assert.assertTrue(transactionEvent.getExternalDurationInSec() > 0);
    Collection<ExternalRequest> externalRequests = introspector.getExternalRequests(txOne);
    Assert.assertEquals(1, externalRequests.size());
    ExternalRequest externalRequest = externalRequests.iterator().next();
    Assert.assertEquals(1, externalRequest.getCount());
    Assert.assertEquals("localhost", externalRequest.getHostname());
    Assert.assertEquals("CommonsHttp", externalRequest.getLibrary());
    Assert.assertEquals("execute", externalRequest.getOperation());
    Assert.assertEquals(Integer.valueOf(200), externalRequest.getStatusCode());
    Assert.assertEquals("OK", externalRequest.getStatusText());
}
Also used : TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) Introspector(com.newrelic.agent.introspec.Introspector) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) Test(org.junit.Test)

Example 25 with ExternalRequest

use of com.newrelic.agent.introspec.ExternalRequest in project newrelic-java-agent by newrelic.

the class HttpAsyncClient4Test method testCat.

@Test
public void testCat() throws IOException, InterruptedException, ExecutionException {
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    httpClientExternal(endpoint.toURL().toString(), true);
    // transaction
    String txName = "OtherTransaction/Custom/com.nr.agent.instrumentation.httpasyncclient4.HttpAsyncClient4Test/httpClientExternal";
    assertEquals(2, introspector.getFinishedTransactionCount());
    Collection<String> names = introspector.getTransactionNames();
    assertEquals(2, names.size());
    assertTrue(names.contains(server.getServerTransactionName()));
    assertTrue(names.contains(txName));
    // scoped metrics
    assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "ExternalTransaction/" + host + "/" + server.getCrossProcessId() + "/" + server.getServerTransactionName()));
    assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "Java/com.nr.agent.instrumentation.httpasyncclient4.HttpAsyncClient4Test/httpClientExternal"));
    // unscoped metrics
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("ExternalTransaction/" + host + "/" + server.getCrossProcessId() + "/" + server.getServerTransactionName()));
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host + "/all"));
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/all"));
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/allOther"));
    // events
    Collection<TransactionEvent> transactionEvents = introspector.getTransactionEvents(txName);
    assertEquals(1, transactionEvents.size());
    TransactionEvent transactionEvent = transactionEvents.iterator().next();
    assertEquals(1, transactionEvent.getExternalCallCount());
    assertTrue(transactionEvent.getExternalDurationInSec() > 0);
    CatHelper.verifyOneSuccessfulCat(introspector, txName);
    // external request information
    Collection<ExternalRequest> externalRequests = introspector.getExternalRequests(txName);
    assertEquals(1, externalRequests.size());
    ExternalRequest externalRequest = externalRequests.iterator().next();
    assertEquals(1, externalRequest.getCount());
    assertEquals(host, externalRequest.getHostname());
    Assert.assertEquals(Integer.valueOf(200), externalRequest.getStatusCode());
    Assert.assertEquals("OK", externalRequest.getStatusText());
}
Also used : TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) Introspector(com.newrelic.agent.introspec.Introspector) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) Test(org.junit.Test)

Aggregations

ExternalRequest (com.newrelic.agent.introspec.ExternalRequest)55 Test (org.junit.Test)52 Introspector (com.newrelic.agent.introspec.Introspector)51 TransactionEvent (com.newrelic.agent.introspec.TransactionEvent)44 URI (java.net.URI)34 TraceSegment (com.newrelic.agent.introspec.TraceSegment)10 TransactionTrace (com.newrelic.agent.introspec.TransactionTrace)10 TracedMetricData (com.newrelic.agent.introspec.TracedMetricData)7 Java7IncompatibleTest (com.newrelic.test.marker.Java7IncompatibleTest)6 Java10IncompatibleTest (com.newrelic.test.marker.Java10IncompatibleTest)5 Java11IncompatibleTest (com.newrelic.test.marker.Java11IncompatibleTest)5 Java12IncompatibleTest (com.newrelic.test.marker.Java12IncompatibleTest)5 Java13IncompatibleTest (com.newrelic.test.marker.Java13IncompatibleTest)5 Java14IncompatibleTest (com.newrelic.test.marker.Java14IncompatibleTest)5 Java15IncompatibleTest (com.newrelic.test.marker.Java15IncompatibleTest)5 Java16IncompatibleTest (com.newrelic.test.marker.Java16IncompatibleTest)5 Java17IncompatibleTest (com.newrelic.test.marker.Java17IncompatibleTest)5 Java9IncompatibleTest (com.newrelic.test.marker.Java9IncompatibleTest)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5