當前位置: 首頁>>代碼示例>>Java>>正文


Java Timeout類代碼示例

本文整理匯總了Java中org.junit.rules.Timeout的典型用法代碼示例。如果您正苦於以下問題:Java Timeout類的具體用法?Java Timeout怎麽用?Java Timeout使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Timeout類屬於org.junit.rules包,在下文中一共展示了Timeout類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: canBeSerialized

import org.junit.rules.Timeout; //導入依賴的package包/類
@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);
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:22,代碼來源:SerializableTimeoutTest.java

示例2: withTimeout

import org.junit.rules.Timeout; //導入依賴的package包/類
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;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:20,代碼來源:CategoryBasedTimeout.java

示例3: getTimeout

import org.junit.rules.Timeout; //導入依賴的package包/類
/**
 * 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());
}
 
開發者ID:jGleitz,項目名稱:JUnit-KIT,代碼行數:23,代碼來源:InteractiveConsoleTest.java

示例4: hasTimeoutRule

import org.junit.rules.Timeout; //導入依賴的package包/類
/**
 * @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;
}
 
開發者ID:saleehk,項目名稱:buck-cutom,代碼行數:20,代碼來源:BuckBlockJUnit4ClassRunner.java

示例5: hasTimeoutRule

import org.junit.rules.Timeout; //導入依賴的package包/類
/**
 * @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;
}
 
開發者ID:facebook,項目名稱:buck,代碼行數:20,代碼來源:BuckBlockJUnit4ClassRunner.java

示例6: getTestRules

import org.junit.rules.Timeout; //導入依賴的package包/類
@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);
    }
}
 
開發者ID:altiplanogao,項目名稱:io-comparison,代碼行數:11,代碼來源:FocusRunner.java

示例7: getAllResourcesRule

import org.junit.rules.Timeout; //導入依賴的package包/類
public static RuleChain getAllResourcesRule(int timeout) {
    if (allResourcesRule == null) {
        allResourcesRule = RuleChain
            .outerRule(new Timeout(timeout))
            .around(CLUSTER_RESOURCE);
    }
    return allResourcesRule;
}
 
開發者ID:epam,項目名稱:Lagerta,代碼行數:9,代碼來源:SingleClusterResource.java

示例8: getAllResourcesRule

import org.junit.rules.Timeout; //導入依賴的package包/類
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;
}
 
開發者ID:epam,項目名稱:Lagerta,代碼行數:14,代碼來源:FullClusterTestResourcesFactory.java

示例9: fieldsCanBeRead

import org.junit.rules.Timeout; //導入依賴的package包/類
@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);
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:15,代碼來源:SerializableTimeoutTest.java

示例10: create

import org.junit.rules.Timeout; //導入依賴的package包/類
public static TestRule create(Timeout seconds) {
    try {
        return new DisableOnDebug(seconds);
    } catch (LinkageError ex) {
        return null;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:NotOnDebug.java

示例11: testTimeout

import org.junit.rules.Timeout; //導入依賴的package包/類
protected Timeout testTimeout() {
	return new TestTimeout(1, SECONDS);
}
 
開發者ID:mezuro,項目名稱:kalibro,代碼行數:4,代碼來源:UnitTest.java

示例12: getTimeoutRule

import org.junit.rules.Timeout; //導入依賴的package包/類
public static TestRule getTimeoutRule() {
    return new DisableOnAndroidDebug(Timeout.seconds(30));
}
 
開發者ID:emartech,項目名稱:android-mobile-engage-sdk,代碼行數:4,代碼來源:TimeoutUtils.java

示例13: getTimeoutRule

import org.junit.rules.Timeout; //導入依賴的package包/類
public static TestRule getTimeoutRule(int timeout) {
  return IS_DEBUG ? new TestName() : new Timeout(timeout);
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:4,代碼來源:TestTools.java

示例14: getGlobalTimeoutValue

import org.junit.rules.Timeout; //導入依賴的package包/類
public Timeout getGlobalTimeoutValue() {
    return Timeout.millis(TypedProperties.getIntValue("globalTimeout"));
}
 
開發者ID:christian-draeger,項目名稱:page-content-tester,代碼行數:4,代碼來源:GlobalConfig.java

示例15: getPerTestMethodRules

import org.junit.rules.Timeout; //導入依賴的package包/類
public static RuleChain getPerTestMethodRules() {
    return RuleChain
        .outerRule(new Timeout(PER_TEST_TIMEOUT))
        .around(CLUSTER_RESOURCE.perTestMethodCleanupRule());
}
 
開發者ID:epam,項目名稱:Lagerta,代碼行數:6,代碼來源:SingleClusterResource.java


注:本文中的org.junit.rules.Timeout類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。