Search in sources :

Example 36 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project mongo-java-driver by mongodb.

the class CrudTest method getOperationMongoOperations.

private BsonDocument getOperationMongoOperations(final BsonDocument operation) {
    String name = operation.getString("name").getValue();
    BsonDocument arguments = operation.getDocument("arguments");
    String methodName = "get" + name.substring(0, 1).toUpperCase() + name.substring(1) + "MongoOperation";
    try {
        Method method = getClass().getDeclaredMethod(methodName, BsonDocument.class);
        return convertMongoOperationToResult(method.invoke(this, arguments));
    } catch (NoSuchMethodException e) {
        throw new UnsupportedOperationException("No handler for operation " + methodName);
    } catch (InvocationTargetException e) {
        if (e.getTargetException() instanceof AssumptionViolatedException) {
            throw (AssumptionViolatedException) e.getTargetException();
        }
        throw new UnsupportedOperationException("Invalid handler for operation " + methodName);
    } catch (IllegalAccessException e) {
        throw new UnsupportedOperationException("Invalid handler access for operation " + methodName);
    }
}
Also used : BsonDocument(org.bson.BsonDocument) AssumptionViolatedException(org.junit.AssumptionViolatedException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 37 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project geode by apache.

the class IgnoreUntilRule method throwOnIgnoreTest.

protected Statement throwOnIgnoreTest(Statement statement, Description description) {
    if (isTest(description)) {
        boolean ignoreTest = false;
        String message = "";
        IgnoreUntil testCaseAnnotation = description.getAnnotation(IgnoreUntil.class);
        if (testCaseAnnotation != null) {
            ignoreTest = evaluate(testCaseAnnotation, description);
            message = testCaseAnnotation.value();
        } else if (description.getTestClass().isAnnotationPresent(IgnoreUntil.class)) {
            IgnoreUntil testClassAnnotation = description.getTestClass().getAnnotation(IgnoreUntil.class);
            ignoreTest = evaluate(testClassAnnotation, description);
            message = testClassAnnotation.value();
        }
        if (ignoreTest) {
            throw new AssumptionViolatedException(format(message, description));
        }
    }
    return statement;
}
Also used : IgnoreUntil(org.apache.geode.test.junit.IgnoreUntil) AssumptionViolatedException(org.junit.AssumptionViolatedException)

Example 38 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project poi by apache.

the class TestAllFiles method testAllFiles.

@Test
public void testAllFiles() throws Exception {
    System.out.println("Reading " + file + " with " + handler.getClass());
    assertNotNull("Unknown file extension for file: " + file + ": " + getExtension(file), handler);
    File inputFile = new File(ROOT_DIR, file);
    // special cases where docx-handling breaks, but OPCPackage handling works
    boolean ignoredOPC = (file.endsWith(".docx") || file.endsWith(".xlsx") || file.endsWith(".xlsb") || file.endsWith(".pptx")) && handler instanceof OPCFileHandler;
    boolean ignoreHPSF = (handler instanceof HPSFFileHandler);
    try {
        InputStream stream = new BufferedInputStream(new FileInputStream(inputFile), 64 * 1024);
        try {
            handler.handleFile(stream, file);
            assertFalse("Expected to fail for file " + file + " and handler " + handler + ", but did not fail!", OLD_FILES_HWPF.contains(file) && !ignoreHPSF);
        } finally {
            stream.close();
        }
        handler.handleExtracting(inputFile);
        assertFalse("Expected to fail for file " + file + " and handler " + handler + ", but did not fail!", EXPECTED_FAILURES.contains(file) && !ignoredOPC && !ignoreHPSF);
    } catch (OldFileFormatException e) {
        // for old word files we should still support extracting text
        if (OLD_FILES_HWPF.contains(file)) {
            handler.handleExtracting(inputFile);
        } else {
            // check if we expect failure for this file
            if (!EXPECTED_FAILURES.contains(file) && !AbstractFileHandler.EXPECTED_EXTRACTOR_FAILURES.contains(file)) {
                System.out.println("Failed: " + file);
                throw new Exception("While handling " + file, e);
            }
        }
    } catch (AssumptionViolatedException e) {
    // file handler ignored this file
    } catch (Exception e) {
        // check if we expect failure for this file
        if (!EXPECTED_FAILURES.contains(file) && !AbstractFileHandler.EXPECTED_EXTRACTOR_FAILURES.contains(file)) {
            System.out.println("Failed: " + file);
            throw new Exception("While handling " + file, e);
        }
    }
    // let some file handlers do additional stuff
    handler.handleAdditional(inputFile);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) AssumptionViolatedException(org.junit.AssumptionViolatedException) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HPSFFileHandler(org.apache.poi.stress.HPSFFileHandler) File(java.io.File) FileInputStream(java.io.FileInputStream) AssumptionViolatedException(org.junit.AssumptionViolatedException) OPCFileHandler(org.apache.poi.stress.OPCFileHandler) Test(org.junit.Test)

Example 39 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project jackrabbit-oak by apache.

the class NonLocalObservationIT method getFixture.

@Override
protected NodeStoreFixture getFixture() {
    /**
     * Fixes the cluster use case plus allowing to control the cache sizes.
     * In theory other users of DocumentMongoFixture might have similar
     * test cases - but keeping it simple for now - thus going via subclass.
     */
    return new DocumentMongoFixture() {

        private String dbName = System.currentTimeMillis() + "-NonLocalObservationIT";

        /**
         * keep a reference to the node stores so that the db only gets closed after the last nodeStore was closed
         */
        private Set<NodeStore> nodeStores = new HashSet<NodeStore>();

        /**
         * This is not implemented in the super class at all.
         * <ul>
         *  <li>use a specific suffix to make sure we have our own, new db and clean it up after the test</li>
         *  <li>properly drop that db created above in dispose</li>
         *  <li>use only 32MB (vs default of 256MB) memory to ensure we're not going OOM just because of this (which happens with the default)</li>
         *  <li>disable the persistent cache for the same reason</li>
         * </ul>
         */
        @Override
        public NodeStore createNodeStore(int clusterNodeId) {
            try {
                DocumentMK.Builder builder = new DocumentMK.Builder();
                // keep this one low to avoid OOME
                builder.memoryCacheSize(32 * 1024 * 1024);
                // turn this one off to avoid OOME
                builder.setPersistentCache(null);
                builder.setMongoDB(createClient(), dbName);
                DocumentNodeStore ns = builder.getNodeStore();
                nodeStores.add(ns);
                return ns;
            } catch (Exception e) {
                throw new AssumptionViolatedException("Mongo instance is not available", e);
            }
        }

        @Override
        public void dispose(NodeStore nodeStore) {
            super.dispose(nodeStore);
            nodeStores.remove(nodeStore);
            if (nodeStores.size() == 0) {
                try (MongoClient c = createClient()) {
                    c.dropDatabase(dbName);
                } catch (Exception e) {
                    log.error("dispose: Can't close Mongo", e);
                }
            }
        }

        @Override
        public String toString() {
            return "NonLocalObservationIT's DocumentMongoFixture flavour";
        }
    };
}
Also used : MongoClient(com.mongodb.MongoClient) HashSet(java.util.HashSet) Set(java.util.Set) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) AssumptionViolatedException(org.junit.AssumptionViolatedException) DocumentMongoFixture(org.apache.jackrabbit.oak.fixture.DocumentMongoFixture) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) RepositoryException(javax.jcr.RepositoryException) AssumptionViolatedException(org.junit.AssumptionViolatedException)

Example 40 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project jackrabbit-oak by apache.

the class DocumentMongoFixture method createNodeStore.

@Override
public NodeStore createNodeStore() {
    try {
        String suffix = String.format("-%d-%d", System.currentTimeMillis(), sequence.incrementAndGet());
        DocumentMK.Builder builder = new DocumentMK.Builder();
        if (blobStore != null) {
            builder.setBlobStore(blobStore);
        }
        builder.setPersistentCache("target/persistentCache,time");
        builder.setMongoDB(createClient(), getDBName(suffix));
        DocumentNodeStore ns = builder.getNodeStore();
        suffixes.put(ns, suffix);
        return ns;
    } catch (Exception e) {
        throw new AssumptionViolatedException("Mongo instance is not available", e);
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) AssumptionViolatedException(org.junit.AssumptionViolatedException)

Aggregations

AssumptionViolatedException (org.junit.AssumptionViolatedException)79 Test (org.junit.Test)26 IOException (java.io.IOException)16 Statement (org.junit.runners.model.Statement)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Method (java.lang.reflect.Method)6 Set (java.util.Set)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 File (java.io.File)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 ZipEntry (java.util.zip.ZipEntry)5 ZipOutputStream (java.util.zip.ZipOutputStream)5 InputStream (java.io.InputStream)4 HashSet (java.util.HashSet)4 ZipInputStream (java.util.zip.ZipInputStream)4 FilterInputStream (java.io.FilterInputStream)3 UnknownHostException (java.net.UnknownHostException)3 JarInputStream (java.util.jar.JarInputStream)3 Configuration (org.apache.flink.configuration.Configuration)3 IInjectorProvider (org.eclipse.xtext.junit4.IInjectorProvider)3