Search in sources :

Example 1 with StatementAdapter

use of com.carrotsearch.randomizedtesting.rules.StatementAdapter in project lucene-solr by apache.

the class RevertDefaultThreadHandlerRule method apply.

@Override
public Statement apply(Statement s, Description d) {
    return new StatementAdapter(s) {

        @Override
        protected void before() throws Throwable {
            if (!applied.getAndSet(true)) {
                UncaughtExceptionHandler p = Thread.getDefaultUncaughtExceptionHandler();
                try {
                    // Try to initialize a zookeeper class that reinitializes default exception handler.
                    Class<?> cl = NIOServerCnxnFactory.class;
                    // Make sure static initializers have been called.
                    Class.forName(cl.getName(), true, cl.getClassLoader());
                } finally {
                    if (p == Thread.getDefaultUncaughtExceptionHandler()) {
                    //  throw new RuntimeException("Zookeeper no longer resets default thread handler.");
                    }
                    Thread.setDefaultUncaughtExceptionHandler(p);
                }
            }
        }
    };
}
Also used : StatementAdapter(com.carrotsearch.randomizedtesting.rules.StatementAdapter) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler)

Aggregations

StatementAdapter (com.carrotsearch.randomizedtesting.rules.StatementAdapter)1 UncaughtExceptionHandler (java.lang.Thread.UncaughtExceptionHandler)1 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)1