Search in sources :

Example 1 with IteratorTestCase

use of org.apache.accumulo.iteratortest.testcases.IteratorTestCase in project accumulo by apache.

the class JUnitFrameworkTest method parameters.

@Parameters
public static Object[][] parameters() {
    IteratorTestInput input = getIteratorInput();
    IteratorTestOutput output = getIteratorOutput();
    List<IteratorTestCase> tests = Collections.singletonList(new NoopIteratorTestCase());
    return BaseJUnit4IteratorTest.createParameters(input, output, tests);
}
Also used : IteratorTestOutput(org.apache.accumulo.iteratortest.IteratorTestOutput) IteratorTestCase(org.apache.accumulo.iteratortest.testcases.IteratorTestCase) IteratorTestInput(org.apache.accumulo.iteratortest.IteratorTestInput) Parameters(org.junit.runners.Parameterized.Parameters)

Example 2 with IteratorTestCase

use of org.apache.accumulo.iteratortest.testcases.IteratorTestCase in project accumulo by apache.

the class IteratorTestCaseFinder method findAllTestCases.

/**
 * Instantiates all test cases provided.
 *
 * @return A list of {@link IteratorTestCase}s.
 */
public static List<IteratorTestCase> findAllTestCases() {
    log.info("Searching {}", IteratorTestCase.class.getPackage().getName());
    ClassPath cp;
    try {
        cp = ClassPath.from(IteratorTestCaseFinder.class.getClassLoader());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    ImmutableSet<ClassInfo> classes = cp.getTopLevelClasses(IteratorTestCase.class.getPackage().getName());
    final List<IteratorTestCase> testCases = new ArrayList<>();
    // final Set<Class<? extends IteratorTestCase>> classes = reflections.getSubTypesOf(IteratorTestCase.class);
    for (ClassInfo classInfo : classes) {
        Class<?> clz;
        try {
            clz = Class.forName(classInfo.getName());
        } catch (Exception e) {
            log.warn("Could not get class for " + classInfo.getName(), e);
            continue;
        }
        if (clz.isInterface() || Modifier.isAbstract(clz.getModifiers()) || !IteratorTestCase.class.isAssignableFrom(clz)) {
            log.debug("Skipping " + clz);
            continue;
        }
        try {
            testCases.add((IteratorTestCase) clz.newInstance());
        } catch (IllegalAccessException | InstantiationException e) {
            log.warn("Could not instantiate {}", clz, e);
        }
    }
    return testCases;
}
Also used : ClassPath(com.google.common.reflect.ClassPath) IteratorTestCase(org.apache.accumulo.iteratortest.testcases.IteratorTestCase) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) ClassInfo(com.google.common.reflect.ClassPath.ClassInfo)

Example 3 with IteratorTestCase

use of org.apache.accumulo.iteratortest.testcases.IteratorTestCase in project accumulo by apache.

the class BaseJUnit4IteratorTest method createParameters.

/**
 * A helper function to convert input, output and a list of test cases into a two-dimensional array for JUnit's Parameterized runner.
 *
 * @param input
 *          The input
 * @param output
 *          The output
 * @param testCases
 *          A list of desired test cases to run.
 * @return A two dimensional array suitable to pass as JUnit's parameters.
 */
public static Object[][] createParameters(IteratorTestInput input, IteratorTestOutput output, Collection<IteratorTestCase> testCases) {
    Object[][] parameters = new Object[testCases.size()][3];
    Iterator<IteratorTestCase> testCaseIter = testCases.iterator();
    for (int i = 0; testCaseIter.hasNext(); i++) {
        final IteratorTestCase testCase = testCaseIter.next();
        parameters[i] = new Object[] { input, output, testCase };
    }
    return parameters;
}
Also used : IteratorTestCase(org.apache.accumulo.iteratortest.testcases.IteratorTestCase)

Example 4 with IteratorTestCase

use of org.apache.accumulo.iteratortest.testcases.IteratorTestCase in project accumulo by apache.

the class IteratorTestRunner method runTests.

/**
 * Invokes each test case on the input, verifying the output.
 *
 * @return true if all tests passed, false
 */
public List<IteratorTestReport> runTests() {
    List<IteratorTestReport> testReports = new ArrayList<>(testCases.size());
    for (IteratorTestCase testCase : testCases) {
        log.info("Invoking {} on {}", testCase.getClass().getName(), testInput.getIteratorClass().getName());
        IteratorTestOutput actualOutput;
        try {
            actualOutput = testCase.test(testInput);
        } catch (Exception e) {
            log.error("Failed to invoke {} on {}", testCase.getClass().getName(), testInput.getIteratorClass().getName(), e);
            actualOutput = new IteratorTestOutput(e);
        }
        // Sanity-check on the IteratorTestCase implementation.
        if (null == actualOutput) {
            throw new IllegalStateException("IteratorTestCase implementations should always return a non-null IteratorTestOutput. " + testCase.getClass().getName() + " did not!");
        }
        testReports.add(new IteratorTestReport(testInput, testOutput, actualOutput, testCase));
    }
    return testReports;
}
Also used : IteratorTestCase(org.apache.accumulo.iteratortest.testcases.IteratorTestCase) ArrayList(java.util.ArrayList)

Example 5 with IteratorTestCase

use of org.apache.accumulo.iteratortest.testcases.IteratorTestCase in project accumulo by apache.

the class AgeOffFilterTest method parameters.

@Parameters
public static Object[][] parameters() {
    // Test ageoff after 30 seconds.
    NOW = System.currentTimeMillis();
    TTL = 30 * 1000;
    IteratorTestInput input = getIteratorInput();
    IteratorTestOutput output = getIteratorOutput();
    List<IteratorTestCase> tests = IteratorTestCaseFinder.findAllTestCases();
    return BaseJUnit4IteratorTest.createParameters(input, output, tests);
}
Also used : IteratorTestOutput(org.apache.accumulo.iteratortest.IteratorTestOutput) IteratorTestCase(org.apache.accumulo.iteratortest.testcases.IteratorTestCase) IteratorTestInput(org.apache.accumulo.iteratortest.IteratorTestInput) Parameters(org.junit.runners.Parameterized.Parameters)

Aggregations

IteratorTestCase (org.apache.accumulo.iteratortest.testcases.IteratorTestCase)8 IteratorTestInput (org.apache.accumulo.iteratortest.IteratorTestInput)5 IteratorTestOutput (org.apache.accumulo.iteratortest.IteratorTestOutput)5 Parameters (org.junit.runners.Parameterized.Parameters)5 ArrayList (java.util.ArrayList)2 ClassPath (com.google.common.reflect.ClassPath)1 ClassInfo (com.google.common.reflect.ClassPath.ClassInfo)1 IOException (java.io.IOException)1