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());
}
Aggregations