Java 类org.junit.rules.Timeout 实例源码

项目:monarch    文件:SerializableTimeoutTest.java   
@Test
public void canBeSerialized() throws Exception {
  long timeout = 2;
  TimeUnit timeUnit = TimeUnit.SECONDS;
  boolean lookingForStuckThread = true;

  SerializableTimeout instance = SerializableTimeout.builder().withTimeout(timeout, timeUnit)
      .withLookingForStuckThread(lookingForStuckThread).build();

  assertThat(readField(Timeout.class, instance, FIELD_TIMEOUT)).isEqualTo(timeout);
  assertThat(readField(Timeout.class, instance, FIELD_TIME_UNIT)).isEqualTo(timeUnit);
  assertThat(readField(Timeout.class, instance, FIELD_LOOK_FOR_STUCK_THREAD))
      .isEqualTo(lookingForStuckThread);

  SerializableTimeout cloned = (SerializableTimeout) SerializationUtils.clone(instance);

  assertThat(readField(Timeout.class, cloned, FIELD_TIMEOUT)).isEqualTo(timeout);
  assertThat(readField(Timeout.class, cloned, FIELD_TIME_UNIT)).isEqualTo(timeUnit);
  assertThat(readField(Timeout.class, cloned, FIELD_LOOK_FOR_STUCK_THREAD))
      .isEqualTo(lookingForStuckThread);
}
项目:ditb    文件:CategoryBasedTimeout.java   
public Timeout.Builder withTimeout(Class<?> clazz) {
  Annotation annotation = clazz.getAnnotation(Category.class);
  if (annotation != null) {
    Category category = (Category)annotation;
    for (Class<?> c: category.value()) {
      if (c == SmallTests.class) {
        // See SmallTests. Supposed to run 15 seconds.
        return withTimeout(30, TimeUnit.SECONDS);
      } else if (c == MediumTests.class) {
        // See MediumTests. Supposed to run 50 seconds.
        return withTimeout(180, TimeUnit.SECONDS);
      } else if (c == LargeTests.class) {
        // Let large tests have a ten minute timeout.
        return withTimeout(10, TimeUnit.MINUTES);
      }
    }
  }
  return this;
}
项目:JUnit-KIT    文件:InteractiveConsoleTest.java   
/**
 * Returns either the timeout set in the configuration or the default timeout returned by
 * {@link #getDefaultTimeoutMs()}.
 * 
 * @return The timeout to use for this test class.
 */
private final Timeout getTimeout() {
    String systemProperty = System.getProperty("timeout");
    if (systemProperty != null) {
        int sysTimeout = 0;
        try {
            sysTimeout = Integer.parseInt(systemProperty);
        } catch (NumberFormatException e) {
            throw new FrameworkException("The timeout set in the configuration cannot be parsed into an integer!");
        }
        if (sysTimeout < 0) {
            throw new FrameworkException("How exactly do you think a negative timeout should work?");
        }
        return new Timeout(sysTimeout);
    }
    return new Timeout(getDefaultTimeoutMs());
}
项目:buck-cutom    文件:BuckBlockJUnit4ClassRunner.java   
/**
 * @return {@code true} if the test class has any fields annotated with {@code Rule} whose type
 *     is {@link Timeout}.
 */
static boolean hasTimeoutRule(TestClass testClass) {
  // Many protected convenience methods in BlockJUnit4ClassRunner that are available in JUnit 4.11
  // such as getTestRules(Object) were not public until
  // https://github.com/junit-team/junit/commit/8782efa08abf5d47afdc16740678661443706740,
  // which appears to be JUnit 4.9. Because we allow users to use JUnit 4.7, we need to include a
  // custom implementation that is backwards compatible to JUnit 4.7.
  List<FrameworkField> fields = testClass.getAnnotatedFields(Rule.class);
  for (FrameworkField field : fields) {
    if (field.getField().getType().equals(Timeout.class)) {
      return true;
    }
  }

  return false;
}
项目:buck    文件:BuckBlockJUnit4ClassRunner.java   
/**
 * @return {@code true} if the test class has any fields annotated with {@code Rule} whose type is
 *     {@link Timeout}.
 */
static boolean hasTimeoutRule(TestClass testClass) {
  // Many protected convenience methods in BlockJUnit4ClassRunner that are available in JUnit 4.11
  // such as getTestRules(Object) were not public until
  // https://github.com/junit-team/junit/commit/8782efa08abf5d47afdc16740678661443706740,
  // which appears to be JUnit 4.9. Because we allow users to use JUnit 4.7, we need to include a
  // custom implementation that is backwards compatible to JUnit 4.7.
  List<FrameworkField> fields = testClass.getAnnotatedFields(Rule.class);
  for (FrameworkField field : fields) {
    if (field.getField().getType().equals(Timeout.class)) {
      return true;
    }
  }

  return false;
}
项目:io-comparison    文件:FocusRunner.java   
@Override
protected List<TestRule> getTestRules(Object target) {
    if (isFocusEnabled()) {
        List<TestRule> old = super.getTestRules(target);
        old.removeIf(rule -> rule instanceof Timeout);
        return old;
    } else {
        return super.getTestRules(target);
    }
}
项目:Lagerta    文件:SingleClusterResource.java   
public static RuleChain getAllResourcesRule(int timeout) {
    if (allResourcesRule == null) {
        allResourcesRule = RuleChain
            .outerRule(new Timeout(timeout))
            .around(CLUSTER_RESOURCE);
    }
    return allResourcesRule;
}
项目:Lagerta    文件:FullClusterTestResourcesFactory.java   
public static RuleChain getAllResourcesRule(int timeout) {
    if (allResourcesRule == null) {
        allResourcesRule = RuleChain
            .outerRule(FOLDER)
            .around(new Timeout(timeout))
            .around(new EmbeddedKafkaRule(FOLDER, "mainKafka", 3, 2181, 9092))
            .around(new EmbeddedKafkaRule(FOLDER, "drKafka", 3, 2182, 9096))
            .around(SUPER_CLUSTER_RESOURCE)
            .around(MAIN_CLUSTER_RESOURCE)
            .around(DR_CLUSTER_RESOURCE);
    }
    return allResourcesRule;
}
项目:monarch    文件:SerializableTimeoutTest.java   
@Test
public void fieldsCanBeRead() throws Exception {
  long timeout = 1000;
  TimeUnit timeUnit = TimeUnit.MILLISECONDS;
  boolean lookingForStuckThread = false;

  SerializableTimeout instance = SerializableTimeout.builder().withTimeout(timeout, timeUnit)
      .withLookingForStuckThread(lookingForStuckThread).build();

  assertThat(readField(Timeout.class, instance, FIELD_TIMEOUT)).isEqualTo(timeout);
  assertThat(readField(Timeout.class, instance, FIELD_TIME_UNIT)).isEqualTo(timeUnit);
  assertThat(readField(Timeout.class, instance, FIELD_LOOK_FOR_STUCK_THREAD))
      .isEqualTo(lookingForStuckThread);
}
项目:openjdk-jdk10    文件:NotOnDebug.java   
public static TestRule create(Timeout seconds) {
    try {
        return new DisableOnDebug(seconds);
    } catch (LinkageError ex) {
        return null;
    }
}
项目:kalibro    文件:UnitTest.java   
protected Timeout testTimeout() {
    return new TestTimeout(1, SECONDS);
}
项目:android-mobile-engage-sdk    文件:TimeoutUtils.java   
public static TestRule getTimeoutRule() {
    return new DisableOnAndroidDebug(Timeout.seconds(30));
}
项目:QDrill    文件:TestTools.java   
public static TestRule getTimeoutRule(int timeout) {
  return IS_DEBUG ? new TestName() : new Timeout(timeout);
}
项目:page-content-tester    文件:GlobalConfig.java   
public Timeout getGlobalTimeoutValue() {
    return Timeout.millis(TypedProperties.getIntValue("globalTimeout"));
}
项目:Lagerta    文件:SingleClusterResource.java   
public static RuleChain getPerTestMethodRules() {
    return RuleChain
        .outerRule(new Timeout(PER_TEST_TIMEOUT))
        .around(CLUSTER_RESOURCE.perTestMethodCleanupRule());
}
项目:Lagerta    文件:FullClusterTestResourcesFactory.java   
public static RuleChain getPerTestMethodRules() {
    return RuleChain
        .outerRule(new Timeout(PER_TEST_TIMEOUT))
        .around(MAIN_CLUSTER_RESOURCE.perTestMethodCleanupRule())
        .around(DR_CLUSTER_RESOURCE.perTestMethodCleanupRule());
}
项目:monarch    文件:SerializableTimeout.java   
SerializationProxy(final SerializableTimeout instance) {
  this.timeout = (long) readField(Timeout.class, instance, FIELD_TIMEOUT);
  this.timeUnit = (TimeUnit) readField(Timeout.class, instance, FIELD_TIME_UNIT);
  this.lookForStuckThread =
      (boolean) readField(Timeout.class, instance, FIELD_LOOK_FOR_STUCK_THREAD);
}
项目:monarch    文件:SerializableTimeoutTest.java   
@Test
public void hasThreeFields() throws Exception {
  Field[] fields = Timeout.class.getDeclaredFields();
  assertThat(fields.length).as("Fields: " + Arrays.asList(fields)).isEqualTo(3);
}
项目:monarch    文件:SerializableTimeoutTest.java   
@Test
public void fieldTimeoutShouldExist() throws Exception {
  Field field = Timeout.class.getDeclaredField(FIELD_TIMEOUT);
  assertThat(field.getType()).isEqualTo(Long.TYPE);
}
项目:monarch    文件:SerializableTimeoutTest.java   
@Test
public void fieldTimeUnitShouldExist() throws Exception {
  Field field = Timeout.class.getDeclaredField(FIELD_TIME_UNIT);
  assertThat(field.getType()).isEqualTo(TimeUnit.class);
}
项目:monarch    文件:SerializableTimeoutTest.java   
@Test
public void fieldLookForStuckThreadShouldExist() throws Exception {
  Field field = Timeout.class.getDeclaredField(FIELD_LOOK_FOR_STUCK_THREAD);
  assertThat(field.getType()).isEqualTo(Boolean.TYPE);
}
项目:dremio-oss    文件:TestTools.java   
public static TestRule getTimeoutRule(int timeout, TimeUnit unit) {
  return IS_DEBUG ? new TestName() : Timeout.builder().withTimeout(timeout, unit).build();
}
项目:drill    文件:TestTools.java   
public static TestRule getTimeoutRule(int timeout) {
  return IS_DEBUG ? new TestName() : new Timeout(timeout);
}
项目:drill    文件:TestTools.java   
public static TestRule getTimeoutRule(int timeout) {
  return IS_DEBUG ? new TestName() : new Timeout(timeout);
}
项目:hbase    文件:HBaseClassTestRule.java   
private HBaseClassTestRule(Class<?> clazz, Timeout timeout) {
  this.clazz = clazz;
  this.timeout = timeout;
}
项目:hbase    文件:HBaseClassTestRule.java   
public static HBaseClassTestRule forClass(Class<?> clazz) {
  return new HBaseClassTestRule(clazz, Timeout.builder().withLookingForStuckThread(true)
      .withTimeout(getTimeoutInSeconds(clazz), TimeUnit.SECONDS).build());
}
项目:cultivar    文件:AbstractZookeeperClusterTest.java   
public AbstractZookeeperClusterTest(final int clusterSize, final long testTime, final TimeUnit unit) {

        timeout = new Timeout(testTime, unit);
        testingCluster = new TestingCluster(clusterSize);
    }
项目:kalibro    文件:MethodReflectorTest.java   
@Test
public void shouldFindSuperclassMethod() {
    assertEquals(Timeout.class, reflector.getReturnType("testTimeout"));
}