Java 类org.junit.internal.runners.statements.FailOnTimeout 实例源码

项目:Bukkit_Bungee_PluginLib    文件:UpdaterTest.java   
public Statement apply(Statement base, Description description)
{
    return new FailOnTimeout(base, TEST_TIMEOUT)
    {
        @Override
        public void evaluate() throws Throwable
        {
            try
            {
                super.evaluate();
                throw new TimeoutException();
            }
            catch(Exception ignored)
            {
            }
        }
    };
}
项目:deltaspike    文件:CdiTestRunner.java   
@Override
protected Statement withPotentialTimeout(FrameworkMethod method, Object test, Statement next)
{
    Statement result = super.withPotentialTimeout(method, test, next);

    if (result instanceof FailOnTimeout)
    {
        return new Statement()
        {
            @Override
            public void evaluate() throws Throwable
            {
                throw new RuntimeException("@" + Test.class.getName() + "#timeout isn't supported");
            }
        };
    }

    return result;
}
项目:io-comparison    文件:Timeout.java   
public Statement apply(Statement base, Description description) {
    if (disabled()) {
        return base;
    } else {
        return new FailOnTimeout(base, (long) this.fMillis);
    }
}
项目:io-comparison    文件:Timeout.java   
public Statement apply(Statement base, Description description) {
    if (disabled()) {
        return base;
    } else {
        return new FailOnTimeout(base, fMillis);
    }
}
项目:sling-org-apache-sling-testing-rules    文件:TestTimeout.java   
public Statement apply(Statement base, Description description) {
    if (fMillis > 0) {
        return new FailOnTimeout(base, fMillis);
    } else {
        return base;
    }
}
项目:stringbench    文件:StringBenchIncubation.java   
@Override
public Statement apply(Statement base, Description description) {
       return FailOnTimeout.builder()
           .withTimeout(40, SECONDS)
           .withLookingForStuckThread(true)
           .build(base);
}
项目:sosiefier    文件:BlockJUnit4ClassRunner.java   
/**
 * Returns a {@link Statement}: if {@code method}'s {@code @Test} annotation
 * has the {@code timeout} attribute, throw an exception if {@code next}
 * takes more than the specified number of milliseconds.
 */
@Deprecated
protected Statement withPotentialTimeout(FrameworkMethod method,
        Object test, Statement next) {
    long timeout = getTimeout(method.getAnnotation(Test.class));
    return timeout > 0 ? new FailOnTimeout(next, timeout) : next;
}
项目:sosiefier    文件:FailOnTimeoutTest.java   
@Test
public void stopEndlessStatement() throws Throwable {
    InfiniteLoopStatement infiniteLoop = new InfiniteLoopStatement();
    FailOnTimeout infiniteLoopTimeout = new FailOnTimeout(infiniteLoop,
            TIMEOUT);
    try {
        infiniteLoopTimeout.evaluate();
    } catch (Exception timeoutException) {
        sleep(20); // time to interrupt the thread
        int firstCount = InfiniteLoopStatement.COUNT;
        sleep(20); // time to increment the count
        assertTrue("Thread has not been stopped.",
                firstCount == InfiniteLoopStatement.COUNT);
    }
}
项目:sosiefier    文件:FailOnTimeoutTest.java   
@Test
public void stackTraceContainsRealCauseOfTimeout() throws Throwable {
    StuckStatement stuck = new StuckStatement();
    FailOnTimeout stuckTimeout = new FailOnTimeout(stuck, TIMEOUT);
    try {
        stuckTimeout.evaluate();
        // We must not get here, we expect a timeout exception
        fail("Expected timeout exception");
    } catch (Exception timeoutException) {
        StackTraceElement[] stackTrace = timeoutException.getStackTrace();
        boolean stackTraceContainsTheRealCauseOfTheTimeout = false;
        boolean stackTraceContainsOtherThanTheRealCauseOfTheTimeout = false;
        for (StackTraceElement element : stackTrace) {
            String methodName = element.getMethodName();
            if ("theRealCauseOfTheTimeout".equals(methodName)) {
                stackTraceContainsTheRealCauseOfTheTimeout = true;
            }
            if ("notTheRealCauseOfTheTimeout".equals(methodName)) {
                stackTraceContainsOtherThanTheRealCauseOfTheTimeout = true;
            }
        }
        assertTrue(
                "Stack trace does not contain the real cause of the timeout",
                stackTraceContainsTheRealCauseOfTheTimeout);
        assertFalse(
                "Stack trace contains other than the real cause of the timeout, which can be very misleading",
                stackTraceContainsOtherThanTheRealCauseOfTheTimeout);
    }
}
项目:qpid-jms    文件:QpidJMSTestRunner.java   
/**
 * Perform the same logic as
 * {@link BlockJUnit4ClassRunner#withPotentialTimeout(FrameworkMethod, Object, Statement)}
 * but with additional support for changing the coded timeout with an extended value.
 *
 * @return either a {@link FailOnTimeout}, or the supplied {@link Statement} as appropriate.
 */
@SuppressWarnings("deprecation")
@Override
protected Statement withPotentialTimeout(FrameworkMethod frameworkMethod, Object testInstance, Statement next) {
    long testTimeout = getOriginalTimeout(frameworkMethod);

    if (testTimeout > 0) {
        String multiplierString = System.getProperty("org.apache.qpid.jms.testTimeoutMultiplier");
        double multiplier = 0.0;

        try {
            multiplier = Double.parseDouble(multiplierString);
        } catch (NullPointerException npe) {
        } catch (NumberFormatException nfe) {
            LOG.warn("Ignoring testTimeoutMultiplier not set to a valid value: " + multiplierString);
        }

        if (multiplier > 0.0) {
            LOG.info("Test timeout multiple {} applied to test timeout {}ms: new timeout = {}",
                multiplier, testTimeout, (long) (testTimeout * multiplier));
            testTimeout = (long) (testTimeout * multiplier);
        }

        next = FailOnTimeout.builder().
            withTimeout(testTimeout, TimeUnit.MILLISECONDS).build(next);
    } else {
        next = super.withPotentialTimeout(frameworkMethod, testInstance, next);
    }

    return next;
}
项目:junit-hierarchicalcontextrunner    文件:FailOnTimeoutStatementBuilderTest.java   
@Test
public void whenTestAnnotationDoesSpecifyATimeout_returnFailOnTimeoutStatement() throws Exception {
    TestClass testClass = TestClassPool.forClass(SingleTestWithTimeoutAnnotation.class);
    FrameworkMethod method = testClass.getAnnotatedMethods(Test.class).get(0);

    Statement actual = builder.createStatement(testClass, method, target, next, description, notifier);
    assertThat(actual, is(instanceOf(FailOnTimeout.class)));
}
项目:junit    文件:FailOnTimeoutTest.java   
@Test
public void stopEndlessStatement() throws Throwable {
    InfiniteLoopStatement infiniteLoop = new InfiniteLoopStatement();
    FailOnTimeout infiniteLoopTimeout = new FailOnTimeout(infiniteLoop,
            TIMEOUT);
    try {
        infiniteLoopTimeout.evaluate();
    } catch (Exception timeoutException) {
        sleep(20); // time to interrupt the thread
        int firstCount = InfiniteLoopStatement.COUNT;
        sleep(20); // time to increment the count
        assertTrue("Thread has not been stopped.",
                firstCount == InfiniteLoopStatement.COUNT);
    }
}
项目:junit    文件:FailOnTimeoutTest.java   
@Test
public void stackTraceContainsRealCauseOfTimeout() throws Throwable {
    StuckStatement stuck = new StuckStatement();
    FailOnTimeout stuckTimeout = new FailOnTimeout(stuck, TIMEOUT);
    try {
        stuckTimeout.evaluate();
        // We must not get here, we expect a timeout exception
        fail("Expected timeout exception");
    } catch (Exception timeoutException) {
        StackTraceElement[] stackTrace = timeoutException.getStackTrace();
        boolean stackTraceContainsTheRealCauseOfTheTimeout = false;
        boolean stackTraceContainsOtherThanTheRealCauseOfTheTimeout = false;
        for (StackTraceElement element : stackTrace) {
            String methodName = element.getMethodName();
            if ("theRealCauseOfTheTimeout".equals(methodName)) {
                stackTraceContainsTheRealCauseOfTheTimeout = true;
            }
            if ("notTheRealCauseOfTheTimeout".equals(methodName)) {
                stackTraceContainsOtherThanTheRealCauseOfTheTimeout = true;
            }
        }
        assertTrue(
                "Stack trace does not contain the real cause of the timeout",
                stackTraceContainsTheRealCauseOfTheTimeout);
        assertFalse(
                "Stack trace contains other than the real cause of the timeout, which can be very misleading",
                stackTraceContainsOtherThanTheRealCauseOfTheTimeout);
    }
}
项目:health-and-care-developer-network    文件:FailOnTimeoutTest.java   
@Test
public void stopEndlessStatement() throws Throwable {
    InfiniteLoopStatement infiniteLoop = new InfiniteLoopStatement();
    FailOnTimeout infiniteLoopTimeout = new FailOnTimeout(infiniteLoop,
            TIMEOUT);
    try {
        infiniteLoopTimeout.evaluate();
    } catch (Exception timeoutException) {
        sleep(20); // time to interrupt the thread
        int firstCount = InfiniteLoopStatement.COUNT;
        sleep(20); // time to increment the count
        assertTrue("Thread has not been stopped.",
                firstCount == InfiniteLoopStatement.COUNT);
    }
}
项目:health-and-care-developer-network    文件:FailOnTimeoutTest.java   
@Test
public void stackTraceContainsRealCauseOfTimeout() throws Throwable {
    StuckStatement stuck = new StuckStatement();
    FailOnTimeout stuckTimeout = new FailOnTimeout(stuck, TIMEOUT);
    try {
        stuckTimeout.evaluate();
        // We must not get here, we expect a timeout exception
        fail("Expected timeout exception");
    } catch (Exception timeoutException) {
        StackTraceElement[] stackTrace = timeoutException.getStackTrace();
        boolean stackTraceContainsTheRealCauseOfTheTimeout = false;
        boolean stackTraceContainsOtherThanTheRealCauseOfTheTimeout = false;
        for (StackTraceElement element : stackTrace) {
            String methodName = element.getMethodName();
            if ("theRealCauseOfTheTimeout".equals(methodName)) {
                stackTraceContainsTheRealCauseOfTheTimeout = true;
            }
            if ("notTheRealCauseOfTheTimeout".equals(methodName)) {
                stackTraceContainsOtherThanTheRealCauseOfTheTimeout = true;
            }
        }
        assertTrue(
                "Stack trace does not contain the real cause of the timeout",
                stackTraceContainsTheRealCauseOfTheTimeout);
        assertFalse(
                "Stack trace contains other than the real cause of the timeout, which can be very misleading",
                stackTraceContainsOtherThanTheRealCauseOfTheTimeout);
    }
}
项目:sosiefier    文件:Timeout.java   
public Statement apply(Statement base, Description description) {
    return new FailOnTimeout(base, fTimeout, fTimeUnit, fLookForStuckThread);
}
项目:lcm    文件:Timeout.java   
public Statement apply(Statement base, Description description) {
    return new FailOnTimeout(base, fMillis);
}
项目:junit-hierarchicalcontextrunner    文件:FailOnTimeoutStatementBuilder.java   
public Statement createStatement(final TestClass testClass, final FrameworkMethod method, final Object target,
                                 final Statement next, final Description description, final RunNotifier notifier) {
    final Test annotation = method.getAnnotation(Test.class);
    return annotation.timeout() <= 0 ? next : new FailOnTimeout(next, annotation.timeout());
}
项目:junit    文件:Timeout.java   
public Statement apply(Statement base, Description description) {
    return new FailOnTimeout(base, fMillis);
}
项目:org.openntf.domino    文件:Timeout.java   
public Statement apply(Statement base, Description description) {
    return new FailOnTimeout(base, fMillis);
}
项目:kc-rice    文件:LoadTimeWeavableTestRunner.java   
/**
 * Returns a {@link org.junit.runners.model.Statement}: if {@code method}'s {@code @Test} annotation
 * has the {@code timeout} attribute, throw an exception if {@code next}
 * takes more than the specified number of milliseconds.
 *
 * @deprecated Will be private soon: use Rules instead
 */
@Deprecated
protected Statement withPotentialTimeout(FrameworkMethod method,
        Object test, Statement next) {
    long timeout = getTimeout(method.getAnnotation(Test.class));
    return timeout > 0 ? new FailOnTimeout(next, timeout) : next;
}
项目:lcm    文件:BlockJUnit4ClassRunner.java   
/**
 * Returns a {@link Statement}: if {@code method}'s {@code @Test} annotation
 * has the {@code timeout} attribute, throw an exception if {@code next}
 * takes more than the specified number of milliseconds.
 *
 * @deprecated Will be private soon: use Rules instead
 */
@Deprecated
protected Statement withPotentialTimeout(FrameworkMethod method,
        Object test, Statement next) {
    long timeout = getTimeout(method.getAnnotation(Test.class));
    return timeout > 0 ? new FailOnTimeout(next, timeout) : next;
}
项目:rice    文件:LoadTimeWeavableTestRunner.java   
/**
 * Returns a {@link org.junit.runners.model.Statement}: if {@code method}'s {@code @Test} annotation
 * has the {@code timeout} attribute, throw an exception if {@code next}
 * takes more than the specified number of milliseconds.
 *
 * @deprecated Will be private soon: use Rules instead
 */
@Deprecated
protected Statement withPotentialTimeout(FrameworkMethod method,
        Object test, Statement next) {
    long timeout = getTimeout(method.getAnnotation(Test.class));
    return timeout > 0 ? new FailOnTimeout(next, timeout) : next;
}
项目:junit    文件:BlockJUnit4ClassRunner.java   
/**
 * Returns a {@link Statement}: if {@code method}'s {@code @Test} annotation
 * has the {@code timeout} attribute, throw an exception if {@code next}
 * takes more than the specified number of milliseconds.
 *
 * @deprecated Will be private soon: use Rules instead
 */
@Deprecated
protected Statement withPotentialTimeout(FrameworkMethod method,
        Object test, Statement next) {
    long timeout = getTimeout(method.getAnnotation(Test.class));
    return timeout > 0 ? new FailOnTimeout(next, timeout) : next;
}
项目:org.openntf.domino    文件:BlockJUnit4ClassRunner.java   
/**
 * Returns a {@link Statement}: if {@code method}'s {@code @Test} annotation
 * has the {@code timeout} attribute, throw an exception if {@code next}
 * takes more than the specified number of milliseconds.
 *
 * @deprecated Will be private soon: use Rules instead
 */
@Deprecated
protected Statement withPotentialTimeout(FrameworkMethod method,
        Object test, Statement next) {
    long timeout = getTimeout(method.getAnnotation(Test.class));
    return timeout > 0 ? new FailOnTimeout(next, timeout) : next;
}