diff --git a/dd-java-agent/agent-jmxfetch/integrations-core b/dd-java-agent/agent-jmxfetch/integrations-core index 3e38b4e75e..e6a01f9e88 160000 --- a/dd-java-agent/agent-jmxfetch/integrations-core +++ b/dd-java-agent/agent-jmxfetch/integrations-core @@ -1 +1 @@ -Subproject commit 3e38b4e75edcee3ca84f022ea50240b0fc0537f2 +Subproject commit e6a01f9e885ac9b71c0ffec8c28dc75668570b15 diff --git a/dd-java-agent/instrumentation/glassfish-4.1/glassfish-4.1.gradle b/dd-java-agent/instrumentation/glassfish-4.1/glassfish-4.1.gradle index 119670b77b..099a4f1c08 100644 --- a/dd-java-agent/instrumentation/glassfish-4.1/glassfish-4.1.gradle +++ b/dd-java-agent/instrumentation/glassfish-4.1/glassfish-4.1.gradle @@ -28,7 +28,7 @@ dependencies { implementation deps.autoservice testCompile project(':dd-java-agent:testing') - testCompile group: 'org.glassfish.main.extras', name: 'glassfish-embedded-all', version: '4.1.2' +// testCompile group: 'org.glassfish.main.extras', name: 'glassfish-embedded-all', version: '4.1.2' latestDepTestCompile sourceSets.test.output } diff --git a/dd-java-agent/instrumentation/glassfish-4.1/src/test/groovy/datadog/trace/instrumentation/glassfish4/GlassfishInstrumentationTest.groovy b/dd-java-agent/instrumentation/glassfish-4.1/src/test/groovy/datadog/trace/instrumentation/glassfish4/GlassfishInstrumentationTest.groovy new file mode 100644 index 0000000000..db89c0d25f --- /dev/null +++ b/dd-java-agent/instrumentation/glassfish-4.1/src/test/groovy/datadog/trace/instrumentation/glassfish4/GlassfishInstrumentationTest.groovy @@ -0,0 +1,33 @@ +package datadog.trace.instrumentation.glassfish4 + +import com.sun.enterprise.v3.server.APIClassLoaderServiceImpl +import datadog.trace.agent.test.AgentTestRunner + +class GlassfishInstrumentationTest extends AgentTestRunner { + + def "classes not related to datadog can be black-listed"() { + setup: + def cli = new APIClassLoaderServiceImpl() + def cl = cli.getApiClassLoader() + cl.triggerAddToBlackList('com.some.Entity') +// def rf = ReflectionFactory.reflectionFactory +// def clazz = Class.forName('com.sun.enterprise.v3.server.APIClassLoaderServiceImpl$APIClassLoader') +// def objDef = clazz.getDeclaredConstructor(ClassLoader.class, ClassLoader.class) +// def intConstr = rf.newConstructorForSerialization(clazz, objDef) +// def instance = clazz.cast(intConstr.newInstance()) + + expect: + 'com.some.Entity' in cl.blacklist + } + + def "classes related to datadog are not black-listed"() { + setup: + def cli = new APIClassLoaderServiceImpl() + def cl = cli.getApiClassLoader() + cl.triggerAddToBlackList('io.opentracing.some.Entity') + + expect: + !('io.opentracing.some.Entity' in cl.blacklist) + '__datadog_no_blacklist.io.opentracing.some.Entity' in cl.blacklist + } +} diff --git a/dd-java-agent/instrumentation/glassfish-4.1/src/test/java/com/sun/enterprise/v3/server/APIClassLoaderServiceImpl.java b/dd-java-agent/instrumentation/glassfish-4.1/src/test/java/com/sun/enterprise/v3/server/APIClassLoaderServiceImpl.java new file mode 100644 index 0000000000..c1b7cfc1aa --- /dev/null +++ b/dd-java-agent/instrumentation/glassfish-4.1/src/test/java/com/sun/enterprise/v3/server/APIClassLoaderServiceImpl.java @@ -0,0 +1,34 @@ +package com.sun.enterprise.v3.server; + +import java.util.HashSet; +import java.util.Set; + +public class APIClassLoaderServiceImpl { + + private APIClassLoader instance; + + public APIClassLoaderServiceImpl() { + this.instance = new APIClassLoader(); + } + + public APIClassLoader getApiClassLoader() { + return instance; + } + + private class APIClassLoader { + + private Set blacklist = new HashSet(); + + public void triggerAddToBlackList(String name) { + addToBlackList(name); + } + + private synchronized void addToBlackList(String name) { + blacklist.add(name); + } + + public Set getBlacklist() { + return blacklist; + } + } +} diff --git a/dd-java-agent/instrumentation/glassfish-4.1/src/test/java/datadog/trace/instrumentation/glassfish4/GlassfishInstrumentationTest.groovy b/dd-java-agent/instrumentation/glassfish-4.1/src/test/java/datadog/trace/instrumentation/glassfish4/GlassfishInstrumentationTest.groovy deleted file mode 100644 index 4cb16f980e..0000000000 --- a/dd-java-agent/instrumentation/glassfish-4.1/src/test/java/datadog/trace/instrumentation/glassfish4/GlassfishInstrumentationTest.groovy +++ /dev/null @@ -1,34 +0,0 @@ -package datadog.trace.instrumentation.glassfish4 - -import datadog.trace.agent.test.AgentTestRunner -import datadog.trace.agent.tooling.Constants -import net.bytebuddy.matcher.NameMatcher - -class GlassfishInstrumentationTest extends AgentTestRunner { - - def "test type matches the correct class loader"() { - setup: - def matchingType = new GlassfishInstrumentation().typeMatcher() - - expect: - matchingType instanceof NameMatcher - matchingType.toString() == 'name(equals(com.sun.enterprise.v3.server.APIClassLoaderServiceImpl$APIClassLoader))' - } - - def "test correct classes are added to the helpers"() { - setup: - def helpers = new GlassfishInstrumentation().helperClassNames() - - expect: - Constants.class.getName() in helpers - } - - def "test the advice is registered for the 'addToBlackList' method"() { - setup: - def transformers = new GlassfishInstrumentation().transformers() - def transformer = transformers.entrySet()[0] - - expect: - transformer.key.toString() == '((isMethod() and name(equals(addToBlackList))) and hasParameter(ofSize(1)))' - } -}