Search in sources :

Example 1 with TokenNullCheckClassVisitor

use of com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessors.TokenNullCheckClassVisitor in project newrelic-java-agent by newrelic.

the class AgentPreprocessorsTest method testTokenExpire.

@Test
public void testTokenExpire() throws Exception {
    final ClassLoader classloader = Thread.currentThread().getContextClassLoader();
    final String classname = "com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessorsTest$WeaveTestClass";
    Map<String, Object> confProps = new HashMap<>();
    AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(confProps);
    byte[] bytes = getClassBytesFromClassLoaderResource(classname, classloader);
    Assert.assertNotNull(bytes);
    ClassNode source = WeaveUtils.convertToClassNode(bytes);
    ClassNode result = new ClassNode(WeaveUtils.ASM_API_LEVEL);
    ClassVisitor cv = result;
    cv = new CheckClassAdapter(result);
    AgentPreprocessors preprocessors = new AgentPreprocessors(agentConfig, null);
    preprocessors.setInstrumentationTitle(INSTRUMENTATION_TITLE);
    TokenNullCheckClassVisitor tcv = preprocessors.nullOutTokenAfterExpire(cv);
    source.accept(tcv);
    Map<String, Integer> rewriteCounts = tcv.getExpireRewriteCounts();
    Assert.assertEquals(1, rewriteCounts.get("doesNotNull").intValue());
    Assert.assertEquals(0, rewriteCounts.get("doesNull").intValue());
    Assert.assertEquals(0, rewriteCounts.get("conditionallyNullsGood").intValue());
    Assert.assertEquals(1, rewriteCounts.get("conditionallyNullsBad").intValue());
    Assert.assertEquals(1, rewriteCounts.get("nullsLater").intValue());
    Assert.assertEquals(1, rewriteCounts.get("returnsBeforeNull").intValue());
    Assert.assertEquals(2, rewriteCounts.get("twoExpires").intValue());
    Assert.assertEquals(1, rewriteCounts.get("nullsOtherToken").intValue());
    Assert.assertEquals(0, rewriteCounts.get("expiresLocal").intValue());
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TokenNullCheckClassVisitor(com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessors.TokenNullCheckClassVisitor) ClassVisitor(org.objectweb.asm.ClassVisitor) TokenNullCheckClassVisitor(com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessors.TokenNullCheckClassVisitor) AgentConfig(com.newrelic.agent.config.AgentConfig) CheckClassAdapter(org.objectweb.asm.util.CheckClassAdapter) Test(org.junit.Test)

Aggregations

AgentConfig (com.newrelic.agent.config.AgentConfig)1 TokenNullCheckClassVisitor (com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessors.TokenNullCheckClassVisitor)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Test (org.junit.Test)1 ClassVisitor (org.objectweb.asm.ClassVisitor)1 ClassNode (org.objectweb.asm.tree.ClassNode)1 CheckClassAdapter (org.objectweb.asm.util.CheckClassAdapter)1