Search in sources :

Example 31 with Introspector

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

the class OkHttp314Test method testError.

@Test
public void testError() throws Exception {
    final String host2 = "www.notarealhostbrosef.bro";
    try {
        httpClientExternal("http://" + host2);
        Assert.fail("Host should not be reachable: " + host2);
    } catch (UnknownHostException e) {
    }
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    Assert.assertEquals(1, introspector.getFinishedTransactionCount());
    final String txTwo = introspector.getTransactionNames().iterator().next();
    // creates a scoped (and unscoped)
    Assert.assertEquals(1, MetricsHelper.getScopedMetricCount(txTwo, "External/UnknownHost/OkHttp/execute"));
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/UnknownHost/OkHttp/execute"));
    // Unknown hosts generate no external rollups
    Assert.assertEquals(0, MetricsHelper.getUnscopedMetricCount("External/allOther"));
    Assert.assertEquals(0, MetricsHelper.getUnscopedMetricCount("External/all"));
}
Also used : UnknownHostException(java.net.UnknownHostException) Introspector(com.newrelic.agent.introspec.Introspector) Test(org.junit.Test) Java7IncompatibleTest(com.newrelic.test.marker.Java7IncompatibleTest)

Example 32 with Introspector

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

the class OkHttp36Test method testCat.

@Test
public void testCat() throws Exception {
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    URI endpoint = server.getEndPoint();
    String host = endpoint.getHost();
    httpClientExternal(endpoint.toURL().toString());
    // transaction
    String txName = "OtherTransaction/Custom/com.nr.agent.instrumentation.okhttp36.OkHttp36Test/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.okhttp36.OkHttp36Test/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());
    // the test server does return the trailing space, this client does not trim it
    Assert.assertEquals("OK ", externalRequest.getStatusText());
}
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 33 with Introspector

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

the class OkHttp4Test method testExternal.

@Test
public void testExternal() throws Exception {
    URI endpoint = server.getEndPoint();
    httpClientExternal(endpoint.toString(), false, 2000);
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    Assert.assertEquals(2, introspector.getFinishedTransactionCount());
    String txOne = null;
    for (String txName : introspector.getTransactionNames()) {
        if (txName.matches(".*OkHttp4Test.*")) {
            txOne = txName;
        }
    }
    String host1 = endpoint.getHost();
    Assert.assertNotNull("Transaction not found", txOne);
    Assert.assertEquals(1, MetricsHelper.getScopedMetricCount(txOne, "External/" + host1 + "/OkHttp/execute"));
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host1 + "/OkHttp/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"));
    // verify timing of External/all metrics
    TracedMetricData externalMetrics = InstrumentationTestRunner.getIntrospector().getUnscopedMetrics().get("External/all");
    assertNotNull(externalMetrics);
    assertTrue(externalMetrics.getTotalTimeInSec() > 2);
    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("OkHttp", externalRequest.getLibrary());
    Assert.assertEquals("execute", externalRequest.getOperation());
    Assert.assertEquals(Integer.valueOf(200), externalRequest.getStatusCode());
    // the test server does return the trailing space, this client does not trim it
    Assert.assertEquals("OK ", externalRequest.getStatusText());
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) 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) Java7IncompatibleTest(com.newrelic.test.marker.Java7IncompatibleTest)

Example 34 with Introspector

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

the class OkHttp4Test method testError.

@Test
public void testError() throws Exception {
    final String host2 = "www.notarealhostbrosef.bro";
    try {
        httpClientExternal("http://" + host2);
        Assert.fail("Host should not be reachable: " + host2);
    } catch (UnknownHostException e) {
    }
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    Assert.assertEquals(1, introspector.getFinishedTransactionCount());
    final String txTwo = introspector.getTransactionNames().iterator().next();
    // creates a scoped (and unscoped)
    Assert.assertEquals(1, MetricsHelper.getScopedMetricCount(txTwo, "External/UnknownHost/OkHttp/execute"));
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/UnknownHost/OkHttp/execute"));
    // Unknown hosts generate no external rollups
    Assert.assertEquals(0, MetricsHelper.getUnscopedMetricCount("External/allOther"));
    Assert.assertEquals(0, MetricsHelper.getUnscopedMetricCount("External/all"));
}
Also used : UnknownHostException(java.net.UnknownHostException) Introspector(com.newrelic.agent.introspec.Introspector) Test(org.junit.Test) Java7IncompatibleTest(com.newrelic.test.marker.Java7IncompatibleTest)

Example 35 with Introspector

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

the class OkHttp44Test method testCat.

@Test
public void testCat() throws Exception {
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    URI endpoint = server.getEndPoint();
    httpClientExternal(endpoint.toURL().toString());
    // transaction
    assertEquals(2, introspector.getFinishedTransactionCount());
    Collection<String> names = introspector.getTransactionNames();
    assertEquals(2, names.size());
    assertTrue(names.contains(server.getServerTransactionName()));
    String txName = "OtherTransaction/Custom/" + this.getClass().getName() + "/httpClientExternal";
    assertTrue(names.contains(txName));
    // scoped metrics
    String host = endpoint.getHost();
    assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "ExternalTransaction/" + host + "/" + server.getCrossProcessId() + "/" + server.getServerTransactionName()));
    assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "Java/" + this.getClass().getName() + "/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());
    assertEquals(Integer.valueOf(200), externalRequest.getStatusCode());
    // the test server does return the trailing space, this client does not trim it
    assertEquals("OK ", externalRequest.getStatusText());
}
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) Java7IncompatibleTest(com.newrelic.test.marker.Java7IncompatibleTest)

Aggregations

Introspector (com.newrelic.agent.introspec.Introspector)452 Test (org.junit.Test)432 TransactionEvent (com.newrelic.agent.introspec.TransactionEvent)150 Java16IncompatibleTest (com.newrelic.test.marker.Java16IncompatibleTest)88 Java17IncompatibleTest (com.newrelic.test.marker.Java17IncompatibleTest)88 Java11IncompatibleTest (com.newrelic.test.marker.Java11IncompatibleTest)86 Java12IncompatibleTest (com.newrelic.test.marker.Java12IncompatibleTest)86 Java13IncompatibleTest (com.newrelic.test.marker.Java13IncompatibleTest)86 Java14IncompatibleTest (com.newrelic.test.marker.Java14IncompatibleTest)86 Java15IncompatibleTest (com.newrelic.test.marker.Java15IncompatibleTest)86 DatastoreHelper (com.newrelic.agent.introspec.DatastoreHelper)69 ExternalRequest (com.newrelic.agent.introspec.ExternalRequest)51 TracedMetricData (com.newrelic.agent.introspec.TracedMetricData)51 URI (java.net.URI)41 Java7IncompatibleTest (com.newrelic.test.marker.Java7IncompatibleTest)32 TransactionTrace (com.newrelic.agent.introspec.TransactionTrace)25 TraceSegment (com.newrelic.agent.introspec.TraceSegment)19 Matchers.containsString (org.hamcrest.Matchers.containsString)16 Java10IncompatibleTest (com.newrelic.test.marker.Java10IncompatibleTest)13 Java9IncompatibleTest (com.newrelic.test.marker.Java9IncompatibleTest)13