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;
}
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;
}
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;
}
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?)
}
Aggregations