本文整理汇总了Java中org.junit.internal.runners.statements.FailOnTimeout类的典型用法代码示例。如果您正苦于以下问题:Java FailOnTimeout类的具体用法?Java FailOnTimeout怎么用?Java FailOnTimeout使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FailOnTimeout类属于org.junit.internal.runners.statements包,在下文中一共展示了FailOnTimeout类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import org.junit.internal.runners.statements.FailOnTimeout; //导入依赖的package包/类
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)
{
}
}
};
}
示例2: withPotentialTimeout
import org.junit.internal.runners.statements.FailOnTimeout; //导入依赖的package包/类
@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;
}
示例3: apply
import org.junit.internal.runners.statements.FailOnTimeout; //导入依赖的package包/类
public Statement apply(Statement base, Description description) {
if (disabled()) {
return base;
} else {
return new FailOnTimeout(base, (long) this.fMillis);
}
}
示例4: apply
import org.junit.internal.runners.statements.FailOnTimeout; //导入依赖的package包/类
public Statement apply(Statement base, Description description) {
if (disabled()) {
return base;
} else {
return new FailOnTimeout(base, fMillis);
}
}
示例5: apply
import org.junit.internal.runners.statements.FailOnTimeout; //导入依赖的package包/类
public Statement apply(Statement base, Description description) {
if (fMillis > 0) {
return new FailOnTimeout(base, fMillis);
} else {
return base;
}
}
示例6: apply
import org.junit.internal.runners.statements.FailOnTimeout; //导入依赖的package包/类
@Override
public Statement apply(Statement base, Description description) {
return FailOnTimeout.builder()
.withTimeout(40, SECONDS)
.withLookingForStuckThread(true)
.build(base);
}
示例7: withPotentialTimeout
import org.junit.internal.runners.statements.FailOnTimeout; //导入依赖的package包/类
/**
* 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;
}
示例8: stopEndlessStatement
import org.junit.internal.runners.statements.FailOnTimeout; //导入依赖的package包/类
@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);
}
}
示例9: stackTraceContainsRealCauseOfTimeout
import org.junit.internal.runners.statements.FailOnTimeout; //导入依赖的package包/类
@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);
}
}
示例10: withPotentialTimeout
import org.junit.internal.runners.statements.FailOnTimeout; //导入依赖的package包/类
/**
* 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;
}
示例11: whenTestAnnotationDoesSpecifyATimeout_returnFailOnTimeoutStatement
import org.junit.internal.runners.statements.FailOnTimeout; //导入依赖的package包/类
@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)));
}
开发者ID:bechte,项目名称:junit-hierarchicalcontextrunner,代码行数:9,代码来源:FailOnTimeoutStatementBuilderTest.java
示例12: apply
import org.junit.internal.runners.statements.FailOnTimeout; //导入依赖的package包/类
public Statement apply(Statement base, Description description) {
return new FailOnTimeout(base, fTimeout, fTimeUnit, fLookForStuckThread);
}
示例13: apply
import org.junit.internal.runners.statements.FailOnTimeout; //导入依赖的package包/类
public Statement apply(Statement base, Description description) {
return new FailOnTimeout(base, fMillis);
}
示例14: createStatement
import org.junit.internal.runners.statements.FailOnTimeout; //导入依赖的package包/类
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());
}
示例15: withPotentialTimeout
import org.junit.internal.runners.statements.FailOnTimeout; //导入依赖的package包/类
/**
* 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;
}