diff --git a/instrumentation-security/lettuce-4.3/src/test/java/com/nr/lettuce43/instrumentation/Lettuce43InstrumentationTest.java b/instrumentation-security/lettuce-4.3/src/test/java/com/nr/lettuce43/instrumentation/Lettuce43InstrumentationTest.java deleted file mode 100644 index f8cf6af05..000000000 --- a/instrumentation-security/lettuce-4.3/src/test/java/com/nr/lettuce43/instrumentation/Lettuce43InstrumentationTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * - * * Copyright 2022 New Relic Corporation. All rights reserved. - * * SPDX-License-Identifier: Apache-2.0 - * - */ -package com.nr.lettuce43.instrumentation; - -import com.newrelic.agent.bridge.datastore.DatastoreVendor; -import com.newrelic.agent.introspec.DatastoreHelper; -import com.newrelic.agent.introspec.InstrumentationTestConfig; -import com.newrelic.agent.introspec.InstrumentationTestRunner; -import com.newrelic.agent.introspec.Introspector; -import com.nr.lettuce43.instrumentation.helper.Data; -import com.nr.lettuce43.instrumentation.helper.RedisDataService; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.utility.DockerImageName; - -import java.util.Collection; -import java.util.concurrent.ExecutionException; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -@RunWith(InstrumentationTestRunner.class) -@InstrumentationTestConfig(includePrefixes = {"com.lambdaworks.redis"}) -public class Lettuce43InstrumentationTest { - - @Rule - public GenericContainer redis = new GenericContainer(DockerImageName.parse("redis:5.0.3-alpine")) - .withExposedPorts(6379); - private RedisDataService redisDataService; - - @Before - public void before() { - redisDataService = new RedisDataService(redis); - redisDataService.init(); - } - - @Test - public void testSync() { - // given some data - String key = "syncKey"; - String value = "syncValue"; - - // when sync 'set' called - String response = redisDataService.syncSet(key, value); - - // then response should be key - assertEquals("Then response should be key", key, response); - - // when 'get' called - String received = redisDataService.syncGet(key); - - // then value returned - assertEquals("Get value", value, received); - - // and 2 transactions have been sent - Introspector introspector = InstrumentationTestRunner.getIntrospector(); - assertEquals("Finished transaction count", 2, introspector.getFinishedTransactionCount(1000)); - Collection transactionNames = introspector.getTransactionNames(); - assertEquals("Transaction name count", 2, transactionNames.size()); - - String setTransactionName = "OtherTransaction/Custom/com.nr.lettuce43.instrumentation.helper.RedisDataService/syncSet"; - String getTransactionName = "OtherTransaction/Custom/com.nr.lettuce43.instrumentation.helper.RedisDataService/syncGet"; - - // 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(DatastoreVendor.Redis.name()); - 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()); - } - - @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 transactionNames = introspector.getTransactionNames(); - assertEquals("Transaction name count", 2, transactionNames.size()); - - String setTransactionName = "OtherTransaction/Custom/com.nr.lettuce43.instrumentation.helper.RedisDataService/asyncSet"; - String getTransactionName = "OtherTransaction/Custom/com.nr.lettuce43.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()); - } -} diff --git a/instrumentation-security/lettuce-4.3/src/test/java/com/nr/lettuce43/instrumentation/RedisDatastoreParametersTest.java b/instrumentation-security/lettuce-4.3/src/test/java/com/nr/lettuce43/instrumentation/RedisDatastoreParametersTest.java deleted file mode 100644 index 7eff025f8..000000000 --- a/instrumentation-security/lettuce-4.3/src/test/java/com/nr/lettuce43/instrumentation/RedisDatastoreParametersTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.nr.lettuce43.instrumentation; - -import com.lambdaworks.redis.RedisURI; -import com.newrelic.api.agent.DatastoreParameters; -import junit.framework.TestCase; -import org.junit.jupiter.api.Test; - -public class RedisDatastoreParametersTest extends TestCase { - - @Test - public void testDatastoreParametersForUri() { - // Given - Integer expectedPort = 12345; - RedisURI uri = RedisURI.create("redis://localhost:" + expectedPort); - String operation = "GET"; - - // When - DatastoreParameters dbParams = RedisDatastoreParameters.from(uri, operation); - - // Then url values are correct - assertEquals(expectedPort, dbParams.getPort()); - assertEquals("localhost", dbParams.getHost()); - - // And database info is populated correctly - assertEquals("Redis", dbParams.getProduct()); - assertEquals(operation, dbParams.getOperation()); - } - - @Test - public void testDatastoreParametersForClustering_noUrl() { - // Given - String operation = "GET"; - - // When - DatastoreParameters dbParams = RedisDatastoreParameters.from(null, operation); - - // Then there are no url values - assertNull(dbParams.getPort()); - assertNull(dbParams.getHost()); - - // And database info is STILL populated correctly - assertEquals("Redis", dbParams.getProduct()); - assertEquals(operation, dbParams.getOperation()); - } -} \ No newline at end of file diff --git a/instrumentation-security/lettuce-4.3/src/test/java/com/nr/lettuce43/instrumentation/helper/Data.java b/instrumentation-security/lettuce-4.3/src/test/java/com/nr/lettuce43/instrumentation/helper/Data.java deleted file mode 100644 index 36688c1c2..000000000 --- a/instrumentation-security/lettuce-4.3/src/test/java/com/nr/lettuce43/instrumentation/helper/Data.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * - * * Copyright 2022 New Relic Corporation. All rights reserved. - * * SPDX-License-Identifier: Apache-2.0 - * - */ -package com.nr.lettuce43.instrumentation.helper; - -public class Data { - public final String key; - public final String value; - - public Data(String key, String value) { - this.key = key; - this.value = value; - } -} diff --git a/instrumentation-security/lettuce-4.3/src/test/java/com/nr/lettuce43/instrumentation/helper/RedisDataService.java b/instrumentation-security/lettuce-4.3/src/test/java/com/nr/lettuce43/instrumentation/helper/RedisDataService.java deleted file mode 100644 index b289ffd61..000000000 --- a/instrumentation-security/lettuce-4.3/src/test/java/com/nr/lettuce43/instrumentation/helper/RedisDataService.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * * Copyright 2022 New Relic Corporation. All rights reserved. - * * SPDX-License-Identifier: Apache-2.0 - * - */ -package com.nr.lettuce43.instrumentation.helper; - -import com.lambdaworks.redis.RedisClient; -import com.lambdaworks.redis.api.StatefulRedisConnection; -import com.lambdaworks.redis.api.async.RedisAsyncCommands; -import com.lambdaworks.redis.api.sync.RedisCommands; -import com.newrelic.api.agent.Trace; -import org.testcontainers.containers.GenericContainer; - -import java.util.concurrent.ExecutionException; - -public class RedisDataService { - private final GenericContainer genericContainer; - private RedisAsyncCommands asyncCommands; - private RedisCommands syncCommands; - - public RedisDataService(GenericContainer container) { - this.genericContainer = container; - } - - @Trace(dispatcher = true) - public String syncSet(String key, String value) { - syncCommands.set(key, value); - return key; - } - - @Trace(dispatcher = true) - public String syncGet(String key) { - return syncCommands.get(key); - } - - @Trace(dispatcher = true) - public String asyncSet(Data data) throws ExecutionException, InterruptedException { - String value = asyncCommands.set(data.key, data.value).get(); - return value; - } - - @Trace(dispatcher = true) - public String asyncGet(String key) throws ExecutionException, InterruptedException { - return asyncCommands.get(key).get(); - } - - public void init() { - setupRedisClient(); - } - - private void setupRedisClient() { - RedisClient redisClient = RedisClient.create("redis://" + genericContainer.getHost() + ":" + genericContainer.getMappedPort(6379)); - StatefulRedisConnection connection = redisClient.connect(); - this.syncCommands = connection.sync(); - this.asyncCommands = connection.async(); - } - -}