Memcached testing: add support for testoingcontainers
This commit is contained in:
parent
adbab8692c
commit
63c4cdff87
|
@ -4,7 +4,7 @@ defaults: &defaults
|
||||||
working_directory: ~/dd-trace-java
|
working_directory: ~/dd-trace-java
|
||||||
resource_class: large
|
resource_class: large
|
||||||
docker:
|
docker:
|
||||||
- image: circleci/openjdk:8
|
- image: &default_container circleci/openjdk:8
|
||||||
|
|
||||||
cache_keys: &cache_keys
|
cache_keys: &cache_keys
|
||||||
# Reset the cache approx every release
|
# Reset the cache approx every release
|
||||||
|
@ -61,6 +61,11 @@ jobs:
|
||||||
default_test_job: &default_test_job
|
default_test_job: &default_test_job
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
|
|
||||||
|
docker:
|
||||||
|
- image: *default_container
|
||||||
|
# This is used by spymemcached instrumentation tests
|
||||||
|
- image: memcached
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
|
||||||
|
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'
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
|
@ -44,6 +44,7 @@ include ':dd-java-agent:instrumentation:servlet-2'
|
||||||
include ':dd-java-agent:instrumentation:servlet-3'
|
include ':dd-java-agent:instrumentation:servlet-3'
|
||||||
include ':dd-java-agent:instrumentation:sparkjava-2.4'
|
include ':dd-java-agent:instrumentation:sparkjava-2.4'
|
||||||
include ':dd-java-agent:instrumentation:spring-web'
|
include ':dd-java-agent:instrumentation:spring-web'
|
||||||
|
include ':dd-java-agent:instrumentation:spymemcached-2.12'
|
||||||
include ':dd-java-agent:instrumentation:trace-annotation'
|
include ':dd-java-agent:instrumentation:trace-annotation'
|
||||||
|
|
||||||
// benchmark
|
// benchmark
|
||||||
|
|
Loading…
Reference in New Issue