Search in sources :

Example 21 with Introspector

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

the class MongoDbAsync360Test method testCollectionApi.

@Test
public void testCollectionApi() throws Exception {
    runMongoDbAsyncQuickStart();
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    assertEquals(1, introspector.getFinishedTransactionCount(1000));
    DatastoreHelper helper = new DatastoreHelper(MONGODB_PRODUCT);
    helper.assertAggregateMetrics();
    Collection<String> transactionNames = InstrumentationTestRunner.getIntrospector().getTransactionNames();
    assertEquals(1, transactionNames.size());
    String txName = transactionNames.iterator().next();
    // Counts based on operations executed in MongoDbAsyncQuickStart
    int insertOpExpectedCount = 1;
    int insertManyOpExpectedCount = 1;
    int updateOpExpectedCount = 1;
    int updateManyOpExpectedCount = 1;
    int deleteOpExpectedCount = 1;
    int deleteManyOpExpectedCount = 1;
    int findOpExpectedCount = 14;
    int dropOpExpectedCount = 3;
    int countOpExpectedCount = 1;
    int bulkWriteOpExpectedCount = 2;
    helper.assertUnifiedMetricCounts(txName, "insert", "test", insertOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "insertMany", "test", insertManyOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "update", "test", updateOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "updateMany", "test", updateManyOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "delete", "test", deleteOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "deleteMany", "test", deleteManyOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "find", "test", findOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "drop", "test", dropOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "count", "test", countOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "bulkWrite", "test", bulkWriteOpExpectedCount);
    int totalOpCount = insertOpExpectedCount + insertManyOpExpectedCount + updateOpExpectedCount + updateManyOpExpectedCount + deleteOpExpectedCount + deleteManyOpExpectedCount + findOpExpectedCount + dropOpExpectedCount + countOpExpectedCount + bulkWriteOpExpectedCount;
    // Should be equal to the sum of all above metric counts
    assertEquals(totalOpCount, MetricsHelper.getUnscopedMetricCount("Datastore/all"));
    assertEquals(totalOpCount, MetricsHelper.getUnscopedMetricCount("Datastore/MongoDB/allOther"));
    assertEquals(totalOpCount, introspector.getTransactionEvents(txName).iterator().next().getDatabaseCallCount());
}
Also used : Introspector(com.newrelic.agent.introspec.Introspector) ConnectionString(com.mongodb.ConnectionString) DatastoreHelper(com.newrelic.agent.introspec.DatastoreHelper) Test(org.junit.Test)

Example 22 with Introspector

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

the class MongoDbAsync3110Test method testCollectionApi.

@Test
public void testCollectionApi() throws Exception {
    runMongoDbAsyncQuickStart();
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    assertEquals(1, introspector.getFinishedTransactionCount(1000));
    DatastoreHelper helper = new DatastoreHelper(MONGODB_PRODUCT);
    helper.assertAggregateMetrics();
    Collection<String> transactionNames = InstrumentationTestRunner.getIntrospector().getTransactionNames();
    assertEquals(1, transactionNames.size());
    String txName = transactionNames.iterator().next();
    // Counts based on operations executed in MongoDbAsyncQuickStart
    int insertOpExpectedCount = 1;
    int insertManyOpExpectedCount = 1;
    int updateOpExpectedCount = 1;
    int updateManyOpExpectedCount = 1;
    int deleteOpExpectedCount = 1;
    int deleteManyOpExpectedCount = 1;
    int findOpExpectedCount = 14;
    int dropOpExpectedCount = 3;
    int countOpExpectedCount = 1;
    int bulkWriteOpExpectedCount = 2;
    helper.assertUnifiedMetricCounts(txName, "insert", "test", insertOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "insertMany", "test", insertManyOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "update", "test", updateOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "updateMany", "test", updateManyOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "delete", "test", deleteOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "deleteMany", "test", deleteManyOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "find", "test", findOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "drop", "test", dropOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "count", "test", countOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "bulkWrite", "test", bulkWriteOpExpectedCount);
    int totalOpCount = insertOpExpectedCount + insertManyOpExpectedCount + updateOpExpectedCount + updateManyOpExpectedCount + deleteOpExpectedCount + deleteManyOpExpectedCount + findOpExpectedCount + dropOpExpectedCount + countOpExpectedCount + bulkWriteOpExpectedCount;
    // Should be equal to the sum of all above metric counts
    assertEquals(totalOpCount, MetricsHelper.getUnscopedMetricCount("Datastore/all"));
    assertEquals(totalOpCount, MetricsHelper.getUnscopedMetricCount("Datastore/MongoDB/allOther"));
    assertEquals(totalOpCount, introspector.getTransactionEvents(txName).iterator().next().getDatabaseCallCount());
}
Also used : Introspector(com.newrelic.agent.introspec.Introspector) ConnectionString(com.mongodb.ConnectionString) DatastoreHelper(com.newrelic.agent.introspec.DatastoreHelper) Test(org.junit.Test)

Example 23 with Introspector

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

the class MongoDbAsync340Test method testCollectionApi.

@Test
public void testCollectionApi() throws Exception {
    runMongoDbAsyncQuickStart();
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    assertEquals(1, introspector.getFinishedTransactionCount(1000));
    DatastoreHelper helper = new DatastoreHelper(MONGODB_PRODUCT);
    helper.assertAggregateMetrics();
    Collection<String> transactionNames = InstrumentationTestRunner.getIntrospector().getTransactionNames();
    assertEquals(1, transactionNames.size());
    String txName = transactionNames.iterator().next();
    // Counts based on operations executed in MongoDbAsyncQuickStart
    int insertOpExpectedCount = 1;
    int insertManyOpExpectedCount = 1;
    int updateOpExpectedCount = 1;
    int updateManyOpExpectedCount = 1;
    int deleteOpExpectedCount = 1;
    int deleteManyOpExpectedCount = 1;
    int findOpExpectedCount = 10;
    int dropOpExpectedCount = 3;
    int countOpExpectedCount = 1;
    int bulkWriteOpExpectedCount = 2;
    helper.assertUnifiedMetricCounts(txName, "insert", "test", insertOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "insertMany", "test", insertManyOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "update", "test", updateOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "updateMany", "test", updateManyOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "delete", "test", deleteOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "deleteMany", "test", deleteManyOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "find", "test", findOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "drop", "test", dropOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "count", "test", countOpExpectedCount);
    helper.assertUnifiedMetricCounts(txName, "bulkWrite", "test", bulkWriteOpExpectedCount);
    int totalOpCount = insertOpExpectedCount + insertManyOpExpectedCount + updateOpExpectedCount + updateManyOpExpectedCount + deleteOpExpectedCount + deleteManyOpExpectedCount + findOpExpectedCount + dropOpExpectedCount + countOpExpectedCount + bulkWriteOpExpectedCount;
    // Should be equal to the sum of all above metric counts
    assertEquals(totalOpCount, MetricsHelper.getUnscopedMetricCount("Datastore/all"));
    assertEquals(totalOpCount, MetricsHelper.getUnscopedMetricCount("Datastore/MongoDB/allOther"));
    assertEquals(totalOpCount, introspector.getTransactionEvents(txName).iterator().next().getDatabaseCallCount());
}
Also used : Introspector(com.newrelic.agent.introspec.Introspector) ConnectionString(com.mongodb.ConnectionString) DatastoreHelper(com.newrelic.agent.introspec.DatastoreHelper) Test(org.junit.Test)

Example 24 with Introspector

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

the class NingAsyncHttpClient10Tests method testCat.

@Test
public void testCat() throws Exception {
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    URI endpoint = server.getEndPoint();
    String host = endpoint.getHost();
    int status = makeAsyncRequest(endpoint.toURL().toString());
    assertEquals(200, status);
    // transaction
    String txName = "OtherTransaction/Custom/com.nr.agent.instrumentation.asynchttpclient.NingAsyncHttpClient10Tests/makeAsyncRequest";
    assertEquals(2, introspector.getFinishedTransactionCount(TIMEOUT));
    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.asynchttpclient.NingAsyncHttpClient10Tests/makeAsyncRequest"));
    // 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());
    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 25 with Introspector

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

the class NingAsyncHttpClient10Tests method testSuccess.

@Test
public void testSuccess() throws Exception {
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    URI endpoint = server.getEndPoint();
    String host = endpoint.getHost();
    String url = endpoint.toURL().toExternalForm();
    int status = makeAsyncRequest(url + "?no-transaction=true");
    assertEquals(200, status);
    // transaction
    assertEquals(1, introspector.getFinishedTransactionCount(TIMEOUT));
    String txName = introspector.getTransactionNames().iterator().next();
    // scoped metrics
    assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "External/" + host + "/AsyncHttpClient/onCompleted"));
    // unscoped metrics
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host + "/AsyncHttpClient/onCompleted"));
    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);
    // traces
    Collection<TransactionTrace> traces = introspector.getTransactionTracesForTransaction(txName);
    assertEquals(1, traces.size());
    TransactionTrace trace = traces.iterator().next();
    for (TraceSegment segment : trace.getInitialTraceSegment().getChildren()) {
        Map<String, Object> attributes = segment.getTracerAttributes();
        Object asyncContext = attributes.get("async_context");
        if (asyncContext != null && asyncContext.equals("External")) {
            assertEquals("", segment.getMethodName());
            assertEquals("External Request", segment.getClassName());
            assertEquals("External/" + host + "/AsyncHttpClient/onCompleted", segment.getName());
            assertEquals(url, segment.getUri());
            assertEquals(1, segment.getCallCount());
        }
    }
    // 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("AsyncHttpClient", externalRequest.getLibrary());
    assertEquals("onCompleted", externalRequest.getOperation());
    assertEquals(Integer.valueOf(200), externalRequest.getStatusCode());
    assertEquals("OK", externalRequest.getStatusText());
// netty?
}
Also used : Introspector(com.newrelic.agent.introspec.Introspector) URI(java.net.URI) TraceSegment(com.newrelic.agent.introspec.TraceSegment) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) Test(org.junit.Test)

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