Search in sources :

Example 16 with TestTimedOutException

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;
}
Also used : TestTimedOutException(org.junit.runners.model.TestTimedOutException) ExecutionException(java.util.concurrent.ExecutionException) TestTimedOutException(org.junit.runners.model.TestTimedOutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 17 with TestTimedOutException

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);
}
Also used : TestTimedOutException(org.junit.runners.model.TestTimedOutException) Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 18 with 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;
    }
}
Also used : MultipleFailureException(org.junit.runners.model.MultipleFailureException) TestTimedOutException(org.junit.runners.model.TestTimedOutException) TestTimedOutException(org.junit.runners.model.TestTimedOutException) TimeoutException(java.util.concurrent.TimeoutException) MultipleFailureException(org.junit.runners.model.MultipleFailureException) ExecutionException(java.util.concurrent.ExecutionException)

Example 19 with TestTimedOutException

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;
            }
        }
    };
}
Also used : Statement(org.junit.runners.model.Statement) TestRule(org.junit.rules.TestRule) MonitorInfo(java.lang.management.MonitorInfo) TestTimedOutException(org.junit.runners.model.TestTimedOutException) FutureTask(java.util.concurrent.FutureTask) TimeoutException(java.util.concurrent.TimeoutException) ThreadMXBean(java.lang.management.ThreadMXBean) StringUtils.join(org.apache.commons.lang.StringUtils.join) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) ThreadInfo(java.lang.management.ThreadInfo) Stream(java.util.stream.Stream) ManagementFactory(java.lang.management.ManagementFactory) Statement(org.junit.runners.model.Statement) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) TestTimedOutException(org.junit.runners.model.TestTimedOutException) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) FutureTask(java.util.concurrent.FutureTask) ExecutionException(java.util.concurrent.ExecutionException) TestTimedOutException(org.junit.runners.model.TestTimedOutException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

TestTimedOutException (org.junit.runners.model.TestTimedOutException)19 ExecutionException (java.util.concurrent.ExecutionException)8 TimeoutException (java.util.concurrent.TimeoutException)8 Test (org.junit.Test)5 ManagementFactory (java.lang.management.ManagementFactory)4 MonitorInfo (java.lang.management.MonitorInfo)4 ThreadInfo (java.lang.management.ThreadInfo)4 ThreadMXBean (java.lang.management.ThreadMXBean)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 FutureTask (java.util.concurrent.FutureTask)4 TimeUnit (java.util.concurrent.TimeUnit)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Stream (java.util.stream.Stream)4 TestRule (org.junit.rules.TestRule)4 Statement (org.junit.runners.model.Statement)4 Failure (org.junit.runner.notification.Failure)3 MultipleFailureException (org.junit.runners.model.MultipleFailureException)3 StringUtils.join (org.apache.commons.lang.StringUtils.join)2 StringUtils.join (org.apache.commons.lang3.StringUtils.join)2 ThreadInterruptedError (org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError)2