use of org.junit.runners.model.TestTimedOutException in project hazelcast by hazelcast.
the class FailOnTimeoutStatement method createTimeoutException.
private Exception createTimeoutException(Thread thread) {
StackTraceElement[] stackTrace = thread.getStackTrace();
Exception currThreadException = new TestTimedOutException(timeout, timeUnit);
if (stackTrace != null) {
currThreadException.setStackTrace(stackTrace);
thread.interrupt();
}
return currThreadException;
}
use of org.junit.runners.model.TestTimedOutException in project scout.rt by eclipse.
the class ServerTestRunnerTimeoutTest method testTimeoutExceeded.
@Test
public void testTimeoutExceeded() throws Exception {
Result result = runServerTestRunner(ServerTestRunnerTimeoutTestFixture.class, m_name.getMethodName(), 1);
Failure f = result.getFailures().get(0);
assertNotNull(f);
assertTrue(f.getException() instanceof TestTimedOutException);
}
use of org.junit.runners.model.TestTimedOutException in project druid by druid-io.
the class DeadlockDetectingFailOnTimeout method createTimeoutException.
private Exception createTimeoutException(Thread thread) {
StackTraceElement[] stackTrace = thread.getStackTrace();
Exception currThreadException = new TestTimedOutException(timeout, timeUnit);
if (stackTrace != null) {
currThreadException.setStackTrace(stackTrace);
thread.interrupt();
}
Exception stuckThreadException = getStuckThreadException(thread);
Exception deadlockException = getDeadlockedThreadsException();
if (stuckThreadException != null || deadlockException != null) {
List<Throwable> exceptions = Stream.of(currThreadException, stuckThreadException, deadlockException).filter(Objects::nonNull).collect(Collectors.toList());
return new MultipleFailureException(exceptions);
} else {
return currThreadException;
}
}
use of org.junit.runners.model.TestTimedOutException in project partyline by Commonjava.
the class ThreadDumper method timeoutRule.
public static TestRule timeoutRule(int timeout, TimeUnit units) {
return (base, description) -> new Statement() {
public void evaluate() throws Throwable {
System.out.printf("Setting up timeout: %d %s to wrap: %s\n", timeout, units, base);
AtomicReference<Throwable> error = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
FutureTask<Void> task = new FutureTask<>(() -> {
try {
latch.countDown();
base.evaluate();
} catch (Throwable t) {
error.set(t);
}
return null;
});
ThreadGroup tg = new ThreadGroup("Test Timeout Group");
Thread t = new Thread(tg, task, "Test Timeout Thread");
t.setDaemon(true);
t.start();
try {
System.out.println("Waiting for test to start.");
latch.await();
} catch (InterruptedException e) {
error.set(e);
}
if (error.get() == null) {
try {
System.out.println("Waiting for test to complete (or timeout)");
task.get(timeout, units);
} catch (InterruptedException e) {
error.set(e);
} catch (ExecutionException e) {
error.set(e.getCause());
} catch (TimeoutException e) {
System.out.printf("Test timeout %d %s expired!\n", timeout, units.name());
dumpThreads();
StackTraceElement[] stackTrace = t.getStackTrace();
Exception currThreadException = new TestTimedOutException(timeout, units);
if (stackTrace != null) {
currThreadException.setStackTrace(stackTrace);
t.interrupt();
}
throw currThreadException;
}
}
Throwable throwable = error.get();
if (throwable != null) {
throw throwable;
}
}
};
}
Aggregations