Last active
June 16, 2016 22:32
-
-
Save ywelsch/233ee4cb54e028feadbc2e5ed7e648dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.carrotsearch.randomizedtesting.RandomizedTest; | |
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; | |
import org.junit.AfterClass; | |
import org.junit.Assert; | |
import org.junit.BeforeClass; | |
import org.junit.Test; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
@ThreadLeakScope(ThreadLeakScope.Scope.SUITE) | |
public class ThreadTest extends RandomizedTest { | |
private static ExecutorService executor; | |
@BeforeClass | |
public static void startExecutorService() { | |
executor = Executors.newFixedThreadPool(1); | |
} | |
@AfterClass | |
public static void shutdownPool() throws InterruptedException { | |
executor.shutdown(); | |
executor = null; | |
} | |
@Test | |
public void testFoo() throws Exception { | |
System.out.println("Test thread foo is " + getRandom().nextInt()); | |
executor.submit(() -> System.out.println("Executor thread foo is " + getRandom().nextInt())).get(); | |
} | |
@Test | |
public void testBar() throws Exception { | |
System.out.println("Test thread bar is " + getRandom().nextInt()); | |
executor.submit(() -> System.out.println("Executor thread bar is " + getRandom().nextInt())).get(); | |
Assert.assertTrue(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment