Search in sources :

Example 6 with MethodMatcher

use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.

the class ExtensionServiceTest method testXMLWithNoNameOrVersion2.

/**
 * The first file should not be read in because it does not have a name or version.
 */
@Test
public void testXMLWithNoNameOrVersion2() throws Exception {
    setupFiles(true, XML_NO_NAME_OR_VERSION, XML_FILE_PATH_1);
    List<ExtensionClassAndMethodMatcher> pcs = extensionService.getEnabledPointCuts();
    assertNotNull(pcs);
    assertEquals(3, pcs.size());
    List<String> classNames = new ArrayList<>();
    List<MethodMatcher> mms = new ArrayList<>();
    for (ExtensionClassAndMethodMatcher pc : pcs) {
        classNames.addAll(pc.getClassMatcher().getClassNames());
        mms.add(pc.getMethodMatcher());
    }
    // verify that classes
    assertEquals(3, classNames.size());
    assertTrue(classNames.contains("test/CustomExtensionTest$1"));
    assertTrue(classNames.contains("test/AbstractCustomExtensionTest"));
    assertTrue(classNames.contains("test/CustomExtensionTest"));
}
Also used : ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) ArrayList(java.util.ArrayList) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) MethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher) Test(org.junit.Test)

Example 7 with MethodMatcher

use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.

the class ExtensionServiceTest method verifyMatch.

private void verifyMatch(String method, String signature, List<MethodMatcher> mms) {
    boolean wasMatch = false;
    for (MethodMatcher current : mms) {
        if (current.matches(MethodMatcher.UNSPECIFIED_ACCESS, method, signature, com.google.common.collect.ImmutableSet.<String>of())) {
            wasMatch = true;
            return;
        }
    }
    assertTrue("One of the method matches should have matched " + method + signature + " but did not", wasMatch);
}
Also used : ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) MethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher)

Example 8 with MethodMatcher

use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.

the class ExtensionServiceTest method testXMLExtensionCaptureMethodParams.

@Test
public void testXMLExtensionCaptureMethodParams() throws Exception {
    setupFiles(true, XML_CAPTURE_METHOD_PARAMS);
    List<ExtensionClassAndMethodMatcher> pcs = extensionService.getEnabledPointCuts();
    assertNotNull(pcs);
    assertEquals(1, pcs.size());
    List<String> classNames = new ArrayList<>();
    List<MethodMatcher> mms = new ArrayList<>();
    for (ExtensionClassAndMethodMatcher pc : pcs) {
        classNames.addAll(pc.getClassMatcher().getClassNames());
        mms.add(pc.getMethodMatcher());
    }
    // verify classes
    assertEquals(1, classNames.size());
    assertTrue(classNames.contains("com/nr/Client/impl/OkClient"));
    // verify the methods
    assertEquals(1, mms.size());
    verifyMatch("myMethod", "(Ljava/lang/String;J)V", mms);
}
Also used : ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) ArrayList(java.util.ArrayList) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) MethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher) Test(org.junit.Test)

Example 9 with MethodMatcher

use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.

the class ExtensionServiceTest method testXMLExtensionDifferentVersions.

/**
 * Tests that only the xml with the higher version gets read in.
 */
@Test
public void testXMLExtensionDifferentVersions() throws Exception {
    setupFiles(true, XML_FILE_PATH_1, XML_FILE_PATH_1_1);
    List<ExtensionClassAndMethodMatcher> pcs = extensionService.getEnabledPointCuts();
    assertNotNull(pcs);
    assertEquals(3, pcs.size());
    List<String> classNames = new ArrayList<>();
    List<MethodMatcher> mms = new ArrayList<>();
    for (ExtensionClassAndMethodMatcher pc : pcs) {
        classNames.addAll(pc.getClassMatcher().getClassNames());
        mms.add(pc.getMethodMatcher());
    }
    // verify that classes
    assertEquals(3, classNames.size());
    assertTrue(classNames.contains("test/CustomExtensionTest$1"));
    assertTrue(classNames.contains("test/AbstractCustomExtensionTest1"));
    assertTrue(classNames.contains("test/CustomExtensionTest1"));
    // verify methods
    assertEquals(3, mms.size());
    verifyMatch("run", "()V", mms);
    verifyMatch("abstractTest11", "()V", mms);
    verifyMatch("abstractTest21", "()V", mms);
    verifyMatch("test2", "(Ljava/lang/String;I)V", mms);
}
Also used : ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) ArrayList(java.util.ArrayList) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) MethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher) Test(org.junit.Test)

Example 10 with MethodMatcher

use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.

the class OptimizedClassMatcherTest method testSkipObjectMethods_exactMatch.

@Test
public void testSkipObjectMethods_exactMatch() throws IOException {
    List<MethodMatcher> matchers = new ArrayList<>();
    for (Method m : OBJECT_METHODS) {
        matchers.add(new ExactMethodMatcher(m.getName(), m.getDescriptor()));
    }
    ClassMatchVisitorFactory matcher = OptimizedClassMatcherBuilder.newBuilder().addClassMethodMatcher(new DefaultClassAndMethodMatcher(new AllClassesMatcher(), OrMethodMatcher.getMethodMatcher(matchers))).build();
    Match match = getMatch(matcher, MyObject.class);
    Assert.assertNull(match);
}
Also used : ClassMatchVisitorFactory(com.newrelic.agent.instrumentation.context.ClassMatchVisitorFactory) ArrayList(java.util.ArrayList) Method(org.objectweb.asm.commons.Method) ExactMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher) AnnotationMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.AnnotationMethodMatcher) ExactReturnTypeMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactReturnTypeMethodMatcher) OrMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.OrMethodMatcher) MethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher) NameMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.NameMethodMatcher) AccessMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.AccessMethodMatcher) ExactMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher) Match(com.newrelic.agent.instrumentation.classmatchers.OptimizedClassMatcher.Match) Test(org.junit.Test)

Aggregations

MethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher)21 ExtensionClassAndMethodMatcher (com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher)19 Test (org.junit.Test)16 ExactMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher)11 ArrayList (java.util.ArrayList)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 ClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ClassMatcher)3 ExactClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher)3 AnnotationMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.AnnotationMethodMatcher)3 OrMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.OrMethodMatcher)3 LambdaMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.LambdaMethodMatcher)2 ReturnTypeMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ReturnTypeMethodMatcher)2 ParameterAttributeName (com.newrelic.agent.instrumentation.tracing.ParameterAttributeName)2 List (java.util.List)2 BaseConfig (com.newrelic.agent.config.BaseConfig)1 Config (com.newrelic.agent.config.Config)1 Extension (com.newrelic.agent.extension.beans.Extension)1 Pointcut (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut)1 Method (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method)1 AllClassesMatcher (com.newrelic.agent.instrumentation.classmatchers.AllClassesMatcher)1