Search in sources :

Example 1 with ParametersFactory

use of com.carrotsearch.randomizedtesting.annotations.ParametersFactory in project lucene-solr by apache.

the class DistanceStrategyTest method parameters.

@ParametersFactory(argumentFormatting = "strategy=%s")
public static Iterable<Object[]> parameters() {
    List<Object[]> ctorArgs = new ArrayList<>();
    SpatialContext ctx = SpatialContext.GEO;
    SpatialPrefixTree grid;
    SpatialStrategy strategy;
    grid = new QuadPrefixTree(ctx, 25);
    strategy = new RecursivePrefixTreeStrategy(grid, "recursive_quad");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    grid = new GeohashPrefixTree(ctx, 12);
    strategy = new TermQueryPrefixTreeStrategy(grid, "termquery_geohash");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    grid = new PackedQuadPrefixTree(ctx, 25);
    strategy = new RecursivePrefixTreeStrategy(grid, "recursive_packedquad");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    strategy = PointVectorStrategy.newInstance(ctx, "pointvector");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    //  Can't test this without un-inverting since PVS legacy config didn't have docValues.
    //    However, note that Solr's tests use UninvertingReader and thus test this.
    //    strategy = PointVectorStrategy.newLegacyInstance(ctx, "pointvector_legacy");
    //    ctorArgs.add(new Object[]{strategy.getFieldName(), strategy});
    strategy = BBoxStrategy.newInstance(ctx, "bbox");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    strategy = new SerializedDVStrategy(ctx, "serialized");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    return ctorArgs;
}
Also used : SpatialContext(org.locationtech.spatial4j.context.SpatialContext) PackedQuadPrefixTree(org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree) QuadPrefixTree(org.apache.lucene.spatial.prefix.tree.QuadPrefixTree) ArrayList(java.util.ArrayList) RecursivePrefixTreeStrategy(org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy) SpatialPrefixTree(org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree) TermQueryPrefixTreeStrategy(org.apache.lucene.spatial.prefix.TermQueryPrefixTreeStrategy) PackedQuadPrefixTree(org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree) SerializedDVStrategy(org.apache.lucene.spatial.serialized.SerializedDVStrategy) GeohashPrefixTree(org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree) ParametersFactory(com.carrotsearch.randomizedtesting.annotations.ParametersFactory)

Example 2 with ParametersFactory

use of com.carrotsearch.randomizedtesting.annotations.ParametersFactory in project lucene-solr by apache.

the class PortedSolr3Test method parameters.

@ParametersFactory(argumentFormatting = "strategy=%s")
public static Iterable<Object[]> parameters() {
    List<Object[]> ctorArgs = new ArrayList<>();
    SpatialContext ctx = SpatialContext.GEO;
    SpatialPrefixTree grid;
    SpatialStrategy strategy;
    grid = new GeohashPrefixTree(ctx, 12);
    strategy = new RecursivePrefixTreeStrategy(grid, "recursive_geohash");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    grid = new QuadPrefixTree(ctx, 25);
    strategy = new RecursivePrefixTreeStrategy(grid, "recursive_quad");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    grid = new GeohashPrefixTree(ctx, 12);
    strategy = new TermQueryPrefixTreeStrategy(grid, "termquery_geohash");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    strategy = PointVectorStrategy.newInstance(ctx, "pointvector");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    strategy = PointVectorStrategy.newInstance(ctx, "pointvector_legacy");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    return ctorArgs;
}
Also used : SpatialContext(org.locationtech.spatial4j.context.SpatialContext) QuadPrefixTree(org.apache.lucene.spatial.prefix.tree.QuadPrefixTree) ArrayList(java.util.ArrayList) RecursivePrefixTreeStrategy(org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy) SpatialPrefixTree(org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree) TermQueryPrefixTreeStrategy(org.apache.lucene.spatial.prefix.TermQueryPrefixTreeStrategy) GeohashPrefixTree(org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree) ParametersFactory(com.carrotsearch.randomizedtesting.annotations.ParametersFactory)

Example 3 with ParametersFactory

use of com.carrotsearch.randomizedtesting.annotations.ParametersFactory in project randomizedtesting by randomizedtesting.

the class RandomizedRunner method collectMethodExecutions.

/**
 * Collect test method executions from list of test methods and
 * potentially parameters from parameter factory methods.
 */
public List<TestMethodExecution> collectMethodExecutions(Constructor<?> constructor, List<Method> testMethods) {
    final List<TestMethodExecution> testCases = new ArrayList<>();
    String argFormattingTemplate = createDefaultArgumentFormatting(constructor);
    final Map<Method, MethodModel> factoryMethods = classModel.getAnnotatedLeafMethods(ParametersFactory.class);
    if (factoryMethods.isEmpty()) {
        Object[] noArgs = new Object[0];
        InstanceProvider instanceProvider = getInstanceProvider(constructor, noArgs);
        for (Method testMethod : testMethods) {
            testCases.add(new TestMethodExecution(testMethod, argFormattingTemplate, noArgs, instanceProvider));
        }
    } else {
        for (Method factoryMethod : factoryMethods.keySet()) {
            Validation.checkThat(factoryMethod).isStatic().isPublic();
            if (!Iterable.class.isAssignableFrom(factoryMethod.getReturnType())) {
                throw new RuntimeException("@" + ParametersFactory.class.getSimpleName() + " annotated " + "methods must be public, static and returning Iterable<Object[]>:" + factoryMethod);
            }
            ParametersFactory pfAnnotation = factoryMethod.getAnnotation(ParametersFactory.class);
            if (!pfAnnotation.argumentFormatting().equals(ParametersFactory.DEFAULT_FORMATTING)) {
                argFormattingTemplate = pfAnnotation.argumentFormatting();
            }
            List<Object[]> args = new ArrayList<>();
            try {
                Iterable<?> factoryArguments = Iterable.class.cast(factoryMethod.invoke(null));
                for (Object o : factoryArguments) {
                    if (!(o instanceof Object[])) {
                        throw new RuntimeException("Expected Object[] for each set of constructor arguments: " + o);
                    }
                    args.add((Object[]) o);
                }
            } catch (InvocationTargetException e) {
                if (isAssumptionViolated(e.getCause())) {
                    return Collections.emptyList();
                }
                Rethrow.rethrow(e.getCause());
            } catch (Throwable t) {
                throw new RuntimeException("Error collecting parameters from: " + factoryMethod, t);
            }
            if (pfAnnotation.shuffle()) {
                Collections.shuffle(args, new Random(runnerRandomness.getSeed()));
            }
            for (Object[] constructorArgs : args) {
                InstanceProvider instanceProvider = getInstanceProvider(constructor, constructorArgs);
                for (Method testMethod : testMethods) {
                    testCases.add(new TestMethodExecution(testMethod, argFormattingTemplate, constructorArgs, instanceProvider));
                }
            }
        }
    }
    return testCases;
}
Also used : MethodModel(com.carrotsearch.randomizedtesting.ClassModel.MethodModel) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) FrameworkMethod(org.junit.runners.model.FrameworkMethod) InvocationTargetException(java.lang.reflect.InvocationTargetException) Random(java.util.Random) ParametersFactory(com.carrotsearch.randomizedtesting.annotations.ParametersFactory) TestCaseInstanceProvider(com.carrotsearch.randomizedtesting.annotations.TestCaseInstanceProvider)

Example 4 with ParametersFactory

use of com.carrotsearch.randomizedtesting.annotations.ParametersFactory in project randomizedtesting by randomizedtesting.

the class RandomizedRunner method validateTarget.

/**
 * Validate methods and hooks in the suiteClass. Follows "standard" JUnit rules,
 * with some exceptions on return values and more rigorous checking of shadowed
 * methods and fields.
 */
private void validateTarget() {
    // Target is accessible (public, concrete, has a parameterless constructor etc).
    Validation.checkThat(suiteClass).describedAs("Suite class " + suiteClass.getName()).isPublic().isConcreteClass();
    // Check constructors.
    Constructor<?>[] constructors = suiteClass.getConstructors();
    if (constructors.length != 1 || !Modifier.isPublic(constructors[0].getModifiers())) {
        throw new RuntimeException("A test class is expected to have one public constructor " + " (parameterless or with types matching static @" + ParametersFactory.class + "-annotated method's output): " + suiteClass.getName());
    }
    // If there is a parameterized constructor, look for a static method that privides parameters.
    if (constructors[0].getParameterTypes().length > 0) {
        Collection<Method> factories = classModel.getAnnotatedLeafMethods(ParametersFactory.class).keySet();
        if (factories.isEmpty()) {
            throw new RuntimeException("A test class with a parameterized constructor is expected " + " to have a static @" + ParametersFactory.class + "-annotated method: " + suiteClass.getName());
        }
        for (Method m : factories) {
            Validation.checkThat(m).describedAs("@ParametersFactory method " + suiteClass.getName() + "#" + m.getName()).isStatic().isPublic().hasArgsCount(0).hasReturnType(Iterable.class);
        }
    }
    // @BeforeClass
    for (Method method : classModel.getAnnotatedLeafMethods(BeforeClass.class).keySet()) {
        Validation.checkThat(method).describedAs("@BeforeClass method " + suiteClass.getName() + "#" + method.getName()).isStatic().hasArgsCount(0);
    }
    // @AfterClass
    for (Method method : classModel.getAnnotatedLeafMethods(AfterClass.class).keySet()) {
        Validation.checkThat(method).describedAs("@AfterClass method " + suiteClass.getName() + "#" + method.getName()).isStatic().hasArgsCount(0);
    }
    // @Before
    for (Method method : classModel.getAnnotatedLeafMethods(Before.class).keySet()) {
        Validation.checkThat(method).describedAs("@Before method " + suiteClass.getName() + "#" + method.getName()).isNotStatic().hasArgsCount(0);
    }
    // @After
    for (Method method : classModel.getAnnotatedLeafMethods(After.class).keySet()) {
        Validation.checkThat(method).describedAs("@After method " + suiteClass.getName() + "#" + method.getName()).isNotStatic().hasArgsCount(0);
    }
// TODO: [GH-214] Validate @Rule fields (what are the "rules" for these anyway?)
}
Also used : Before(org.junit.Before) BeforeClass(org.junit.BeforeClass) Constructor(java.lang.reflect.Constructor) ParametersFactory(com.carrotsearch.randomizedtesting.annotations.ParametersFactory) After(org.junit.After) Method(java.lang.reflect.Method) FrameworkMethod(org.junit.runners.model.FrameworkMethod) AfterClass(org.junit.AfterClass)

Aggregations

ParametersFactory (com.carrotsearch.randomizedtesting.annotations.ParametersFactory)4 ArrayList (java.util.ArrayList)3 Method (java.lang.reflect.Method)2 RecursivePrefixTreeStrategy (org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy)2 TermQueryPrefixTreeStrategy (org.apache.lucene.spatial.prefix.TermQueryPrefixTreeStrategy)2 GeohashPrefixTree (org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree)2 QuadPrefixTree (org.apache.lucene.spatial.prefix.tree.QuadPrefixTree)2 SpatialPrefixTree (org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree)2 FrameworkMethod (org.junit.runners.model.FrameworkMethod)2 SpatialContext (org.locationtech.spatial4j.context.SpatialContext)2 MethodModel (com.carrotsearch.randomizedtesting.ClassModel.MethodModel)1 TestCaseInstanceProvider (com.carrotsearch.randomizedtesting.annotations.TestCaseInstanceProvider)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Random (java.util.Random)1 PackedQuadPrefixTree (org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree)1 SerializedDVStrategy (org.apache.lucene.spatial.serialized.SerializedDVStrategy)1 After (org.junit.After)1 AfterClass (org.junit.AfterClass)1 Before (org.junit.Before)1