use of org.apache.drill.common.scanner.persistence.AnnotationDescriptor in project drill by apache.
the class TestClassPathScanner method test.
@Test
public void test() throws Exception {
ScanResult result = ClassPathScanner.fromPrescan(DrillConfig.create());
// if the build has run properly. BuildTimeScan.REGISTRY_FILE was created with a prescan
// assertListEqualsUnordered(result.getPrescannedPackages(),
// "org.apache.drill.common.logical",
// "org.apache.drill.exec.expr",
// "org.apache.drill.exec.physical.base",
// "org.apache.drill.exec.expr.fn.impl",
// "org.apache.drill.exec.physical.impl",
// "org.apache.drill.exec.rpc.user.security",
// "org.apache.drill.exec.store",
// "org.apache.drill.exec.store.mock",
// "org.apache.drill.exec.physical.config",
// "org.apache.drill.storage"
// );
// // this is added in the unit test folder that was not scanned so far
// assertListEqualsUnordered(result.getScannedPackages(),
// "org.apache.drill.exec.testing",
// "org.apache.drill.exec.fn.impl.testing",
// "org.apache.drill.exec.rpc.user.security.testing"
// );
List<AnnotatedClassDescriptor> functions = result.getAnnotatedClasses();
Set<String> scanned = new HashSet<>();
AnnotatedClassDescriptor functionRandomBigIntGauss = null;
for (AnnotatedClassDescriptor function : functions) {
assertTrue(function.getClassName() + " scanned twice", scanned.add(function.getClassName()));
if (function.getClassName().equals(RandomBigIntGauss.class.getName())) {
functionRandomBigIntGauss = function;
}
}
if (functionRandomBigIntGauss == null) {
Assert.fail("functionRandomBigIntGauss not found");
}
// TODO: use Andrew's randomized test framework to verify a subset of the functions
for (AnnotatedClassDescriptor function : functions) {
Class<?> c = Class.forName(function.getClassName(), false, this.getClass().getClassLoader());
Field[] fields = c.getDeclaredFields();
assertEquals("fields count for " + function, fields.length, function.getFields().size());
for (int i = 0; i < fields.length; i++) {
FieldDescriptor fieldDescriptor = function.getFields().get(i);
Field field = fields[i];
assertEquals("Class fields:\n" + Arrays.toString(fields) + "\n != \nDescriptor fields:\n" + function.getFields(), field.getName(), fieldDescriptor.getName());
verifyAnnotations(field.getDeclaredAnnotations(), fieldDescriptor.getAnnotations());
assertEquals(field.getType(), fieldDescriptor.getFieldClass());
}
Annotation[] annotations = c.getDeclaredAnnotations();
List<AnnotationDescriptor> scannedAnnotations = function.getAnnotations();
verifyAnnotations(annotations, scannedAnnotations);
FunctionTemplate bytecodeAnnotation = function.getAnnotationProxy(FunctionTemplate.class);
FunctionTemplate reflectionAnnotation = c.getAnnotation(FunctionTemplate.class);
assertEquals(reflectionAnnotation.name(), bytecodeAnnotation.name());
assertArrayEquals(reflectionAnnotation.names(), bytecodeAnnotation.names());
assertEquals(reflectionAnnotation.scope(), bytecodeAnnotation.scope());
assertEquals(reflectionAnnotation.nulls(), bytecodeAnnotation.nulls());
assertEquals(reflectionAnnotation.isBinaryCommutative(), bytecodeAnnotation.isBinaryCommutative());
assertEquals(reflectionAnnotation.desc(), bytecodeAnnotation.desc());
assertEquals(reflectionAnnotation.costCategory(), bytecodeAnnotation.costCategory());
}
for (String baseType : result.getScannedClasses()) {
validateType(result, baseType);
}
assertTrue(result.getImplementations(PhysicalOperator.class).size() > 0);
assertTrue(result.getImplementations(DrillFunc.class).size() > 0);
}
use of org.apache.drill.common.scanner.persistence.AnnotationDescriptor in project drill by axbaretto.
the class TestClassPathScanner method verifyAnnotations.
private void verifyAnnotations(Annotation[] annotations, List<AnnotationDescriptor> scannedAnnotations) throws Exception {
assertEquals(Arrays.toString(annotations) + " expected but got " + scannedAnnotations, annotations.length, scannedAnnotations.size());
for (int i = 0; i < annotations.length; i++) {
Annotation annotation = annotations[i];
AnnotationDescriptor scannedAnnotation = scannedAnnotations.get(i);
Class<? extends Annotation> annotationType = annotation.annotationType();
assertEquals(annotationType.getName(), scannedAnnotation.getAnnotationType());
if (annotation instanceof FunctionTemplate) {
FunctionTemplate ft = (FunctionTemplate) annotation;
if (ft.name() != null && !ft.name().equals("")) {
assertEquals(ft.name(), scannedAnnotation.getSingleValue("name"));
}
}
// generally verify all properties
Annotation proxy = scannedAnnotation.getProxy(annotationType);
Method[] declaredMethods = annotationType.getDeclaredMethods();
for (Method method : declaredMethods) {
if (method.getParameterTypes().length == 0) {
Object reflectValue = method.invoke(annotation);
Object byteCodeValue = method.invoke(proxy);
String message = annotationType.getSimpleName() + "." + method.getName();
if (method.getReturnType().isArray()) {
assertArrayEquals(message, (Object[]) reflectValue, (Object[]) byteCodeValue);
} else {
assertEquals(message, reflectValue, byteCodeValue);
}
}
}
}
}
use of org.apache.drill.common.scanner.persistence.AnnotationDescriptor in project drill by axbaretto.
the class TestClassPathScanner method test.
@Test
public void test() throws Exception {
ScanResult result = ClassPathScanner.fromPrescan(DrillConfig.create());
List<AnnotatedClassDescriptor> functions = result.getAnnotatedClasses();
Set<String> scanned = new HashSet<>();
AnnotatedClassDescriptor functionRandomBigIntGauss = null;
for (AnnotatedClassDescriptor function : functions) {
assertTrue(function.getClassName() + " scanned twice", scanned.add(function.getClassName()));
if (function.getClassName().equals(RandomBigIntGauss.class.getName())) {
functionRandomBigIntGauss = function;
}
}
if (functionRandomBigIntGauss == null) {
Assert.fail("functionRandomBigIntGauss not found");
}
// TODO: use Andrew's randomized test framework to verify a subset of the functions
for (AnnotatedClassDescriptor function : functions) {
Class<?> c = Class.forName(function.getClassName(), false, this.getClass().getClassLoader());
Field[] fields = c.getDeclaredFields();
assertEquals("fields count for " + function, fields.length, function.getFields().size());
for (int i = 0; i < fields.length; i++) {
FieldDescriptor fieldDescriptor = function.getFields().get(i);
Field field = fields[i];
assertEquals("Class fields:\n" + Arrays.toString(fields) + "\n != \nDescriptor fields:\n" + function.getFields(), field.getName(), fieldDescriptor.getName());
verifyAnnotations(field.getDeclaredAnnotations(), fieldDescriptor.getAnnotations());
assertEquals(field.getType(), fieldDescriptor.getFieldClass());
}
Annotation[] annotations = c.getDeclaredAnnotations();
List<AnnotationDescriptor> scannedAnnotations = function.getAnnotations();
verifyAnnotations(annotations, scannedAnnotations);
FunctionTemplate bytecodeAnnotation = function.getAnnotationProxy(FunctionTemplate.class);
FunctionTemplate reflectionAnnotation = c.getAnnotation(FunctionTemplate.class);
assertEquals(reflectionAnnotation.name(), bytecodeAnnotation.name());
assertArrayEquals(reflectionAnnotation.names(), bytecodeAnnotation.names());
assertEquals(reflectionAnnotation.scope(), bytecodeAnnotation.scope());
assertEquals(reflectionAnnotation.nulls(), bytecodeAnnotation.nulls());
assertEquals(reflectionAnnotation.isBinaryCommutative(), bytecodeAnnotation.isBinaryCommutative());
assertEquals(reflectionAnnotation.desc(), bytecodeAnnotation.desc());
assertEquals(reflectionAnnotation.costCategory(), bytecodeAnnotation.costCategory());
}
for (String baseType : result.getScannedClasses()) {
validateType(result, baseType);
}
assertTrue(result.getImplementations(PhysicalOperator.class).size() > 0);
assertTrue(result.getImplementations(DrillFunc.class).size() > 0);
}
use of org.apache.drill.common.scanner.persistence.AnnotationDescriptor in project drill by apache.
the class TestClassPathScanner method testFunctionTemplates.
@Test
public void testFunctionTemplates() throws Exception {
List<AnnotatedClassDescriptor> functions = result.getAnnotatedClasses(FunctionTemplate.class.getName());
Set<String> scanned = new HashSet<>();
AnnotatedClassDescriptor functionRandomBigIntGauss = null;
for (AnnotatedClassDescriptor function : functions) {
assertTrue(function.getClassName() + " scanned twice", scanned.add(function.getClassName()));
if (function.getClassName().equals(RandomBigIntGauss.class.getName())) {
functionRandomBigIntGauss = function;
}
}
if (functionRandomBigIntGauss == null) {
Assert.fail("functionRandomBigIntGauss not found");
}
// TODO: use Andrew's randomized test framework to verify a subset of the functions
for (AnnotatedClassDescriptor function : functions) {
Class<?> c = Class.forName(function.getClassName(), false, this.getClass().getClassLoader());
Field[] fields = c.getDeclaredFields();
assertEquals("fields count for " + function, fields.length, function.getFields().size());
for (int i = 0; i < fields.length; i++) {
FieldDescriptor fieldDescriptor = function.getFields().get(i);
Field field = fields[i];
assertEquals("Class fields:\n" + Arrays.toString(fields) + "\n != \nDescriptor fields:\n" + function.getFields(), field.getName(), fieldDescriptor.getName());
verifyAnnotations(field.getDeclaredAnnotations(), fieldDescriptor.getAnnotations());
assertEquals(field.getType(), fieldDescriptor.getFieldClass());
}
Annotation[] annotations = c.getDeclaredAnnotations();
List<AnnotationDescriptor> scannedAnnotations = function.getAnnotations();
verifyAnnotations(annotations, scannedAnnotations);
FunctionTemplate bytecodeAnnotation = function.getAnnotationProxy(FunctionTemplate.class);
assertNotNull(bytecodeAnnotation);
FunctionTemplate reflectionAnnotation = c.getAnnotation(FunctionTemplate.class);
assertEquals(reflectionAnnotation.name(), bytecodeAnnotation.name());
assertArrayEquals(reflectionAnnotation.names(), bytecodeAnnotation.names());
assertEquals(reflectionAnnotation.scope(), bytecodeAnnotation.scope());
assertEquals(reflectionAnnotation.nulls(), bytecodeAnnotation.nulls());
assertEquals(reflectionAnnotation.isBinaryCommutative(), bytecodeAnnotation.isBinaryCommutative());
assertEquals(reflectionAnnotation.desc(), bytecodeAnnotation.desc());
assertEquals(reflectionAnnotation.costCategory(), bytecodeAnnotation.costCategory());
}
for (String baseType : result.getScannedClasses()) {
validateType(result, baseType);
}
assertTrue(result.getImplementations(PhysicalOperator.class).size() > 0);
assertTrue(result.getImplementations(DrillFunc.class).size() > 0);
}
use of org.apache.drill.common.scanner.persistence.AnnotationDescriptor in project drill by apache.
the class TestClassPathScanner method verifyAnnotations.
private void verifyAnnotations(Annotation[] annotations, List<AnnotationDescriptor> scannedAnnotations) throws Exception {
assertEquals(Arrays.toString(annotations) + " expected but got " + scannedAnnotations, annotations.length, scannedAnnotations.size());
for (int i = 0; i < annotations.length; i++) {
Annotation annotation = annotations[i];
AnnotationDescriptor scannedAnnotation = scannedAnnotations.get(i);
Class<? extends Annotation> annotationType = annotation.annotationType();
assertEquals(annotationType.getName(), scannedAnnotation.getAnnotationType());
if (annotation instanceof FunctionTemplate) {
FunctionTemplate ft = (FunctionTemplate) annotation;
if (!"".equals(ft.name())) {
assertEquals(ft.name(), scannedAnnotation.getSingleValue("name"));
}
}
// generally verify all properties
Annotation proxy = scannedAnnotation.getProxy(annotationType);
Method[] declaredMethods = annotationType.getDeclaredMethods();
for (Method method : declaredMethods) {
if (method.getParameterTypes().length == 0) {
Object reflectValue = method.invoke(annotation);
Object byteCodeValue = method.invoke(proxy);
String message = annotationType.getSimpleName() + "." + method.getName();
if (method.getReturnType().isArray()) {
assertArrayEquals(message, (Object[]) reflectValue, (Object[]) byteCodeValue);
} else {
assertEquals(message, reflectValue, byteCodeValue);
}
}
}
}
}
Aggregations