use of com.newrelic.agent.extension.beans.Extension.Instrumentation in project newrelic-java-agent by newrelic.
the class ReinstrumentUtilsTest method checkInputClassesNullPointers5.
@Test
public void checkInputClassesNullPointers5() {
SampleObject obj = new SampleObject();
ReinstrumentResult result = new ReinstrumentResult();
obj.getClass().getClassLoader();
Set<ClassLoader> loaders = new HashSet<>();
loaders.add(this.getClass().getClassLoader());
Extension ext = new Extension();
Instrumentation inst = new Instrumentation();
ext.setInstrumentation(inst);
Pointcut pc = new Pointcut();
inst.getPointcut().add(pc);
setClassName(pc, SampleObject.class);
Method m1 = new Method();
m1.setName("falala");
// no method parameters set
Map<String, Class<?>> daClasses = new HashMap<>();
daClasses.put(SampleObject.class.getName(), SampleObject.class);
ReinstrumentUtils.checkInputClasses(result, loaders, ext, daClasses);
Object actual = result.getStatusMap().get(ReinstrumentResult.ERROR_KEY);
Assert.assertNull("There should not have been an error. Errors: " + actual, actual);
}
use of com.newrelic.agent.extension.beans.Extension.Instrumentation in project newrelic-java-agent by newrelic.
the class ExtensionConversionUtility method convertToPointCutsForValidation.
/**
* Should be used to validate the XML. No logging is performed with this method.
*
* @param ext The extension read in.
* @return The list of point cuts.
* @throws XmlException
*/
public static List<ExtensionClassAndMethodMatcher> convertToPointCutsForValidation(Extension ext) throws XmlException {
List<ExtensionClassAndMethodMatcher> pointCutsOut = new ArrayList<>();
Instrumentation inst = ext.getInstrumentation();
validateExtensionAttributes(ext);
// this mandates that an instrumentation element is present
validateInstrument(inst);
List<Pointcut> pcs = inst.getPointcut();
String defaultMetricPrefix = createDefaultMetricPrefix(inst, true);
Map<String, MethodMapper> classesToMethods = new HashMap<>();
for (Pointcut pc : pcs) {
pointCutsOut.add(createPointCut(ext, pc, defaultMetricPrefix, ext.getName(), classesToMethods, true, InstrumentationType.LocalCustomXml, false));
}
return pointCutsOut;
}
use of com.newrelic.agent.extension.beans.Extension.Instrumentation in project newrelic-java-agent by newrelic.
the class ExtensionDomParserTest method testDomOnePointCutWithReadString.
@Test
public void testDomOnePointCutWithReadString() throws Exception {
File file = getFile(FILE_PATH_1);
Extension ext = ExtensionDomParser.readStringCatchException(readInFile(file));
Assert.assertNotNull(ext);
// ext attributes
Assert.assertEquals("test1", ext.getName());
Assert.assertEquals(1.0, ext.getVersion(), .001);
Assert.assertTrue(ext.isEnabled());
Instrumentation inst = ext.getInstrumentation();
Assert.assertEquals("PREFIX", inst.getMetricPrefix());
List<Pointcut> thePcs = inst.getPointcut();
Assert.assertEquals(1, thePcs.size());
Pointcut pc = thePcs.get(0);
Assert.assertTrue(pc.isTransactionStartPoint());
Assert.assertFalse(pc.isIgnoreTransaction());
Assert.assertFalse(pc.isExcludeFromTransactionTrace());
Assert.assertNull(pc.getMetricNameFormat());
Assert.assertEquals("test.CustomExampleTest", pc.getClassName().getValue());
List<Method> methods = pc.getMethod();
Assert.assertEquals(2, methods.size());
Assert.assertEquals("run", methods.get(0).getName());
Assert.assertEquals("finish", methods.get(1).getName());
Assert.assertEquals("(Ljava/lang/String;Ljava/lang/String;)", MethodParameters.getDescriptor(methods.get(0).getParameters()));
Assert.assertEquals("(F)", MethodParameters.getDescriptor(methods.get(1).getParameters()));
List<ExtensionClassAndMethodMatcher> pcs = ExtensionConversionUtility.convertToPointCutsForValidation(ext);
Assert.assertNotNull(pcs);
Assert.assertEquals(1, pcs.size());
ExtensionClassAndMethodMatcher actual = pcs.get(0);
// test method matching
Assert.assertTrue(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "run", "(Ljava/lang/String;Ljava/lang/String;)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertFalse(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "finish", "(Ljava/lang/String;Ljava/lang/String;)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertTrue(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "finish", "(F)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertFalse(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "run", "(F)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertFalse(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "finish", "(B)V", com.google.common.collect.ImmutableSet.<String>of()));
// test class matching
Assert.assertEquals(1, actual.getClassMatcher().getClassNames().size());
Assert.assertEquals("test/CustomExampleTest", actual.getClassMatcher().getClassNames().toArray()[0]);
}
use of com.newrelic.agent.extension.beans.Extension.Instrumentation in project newrelic-java-agent by newrelic.
the class ExtensionDomParserTest method testMethodAnnotation.
@Test
public void testMethodAnnotation() throws Exception {
Extension ext = ExtensionDomParser.readFile(getFile(METHOD_ANNOTATION_FILE_PATH));
Instrumentation inst = ext.getInstrumentation();
List<Pointcut> thePcs = inst.getPointcut();
Assert.assertEquals(1, thePcs.size());
Pointcut pc = thePcs.get(0);
Assert.assertNull(pc.getClassName());
Assert.assertNull(pc.getInterfaceName());
Assert.assertNotNull(pc.getMethodAnnotation());
Assert.assertEquals("javax.ws.rs.DELETE", pc.getMethodAnnotation());
ExtensionConversionUtility.convertToPointCutsForValidation(ext);
}
use of com.newrelic.agent.extension.beans.Extension.Instrumentation in project newrelic-java-agent by newrelic.
the class ExtensionDomParserTest method testDomOnePointCutNoPrefix.
@Test
public void testDomOnePointCutNoPrefix() throws Exception {
Extension ext = ExtensionDomParser.readFile(getFile(FILE_PATH_1_NO_PREFIX));
// ext attributes
Assert.assertEquals("test1", ext.getName());
Assert.assertEquals(1.0, ext.getVersion(), .001);
Assert.assertTrue(ext.isEnabled());
Instrumentation inst = ext.getInstrumentation();
Assert.assertEquals("PREFIX", inst.getMetricPrefix());
List<Pointcut> thePcs = inst.getPointcut();
Assert.assertEquals(1, thePcs.size());
Pointcut pc = thePcs.get(0);
Assert.assertTrue(pc.isTransactionStartPoint());
Assert.assertFalse(pc.isIgnoreTransaction());
Assert.assertFalse(pc.isExcludeFromTransactionTrace());
Assert.assertFalse(pc.isLeaf());
Assert.assertNull(pc.getMetricNameFormat());
Assert.assertEquals("test.CustomExampleTest", pc.getClassName().getValue());
List<Method> methods = pc.getMethod();
Assert.assertEquals(2, methods.size());
Assert.assertEquals("run", methods.get(0).getName());
Assert.assertEquals("finish", methods.get(1).getName());
Assert.assertEquals("(Ljava/lang/String;Ljava/lang/String;)", MethodParameters.getDescriptor(methods.get(0).getParameters()));
Assert.assertEquals("(F)", MethodParameters.getDescriptor(methods.get(1).getParameters()));
List<ExtensionClassAndMethodMatcher> pcs = ExtensionConversionUtility.convertToPointCutsForValidation(ext);
Assert.assertNotNull(pcs);
Assert.assertEquals(1, pcs.size());
ExtensionClassAndMethodMatcher actual = pcs.get(0);
// test method matching
Assert.assertTrue(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "run", "(Ljava/lang/String;Ljava/lang/String;)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertFalse(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "finish", "(Ljava/lang/String;Ljava/lang/String;)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertTrue(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "finish", "(F)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertFalse(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "run", "(F)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertFalse(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "finish", "(B)V", com.google.common.collect.ImmutableSet.<String>of()));
// test class matching
Assert.assertEquals(1, actual.getClassMatcher().getClassNames().size());
Assert.assertEquals("test/CustomExampleTest", actual.getClassMatcher().getClassNames().toArray()[0]);
}
Aggregations