Some more attempts to UT glassfish classloader
This commit is contained in:
parent
f62e1dedeb
commit
37b734dd50
|
@ -1 +1 @@
|
|||
Subproject commit 3e38b4e75edcee3ca84f022ea50240b0fc0537f2
|
||||
Subproject commit e6a01f9e885ac9b71c0ffec8c28dc75668570b15
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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<String> blacklist = new HashSet<String>();
|
||||
|
||||
public void triggerAddToBlackList(String name) {
|
||||
addToBlackList(name);
|
||||
}
|
||||
|
||||
private synchronized void addToBlackList(String name) {
|
||||
blacklist.add(name);
|
||||
}
|
||||
|
||||
public Set<String> getBlacklist() {
|
||||
return blacklist;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)))'
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue