Memcached testing: add support for testoingcontainers
MODIFY
.circleci/config.yml
.circleci/config.yml
@@ -4,7 +4,7 @@ defaults: &defaults
working_directory: ~/dd-trace-java
resource_class: large
docker:
- - image: circleci/openjdk:8
+ - image: &default_container circleci/openjdk:8
cache_keys: &cache_keys
# Reset the cache approx every release
@@ -61,6 +61,11 @@ jobs:
default_test_job: &default_test_job
<<: *defaults
+ docker:
+ - image: *default_container
+ # This is used by spymemcached instrumentation tests
+ - image: memcached
+
steps:
- checkout

ADD
dd-java-agent/instrumentation/spymemcached-2.12/spymemcached-2.12.gradle
+
+apply from: "${rootDir}/gradle/java.gradle"
+
+dependencies {
+ compileOnly group: 'net.spy', name: 'spymemcached', version: '2.12.0'
+
+ compile project(':dd-java-agent:agent-tooling')
+
+ compile deps.bytebuddy
+ compile deps.opentracing
+ annotationProcessor deps.autoservice
+ implementation deps.autoservice
+
+ testCompile project(':dd-java-agent:testing')
+
+ // Include servlet instrumentation for verifying the tomcat requests
+ testCompile project(':dd-java-agent:instrumentation:servlet-3')
+
+
+ testCompile group: 'net.spy', name: 'spymemcached', version: '2.12.0'
+ testCompile group: 'org.spockframework', name:'spock-core', version:'1.1-groovy-2.4'
+ testCompile group: 'org.testcontainers', name:'testcontainers', version:'1.7.3'
+}

ADD
dd-java-agent/instrumentation/spymemcached-2.12/src/test/groovy/datadog/trace/instrumentation/spymemcached/SpymemcachedTest.groovy
+package datadog.trace.instrumentation.spymemcached
+
+import datadog.trace.agent.test.AgentTestRunner
+import net.spy.memcached.MemcachedClient
+import org.testcontainers.containers.GenericContainer
+import spock.lang.Shared
+
+class SpymemcachedTest extends AgentTestRunner {
+
+ @Shared
+ def defaultMemcachedPort = 11211
+ @Shared
+ /*
+ Note: type here has to stay undefined, otherwise tests will fail in CI in Java 7 because
+ 'testcontainers' are built for Java 8 and Java 7 cannot load this class.
+ */
+ def memcachedContainer
+
+ @Shared
+ MemcachedClient memcached
+
+ def setupSpec() {
+ // Setup default hostname and port
+ String ip = "127.0.0.1"
+ int port = defaultMemcachedPort
+
+ /*
+ CI will provide us with memcached container running along side our build.
+ When building locally, however, we need to take matters into our own hands
+ and we use 'testcontainers' for this.
+ */
+ if ("true" != System.getenv("CI")) {
+ memcachedContainer = new GenericContainer('memcached:latest')
+ .withExposedPorts(defaultMemcachedPort)
+ memcachedContainer.start()
+ ip = memcachedContainer.containerIpAddress
+ port = memcachedContainer.getMappedPort(defaultMemcachedPort)
+ }
+
+ memcached = new MemcachedClient(new InetSocketAddress(ip, port))
+ }
+
+ def cleanupSpec() {
+ if (memcachedContainer) {
+ memcachedContainer.stop()
+ }
+ }
+
+ def "command with no arguments"() {
+ when:
+ memcached.set("foo", 3600, "bar").get()
+
+ then:
+ memcached.get("foo") == "bar"
+ }
+}

MODIFY
settings.gradle
settings.gradle
@@ -44,6 +44,7 @@ include ':dd-java-agent:instrumentation:servlet-2'
include ':dd-java-agent:instrumentation:servlet-3'
include ':dd-java-agent:instrumentation:sparkjava-2.4'
include ':dd-java-agent:instrumentation:spring-web'
+include ':dd-java-agent:instrumentation:spymemcached-2.12'
include ':dd-java-agent:instrumentation:trace-annotation'
// benchmark

Memcached testing: add support for testoingcontainers