Search in sources :

Example 6 with Method

use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method in project newrelic-java-agent by newrelic.

the class MethodMatcherTests method createOrMethodMatcherExactOnly.

@Test
public void createOrMethodMatcherExactOnly() throws XmlException {
    Method m1 = new Method();
    m1.setName("m1");
    m1.setParameters(new MethodParameters(Arrays.asList("int")));
    Method m2 = new Method();
    m2.setName("m2");
    m2.setParameters(new MethodParameters(Arrays.asList("int[]")));
    Method m3 = new Method();
    m3.setName("m3");
    m3.setParameters(new MethodParameters(null));
    Method m4 = new Method();
    m4.setName("m4");
    m4.setParameters(new MethodParameters(Collections.EMPTY_LIST));
    MethodMatcher matcher = MethodMatcherUtility.createMethodMatcher("myclass", Arrays.asList(m1, m2, m3, m4), new HashMap<String, MethodMapper>(), "EXT");
    Assert.assertNotNull(matcher);
    Assert.assertTrue(matcher + " not of type OrMethodMatcher", matcher instanceof OrMethodMatcher);
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "([I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "([I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m3", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m3", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m4", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m4", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
}
Also used : Method(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method) MethodParameters(com.newrelic.agent.extension.beans.MethodParameters) MethodMapper(com.newrelic.agent.extension.util.MethodMapper) Test(org.junit.Test)

Example 7 with Method

use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method in project newrelic-java-agent by newrelic.

the class MethodMatcherTests method createMethodMatcherNameOnly.

@Test
public void createMethodMatcherNameOnly() throws XmlException {
    Method m1 = new Method();
    m1.setName("m1");
    MethodMatcher matcher = MethodMatcherUtility.createMethodMatcher("myclass", Arrays.asList(m1), new HashMap<String, MethodMapper>(), "EXT");
    Assert.assertNotNull(matcher);
    Assert.assertTrue(matcher + " not of type NameMethodMatcher", matcher instanceof NameMethodMatcher);
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "([I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "()V", com.google.common.collect.ImmutableSet.<String>of()));
}
Also used : Method(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method) MethodMapper(com.newrelic.agent.extension.util.MethodMapper) Test(org.junit.Test)

Example 8 with Method

use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method in project newrelic-java-agent by newrelic.

the class MethodMatcherTests method createMethodMatcherExactOnly.

@Test
public void createMethodMatcherExactOnly() throws XmlException {
    Method m1 = new Method();
    m1.setName("m1");
    m1.setParameters(new MethodParameters(Arrays.asList("int")));
    MethodMatcher matcher = MethodMatcherUtility.createMethodMatcher("myclass", Arrays.asList(m1), new HashMap<String, MethodMapper>(), "EXT");
    Assert.assertNotNull(matcher);
    Assert.assertTrue(matcher + " not of type ExactParamsMethodMatcher", matcher instanceof ExactParamsMethodMatcher);
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "([I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "()V", com.google.common.collect.ImmutableSet.<String>of()));
}
Also used : Method(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method) MethodParameters(com.newrelic.agent.extension.beans.MethodParameters) MethodMapper(com.newrelic.agent.extension.util.MethodMapper) Test(org.junit.Test)

Example 9 with Method

use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method in project newrelic-java-agent by newrelic.

the class OrExactParamMethodMatcherTest method testNoParamTag.

@Test
public void testNoParamTag() throws Exception {
    Method m1 = new Method();
    m1.setName("hello");
    List<Method> methods = new ArrayList<>();
    methods.add(m1);
    Map<String, MethodMapper> mapper = new HashMap<>();
    MethodMatcher matcher = MethodMatcherUtility.createMethodMatcher("hello", methods, mapper, "EXT");
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "hello", "()V", com.google.common.collect.ImmutableSet.<String>of()));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Method(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method) MethodMapper(com.newrelic.agent.extension.util.MethodMapper) Test(org.junit.Test)

Example 10 with Method

use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method in project newrelic-java-agent by newrelic.

the class OrExactParamMethodMatcherTest method testMatchingBasicEmptyParameterTypeMultiples.

@Test
public void testMatchingBasicEmptyParameterTypeMultiples() throws Exception {
    Method m1 = new Method();
    m1.setName("hello");
    List<String> pts = new ArrayList<>();
    m1.setParameters(new MethodParameters(pts));
    Method m2 = new Method();
    m2.setName("configure");
    m2.setParameters(new MethodParameters(null));
    List<Method> methods = new ArrayList<>();
    methods.add(m1);
    methods.add(m2);
    Map<String, MethodMapper> mapper = new HashMap<>();
    MethodMatcher matcher1 = MethodMatcherUtility.createMethodMatcher("classy", methods, mapper, "EXT");
    Assert.assertTrue(matcher1.matches(MethodMatcher.UNSPECIFIED_ACCESS, "hello", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher1.matches(MethodMatcher.UNSPECIFIED_ACCESS, "configure", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    // different class and so this should be okay
    MethodMatcher matcher2 = MethodMatcherUtility.createMethodMatcher("classing", methods, mapper, "EXT");
    Assert.assertTrue(matcher2.matches(MethodMatcher.UNSPECIFIED_ACCESS, "hello", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher2.matches(MethodMatcher.UNSPECIFIED_ACCESS, "configure", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    try {
        // we should fail here
        MethodMatcherUtility.createMethodMatcher("classing", methods, mapper, "EXT");
        Assert.fail("Should fail due to methods already being added.");
    } catch (Exception e) {
    // should get to here
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Method(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method) MethodParameters(com.newrelic.agent.extension.beans.MethodParameters) MethodMapper(com.newrelic.agent.extension.util.MethodMapper) XmlException(com.newrelic.agent.extension.util.XmlException) Test(org.junit.Test)

Aggregations

Method (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method)27 Test (org.junit.Test)25 MethodParameters (com.newrelic.agent.extension.beans.MethodParameters)14 HashMap (java.util.HashMap)14 Pointcut (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut)13 MethodMapper (com.newrelic.agent.extension.util.MethodMapper)13 Extension (com.newrelic.agent.extension.beans.Extension)12 Instrumentation (com.newrelic.agent.extension.beans.Extension.Instrumentation)11 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)6 ExtensionClassAndMethodMatcher (com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher)5 AnnotationMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.AnnotationMethodMatcher)2 LambdaMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.LambdaMethodMatcher)2 ReturnTypeMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ReturnTypeMethodMatcher)2 AgentHelper.getFile (com.newrelic.agent.AgentHelper.getFile)1 XmlException (com.newrelic.agent.extension.util.XmlException)1 MethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher)1 ParameterAttributeName (com.newrelic.agent.instrumentation.tracing.ParameterAttributeName)1 File (java.io.File)1