Fix tests

This commit is contained in:
Tyler Benson 2017-08-18 10:25:07 -06:00
parent 988a3d0fdf
commit aad3746c2b
7 changed files with 67 additions and 29 deletions

View File

@ -38,9 +38,10 @@ class VersionScanPlugin implements Plugin<Project> {
description = "Queries for all versions of configured modules and finds key classes" description = "Queries for all versions of configured modules and finds key classes"
} }
if (!project.gradle.startParameter.taskNames.each { it.endsWith('scanVersions') }.any()) { if (!project.gradle.startParameter.taskNames.contains('scanVersions')) {
return return
} }
println "Adding scan tasks for $project"
Set<String> allInclude = Sets.newConcurrentHashSet() Set<String> allInclude = Sets.newConcurrentHashSet()
Set<String> allExclude = Sets.newConcurrentHashSet() Set<String> allExclude = Sets.newConcurrentHashSet()

View File

@ -17,6 +17,8 @@ whitelistedInstructionClasses += whitelistedBranchClasses += [
'com.datadoghq.trace.agent.InstrumentationChecker', 'com.datadoghq.trace.agent.InstrumentationChecker',
'com.datadoghq.trace.agent.DDJavaAgentInfo', 'com.datadoghq.trace.agent.DDJavaAgentInfo',
'io.opentracing.contrib.mongo.TracingCommandListenerFactory', 'io.opentracing.contrib.mongo.TracingCommandListenerFactory',
'com.datadoghq.trace.agent.InstrumentationChecker.1',
'com.datadoghq.trace.agent.InstrumentationChecker.ArtifactSupport',
] ]
dependencies { dependencies {

View File

@ -42,7 +42,7 @@ public class InstrumentationChecker {
this.classLoader = classLoader; this.classLoader = classLoader;
rules = rules =
FactoryUtils.loadConfigFromResource( FactoryUtils.loadConfigFromResource(
CONFIG_FILE, new TypeReference<Map<String, List<Map<String, String>>>>() {}); CONFIG_FILE, new TypeReference<Map<String, List<ArtifactSupport>>>() {});
frameworks = scanLoadedLibraries(); frameworks = scanLoadedLibraries();
} }

View File

@ -37,7 +37,7 @@ opentracing-cassandra-driver:
opentracing-web-servlet-filter: opentracing-web-servlet-filter:
- artifact: jetty-server - artifact: jetty-server
supported_version: (8\.|9\.).* supported_version: (8\.|9\.).*
identifying_present_classes: # identifying_present_classes:
- artifact: tomcat_catalina - artifact: tomcat_catalina
supported_version: (8\.|9\.).* supported_version: (8\.|9\.).*
@ -65,7 +65,7 @@ opentracing-okhttp3:
opentracing-jms-2: opentracing-jms-2:
- artifact: javax.jms-api - artifact: javax.jms-api
supported_version: 2\..* supported_version: 2\..*
identifying_present_classes identifying_present_classes:
- javax.jms.JMSContext - javax.jms.JMSContext
- javax.jms.CompletionListener - javax.jms.CompletionListener

View File

@ -7,7 +7,7 @@ import spock.lang.Specification
class InstrumentationCheckerTest extends Specification { class InstrumentationCheckerTest extends Specification {
Map<String, List<Map<String, String>>> rules = Map<String, List<Map<String, String>>> rules =
FactoryUtils.loadConfigFromResource("supported-version-test", new TypeReference<Map<String, List<InstrumentationChecker.ArtifactSupport>>>() { FactoryUtils.loadConfigFromResource("supported-version-test", new TypeReference<Map<String, List<InstrumentationChecker.ArtifactSupport>>>() {
}); })
Map<String, String> frameworks = [ Map<String, String> frameworks = [
"artifact-1": "1.2.3.1232", "artifact-1": "1.2.3.1232",
"artifact-2": "4.y.z", "artifact-2": "4.y.z",
@ -18,7 +18,7 @@ class InstrumentationCheckerTest extends Specification {
def "test rules"() { def "test rules"() {
setup: setup:
def rules = InstrumentationChecker.getUnsupportedRules(java.lang.ClassLoader.getSystemClassLoader()); def rules = InstrumentationChecker.getUnsupportedRules(java.lang.ClassLoader.getSystemClassLoader())
expect: expect:
rules.size() == 3 rules.size() == 3

View File

@ -15,6 +15,7 @@ whitelistedInstructionClasses += whitelistedBranchClasses += [
'com.datadoghq.trace.DDTags', 'com.datadoghq.trace.DDTags',
'com.datadoghq.trace.DDTraceInfo', 'com.datadoghq.trace.DDTraceInfo',
'com.datadoghq.trace.util.Clock', 'com.datadoghq.trace.util.Clock',
'com.datadoghq.trace.resolver.FactoryUtils',
] ]
dependencies { dependencies {

View File

@ -15,8 +15,18 @@ public class FactoryUtils {
public static <A> A loadConfigFromFilePropertyOrResource( public static <A> A loadConfigFromFilePropertyOrResource(
final String systemProperty, final String resourceName, final Class<A> targetClass) { final String systemProperty, final String resourceName, final Class<A> targetClass) {
return loadConfigFromFilePropertyOrResource( final String filePath = System.getProperty(systemProperty);
systemProperty, resourceName, new TypeReference<A>() {}); if (filePath != null) {
try {
log.info("Loading config from file " + filePath);
return objectMapper.readValue(new File(filePath), targetClass);
} catch (final Exception e) {
log.error(
"Cannot read provided configuration file " + filePath + ". Using the default one.", e);
}
}
return loadConfigFromResource(resourceName, targetClass);
} }
public static <A> A loadConfigFromFilePropertyOrResource( public static <A> A loadConfigFromFilePropertyOrResource(
@ -37,7 +47,31 @@ public class FactoryUtils {
public static <A> A loadConfigFromResource( public static <A> A loadConfigFromResource(
final String resourceName, final Class<A> targetClass) { final String resourceName, final Class<A> targetClass) {
return loadConfigFromResource(resourceName, new TypeReference<A>() {}); A config = null;
// Try loading both suffixes
if (!resourceName.endsWith(".yaml") && !resourceName.endsWith(".yml")) {
config = loadConfigFromResource(resourceName + ".yaml", targetClass);
if (config == null) {
config = loadConfigFromResource(resourceName + ".yml", targetClass);
}
if (config != null) {
return config;
}
}
try {
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final URL resource = classLoader.getResource(resourceName);
if (resource != null) {
log.info("Loading config from resource " + resource);
config = objectMapper.readValue(resource.openStream(), targetClass);
}
} catch (final IOException e) {
log.warn("Could not load configuration file {}.", resourceName);
log.error("Error when loading config file", e);
}
return config;
} }
public static <A> A loadConfigFromResource(final String resourceName, final TypeReference type) { public static <A> A loadConfigFromResource(final String resourceName, final TypeReference type) {