Created
February 16, 2017 20:47
-
-
Save ivportilla/3da524e934a69156499037b7aef0bc97 to your computer and use it in GitHub Desktop.
Blocking future test
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
test("blocking in Future") { | |
var threadsBlock: mutable.Set[String] = scala.collection.mutable.Set() | |
var threads: mutable.Set[String] = scala.collection.mutable.Set() | |
def currentThread = Thread.currentThread().getName | |
/*def nonBlockingFuture = Future{ | |
threads += currentThread | |
Thread.sleep(1000) | |
}*/ | |
def blockingFuture = Future{ | |
blocking { | |
threadsBlock += currentThread | |
Thread.sleep(1000) | |
} | |
} | |
/*val futures = (1 to 20).map(_ => nonBlockingFuture) | |
val resolvedFutures = Future.sequence(futures) | |
Await.ready(resolvedFutures, Duration.Inf)*/ | |
val futuresBlock = (1 to 20).map(_ => blockingFuture) | |
val resolvedFuturesBlock = Future.sequence(futuresBlock) | |
Await.ready(resolvedFuturesBlock, Duration.Inf) | |
println(threadsBlock.size) | |
assert(threadsBlock.size > threads.size) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment