Search in sources :

Example 16 with Introspector

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

the class MongoDb212Test method testCRUD.

@Test
public void testCRUD() throws Exception {
    demoCRUD(new PokemonMaster(mongoClient));
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    assertEquals(1, introspector.getFinishedTransactionCount());
    DatastoreHelper helper = new DatastoreHelper(MONGODB_PRODUCT);
    helper.assertAggregateMetrics();
    Collection<String> transactionNames = InstrumentationTestRunner.getIntrospector().getTransactionNames();
    assertEquals(1, transactionNames.size());
    String txName = transactionNames.iterator().next();
    helper.assertUnifiedMetricCounts(txName, "insert", "pokemon", 1);
    helper.assertUnifiedMetricCounts(txName, "find", "pokemon", 2);
    helper.assertUnifiedMetricCounts(txName, "update", "pokemon", 1);
    helper.assertUnifiedMetricCounts(txName, "remove", "pokemon", 1);
}
Also used : Introspector(com.newrelic.agent.introspec.Introspector) DatastoreHelper(com.newrelic.agent.introspec.DatastoreHelper) Test(org.junit.Test)

Example 17 with Introspector

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

the class Lettuce5InstrumentationTest method testAsync.

@Test
public void testAsync() throws ExecutionException, InterruptedException {
    // given some data
    Data data = new Data("asyncKey1", "asyncValue1");
    // when async 'set' called
    String response = redisDataService.asyncSet(data);
    // then response should be 'OK'
    assertEquals("Then response should be 'OK'", "OK", response);
    // when async 'get' called
    String value = redisDataService.asyncGet(data.key);
    // then value returned
    assertEquals("Get value", data.value, value);
    // and 2 transactions have been sent
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    assertEquals("Finished transaction count", 2, introspector.getFinishedTransactionCount(1000));
    Collection<String> transactionNames = introspector.getTransactionNames();
    assertEquals("Transaction name count", 2, transactionNames.size());
    String setTransactionName = "OtherTransaction/Custom/com.nr.lettuce5.instrumentation.helper.RedisDataService/asyncSet";
    String getTransactionName = "OtherTransaction/Custom/com.nr.lettuce5.instrumentation.helper.RedisDataService/asyncGet";
    // and transaction names are in collection
    assertTrue("Should contain transaction name for 'set'", transactionNames.contains(setTransactionName));
    assertTrue("Should contain transaction name for 'get'", transactionNames.contains(getTransactionName));
    // and required datastore metrics are sent
    DatastoreHelper helper = new DatastoreHelper("Redis");
    helper.assertAggregateMetrics();
    assertEquals(1, introspector.getTransactionEvents(setTransactionName).iterator().next().getDatabaseCallCount());
    assertEquals(1, introspector.getTransactionEvents(getTransactionName).iterator().next().getDatabaseCallCount());
    helper.assertUnscopedOperationMetricCount("SET", 1);
    helper.assertUnscopedOperationMetricCount("GET", 1);
    helper.assertInstanceLevelMetric(DatastoreVendor.Redis.name(), redis.getHost(), redis.getFirstMappedPort().toString());
}
Also used : Introspector(com.newrelic.agent.introspec.Introspector) Data(com.nr.lettuce5.instrumentation.helper.Data) DatastoreHelper(com.newrelic.agent.introspec.DatastoreHelper) Test(org.junit.Test)

Example 18 with Introspector

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

the class Lettuce5InstrumentationTest method testReactive.

@Test
public void testReactive() {
    // given some data
    Data data1 = new Data("key1", "value1");
    Data data2 = new Data("key2", "value3");
    Data data3 = new Data("key3", "value3");
    // when reactive 'set' called
    List<String> ids = redisDataService.reactiveSet(Flux.just(data1, data2, data3));
    // then all 'OK'
    assertArrayEquals("All responses should be 'OK'", new String[] { "OK", "OK", "OK" }, ids.toArray());
    // when reactive 'get' called
    List<String> values = redisDataService.reactiveGet(Flux.just(data1.key, data2.key, data3.key));
    // then 3 values returned
    String[] expectedValues = new String[] { data1.value, data2.value, data3.value };
    assertEquals("Get values size did not math the amount set", 3, values.size());
    assertArrayEquals("Values returned should equal sent", expectedValues, values.toArray());
    // and 2 transactions have been sent
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    assertEquals(2, introspector.getFinishedTransactionCount(1000));
    Collection<String> transactionNames = introspector.getTransactionNames();
    assertEquals(2, transactionNames.size());
    String setTransactionName = "OtherTransaction/Custom/com.nr.lettuce5.instrumentation.helper.RedisDataService/reactiveSet";
    String getTransactionName = "OtherTransaction/Custom/com.nr.lettuce5.instrumentation.helper.RedisDataService/reactiveGet";
    // and transaction names are in collection
    assertTrue("Should contain transaction name for 'set'", transactionNames.contains(setTransactionName));
    assertTrue("Should contain transaction name for 'get'", transactionNames.contains(getTransactionName));
    // and required datastore metrics are sent
    DatastoreHelper helper = new DatastoreHelper("Redis");
    helper.assertAggregateMetrics();
    assertEquals(3, introspector.getTransactionEvents(setTransactionName).iterator().next().getDatabaseCallCount());
    assertEquals(3, introspector.getTransactionEvents(getTransactionName).iterator().next().getDatabaseCallCount());
    helper.assertUnscopedOperationMetricCount("SET", 3);
    helper.assertUnscopedOperationMetricCount("GET", 3);
    helper.assertInstanceLevelMetric("Redis", "localhost", redis.getFirstMappedPort().toString());
}
Also used : Introspector(com.newrelic.agent.introspec.Introspector) Data(com.nr.lettuce5.instrumentation.helper.Data) DatastoreHelper(com.newrelic.agent.introspec.DatastoreHelper) Test(org.junit.Test)

Example 19 with Introspector

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

the class Lettuce6InstrumentationTest method testReactive.

@Test
public void testReactive() {
    // given some data
    Data data1 = new Data("key1", "value1");
    Data data2 = new Data("key2", "value3");
    Data data3 = new Data("key3", "value3");
    // when reactive 'set' called
    List<String> ids = redisDataService.reactiveSet(Flux.just(data1, data2, data3));
    // then all 'OK'
    assertArrayEquals("All responses should be 'OK'", new String[] { "OK", "OK", "OK" }, ids.toArray());
    // when reactive 'get' called
    List<String> values = redisDataService.reactiveGet(Flux.just(data1.key, data2.key, data3.key));
    // then 3 values returned
    String[] expectedValues = new String[] { data1.value, data2.value, data3.value };
    assertEquals("Get values size did not math the amount set", 3, values.size());
    assertArrayEquals("Values returned should equal sent", expectedValues, values.toArray());
    // and 2 transactions have been sent
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    assertEquals(2, introspector.getFinishedTransactionCount(1000));
    Collection<String> transactionNames = introspector.getTransactionNames();
    assertEquals(2, transactionNames.size());
    String setTransactionName = "OtherTransaction/Custom/com.nr.lettuce6.instrumentation.helper.RedisDataService/reactiveSet";
    String getTransactionName = "OtherTransaction/Custom/com.nr.lettuce6.instrumentation.helper.RedisDataService/reactiveGet";
    // and transaction names are in collection
    assertTrue("Should contain transaction name for 'set'", transactionNames.contains(setTransactionName));
    assertTrue("Should contain transaction name for 'get'", transactionNames.contains(getTransactionName));
    // and required datastore metrics are sent
    DatastoreHelper helper = new DatastoreHelper("Redis");
    helper.assertAggregateMetrics();
    assertEquals(3, introspector.getTransactionEvents(setTransactionName).iterator().next().getDatabaseCallCount());
    assertEquals(3, introspector.getTransactionEvents(getTransactionName).iterator().next().getDatabaseCallCount());
    helper.assertUnscopedOperationMetricCount("SET", 3);
    helper.assertUnscopedOperationMetricCount("GET", 3);
    helper.assertInstanceLevelMetric("Redis", "localhost", redis.getFirstMappedPort().toString());
}
Also used : Introspector(com.newrelic.agent.introspec.Introspector) Data(com.nr.lettuce6.instrumentation.helper.Data) DatastoreHelper(com.newrelic.agent.introspec.DatastoreHelper) Test(org.junit.Test)

Example 20 with Introspector

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

the class MongoDb214Test method testBulkOps.

@Test
public void testBulkOps() throws Exception {
    demoBulkOps(new PokemonMaster(mongoClient));
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    assertEquals(1, introspector.getFinishedTransactionCount());
    DatastoreHelper helper = new DatastoreHelper(MONGODB_PRODUCT);
    helper.assertAggregateMetrics();
    Collection<String> transactionNames = InstrumentationTestRunner.getIntrospector().getTransactionNames();
    assertEquals(1, transactionNames.size());
    String txName = transactionNames.iterator().next();
    helper.assertUnifiedMetricCounts(txName, "insert", "pokemon", 3);
    helper.assertUnifiedMetricCounts(txName, "parallelCollectionScan", "pokemon", 1);
}
Also used : Introspector(com.newrelic.agent.introspec.Introspector) DatastoreHelper(com.newrelic.agent.introspec.DatastoreHelper) 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