use of com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand in project pinpoint by naver.
the class DefaultMultiClassBasedMatcherTest method getMatcherOperandWithMultiClassNameAndAdditional.
@Test
public void getMatcherOperandWithMultiClassNameAndAdditional() {
// (class OR class) AND interface
InterfaceInternalNameMatcherOperand additional = new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false);
DefaultMultiClassBasedMatcher matcher = new DefaultMultiClassBasedMatcher(Arrays.asList("java.lang.String", "java.lang.Thread"), additional);
assertTrue(matcher.getBaseClassNames().contains("java.lang.String"));
assertTrue(matcher.getBaseClassNames().contains("java.lang.Thread"));
MatcherOperand operand = matcher.getMatcherOperand();
assertTrue(operand instanceof AndMatcherOperator);
AndMatcherOperator operator = (AndMatcherOperator) operand;
// (class OR class)
assertTrue(operator.getLeftOperand() instanceof OrMatcherOperator);
// ... AND interface
assertTrue(operator.getRightOperand() instanceof InterfaceInternalNameMatcherOperand);
InterfaceInternalNameMatcherOperand rightOperand = (InterfaceInternalNameMatcherOperand) operator.getRightOperand();
assertEquals("java/lang/Runnable", rightOperand.getInterfaceInternalName());
}
use of com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand in project pinpoint by naver.
the class DefaultMultiPackageBasedMatcherTest method getMatcherOperandWithMulitPackageName.
@Test
public void getMatcherOperandWithMulitPackageName() {
DefaultMultiPackageBasedMatcher matcher = new DefaultMultiPackageBasedMatcher(Arrays.asList("java", "javax"));
assertTrue(matcher.getBasePackageNames().contains("java"));
assertTrue(matcher.getBasePackageNames().contains("javax"));
MatcherOperand operand = matcher.getMatcherOperand();
assertTrue(operand instanceof OrMatcherOperator);
OrMatcherOperator operator = (OrMatcherOperator) operand;
assertTrue(operator.getLeftOperand() instanceof PackageInternalNameMatcherOperand);
PackageInternalNameMatcherOperand leftOperand = (PackageInternalNameMatcherOperand) operator.getLeftOperand();
assertEquals("java", leftOperand.getPackageInternalName());
assertTrue(operator.getRightOperand() instanceof PackageInternalNameMatcherOperand);
PackageInternalNameMatcherOperand rightOperand = (PackageInternalNameMatcherOperand) operator.getRightOperand();
assertEquals("javax", rightOperand.getPackageInternalName());
}
use of com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand in project pinpoint by naver.
the class DefaultPackageBasedMatcherTest method getMatcherOperandWithPackageNameAndAdditional.
@Test
public void getMatcherOperandWithPackageNameAndAdditional() {
InterfaceInternalNameMatcherOperand additional = new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false);
PackageBasedMatcher packageBasedMatcher = new DefaultPackageBasedMatcher("java.lang", additional);
assertEquals("java.lang", packageBasedMatcher.getBasePackageName());
MatcherOperand operand = packageBasedMatcher.getMatcherOperand();
assertTrue(operand instanceof AndMatcherOperator);
AndMatcherOperator operator = (AndMatcherOperator) operand;
assertTrue(operator.getLeftOperand() instanceof PackageInternalNameMatcherOperand);
assertTrue(operator.getRightOperand() instanceof InterfaceInternalNameMatcherOperand);
}
use of com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand in project pinpoint by naver.
the class DefaultPackageBasedMatcherTest method getMatcherOperandWithPackageName.
@Test
public void getMatcherOperandWithPackageName() {
DefaultPackageBasedMatcher packageBasedMatcher = new DefaultPackageBasedMatcher("java.lang");
assertEquals("java.lang", packageBasedMatcher.getBasePackageName());
MatcherOperand operand = packageBasedMatcher.getMatcherOperand();
assertTrue(operand instanceof PackageInternalNameMatcherOperand);
PackageInternalNameMatcherOperand packageInternalNameMatcherOperand = (PackageInternalNameMatcherOperand) operand;
assertEquals("java/lang", packageInternalNameMatcherOperand.getPackageInternalName());
}
use of com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand in project pinpoint by naver.
the class DefaultTransformerMatcherTest method matchClass.
@Test
public void matchClass() throws Exception {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InstrumentMatcherCacheConfig config = new DefaultInstrumentMatcherCacheConfig();
TransformerMatcher matcher = new DefaultTransformerMatcher(config);
InternalClassMetadata stringClassMetadata = readClassMetadata(classLoader, String.class.getName());
InternalClassMetadata threadClassMetadata = readClassMetadata(classLoader, Thread.class.getName());
InternalClassMetadata inputStreamClassMetadata = readClassMetadata(classLoader, InputStream.class.getName());
MatcherOperand operand = null;
// single operand.
operand = new ClassInternalNameMatcherOperand("java/lang/String");
boolean result = matcher.match(classLoader, operand, stringClassMetadata);
assertTrue(result);
// not matched.
operand = new ClassInternalNameMatcherOperand("java/io/InputStream");
result = matcher.match(classLoader, operand, stringClassMetadata);
assertFalse(result);
// and operator
// package AND interface
operand = new PackageInternalNameMatcherOperand("java/lang").and(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false));
// java.lang.Thread
result = matcher.match(classLoader, operand, threadClassMetadata);
assertTrue(result);
// java.lang.String
result = matcher.match(classLoader, operand, stringClassMetadata);
assertFalse(result);
// or operator
// package OR interface
operand = new PackageInternalNameMatcherOperand("java/lang").or(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false));
// java.lang.Thread
result = matcher.match(classLoader, operand, threadClassMetadata);
assertTrue(result);
// java.lang.String
result = matcher.match(classLoader, operand, stringClassMetadata);
assertTrue(result);
// not operator
// NOT interface.
operand = new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false);
operand = operand.not();
// java.lang.Thread
result = matcher.match(classLoader, operand, threadClassMetadata);
assertFalse(result);
// java.lang.String
result = matcher.match(classLoader, operand, stringClassMetadata);
assertTrue(result);
// complex operator
// (class or interface) AND (class or interface) ==> class, interface
operand = new ClassInternalNameMatcherOperand("java/lang/String").or(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false));
operand = operand.and(new ClassInternalNameMatcherOperand("java/lang/Thread").or(new InterfaceInternalNameMatcherOperand("java/lang/Comparable", false)));
result = matcher.match(classLoader, operand, stringClassMetadata);
assertTrue(result);
result = matcher.match(classLoader, operand, threadClassMetadata);
assertTrue(result);
// (class AND interface) OR (class AND interface) ==> class, class
operand = new ClassInternalNameMatcherOperand("java/lang/String").and(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false));
operand = operand.or(new ClassInternalNameMatcherOperand("java/lang/Thread").and(new InterfaceInternalNameMatcherOperand("java/lang/Comparable", false)));
result = matcher.match(classLoader, operand, stringClassMetadata);
assertFalse(result);
result = matcher.match(classLoader, operand, threadClassMetadata);
assertFalse(result);
// package AND (interface OR annotation) ==> package
operand = new PackageInternalNameMatcherOperand("java/lang");
operand = operand.and(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false).or(new AnnotationInternalNameMatcherOperand("java/lang/Override", false)));
result = matcher.match(classLoader, operand, stringClassMetadata);
assertFalse(result);
result = matcher.match(classLoader, operand, threadClassMetadata);
assertTrue(result);
// class OR (interface AND NOT annotation)
operand = new ClassInternalNameMatcherOperand("java/lang/String");
operand = operand.or(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false).and(new AnnotationInternalNameMatcherOperand("java/lang/Override", false).not()));
result = matcher.match(classLoader, operand, stringClassMetadata);
assertTrue(result);
result = matcher.match(classLoader, operand, threadClassMetadata);
assertTrue(result);
}
Aggregations