use of com.newrelic.agent.instrumentation.methodmatchers.AllMethodsMatcher in project newrelic-java-agent by newrelic.
the class InstrumentationMetricsTest method testMultipleMethodTransformationMetrics.
@Test
public void testMultipleMethodTransformationMetrics() throws Exception {
ServiceFactory.getClassTransformerService().getClassTransformer().getClassNameFilter().addIncludeClass(getClass().getName().replace('.', '/') + "$ClassToRetransform3");
Map<String, Integer> metricData = InstrumentTestUtils.getAndClearMetricData();
// This will load the class also:
String className = ClassToRetransform3Object.class.getName();
String constructorMetric = MetricNames.SUPPORTABILITY_INIT + className + "/<init>(I)V";
String methodMetric1 = MetricNames.SUPPORTABILITY_INIT + className + "/getVal()I";
String methodMetric2 = MetricNames.SUPPORTABILITY_INIT + className + "/getVal2()I";
Assert.assertEquals(1, new ClassToRetransform3Object(1).getVal());
Assert.assertEquals(2, new ClassToRetransform3Object(1).getVal2());
metricData = InstrumentTestUtils.getAndClearMetricData();
Assert.assertNull(metricData.get(constructorMetric));
Assert.assertNull(metricData.get(methodMetric1));
Assert.assertNull(metricData.get(methodMetric2));
ExtensionClassAndMethodMatcher pc1 = new ExtensionClassAndMethodMatcher(null, null, "Custom", new ExactClassMatcher(className), new AllMethodsMatcher(), false, false, false, false, null);
List<ExtensionClassAndMethodMatcher> list = new LinkedList<>();
list.add(pc1);
ServiceFactory.getClassTransformerService().getLocalRetransformer().appendClassMethodMatchers(list);
InstrumentTestUtils.retransformClass(className);
Assert.assertEquals(1, new ClassToRetransform3Object(1).getVal());
Assert.assertEquals(2, new ClassToRetransform3Object(1).getVal2());
metricData = InstrumentTestUtils.getAndClearMetricData();
Assert.assertNull(metricData.get(constructorMetric));
Assert.assertEquals(Integer.valueOf(1), metricData.get(methodMetric1));
Assert.assertEquals(Integer.valueOf(1), metricData.get(methodMetric2));
}
use of com.newrelic.agent.instrumentation.methodmatchers.AllMethodsMatcher in project newrelic-java-agent by newrelic.
the class OptimizedClassMatcherTest method testSkipObjectMethods_looseMatch.
@Test
public void testSkipObjectMethods_looseMatch() throws IOException {
ClassMatchVisitorFactory matcher = OptimizedClassMatcherBuilder.newBuilder().addClassMethodMatcher(new DefaultClassAndMethodMatcher(new AllClassesMatcher(), new AllMethodsMatcher())).build();
Match match = getMatch(matcher, MyObject.class);
Assert.assertNotNull(match);
for (Method m : OBJECT_METHODS) {
Assert.assertFalse(match.getMethods().contains(m));
}
}
use of com.newrelic.agent.instrumentation.methodmatchers.AllMethodsMatcher in project newrelic-java-agent by newrelic.
the class ClassTransformerServiceTest method addTraceMatcher.
@Test
public void addTraceMatcher() throws UnmodifiableClassException {
Assert.assertFalse(TestClass.class.isAnnotationPresent(InstrumentedClass.class));
ServiceFactory.getClassTransformerService().addTraceMatcher(new DefaultClassAndMethodMatcher(new ExactClassMatcher(Type.getType(ClassTransformerServiceTest.class).getInternalName() + "$TestClass"), new AllMethodsMatcher()), "dude");
ServiceFactory.getCoreService().getInstrumentation().retransformClasses(TestClass.class);
Assert.assertTrue(TestClass.class.isAnnotationPresent(InstrumentedClass.class));
}
use of com.newrelic.agent.instrumentation.methodmatchers.AllMethodsMatcher in project newrelic-java-agent by newrelic.
the class OptimizedClassMatcherTest method before.
@Before
public void before() {
initializeServiceManager();
OptimizedClassMatcherBuilder builder = OptimizedClassMatcherBuilder.newBuilder();
match1 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(Collection.class), new ExactMethodMatcher("size", "()I"));
match2 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(List.class), new ExactMethodMatcher("get", "(I)Ljava/lang/Object;"));
match3 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(InvocationHandler.class), new ExactMethodMatcher("invoke", "(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;"));
match4 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(Statement.class), new AllMethodsMatcher());
match5 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(Runnable.class), OrMethodMatcher.getMethodMatcher(new NameMethodMatcher("run"), new ExactMethodMatcher("bogus", "()V")));
match6 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(Map.class), new AccessMethodMatcher(Opcodes.ACC_PUBLIC));
match7 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(List.class), new ExactMethodMatcher("add", "(Ljava/lang/Object;)Z"));
annotationMatch = new DefaultClassAndMethodMatcher(new AllClassesMatcher(), new AnnotationMethodMatcher(Type.getType(MyAnnotation.class)));
// this is a bogus matcher to attempt to throw off match5
builder.addClassMethodMatcher(new DefaultClassAndMethodMatcher(createInterfaceMatcher(PreparedStatement.class), new NameMethodMatcher("run")));
builder.addClassMethodMatcher(match1);
builder.addClassMethodMatcher(match2);
builder.addClassMethodMatcher(match3);
builder.addClassMethodMatcher(match4);
builder.addClassMethodMatcher(match5);
builder.addClassMethodMatcher(match6);
builder.addClassMethodMatcher(match7);
builder.addClassMethodMatcher(annotationMatch);
this.matcher = builder.build();
}
Aggregations