use of java.lang.Thread.UncaughtExceptionHandler in project robovm by robovm.
the class SSLSocketTest method test_SSLSocket_HandshakeCompletedListener_RuntimeException.
public void test_SSLSocket_HandshakeCompletedListener_RuntimeException() throws Exception {
final Thread self = Thread.currentThread();
final UncaughtExceptionHandler original = self.getUncaughtExceptionHandler();
final RuntimeException expectedException = new RuntimeException("expected");
final TestUncaughtExceptionHandler test = new TestUncaughtExceptionHandler();
self.setUncaughtExceptionHandler(test);
final TestSSLContext c = TestSSLContext.create();
final SSLSocket client = (SSLSocket) c.clientContext.getSocketFactory().createSocket(c.host, c.port);
final SSLSocket server = (SSLSocket) c.serverSocket.accept();
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Void> future = executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
server.startHandshake();
return null;
}
});
executor.shutdown();
client.addHandshakeCompletedListener(new HandshakeCompletedListener() {
public void handshakeCompleted(HandshakeCompletedEvent event) {
throw expectedException;
}
});
client.startHandshake();
future.get();
client.close();
server.close();
c.close();
assertSame(expectedException, test.actualException);
self.setUncaughtExceptionHandler(original);
}
use of java.lang.Thread.UncaughtExceptionHandler in project randomizedtesting by randomizedtesting.
the class RandomizedRunner method runSuite.
/**
* Test execution logic for the entire suite.
*/
private void runSuite(final RunNotifier notifier) {
// NOTE: this effectively means we can't run concurrent randomized runners.
final UncaughtExceptionHandler previous = Thread.getDefaultUncaughtExceptionHandler();
handler = new QueueUncaughtExceptionsHandler();
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
Thread.setDefaultUncaughtExceptionHandler(handler);
return null;
}
});
this.runnerThreadGroup = new RunnerThreadGroup("TGRP-" + Classes.simpleName(suiteClass));
final Thread runner = new Thread(runnerThreadGroup, "SUITE-" + Classes.simpleName(suiteClass) + "-seed#" + SeedUtils.formatSeedChain(runnerRandomness)) {
public void run() {
try {
// on the class NOT being initialized before.
try {
Class.forName(suiteClass.getName(), true, suiteClass.getClassLoader());
} catch (ExceptionInInitializerError e) {
throw e.getCause();
}
RandomizedContext context = createContext(runnerThreadGroup);
runSuite(context, notifier);
context.dispose();
} catch (Throwable t) {
notifier.fireTestFailure(new Failure(suiteDescription, t));
}
}
};
runner.start();
try {
runner.join();
} catch (InterruptedException e) {
notifier.fireTestFailure(new Failure(suiteDescription, new RuntimeException("Interrupted while waiting for the suite runner? Weird.", e)));
}
UncaughtExceptionHandler current = Thread.getDefaultUncaughtExceptionHandler();
if (current != handler) {
notifier.fireTestFailure(new Failure(suiteDescription, new RuntimeException("Suite replaced Thread.defaultUncaughtExceptionHandler. " + "It's better not to touch it. Or at least revert it to what it was before. Current: " + (current == null ? "(null)" : current.getClass()))));
}
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
Thread.setDefaultUncaughtExceptionHandler(previous);
return null;
}
});
runnerThreadGroup = null;
handler = null;
}
use of java.lang.Thread.UncaughtExceptionHandler in project voltdb by VoltDB.
the class ThreadFactoryBuilder method build.
private static ThreadFactory build(ThreadFactoryBuilder builder) {
final String nameFormat = builder.nameFormat;
final Boolean daemon = builder.daemon;
final Integer priority = builder.priority;
final UncaughtExceptionHandler uncaughtExceptionHandler = builder.uncaughtExceptionHandler;
final ThreadFactory backingThreadFactory = (builder.backingThreadFactory != null) ? builder.backingThreadFactory : Executors.defaultThreadFactory();
final AtomicLong count = (nameFormat != null) ? new AtomicLong(0) : null;
return new ThreadFactory() {
@Override
public Thread newThread(Runnable runnable) {
Thread thread = backingThreadFactory.newThread(runnable);
if (nameFormat != null) {
thread.setName(format(nameFormat, count.getAndIncrement()));
}
if (daemon != null) {
thread.setDaemon(daemon);
}
if (priority != null) {
thread.setPriority(priority);
}
if (uncaughtExceptionHandler != null) {
thread.setUncaughtExceptionHandler(uncaughtExceptionHandler);
}
return thread;
}
};
}
use of java.lang.Thread.UncaughtExceptionHandler in project geode by apache.
the class NamedThreadFactory method newThread.
/**
* {@inheritDoc}
* <p/>
* This implementation sets the name of the thread, sets the thread to be a daemon thread, and
* adds an uncaught exception handler.
*/
@Override
public Thread newThread(Runnable r) {
Thread thr = new Thread(r);
thr.setDaemon(true);
thr.setName(id + " - " + serial.incrementAndGet());
thr.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
LOG.log(Level.WARNING, "Uncaught Exception in thread: " + t.getName(), e);
}
});
return thr;
}
use of java.lang.Thread.UncaughtExceptionHandler in project android_frameworks_base by ResurrectionRemix.
the class UiAutomatorTestRunner method run.
public void run(List<String> testClasses, Bundle params, boolean debug, boolean monkey) {
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Log.e(LOGTAG, "uncaught exception", ex);
Bundle results = new Bundle();
results.putString("shortMsg", ex.getClass().getName());
results.putString("longMsg", ex.getMessage());
mWatcher.instrumentationFinished(null, 0, results);
// bailing on uncaught exception
System.exit(EXIT_EXCEPTION);
}
});
mTestClasses = testClasses;
mParams = params;
mDebug = debug;
mMonkey = monkey;
start();
System.exit(EXIT_OK);
}
Aggregations