Search in sources :

Example 11 with MethodMapper

use of com.newrelic.agent.extension.util.MethodMapper in project newrelic-java-agent by newrelic.

the class OrExactParamMethodMatcherTest method testMatchingBasic.

@Test
public void testMatchingBasic() throws XmlException {
    List<String> pts = new ArrayList<>();
    Method m1 = new Method();
    m1.setName("hello");
    pts.add("int[]");
    pts.add("char");
    pts.add("boolean");
    pts.add("float");
    pts.add("byte");
    pts.add("double");
    pts.add("java.lang.String");
    MethodParameters mps = new MethodParameters(pts);
    m1.setParameters(mps);
    Method m2 = new Method();
    m2.setName("configure");
    List<String> ptsForM2 = new ArrayList<>();
    ptsForM2.add("java.util.List<String>");
    ptsForM2.add("java.util.Map<Integer>[][][]");
    ptsForM2.add("short");
    MethodParameters mps2 = new MethodParameters(ptsForM2);
    m2.setParameters(mps2);
    List<Method> methods = new ArrayList<>();
    methods.add(m1);
    methods.add(m2);
    Map<String, MethodMapper> mapper = new HashMap<>();
    MethodMatcher matcher = MethodMatcherUtility.createMethodMatcher("classz", methods, mapper, "EXT");
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "hello", "([ICZFBDLjava/lang/String;)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "configure", "([ICZFBDLjava/lang/String;)I", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "hello", "([ICZBFDLjava/lang/String;)S", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "configure", "(Ljava/util/List;[[[Ljava/util/Map;S)java/lang/String", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "hello", "(Ljava/util/List;[[[Ljava/util/Map;S)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "configure", "(Ljava/util/List;[[[Ljava/util/Map;)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) MethodParameters(com.newrelic.agent.extension.beans.MethodParameters) MethodMapper(com.newrelic.agent.extension.util.MethodMapper) Test(org.junit.Test)

Example 12 with MethodMapper

use of com.newrelic.agent.extension.util.MethodMapper in project newrelic-java-agent by newrelic.

the class OrExactParamMethodMatcherTest method testMachesWithSameNames.

@Test
public void testMachesWithSameNames() throws XmlException {
    List<String> pts = new ArrayList<>();
    Method m1 = new Method();
    m1.setName("hello");
    pts.add("int[]");
    pts.add("char");
    pts.add("boolean");
    pts.add("float");
    pts.add("byte");
    pts.add("double");
    pts.add("java.lang.String");
    MethodParameters mps1 = new MethodParameters(pts);
    m1.setParameters(mps1);
    Method m2 = new Method();
    m2.setName("hello");
    List<String> ptsForM2 = new ArrayList<>();
    ptsForM2.add("java.util.List<String>");
    ptsForM2.add("java.util.Map<Integer>[][][]");
    ptsForM2.add("short");
    MethodParameters mps2 = new MethodParameters(ptsForM2);
    m2.setParameters(mps2);
    Method m3 = new Method();
    m3.setName("hello");
    List<String> ptsForM3 = new ArrayList<>();
    MethodParameters mps3 = new MethodParameters(ptsForM3);
    m3.setParameters(mps3);
    List<Method> methods = new ArrayList<>();
    methods.add(m1);
    methods.add(m2);
    methods.add(m3);
    Map<String, MethodMapper> mapper = new HashMap<>();
    MethodMatcher matcher = MethodMatcherUtility.createMethodMatcher("classy", methods, mapper, "EXT");
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "hello", "([ICZFBDLjava/lang/String;)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "configure", "([ICZFBDLjava/lang/String;)I", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "hello", "([ICZBFDLjava/lang/String;)java/lang/String", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "hello", "(Ljava/util/List;[[[Ljava/util/Map;S)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "configure", "(Ljava/util/List;[[[Ljava/util/Map;S)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "hello", "(Ljava/util/List;[[[[Ljava/util/Map;)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "hello", "()java/lang/String", 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) MethodParameters(com.newrelic.agent.extension.beans.MethodParameters) MethodMapper(com.newrelic.agent.extension.util.MethodMapper) Test(org.junit.Test)

Example 13 with MethodMapper

use of com.newrelic.agent.extension.util.MethodMapper in project newrelic-java-agent by newrelic.

the class OrExactParamMethodMatcherTest method testMatchingBasicEmptyParameterType.

@Test
public void testMatchingBasicEmptyParameterType() throws Exception {
    Method m1 = new Method();
    m1.setName("hello");
    List<String> pts = new ArrayList<>();
    MethodParameters mps1 = new MethodParameters(pts);
    m1.setParameters(mps1);
    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 matcher = MethodMatcherUtility.createMethodMatcher("classz", methods, mapper, "EXT");
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "hello", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "configure", "()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) MethodParameters(com.newrelic.agent.extension.beans.MethodParameters) MethodMapper(com.newrelic.agent.extension.util.MethodMapper) Test(org.junit.Test)

Aggregations

Method (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method)13 MethodMapper (com.newrelic.agent.extension.util.MethodMapper)13 Test (org.junit.Test)13 MethodParameters (com.newrelic.agent.extension.beans.MethodParameters)10 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 XmlException (com.newrelic.agent.extension.util.XmlException)1