org.junit.jupiter.api.Assertions#assertTimeout()源码实例Demo

下面列出了org.junit.jupiter.api.Assertions#assertTimeout() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Disabled
@Test
public void performanceTestNuget() {
    Assertions.assertTimeout(Duration.ofSeconds(120), () -> {
        final String dependencyGraphFile = FunctionalTestFiles.asString("/nuget/dwCheckApi_inspection.json");

        final NugetInspectorParser packager = new NugetInspectorParser(gson, externalIdFactory);

        final NugetParseResult result = packager.createCodeLocation(dependencyGraphFile);
        final CodeLocation codeLocation = result.getCodeLocations().get(0);

        final BdioPropertyHelper bdioPropertyHelper = new BdioPropertyHelper();
        final BdioNodeFactory bdioNodeFactory = new BdioNodeFactory(bdioPropertyHelper);
        final DependencyGraphTransformer dependencyGraphTransformer = new DependencyGraphTransformer(bdioPropertyHelper, bdioNodeFactory);

        final BdioProject bdioNode = bdioNodeFactory.createProject("test", "1.0.0", BdioId.createFromPieces("bdioId"), externalIdFactory.createMavenExternalId("group", "name", "version"));

        final List<BdioComponent> components = dependencyGraphTransformer
                                                   .transformDependencyGraph(codeLocation.getDependencyGraph(), bdioNode, codeLocation.getDependencyGraph().getRootDependencies(), new HashMap<ExternalId, BdioNode>());

        assertEquals(211, components.size());
    });
}
 
@Test
public void fixedDelay() {
    final Delay fixed = Constant.of().delay(Duration.ofMillis(50)).timeout(Duration.ofMillis(5 * 50)).build();
    int[] attempt = { 1 };
    final Executable fn = () -> {
        Duration next = Duration.ZERO;
        while ((next = fixed.nextDelay(attempt[0])) != Duration.ZERO) {
            attempt[0]++;
            TimeUnit.MILLISECONDS.sleep(next.toMillis());
        }
    };
    //
    // Small 5ms jitter to ensure we complete within time
    //
    Assertions.assertTimeout(Duration.ofMillis(6 * 50), fn);
    assertThat(6).isEqualTo(attempt[0]);
    assertThat(fixed.nextDelay(8) == Duration.ZERO).isEqualTo(true);
    assertThat(fixed.nextDelay(10) == Duration.ZERO).isEqualTo(true);
    assertThat(fixed.nextDelay(15) == Duration.ZERO).isEqualTo(true);
}
 
源代码3 项目: robozonky   文件: DaemonShutdownHookTest.java
@Test
void runtime() {
    final Lifecycle lifecycle = mock(Lifecycle.class);
    final ShutdownEnabler se = mock(ShutdownEnabler.class);
    final DaemonShutdownHook hook = new DaemonShutdownHook(lifecycle, se);
    hook.start();
    se.get()
        .ifPresent(c -> c.accept(ReturnCode.OK));
    Assertions.assertTimeout(Duration.ofSeconds(5), () -> {
        while (hook.isAlive()) { // wait until the hook to terminate
            Thread.sleep(1);
        }
        verify(se).waitUntilTriggered();
        verify(lifecycle).resumeToShutdown();
    });
}
 
源代码4 项目: rapidoid   文件: AutoExpandingMapTest.java
@Test
public void testConcurrentMapAccess() {
	final AtomicInteger counter = new AtomicInteger();
	final Map<Object, Object> map = autoToStr(counter);

	final int k = 1000;

	Assertions.assertTimeout(Duration.ofSeconds(60), () -> {
		Msc.benchmarkMT(200, "gets", 100000000, () -> {
			int rnd = Rnd.rnd(k);
			eq(map.get(rnd), rnd + "");
		});
	});

	// it is highly unlikely to be less than K, for a small value of K
	eq(counter.get(), k);
}
 
源代码5 项目: rapidoid   文件: ResTest.java
@Test
public void shouldBeFast() {
	// typically 1M reads should take less than a second
	Assertions.assertTimeout(Duration.ofSeconds(5), () -> {

		for (int i = 0; i < 900; i++) {
			// fill-in the cache (with non-existing resources)
			Res.from("abc", "x-location");
		}

		// should be fast
		multiThreaded(100, 1000000, () -> {
			Res file = Res.from("abc.txt", "");
			notNull(file.getBytes());
		});
	});
}
 
@Test
public void createCodeLocationDWService() {
    Assertions.assertTimeout(Duration.ofMillis(5000L), () -> {
        final String dependencyNodeFile = FunctionalTestFiles.asString("/nuget/dwCheckApi_inspection_martin.json");
        final ExternalIdFactory externalIdFactory = new ExternalIdFactory();

        final NugetInspectorParser packager = new NugetInspectorParser(gson, externalIdFactory);
        final NugetParseResult result = packager.createCodeLocation(dependencyNodeFile);

        for (final CodeLocation codeLocation : result.getCodeLocations()) {
            final BdioPropertyHelper bdioPropertyHelper = new BdioPropertyHelper();
            final BdioNodeFactory bdioNodeFactory = new BdioNodeFactory(bdioPropertyHelper);

            final DependencyGraphTransformer dependencyNodeTransformer = new DependencyGraphTransformer(bdioPropertyHelper, bdioNodeFactory);

            final BdioExternalIdentifier projectId = bdioPropertyHelper.createExternalIdentifier(codeLocation.getExternalId().get());
            final BdioProject project = bdioNodeFactory.createProject(result.getProjectName(), result.getProjectVersion(), BdioId.createFromPieces(Forge.NUGET.toString()), projectId);

            final Map<ExternalId, BdioNode> components = new HashMap<>();
            components.put(codeLocation.getExternalId().get(), project);

            final List<BdioComponent> bdioComponents = dependencyNodeTransformer.transformDependencyGraph(codeLocation.getDependencyGraph(), project, codeLocation.getDependencyGraph().getRootDependencies(), components);

            assertEquals(bdioComponents.size(), bdioComponents.size());
        }
    });
}
 
@Test
void canCancel() {
  final RandomSourceFunction function = new RandomSourceFunction(Integer.MAX_VALUE);
  function.cancel();

  env.addSource(function).addSink(new CollectSink());
  Assertions.assertTimeout(Duration.ofSeconds(2), () -> env.execute());

  assertThat(CollectSink.values).isEmpty();
}
 
源代码8 项目: rapidoid   文件: EventsTest.java
@Test
public void firingUnusedEventsMustBeFast() {
	Assertions.assertTimeout(Duration.ofSeconds(1), () -> {
		for (int i = 0; i < 100 * 1000 * 1000; i++) {
			Fire.event(Events.LOG_TRACE);
		}
	});
}
 
源代码9 项目: rapidoid   文件: JobsTest.java
@Test
public void testJobsExecution() {

	int total = 100000;
	final AtomicInteger counter = new AtomicInteger();

	Assertions.assertTimeout(Duration.ofSeconds(30), () -> {

		multiThreaded(1000, total, () -> {
			Ctxs.open("test-job");

			final UserInfo user = new UserInfo(TestRnd.rndStr(50), U.set("role1"));

			Ctxs.required().setUser(user);
			ensureProperContext(user);

			ScheduledFuture<?> future = Jobs.after(100, TimeUnit.MILLISECONDS).run(() -> {
				ensureProperContext(user);
				counter.incrementAndGet();
			});

			try {
				future.get();
			} catch (Exception e) {
				e.printStackTrace();
				fail("The job throwed an exception!");
			}

			Ctxs.close();
		});
	});

	eq(counter.get(), total);
}
 
源代码10 项目: rapidoid   文件: MultiWatchTest.java
@Test
public void shouldSupportMultipleWatchCalls() {
	String dir = TestIO.createTempDir("watch-service-test");

	Assertions.assertTimeout(Duration.ofSeconds(60), () -> {
		if (!TestCommons.RAPIDOID_CI) {
			for (int i = 0; i < 10; i++) {
				exerciseMultiWatch(dir);
			}
		}
	});
}
 
源代码11 项目: Spring   文件: TesterExceptionTests.java
@Test
public void timeout() {
    Assertions.assertTimeout(Duration.ofMillis(10), () -> Thread.sleep(5));
}
 
源代码12 项目: java-9-wtf   文件: NotoSansTest.java
@Test
void createNotoSansScaler() throws Exception {
	Assertions.assertTimeout(
			Duration.of(250, ChronoUnit.MILLIS),
			NotoSans::createScaler);
}
 
源代码13 项目: tutorials   文件: AnnotationTestExampleUnitTest.java
@Test
@Disabled
public void shouldFailBecauseTimeout() throws InterruptedException {
    Assertions.assertTimeout(Duration.ofMillis(1), () -> Thread.sleep(10));
}
 
源代码14 项目: tutorials   文件: AnnotationTestExampleUnitTest.java
@Test
@Disabled
public void shouldFailBecauseTimeout() throws InterruptedException {
    Assertions.assertTimeout(Duration.ofMillis(1), () -> Thread.sleep(10));
}