Created
June 19, 2015 18:55
-
-
Save FossiFoo/7de2231f24e7b0b5214e to your computer and use it in GitHub Desktop.
withTimeout does not fail task after timeout
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 java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.ScheduledExecutorService; | |
import java.util.concurrent.TimeUnit; | |
import org.testng.annotations.Test; | |
import com.linkedin.parseq.Engine; | |
import com.linkedin.parseq.EngineBuilder; | |
import com.linkedin.parseq.Task; | |
@Test | |
public class ParseqTest { | |
public static void testParallelTasks() throws InterruptedException { | |
final Task<Void> noReturn = Task.action( () -> { while ( true ) {} } ) | |
.withTimeout( 100, TimeUnit.MILLISECONDS ); | |
final int numCores = Runtime.getRuntime().availableProcessors(); | |
final ExecutorService taskScheduler = Executors.newFixedThreadPool(numCores + 1); | |
final ScheduledExecutorService timerScheduler = Executors.newSingleThreadScheduledExecutor(); | |
final Engine engine = new EngineBuilder() | |
.setTaskExecutor(taskScheduler) | |
.setTimerScheduler(timerScheduler) | |
.build(); | |
engine.run( noReturn ); | |
noReturn.await( ); | |
System.out.print( "will never reach: " + noReturn.get() ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment