use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut in project newrelic-java-agent by newrelic.
the class ReinstrumentUtilsTest method checkInputMildCardClasses.
@Test
public void checkInputMildCardClasses() {
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);
// this should match
Method m1 = new Method();
m1.setName("yada");
pc.getMethod().add(m1);
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.Pointcut in project newrelic-java-agent by newrelic.
the class ReinstrumentUtilsTest method checkInputMatchesClasses.
@Test
public void checkInputMatchesClasses() {
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("getHello");
MethodParameters params1 = new MethodParameters(new ArrayList<String>());
m1.setParameters(params1);
Method m2 = new Method();
m2.setName("setHello");
MethodParameters params2 = new MethodParameters(Arrays.asList("boolean"));
m2.setParameters(params2);
Method m3 = new Method();
m3.setName("doTheWork");
MethodParameters params3 = new MethodParameters(Arrays.asList("java.lang.String", "int"));
m3.setParameters(params3);
pc.getMethod().addAll(Arrays.asList(m1, m2, m3));
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.Pointcut in project newrelic-java-agent by newrelic.
the class XmlInstrumentValidator method validateInstrumentation.
/**
* Validates the instrumentation.
*
* @param params The command line parameters.
* @throws ClassNotFoundException Thrown if the class is not found.
* @throws RuntimeException Thrown if a problem when converting the xml.
* @throws IllegalArgumentException Thrown when the method or class can not be found on the class path.
* @throws IOException Thrown if the file can not be read.
* @throws SAXException Thrown if a problem parsing the document.
*/
protected static void validateInstrumentation(final XmlInstrumentParams params) throws Exception {
// read in the file - DOM Exception potentially thrown
Extension extension = ExtensionDomParser.readFile(params.getFile());
if (params.isDebug()) {
System.out.println("Xml was successfully read. Starting processing.");
}
// attempt to convert to point cuts - RuntimeException
// potentially thrown
List<ExtensionClassAndMethodMatcher> convertedPcs = ExtensionConversionUtility.convertToPointCutsForValidation(extension);
Instrumentation inst = extension.getInstrumentation();
// this really has already been checked
if (inst == null) {
throw new RuntimeException("The instrumentation propery must be set for the extension.");
}
List<Pointcut> origPcs = inst.getPointcut();
if (convertedPcs.size() != origPcs.size()) {
throw new IllegalArgumentException("The processed number of point cuts does not match the" + "original number of point cuts in the xml. Remove duplicates.");
}
for (int i = 0; i < convertedPcs.size(); i++) {
MethodHolder holder = sortData(origPcs.get(i), params.isDebug());
verifyPointCut(convertedPcs.get(i), holder);
verifyAllMethodsAccounted(holder);
}
}
use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut in project newrelic-java-agent by newrelic.
the class ExtensionDomParserTest method testPrimitiveReturnType.
@Test
public void testPrimitiveReturnType() throws Exception {
Extension ext = ExtensionDomParser.readFile(getFile(PRIMITIVE_RETURN_TYPE_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.assertEquals("com.company.SomeInterface", pc.getInterfaceName());
Assert.assertEquals(1, pc.getMethod().size());
Assert.assertEquals("boolean", pc.getMethod().iterator().next().getReturnType());
try {
ExtensionConversionUtility.convertToPointCutsForValidation(ext);
Assert.fail();
} catch (XmlException ex) {
Assert.assertEquals("The return type 'boolean' is not valid. Primitive types are not allowed.", ex.getMessage());
}
}
use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut in project newrelic-java-agent by newrelic.
the class ExtensionDomParserTest method testInterfacePointCut.
@Test
public void testInterfacePointCut() throws Exception {
Extension ext = ExtensionDomParser.readFile(getFile(INTERFACE_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.assertEquals("javax.servlet.Filter", pc.getInterfaceName());
// Assert.assertEquals(ClassType.INTERFACE_NAME, pc.getClassType());
List<ExtensionClassAndMethodMatcher> pcs = ExtensionConversionUtility.convertToPointCutsForValidation(ext);
Assert.assertNotNull(pcs);
Assert.assertEquals(1, pcs.size());
ExtensionClassAndMethodMatcher actual = pcs.get(0);
Assert.assertTrue(actual.getClassMatcher() instanceof InterfaceMatcher);
}
Aggregations