From 58e7e33ea3d0b2841c610fdf218da0d0fcc53f3a Mon Sep 17 00:00:00 2001 From: NthPortal Date: Wed, 21 Feb 2018 22:24:51 -0500 Subject: Remove uses of deprecated Future APIs --- .../scala/async/run/anf/AnfTransformSpec.scala | 4 +- .../scala/scala/async/run/await0/Await0Spec.scala | 12 ++--- .../scala/scala/async/run/block0/AsyncSpec.scala | 4 +- src/test/scala/scala/async/run/block1/block1.scala | 4 +- .../async/run/exceptions/ExceptionsSpec.scala | 12 ++--- .../scala/scala/async/run/futures/FutureSpec.scala | 55 +++++++++++++--------- .../scala/scala/async/run/ifelse0/IfElse0.scala | 4 +- .../scala/scala/async/run/ifelse1/IfElse1.scala | 4 +- .../scala/scala/async/run/ifelse2/ifelse2.scala | 4 +- .../scala/scala/async/run/ifelse3/IfElse3.scala | 4 +- .../scala/scala/async/run/ifelse4/IfElse4.scala | 2 +- src/test/scala/scala/async/run/match0/Match0.scala | 4 +- .../scala/async/run/toughtype/ToughType.scala | 10 ++-- 13 files changed, 66 insertions(+), 57 deletions(-) diff --git a/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala b/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala index 0705f3e..661b6dc 100644 --- a/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala +++ b/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala @@ -7,7 +7,7 @@ package run package anf import language.{reflectiveCalls, postfixOps} -import scala.concurrent.{Future, ExecutionContext, future, Await} +import scala.concurrent.{Future, ExecutionContext, Await} import scala.concurrent.duration._ import scala.async.Async.{async, await} import org.junit.Test @@ -18,7 +18,7 @@ class AnfTestClass { import ExecutionContext.Implicits.global - def base(x: Int): Future[Int] = future { + def base(x: Int): Future[Int] = Future { x + 2 } diff --git a/src/test/scala/scala/async/run/await0/Await0Spec.scala b/src/test/scala/scala/async/run/await0/Await0Spec.scala index 7cc4095..e8190c7 100644 --- a/src/test/scala/scala/async/run/await0/Await0Spec.scala +++ b/src/test/scala/scala/async/run/await0/Await0Spec.scala @@ -12,7 +12,7 @@ package await0 import language.{reflectiveCalls, postfixOps} -import scala.concurrent.{Future, ExecutionContext, future, Await} +import scala.concurrent.{Future, ExecutionContext, Await} import scala.concurrent.duration._ import scala.async.Async.{async, await} import org.junit.Test @@ -21,23 +21,23 @@ class Await0Class { import ExecutionContext.Implicits.global - def m1(x: Double): Future[Double] = future { + def m1(x: Double): Future[Double] = Future { x + 2.0 } - def m2(x: Float): Future[Float] = future { + def m2(x: Float): Future[Float] = Future { x + 2.0f } - def m3(x: Char): Future[Char] = future { + def m3(x: Char): Future[Char] = Future { (x.toInt + 2).toChar } - def m4(x: Short): Future[Short] = future { + def m4(x: Short): Future[Short] = Future { (x + 2).toShort } - def m5(x: Byte): Future[Byte] = future { + def m5(x: Byte): Future[Byte] = Future { (x + 2).toByte } diff --git a/src/test/scala/scala/async/run/block0/AsyncSpec.scala b/src/test/scala/scala/async/run/block0/AsyncSpec.scala index a12b23f..c5f759c 100644 --- a/src/test/scala/scala/async/run/block0/AsyncSpec.scala +++ b/src/test/scala/scala/async/run/block0/AsyncSpec.scala @@ -7,7 +7,7 @@ package run package block0 import language.{reflectiveCalls, postfixOps} -import scala.concurrent.{Future, ExecutionContext, future, Await} +import scala.concurrent.{Future, ExecutionContext, Await} import scala.concurrent.duration._ import scala.async.Async.{async, await} import org.junit.Test @@ -17,7 +17,7 @@ class Test1Class { import ExecutionContext.Implicits.global - def m1(x: Int): Future[Int] = future { + def m1(x: Int): Future[Int] = Future { x + 2 } diff --git a/src/test/scala/scala/async/run/block1/block1.scala b/src/test/scala/scala/async/run/block1/block1.scala index 5300168..7cef8ef 100644 --- a/src/test/scala/scala/async/run/block1/block1.scala +++ b/src/test/scala/scala/async/run/block1/block1.scala @@ -7,7 +7,7 @@ package run package block1 import language.{reflectiveCalls, postfixOps} -import scala.concurrent.{Future, ExecutionContext, future, Await} +import scala.concurrent.{Future, ExecutionContext, Await} import scala.concurrent.duration._ import scala.async.Async.{async, await} import org.junit.Test @@ -17,7 +17,7 @@ class Test1Class { import ExecutionContext.Implicits.global - def m1(x: Int): Future[Int] = future { + def m1(x: Int): Future[Int] = Future { x + 2 } diff --git a/src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala b/src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala index d66c5ed..649543f 100644 --- a/src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala +++ b/src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala @@ -8,7 +8,7 @@ package exceptions import scala.async.Async.{async, await} -import scala.concurrent.{future, ExecutionContext, Await} +import scala.concurrent.{Future, ExecutionContext, Await} import ExecutionContext.Implicits._ import scala.concurrent.duration._ import scala.reflect.ClassTag @@ -25,7 +25,7 @@ class ExceptionsSpec { @Test def `uncaught exception within async after await`() { - val base = future { "five!".length } + val base = Future { "five!".length } val fut = async { val len = await(base) throw new Exception(s"illegal length: $len") @@ -35,7 +35,7 @@ class ExceptionsSpec { @Test def `await failing future within async`() { - val base = future[Int] { throw new Exception("problem") } + val base = Future[Int] { throw new Exception("problem") } val fut = async { val x = await(base) x * 2 @@ -45,11 +45,11 @@ class ExceptionsSpec { @Test def `await failing future within async after await`() { - val base = future[Any] { "five!".length } + val base = Future[Any] { "five!".length } val fut = async { val a = await(base.mapTo[Int]) // result: 5 - val b = await((future { (a * 2).toString }).mapTo[Int]) // result: ClassCastException - val c = await(future { (7 * 2).toString }) // result: "14" + val b = await((Future { (a * 2).toString }).mapTo[Int]) // result: ClassCastException + val c = await(Future { (7 * 2).toString }) // result: "14" b + "-" + c } intercept[ClassCastException] { Await.result(fut, 2.seconds) } diff --git a/src/test/scala/scala/async/run/futures/FutureSpec.scala b/src/test/scala/scala/async/run/futures/FutureSpec.scala index 34c8a21..3f3f726 100644 --- a/src/test/scala/scala/async/run/futures/FutureSpec.scala +++ b/src/test/scala/scala/async/run/futures/FutureSpec.scala @@ -24,7 +24,7 @@ class FutureSpec { /* some utils */ def testAsync(s: String)(implicit ec: ExecutionContext): Future[String] = s match { - case "Hello" => future { "World" } + case "Hello" => Future { "World" } case "Failure" => Future.failed(new RuntimeException("Expected exception; to test fault-tolerance")) case "NoReply" => Promise[String]().future } @@ -42,7 +42,7 @@ class FutureSpec { class ThrowableTest(m: String) extends Throwable(m) - val f1 = future[Any] { + val f1 = Future[Any] { throw new ThrowableTest("test") } @@ -51,7 +51,7 @@ class FutureSpec { } val latch = new TestLatch - val f2 = future { + val f2 = Future { Await.ready(latch, 5 seconds) "success" } @@ -72,7 +72,7 @@ class FutureSpec { Await.result(f3, defaultTimeout) mustBe ("SUCCESS") - val waiting = future { + val waiting = Future { Thread.sleep(1000) } Await.ready(waiting, 2000 millis) @@ -86,8 +86,8 @@ class FutureSpec { @Test def `A future with global ExecutionContext should compose with for-comprehensions`() { import scala.reflect.ClassTag - def asyncInt(x: Int) = future { (x * 2).toString } - val future0 = future[Any] { + def asyncInt(x: Int) = Future { (x * 2).toString } + val future0 = Future[Any] { "five!".length } @@ -100,8 +100,8 @@ class FutureSpec { val future2 = async { val a = await(future0.mapTo[Int]) - val b = await((future { (a * 2).toString }).mapTo[Int]) - val c = await(future { (7 * 2).toString }) + val b = await((Future { (a * 2).toString }).mapTo[Int]) + val c = await(Future { (7 * 2).toString }) b + "-" + c } @@ -115,8 +115,8 @@ class FutureSpec { case class Req[T](req: T) case class Res[T](res: T) def asyncReq[T](req: Req[T]) = req match { - case Req(s: String) => future { Res(s.length) } - case Req(i: Int) => future { Res((i * 2).toString) } + case Req(s: String) => Future { Res(s.length) } + case Req(i: Int) => Future { Res((i * 2).toString) } } val future1 = for { @@ -217,7 +217,7 @@ class FutureSpec { @Test def `andThen like a boss`() { val q = new java.util.concurrent.LinkedBlockingQueue[Int] for (i <- 1 to 1000) { - val chained = future { + val chained = Future { q.add(1); 3 } andThen { case _ => q.add(2) @@ -244,7 +244,7 @@ class FutureSpec { } @Test def `find`() { - val futures = for (i <- 1 to 10) yield future { + val futures = for (i <- 1 to 10) yield Future { i } @@ -279,7 +279,7 @@ class FutureSpec { @Test def `fold`() { val timeout = 10000 millis - def async(add: Int, wait: Int) = future { + def async(add: Int, wait: Int) = Future { Thread.sleep(wait) add } @@ -287,19 +287,21 @@ class FutureSpec { val futures = (0 to 9) map { idx => async(idx, idx * 20) } + // TODO: change to `foldLeft` after support for 2.11 is dropped val folded = Future.fold(futures)(0)(_ + _) Await.result(folded, timeout) mustBe (45) val futuresit = (0 to 9) map { idx => async(idx, idx * 20) } + // TODO: change to `foldLeft` after support for 2.11 is dropped val foldedit = Future.fold(futures)(0)(_ + _) Await.result(foldedit, timeout) mustBe (45) } @Test def `fold by composing`() { val timeout = 10000 millis - def async(add: Int, wait: Int) = future { + def async(add: Int, wait: Int) = Future { Thread.sleep(wait) add } @@ -314,7 +316,7 @@ class FutureSpec { @Test def `fold with an exception`() { val timeout = 10000 millis - def async(add: Int, wait: Int) = future { + def async(add: Int, wait: Int) = Future { Thread.sleep(wait) if (add == 6) throw new IllegalArgumentException("shouldFoldResultsWithException: expected") add @@ -322,6 +324,7 @@ class FutureSpec { def futures = (0 to 9) map { idx => async(idx, idx * 10) } + // TODO: change to `foldLeft` after support for 2.11 is dropped val folded = Future.fold(futures)(0)(_ + _) intercept[IllegalArgumentException] { Await.result(folded, timeout) @@ -332,6 +335,7 @@ class FutureSpec { import scala.collection.mutable.ArrayBuffer def test(testNumber: Int) { val fs = (0 to 1000) map (i => Future(i)) + // TODO: change to `foldLeft` after support for 2.11 is dropped val f = Future.fold(fs)(ArrayBuffer.empty[AnyRef]) { case (l, i) if i % 2 == 0 => l += i.asInstanceOf[AnyRef] case (l, _) => l @@ -345,28 +349,31 @@ class FutureSpec { } @Test def `return zero value if folding empty list`() { + // TODO: change to `foldLeft` after support for 2.11 is dropped val zero = Future.fold(List[Future[Int]]())(0)(_ + _) Await.result(zero, defaultTimeout) mustBe (0) } @Test def `shouldReduceResults`() { - def async(idx: Int) = future { + def async(idx: Int) = Future { Thread.sleep(idx * 20) idx } val timeout = 10000 millis val futures = (0 to 9) map { async } + // TODO: change to `reduceLeft` after support for 2.11 is dropped val reduced = Future.reduce(futures)(_ + _) Await.result(reduced, timeout) mustBe (45) val futuresit = (0 to 9) map { async } + // TODO: change to `reduceLeft` after support for 2.11 is dropped val reducedit = Future.reduce(futuresit)(_ + _) Await.result(reducedit, timeout) mustBe (45) } @Test def `shouldReduceResultsWithException`() { - def async(add: Int, wait: Int) = future { + def async(add: Int, wait: Int) = Future { Thread.sleep(wait) if (add == 6) throw new IllegalArgumentException("shouldFoldResultsWithException: expected") else add @@ -375,6 +382,7 @@ class FutureSpec { def futures = (1 to 10) map { idx => async(idx, idx * 10) } + // TODO: change to `reduceLeft` after support for 2.11 is dropped val failed = Future.reduce(futures)(_ + _) intercept[IllegalArgumentException] { Await.result(failed, timeout) @@ -383,6 +391,7 @@ class FutureSpec { @Test def `shouldReduceThrowNSEEOnEmptyInput`() { intercept[java.util.NoSuchElementException] { + // TODO: change to `reduceLeft` after support for 2.11 is dropped val emptyreduced = Future.reduce(List[Future[Int]]())(_ + _) Await.result(emptyreduced, defaultTimeout) } @@ -397,7 +406,7 @@ class FutureSpec { } } - val oddFutures = List.fill(100)(future { counter.incAndGet() }).iterator + val oddFutures = List.fill(100)(Future { counter.incAndGet() }).iterator val traversed = Future.sequence(oddFutures) Await.result(traversed, defaultTimeout).sum mustBe (10000) @@ -413,11 +422,11 @@ class FutureSpec { @Test def `shouldBlockUntilResult`() { val latch = new TestLatch - val f = future { + val f = Future { Await.ready(latch, 5 seconds) 5 } - val f2 = future { + val f2 = Future { val res = Await.result(f, Inf) res + 9 } @@ -430,7 +439,7 @@ class FutureSpec { Await.result(f2, defaultTimeout) mustBe (14) - val f3 = future { + val f3 = Future { Thread.sleep(100) 5 } @@ -443,7 +452,7 @@ class FutureSpec { @Test def `run callbacks async`() { val latch = Vector.fill(10)(new TestLatch) - val f1 = future { + val f1 = Future { latch(0).open() Await.ready(latch(1), TestLatch.DefaultTimeout) "Hello" @@ -535,7 +544,7 @@ class FutureSpec { @Test def `should not throw when Await.ready`() { val expected = try Success(5 / 0) catch { case a: ArithmeticException => Failure(a) } - val f = async { await(future(5)) / 0 } + val f = async { await(Future(5)) / 0 } Await.ready(f, defaultTimeout).value.get.toString mustBe expected.toString } } diff --git a/src/test/scala/scala/async/run/ifelse0/IfElse0.scala b/src/test/scala/scala/async/run/ifelse0/IfElse0.scala index 922c462..62e1970 100644 --- a/src/test/scala/scala/async/run/ifelse0/IfElse0.scala +++ b/src/test/scala/scala/async/run/ifelse0/IfElse0.scala @@ -7,7 +7,7 @@ package run package ifelse0 import language.{reflectiveCalls, postfixOps} -import scala.concurrent.{Future, ExecutionContext, future, Await} +import scala.concurrent.{Future, ExecutionContext, Await} import scala.concurrent.duration._ import scala.async.Async.{async, await} import org.junit.Test @@ -18,7 +18,7 @@ class TestIfElseClass { import ExecutionContext.Implicits.global - def m1(x: Int): Future[Int] = future { + def m1(x: Int): Future[Int] = Future { x + 2 } diff --git a/src/test/scala/scala/async/run/ifelse1/IfElse1.scala b/src/test/scala/scala/async/run/ifelse1/IfElse1.scala index 46fb57d..855f767 100644 --- a/src/test/scala/scala/async/run/ifelse1/IfElse1.scala +++ b/src/test/scala/scala/async/run/ifelse1/IfElse1.scala @@ -7,7 +7,7 @@ package run package ifelse1 import language.{reflectiveCalls, postfixOps} -import scala.concurrent.{Future, ExecutionContext, future, Await} +import scala.concurrent.{Future, ExecutionContext, Await} import scala.concurrent.duration._ import scala.async.Async.{async, await} import org.junit.Test @@ -17,7 +17,7 @@ class TestIfElse1Class { import ExecutionContext.Implicits.global - def base(x: Int): Future[Int] = future { + def base(x: Int): Future[Int] = Future { x + 2 } diff --git a/src/test/scala/scala/async/run/ifelse2/ifelse2.scala b/src/test/scala/scala/async/run/ifelse2/ifelse2.scala index c998024..19035ef 100644 --- a/src/test/scala/scala/async/run/ifelse2/ifelse2.scala +++ b/src/test/scala/scala/async/run/ifelse2/ifelse2.scala @@ -7,7 +7,7 @@ package run package ifelse2 import language.{reflectiveCalls, postfixOps} -import scala.concurrent.{Future, ExecutionContext, future, Await} +import scala.concurrent.{Future, ExecutionContext, Await} import scala.concurrent.duration._ import scala.async.Async.{async, await} import org.junit.Test @@ -17,7 +17,7 @@ class TestIfElse2Class { import ExecutionContext.Implicits.global - def base(x: Int): Future[Int] = future { + def base(x: Int): Future[Int] = Future { x + 2 } diff --git a/src/test/scala/scala/async/run/ifelse3/IfElse3.scala b/src/test/scala/scala/async/run/ifelse3/IfElse3.scala index bbae55c..2f9ae1c 100644 --- a/src/test/scala/scala/async/run/ifelse3/IfElse3.scala +++ b/src/test/scala/scala/async/run/ifelse3/IfElse3.scala @@ -7,7 +7,7 @@ package run package ifelse3 import language.{reflectiveCalls, postfixOps} -import scala.concurrent.{Future, ExecutionContext, future, Await} +import scala.concurrent.{Future, ExecutionContext, Await} import scala.concurrent.duration._ import scala.async.Async.{async, await} import org.junit.Test @@ -17,7 +17,7 @@ class TestIfElse3Class { import ExecutionContext.Implicits.global - def base(x: Int): Future[Int] = future { + def base(x: Int): Future[Int] = Future { x + 2 } diff --git a/src/test/scala/scala/async/run/ifelse4/IfElse4.scala b/src/test/scala/scala/async/run/ifelse4/IfElse4.scala index 6a98ff4..96fc14c 100644 --- a/src/test/scala/scala/async/run/ifelse4/IfElse4.scala +++ b/src/test/scala/scala/async/run/ifelse4/IfElse4.scala @@ -7,7 +7,7 @@ package run package ifelse4 import language.{reflectiveCalls, postfixOps} -import scala.concurrent.{Future, ExecutionContext, future, Await} +import scala.concurrent.{Future, ExecutionContext, Await} import scala.concurrent.duration._ import scala.async.Async.{async, await} import org.junit.Test diff --git a/src/test/scala/scala/async/run/match0/Match0.scala b/src/test/scala/scala/async/run/match0/Match0.scala index 7c553c6..824391f 100644 --- a/src/test/scala/scala/async/run/match0/Match0.scala +++ b/src/test/scala/scala/async/run/match0/Match0.scala @@ -7,7 +7,7 @@ package run package match0 import language.{reflectiveCalls, postfixOps} -import scala.concurrent.{Future, ExecutionContext, future, Await} +import scala.concurrent.{Future, ExecutionContext, Await} import scala.concurrent.duration._ import scala.async.Async.{async, await} import org.junit.Test @@ -18,7 +18,7 @@ class TestMatchClass { import ExecutionContext.Implicits.global - def m1(x: Int): Future[Int] = future { + def m1(x: Int): Future[Int] = Future { x + 2 } diff --git a/src/test/scala/scala/async/run/toughtype/ToughType.scala b/src/test/scala/scala/async/run/toughtype/ToughType.scala index 2bf912b..50c6300 100644 --- a/src/test/scala/scala/async/run/toughtype/ToughType.scala +++ b/src/test/scala/scala/async/run/toughtype/ToughType.scala @@ -21,8 +21,8 @@ object ToughTypeObject { class Inner def m2 = async[(List[_], ToughTypeObject.Inner)] { - val y = await(future[List[_]](Nil)) - val z = await(future[Inner](new Inner)) + val y = await(Future[List[_]](Nil)) + val z = await(Future[Inner](new Inner)) (y, z) } } @@ -86,11 +86,11 @@ class ToughTypeSpec { def m3 = async { val p: List[Option[_]] = conjure[List[Option[_]]] - await(future(1)) + await(Future(1)) } def m4 = async { - await(future[List[_]](Nil)) + await(Future[List[_]](Nil)) } } @@ -153,7 +153,7 @@ class ToughTypeSpec { // Turns out the behaviour stems from `thisMethodType` in `Namers`, which treats type parameter skolem symbols. @Test def nestedMethodWithInconsistencyTreeAndInfoParamSymbols() { import language.{reflectiveCalls, postfixOps} - import scala.concurrent.{Future, ExecutionContext, future, Await} + import scala.concurrent.{Future, ExecutionContext, Await} import scala.concurrent.duration._ import scala.async.Async.{async, await} import scala.async.internal.AsyncId -- cgit v1.2.3