Skip to content

Commit 37b734d

Browse files
committed
Some more attempts to UT glassfish classloader
1 parent f62e1de commit 37b734d

5 files changed

Lines changed: 69 additions & 36 deletions

File tree

Submodule integrations-core updated 1416 files

dd-java-agent/instrumentation/glassfish-4.1/glassfish-4.1.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies {
2828
implementation deps.autoservice
2929

3030
testCompile project(':dd-java-agent:testing')
31-
testCompile group: 'org.glassfish.main.extras', name: 'glassfish-embedded-all', version: '4.1.2'
31+
// testCompile group: 'org.glassfish.main.extras', name: 'glassfish-embedded-all', version: '4.1.2'
3232

3333
latestDepTestCompile sourceSets.test.output
3434
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package datadog.trace.instrumentation.glassfish4
2+
3+
import com.sun.enterprise.v3.server.APIClassLoaderServiceImpl
4+
import datadog.trace.agent.test.AgentTestRunner
5+
6+
class GlassfishInstrumentationTest extends AgentTestRunner {
7+
8+
def "classes not related to datadog can be black-listed"() {
9+
setup:
10+
def cli = new APIClassLoaderServiceImpl()
11+
def cl = cli.getApiClassLoader()
12+
cl.triggerAddToBlackList('com.some.Entity')
13+
// def rf = ReflectionFactory.reflectionFactory
14+
// def clazz = Class.forName('com.sun.enterprise.v3.server.APIClassLoaderServiceImpl$APIClassLoader')
15+
// def objDef = clazz.getDeclaredConstructor(ClassLoader.class, ClassLoader.class)
16+
// def intConstr = rf.newConstructorForSerialization(clazz, objDef)
17+
// def instance = clazz.cast(intConstr.newInstance())
18+
19+
expect:
20+
'com.some.Entity' in cl.blacklist
21+
}
22+
23+
def "classes related to datadog are not black-listed"() {
24+
setup:
25+
def cli = new APIClassLoaderServiceImpl()
26+
def cl = cli.getApiClassLoader()
27+
cl.triggerAddToBlackList('io.opentracing.some.Entity')
28+
29+
expect:
30+
!('io.opentracing.some.Entity' in cl.blacklist)
31+
'__datadog_no_blacklist.io.opentracing.some.Entity' in cl.blacklist
32+
}
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.sun.enterprise.v3.server;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
public class APIClassLoaderServiceImpl {
7+
8+
private APIClassLoader instance;
9+
10+
public APIClassLoaderServiceImpl() {
11+
this.instance = new APIClassLoader();
12+
}
13+
14+
public APIClassLoader getApiClassLoader() {
15+
return instance;
16+
}
17+
18+
private class APIClassLoader {
19+
20+
private Set<String> blacklist = new HashSet<String>();
21+
22+
public void triggerAddToBlackList(String name) {
23+
addToBlackList(name);
24+
}
25+
26+
private synchronized void addToBlackList(String name) {
27+
blacklist.add(name);
28+
}
29+
30+
public Set<String> getBlacklist() {
31+
return blacklist;
32+
}
33+
}
34+
}

dd-java-agent/instrumentation/glassfish-4.1/src/test/java/datadog/trace/instrumentation/glassfish4/GlassfishInstrumentationTest.groovy

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)