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

下面列出了怎么用org.junit.internal.runners.statements.FailOnTimeout的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: android-test   文件: AndroidJUnit4ClassRunner.java
/**
 * Default to <a href="http://junit.org/javadoc/latest/org/junit/Test.html#timeout()"><code>
 * org.junit.Test#timeout()</code></a> level timeout if set. Otherwise, set the timeout that was
 * passed to the instrumentation via argument.
 */
@Override
protected Statement withPotentialTimeout(FrameworkMethod method, Object test, Statement next) {
  // test level timeout i.e @Test(timeout = 123)
  long timeout = getTimeout(method.getAnnotation(Test.class));

  // use runner arg timeout if test level timeout is not present
  if (timeout <= 0 && androidRunnerParams.getPerTestTimeout() > 0) {
    timeout = androidRunnerParams.getPerTestTimeout();
  }

  if (timeout <= 0) {
    // no timeout was set
    return next;
  }

  // Cannot switch to use builder as that is not supported in JUnit 4.10 which is what is
  // available in AOSP.
  return new FailOnTimeout(next, timeout);
}
 
源代码2 项目: 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;
}
 
源代码3 项目: bcrypt   文件: BCryptHighCostTest.java
public Statement apply(Statement base, Description description) {
    return new FailOnTimeout(base, MIN_TIMEOUT) {
        @Override
        public void evaluate() throws Throwable {
            try {
                super.evaluate();
                throw new TimeoutException();
            } catch (Exception e) {
            }
        }
    };
}
 
源代码4 项目: incubator-ratis   文件: JUnitRunListener.java
private static Throwable getTimeoutException() {
  final FailOnTimeout f = FailOnTimeout.builder().withTimeout(1, TimeUnit.NANOSECONDS).build(new Statement() {
    @Override
    public void evaluate() throws InterruptedException {
      Thread.sleep(1000);
    }
  });
  try {
    f.evaluate();
  } catch(Throwable throwable) {
    return throwable;
  }
  throw new IllegalStateException("Failed to getTimeoutException");
}
 
源代码5 项目: ratis   文件: JUnitRunListener.java
private static Throwable getTimeoutException() {
  final FailOnTimeout f = new FailOnTimeout(new Statement() {
    @Override
    public void evaluate() throws InterruptedException {
      Thread.sleep(1000);
    }
  }, 1);
  try {
    f.evaluate();
  } catch(Throwable throwable) {
    return throwable;
  }
  return null;
}
 
源代码6 项目: stringbench   文件: StringBenchIncubation.java
@Override
public Statement apply(Statement base, Description description) {
       return FailOnTimeout.builder()
           .withTimeout(40, SECONDS)
           .withLookingForStuckThread(true)
           .build(base);
}
 
源代码7 项目: android-test   文件: UiThreadTestRule.java
@Override
public Statement apply(final Statement base, Description description) {
  if (base instanceof FailOnTimeout
      || (base instanceof UiThreadStatement && !((UiThreadStatement) base).isRunOnUiThread())) {
    // In upstream junit code Rules Statements are handled last. Since we now handle
    // @UiThreadTest as part of the core Android runner, there is a chance that
    // UiThreadStatement was already applied on the current statement.
    // This is mainly for compatibility reasons to deprecated this rule.
    return base;
  }
  return new UiThreadStatement(base, shouldRunOnUiThread(description));
}
 
源代码8 项目: spectrum   文件: TimeoutWrapper.java
/**
 * Convert the timeout into a {@link NonReportingHook} which executes
 * the inner inside a daemon thread, failing if it takes too long.
 * @param timeout duration of the timeout
 * @return hook which implements the timeout
 */
static NonReportingHook timeoutHook(Duration timeout) {
  return nonReportingHookFrom(
      (description, reporting, block) -> withAppliedTimeout(FailOnTimeout.builder(), timeout)
          .build(statementOf(block))
          .evaluate());
}
 
源代码9 项目: 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;
}
 
源代码10 项目: 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;
}
 
源代码11 项目: spectrum   文件: TimeoutWrapper.java
/**
 * Apply a timeout expressed as a duration to a builder of a {@link FailOnTimeout} object.
 * @param builder to modify
 * @param timeout duration of the timeout
 * @return the builder input - for fluent use.
 */
static FailOnTimeout.Builder withAppliedTimeout(FailOnTimeout.Builder builder, Duration timeout) {
  builder.withTimeout(timeout.toNanos(), TimeUnit.NANOSECONDS);

  return builder;
}
 
 类所在包
 同包方法