Search in sources :

Example 1 with ThreadLeakLingering

use of com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering in project randomizedtesting by randomizedtesting.

the class Test011RunawayThreads method ExecutorServiceContextPropagation.

@ThreadLeakLingering(linger = 2000)
@Test
public void ExecutorServiceContextPropagation() throws Throwable {
    final long seed = Utils.getRunnerSeed();
    final ExecutorService executor = Executors.newCachedThreadPool();
    try {
        executor.submit(new Runnable() {

            public void run() {
                RandomizedContext ctx = RandomizedContext.current();
                Assert.assertEquals(seed, Utils.getSeed(ctx.getRandomness()));
            }
        }).get();
    } catch (ExecutionException e) {
        throw e.getCause();
    } finally {
        executor.shutdown();
        executor.awaitTermination(1, TimeUnit.SECONDS);
    }
}
Also used : RandomizedContext(com.carrotsearch.randomizedtesting.RandomizedContext) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest) ThreadLeakLingering(com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering)

Aggregations

RandomizedContext (com.carrotsearch.randomizedtesting.RandomizedContext)1 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)1 ThreadLeakLingering (com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering)1 Test (org.junit.Test)1