Search in sources :

Example 1 with WeavePackageConfig

use of com.newrelic.weave.weavepackage.WeavePackageConfig in project newrelic-java-agent by newrelic.

the class ClassTransformerConfigImplTest method weavePackageConfigNameSystemPropertyOverride.

@Test
public void weavePackageConfigNameSystemPropertyOverride() {
    final String moduleName = "com.newrelic.instrumentation.mymodule-1.0";
    HashMap<String, Object> props = new HashMap<>();
    ClassTransformerConfig config = new ClassTransformerConfigImpl(props, true);
    System.setProperty("newrelic.config.class_transformer." + moduleName + ".enabled", "false");
    WeavePackageConfig weaveConfig = WeavePackageConfig.builder().name(moduleName).enabled(true).build();
    Assert.assertFalse(config.isWeavePackageEnabled(weaveConfig));
    System.clearProperty("newrelic.config.class_transformer." + moduleName + ".enabled");
}
Also used : WeavePackageConfig(com.newrelic.weave.weavepackage.WeavePackageConfig) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 2 with WeavePackageConfig

use of com.newrelic.weave.weavepackage.WeavePackageConfig in project newrelic-java-agent by newrelic.

the class ClassTransformerConfigImplTest method weavePackageConfigAliasOverride.

@Test
public void weavePackageConfigAliasOverride() {
    final String moduleName = "com.newrelic.instrumentation.mymodule-1.0";
    final String aliasName = "my_alias";
    HashMap<String, Object> props = new HashMap<>();
    props.put(aliasName, ImmutableMap.of("enabled", false));
    ClassTransformerConfig config = new ClassTransformerConfigImpl(props, true);
    WeavePackageConfig weaveConfig = WeavePackageConfig.builder().name(moduleName).alias(aliasName).enabled(true).build();
    Assert.assertFalse(config.isWeavePackageEnabled(weaveConfig));
}
Also used : WeavePackageConfig(com.newrelic.weave.weavepackage.WeavePackageConfig) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with WeavePackageConfig

use of com.newrelic.weave.weavepackage.WeavePackageConfig in project newrelic-java-agent by newrelic.

the class ClassTransformerConfigImplTest method weavePackageConfigNameAndAliasSystemPropertyOverride.

@Test
public void weavePackageConfigNameAndAliasSystemPropertyOverride() {
    // if both alias and name are present, both must be set to enabled for the module to be loaded
    final String moduleName = "com.newrelic.instrumentation.mymodule-1.0";
    final String aliasName = "my_alias";
    HashMap<String, Object> props = new HashMap<>();
    ClassTransformerConfig config = new ClassTransformerConfigImpl(props, true);
    System.setProperty("newrelic.config.class_transformer." + moduleName + ".enabled", "true");
    System.setProperty("newrelic.config.class_transformer." + aliasName + ".enabled", "false");
    WeavePackageConfig weaveConfig = WeavePackageConfig.builder().name(moduleName).alias(aliasName).enabled(true).build();
    Assert.assertFalse(config.isWeavePackageEnabled(weaveConfig));
    System.clearProperty("newrelic.config.class_transformer." + moduleName + ".enabled");
    System.clearProperty("newrelic.config.class_transformer." + aliasName + ".enabled");
}
Also used : WeavePackageConfig(com.newrelic.weave.weavepackage.WeavePackageConfig) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 4 with WeavePackageConfig

use of com.newrelic.weave.weavepackage.WeavePackageConfig in project newrelic-java-agent by newrelic.

the class ClassTransformerConfigImplTest method weavePackageConfigNameOverride.

@Test
public void weavePackageConfigNameOverride() {
    final String moduleName = "com.newrelic.instrumentation.mymodule-1.0";
    HashMap<String, Object> props = new HashMap<>();
    props.put(moduleName, ImmutableMap.of("enabled", false));
    ClassTransformerConfig config = new ClassTransformerConfigImpl(props, true);
    WeavePackageConfig weaveConfig = WeavePackageConfig.builder().name(moduleName).enabled(true).build();
    Assert.assertFalse(config.isWeavePackageEnabled(weaveConfig));
}
Also used : WeavePackageConfig(com.newrelic.weave.weavepackage.WeavePackageConfig) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 5 with WeavePackageConfig

use of com.newrelic.weave.weavepackage.WeavePackageConfig in project newrelic-java-agent by newrelic.

the class ClassTransformerConfigImplTest method weavePackageConfigNameAndAliasOverride.

@Test
public void weavePackageConfigNameAndAliasOverride() {
    // if both alias and name are present, both must be set to enabled for the module to be loaded
    final String moduleName = "com.newrelic.instrumentation.mymodule-1.0";
    final String aliasName = "my_alias";
    Map<String, Object> configuration = new HashMap<>();
    configuration.put(moduleName + ":enabled", true);
    configuration.put(aliasName + ":enabled", false);
    configuration = buildConfigMap(configuration);
    ClassTransformerConfig ctConfig = new ClassTransformerConfigImpl(configuration, true);
    WeavePackageConfig weaveConfig = WeavePackageConfig.builder().name(moduleName).alias(aliasName).enabled(true).build();
    Assert.assertFalse(ctConfig.isWeavePackageEnabled(weaveConfig));
}
Also used : WeavePackageConfig(com.newrelic.weave.weavepackage.WeavePackageConfig) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

WeavePackageConfig (com.newrelic.weave.weavepackage.WeavePackageConfig)22 Test (org.junit.Test)10 WeavePackage (com.newrelic.weave.weavepackage.WeavePackage)9 HashMap (java.util.HashMap)9 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)4 ClassTransformerConfig (com.newrelic.agent.config.ClassTransformerConfig)3 URL (java.net.URL)3 JarInputStream (java.util.jar.JarInputStream)3 AgentConfig (com.newrelic.agent.config.AgentConfig)2 WeaveViolation (com.newrelic.weave.violation.WeaveViolation)2 CachedWeavePackage (com.newrelic.weave.weavepackage.CachedWeavePackage)2 File (java.io.File)2 HashSet (java.util.HashSet)2 AgentClassLoaderBaseInstrumentation (com.newrelic.agent.instrumentation.builtin.AgentClassLoaderBaseInstrumentation)1 AgentClassLoaderInstrumentation (com.newrelic.agent.instrumentation.builtin.AgentClassLoaderInstrumentation)1 ClassLoaderPackageAccessInstrumentation (com.newrelic.agent.instrumentation.builtin.ClassLoaderPackageAccessInstrumentation)1 ClassMatchVisitorFactory (com.newrelic.agent.instrumentation.context.ClassMatchVisitorFactory)1 AgentPostprocessors (com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPostprocessors)1 AgentPreprocessors (com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessors)1