diff options
author | Adriaan Moors <adriaan@lightbend.com> | 2016-05-23 16:33:31 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan@lightbend.com> | 2016-05-23 16:33:31 -0700 |
commit | 095295a89a1fb1c3eb27d581662ed1a2fba5d2c5 (patch) | |
tree | b51a9f5710fcfb1f86eccdc0713c41ff738e57ec /test | |
parent | d169d48a31a38749328be195855e175eeaf5b454 (diff) | |
parent | 481a39010f63ccc5811c1d532eb510fd07e265a8 (diff) | |
download | scala-095295a89a1fb1c3eb27d581662ed1a2fba5d2c5.tar.gz scala-095295a89a1fb1c3eb27d581662ed1a2fba5d2c5.tar.bz2 scala-095295a89a1fb1c3eb27d581662ed1a2fba5d2c5.zip |
Merge pull request #5164 from viktorklang/wip-future-docs-√
Improve Future documentation (+ minor code cleanups)
Diffstat (limited to 'test')
-rw-r--r-- | test/files/jvm/scala-concurrent-tck.check | 2 | ||||
-rw-r--r-- | test/files/jvm/scala-concurrent-tck.scala | 31 |
2 files changed, 32 insertions, 1 deletions
diff --git a/test/files/jvm/scala-concurrent-tck.check b/test/files/jvm/scala-concurrent-tck.check index 9aef07d1e5..8aec46e5d6 100644 --- a/test/files/jvm/scala-concurrent-tck.check +++ b/test/files/jvm/scala-concurrent-tck.check @@ -1 +1 @@ -warning: there were 73 deprecation warnings; re-run with -deprecation for details +warning: there were 75 deprecation warnings; re-run with -deprecation for details diff --git a/test/files/jvm/scala-concurrent-tck.scala b/test/files/jvm/scala-concurrent-tck.scala index 8069028cf5..7197c1d853 100644 --- a/test/files/jvm/scala-concurrent-tck.scala +++ b/test/files/jvm/scala-concurrent-tck.scala @@ -90,6 +90,25 @@ trait FutureCallbacks extends TestBase { promise.success(-1) } + def stressTestNumberofCallbacks(): Unit = once { + done => + val promise = Promise[Unit] + val otherPromise = Promise[Unit] + def attachMeaninglessCallbacksTo(f: Future[Any]): Unit = (1 to 1000).foreach(_ => f.onComplete(_ => ())) + attachMeaninglessCallbacksTo(promise.future) + val future = promise.future.flatMap { _ => + attachMeaninglessCallbacksTo(otherPromise.future) + otherPromise.future + } + val numbers = new java.util.concurrent.ConcurrentHashMap[Int, Unit]() + (0 to 10000) foreach { x => numbers.put(x, ()) } + Future.sequence((0 to 10000) map { x => future.andThen({ case _ => numbers.remove(x) }) }) onComplete { + _ => done(numbers.isEmpty) + } + promise.success(()) + otherPromise.success(()) + } + testOnSuccess() testOnSuccessWhenCompleted() testOnSuccessWhenFailed() @@ -100,6 +119,7 @@ trait FutureCallbacks extends TestBase { //testOnFailureWhenSpecialThrowable(7, new InterruptedException) testThatNestedCallbacksDoNotYieldStackOverflow() testOnFailureWhenTimeoutException() + stressTestNumberofCallbacks() } @@ -283,6 +303,16 @@ def testTransformFailure(): Unit = once { g onFailure { case t => done(t.getMessage() == "expected") } } + def testFlatMapDelayed(): Unit = once { + done => + val f = Future { 5 } + val p = Promise[Int] + val g = f flatMap { _ => p.future } + g onSuccess { case x => done(x == 10) } + g onFailure { case _ => done(false) } + p.success(10) + } + def testFilterSuccess(): Unit = once { done => val f = Future { 4 } @@ -458,6 +488,7 @@ def testTransformFailure(): Unit = once { testMapFailure() testFlatMapSuccess() testFlatMapFailure() + testFlatMapDelayed() testFilterSuccess() testFilterFailure() testCollectSuccess() |