Java Code Examples for org.junit.jupiter.api.Assertions#assertTimeout()

The following examples show how to use org.junit.jupiter.api.Assertions#assertTimeout() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NugetInspectorParserPerfTest.java    From synopsys-detect with Apache License 2.0 6 votes vote down vote up
@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());
    });
}
 
Example 2
Source File: DelayTest.java    From cloudformation-cli-java-plugin with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 3
Source File: DaemonShutdownHookTest.java    From robozonky with Apache License 2.0 6 votes vote down vote up
@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();
    });
}
 
Example 4
Source File: AutoExpandingMapTest.java    From rapidoid with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 5
Source File: ResTest.java    From rapidoid with Apache License 2.0 6 votes vote down vote up
@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());
		});
	});
}
 
Example 6
Source File: NugetInspectorParserTest.java    From synopsys-detect with Apache License 2.0 5 votes vote down vote up
@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());
        }
    });
}
 
Example 7
Source File: RandomSourceFunctionTest.java    From flink-prometheus-example with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 8
Source File: EventsTest.java    From rapidoid with Apache License 2.0 5 votes vote down vote up
@Test
public void firingUnusedEventsMustBeFast() {
	Assertions.assertTimeout(Duration.ofSeconds(1), () -> {
		for (int i = 0; i < 100 * 1000 * 1000; i++) {
			Fire.event(Events.LOG_TRACE);
		}
	});
}
 
Example 9
Source File: JobsTest.java    From rapidoid with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 10
Source File: MultiWatchTest.java    From rapidoid with Apache License 2.0 5 votes vote down vote up
@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);
			}
		}
	});
}
 
Example 11
Source File: TesterExceptionTests.java    From Spring with Apache License 2.0 4 votes vote down vote up
@Test
public void timeout() {
    Assertions.assertTimeout(Duration.ofMillis(10), () -> Thread.sleep(5));
}
 
Example 12
Source File: NotoSansTest.java    From java-9-wtf with Apache License 2.0 4 votes vote down vote up
@Test
void createNotoSansScaler() throws Exception {
	Assertions.assertTimeout(
			Duration.of(250, ChronoUnit.MILLIS),
			NotoSans::createScaler);
}
 
Example 13
Source File: AnnotationTestExampleUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
@Disabled
public void shouldFailBecauseTimeout() throws InterruptedException {
    Assertions.assertTimeout(Duration.ofMillis(1), () -> Thread.sleep(10));
}
 
Example 14
Source File: AnnotationTestExampleUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
@Disabled
public void shouldFailBecauseTimeout() throws InterruptedException {
    Assertions.assertTimeout(Duration.ofMillis(1), () -> Thread.sleep(10));
}