@@ -24,7 +24,7 @@ class FutureSpec {
24
24
/* some utils */
25
25
26
26
def testAsync (s : String )(implicit ec : ExecutionContext ): Future [String ] = s match {
27
- case " Hello" => future { " World" }
27
+ case " Hello" => Future { " World" }
28
28
case " Failure" => Future .failed(new RuntimeException (" Expected exception; to test fault-tolerance" ))
29
29
case " NoReply" => Promise [String ]().future
30
30
}
@@ -42,7 +42,7 @@ class FutureSpec {
42
42
43
43
class ThrowableTest (m : String ) extends Throwable (m)
44
44
45
- val f1 = future [Any ] {
45
+ val f1 = Future [Any ] {
46
46
throw new ThrowableTest (" test" )
47
47
}
48
48
@@ -51,7 +51,7 @@ class FutureSpec {
51
51
}
52
52
53
53
val latch = new TestLatch
54
- val f2 = future {
54
+ val f2 = Future {
55
55
Await .ready(latch, 5 seconds)
56
56
" success"
57
57
}
@@ -72,7 +72,7 @@ class FutureSpec {
72
72
73
73
Await .result(f3, defaultTimeout) mustBe (" SUCCESS" )
74
74
75
- val waiting = future {
75
+ val waiting = Future {
76
76
Thread .sleep(1000 )
77
77
}
78
78
Await .ready(waiting, 2000 millis)
@@ -86,8 +86,8 @@ class FutureSpec {
86
86
@ Test def `A future with global ExecutionContext should compose with for-comprehensions` () {
87
87
import scala .reflect .ClassTag
88
88
89
- def asyncInt (x : Int ) = future { (x * 2 ).toString }
90
- val future0 = future [Any ] {
89
+ def asyncInt (x : Int ) = Future { (x * 2 ).toString }
90
+ val future0 = Future [Any ] {
91
91
" five!" .length
92
92
}
93
93
@@ -100,8 +100,8 @@ class FutureSpec {
100
100
101
101
val future2 = async {
102
102
val a = await(future0.mapTo[Int ])
103
- val b = await((future { (a * 2 ).toString }).mapTo[Int ])
104
- val c = await(future { (7 * 2 ).toString })
103
+ val b = await((Future { (a * 2 ).toString }).mapTo[Int ])
104
+ val c = await(Future { (7 * 2 ).toString })
105
105
b + " -" + c
106
106
}
107
107
@@ -115,8 +115,8 @@ class FutureSpec {
115
115
case class Req [T ](req : T )
116
116
case class Res [T ](res : T )
117
117
def asyncReq [T ](req : Req [T ]) = req match {
118
- case Req (s : String ) => future { Res (s.length) }
119
- case Req (i : Int ) => future { Res ((i * 2 ).toString) }
118
+ case Req (s : String ) => Future { Res (s.length) }
119
+ case Req (i : Int ) => Future { Res ((i * 2 ).toString) }
120
120
}
121
121
122
122
val future1 = for {
@@ -217,7 +217,7 @@ class FutureSpec {
217
217
@ Test def `andThen like a boss` () {
218
218
val q = new java.util.concurrent.LinkedBlockingQueue [Int ]
219
219
for (i <- 1 to 1000 ) {
220
- val chained = future {
220
+ val chained = Future {
221
221
q.add(1 ); 3
222
222
} andThen {
223
223
case _ => q.add(2 )
@@ -244,7 +244,7 @@ class FutureSpec {
244
244
}
245
245
246
246
@ Test def `find` () {
247
- val futures = for (i <- 1 to 10 ) yield future {
247
+ val futures = for (i <- 1 to 10 ) yield Future {
248
248
i
249
249
}
250
250
@@ -279,27 +279,29 @@ class FutureSpec {
279
279
280
280
@ Test def `fold` () {
281
281
val timeout = 10000 millis
282
- def async (add : Int , wait : Int ) = future {
282
+ def async (add : Int , wait : Int ) = Future {
283
283
Thread .sleep(wait)
284
284
add
285
285
}
286
286
287
287
val futures = (0 to 9 ) map {
288
288
idx => async(idx, idx * 20 )
289
289
}
290
+ // TODO: change to `foldLeft` after support for 2.11 is dropped
290
291
val folded = Future .fold(futures)(0 )(_ + _)
291
292
Await .result(folded, timeout) mustBe (45 )
292
293
293
294
val futuresit = (0 to 9 ) map {
294
295
idx => async(idx, idx * 20 )
295
296
}
297
+ // TODO: change to `foldLeft` after support for 2.11 is dropped
296
298
val foldedit = Future .fold(futures)(0 )(_ + _)
297
299
Await .result(foldedit, timeout) mustBe (45 )
298
300
}
299
301
300
302
@ Test def `fold by composing` () {
301
303
val timeout = 10000 millis
302
- def async (add : Int , wait : Int ) = future {
304
+ def async (add : Int , wait : Int ) = Future {
303
305
Thread .sleep(wait)
304
306
add
305
307
}
@@ -314,14 +316,15 @@ class FutureSpec {
314
316
315
317
@ Test def `fold with an exception` () {
316
318
val timeout = 10000 millis
317
- def async (add : Int , wait : Int ) = future {
319
+ def async (add : Int , wait : Int ) = Future {
318
320
Thread .sleep(wait)
319
321
if (add == 6 ) throw new IllegalArgumentException (" shouldFoldResultsWithException: expected" )
320
322
add
321
323
}
322
324
def futures = (0 to 9 ) map {
323
325
idx => async(idx, idx * 10 )
324
326
}
327
+ // TODO: change to `foldLeft` after support for 2.11 is dropped
325
328
val folded = Future .fold(futures)(0 )(_ + _)
326
329
intercept[IllegalArgumentException ] {
327
330
Await .result(folded, timeout)
@@ -332,6 +335,7 @@ class FutureSpec {
332
335
import scala .collection .mutable .ArrayBuffer
333
336
def test (testNumber : Int ) {
334
337
val fs = (0 to 1000 ) map (i => Future (i))
338
+ // TODO: change to `foldLeft` after support for 2.11 is dropped
335
339
val f = Future .fold(fs)(ArrayBuffer .empty[AnyRef ]) {
336
340
case (l, i) if i % 2 == 0 => l += i.asInstanceOf [AnyRef ]
337
341
case (l, _) => l
@@ -345,28 +349,31 @@ class FutureSpec {
345
349
}
346
350
347
351
@ Test def `return zero value if folding empty list` () {
352
+ // TODO: change to `foldLeft` after support for 2.11 is dropped
348
353
val zero = Future .fold(List [Future [Int ]]())(0 )(_ + _)
349
354
Await .result(zero, defaultTimeout) mustBe (0 )
350
355
}
351
356
352
357
@ Test def `shouldReduceResults` () {
353
- def async (idx : Int ) = future {
358
+ def async (idx : Int ) = Future {
354
359
Thread .sleep(idx * 20 )
355
360
idx
356
361
}
357
362
val timeout = 10000 millis
358
363
359
364
val futures = (0 to 9 ) map { async }
365
+ // TODO: change to `reduceLeft` after support for 2.11 is dropped
360
366
val reduced = Future .reduce(futures)(_ + _)
361
367
Await .result(reduced, timeout) mustBe (45 )
362
368
363
369
val futuresit = (0 to 9 ) map { async }
370
+ // TODO: change to `reduceLeft` after support for 2.11 is dropped
364
371
val reducedit = Future .reduce(futuresit)(_ + _)
365
372
Await .result(reducedit, timeout) mustBe (45 )
366
373
}
367
374
368
375
@ Test def `shouldReduceResultsWithException` () {
369
- def async (add : Int , wait : Int ) = future {
376
+ def async (add : Int , wait : Int ) = Future {
370
377
Thread .sleep(wait)
371
378
if (add == 6 ) throw new IllegalArgumentException (" shouldFoldResultsWithException: expected" )
372
379
else add
@@ -375,6 +382,7 @@ class FutureSpec {
375
382
def futures = (1 to 10 ) map {
376
383
idx => async(idx, idx * 10 )
377
384
}
385
+ // TODO: change to `reduceLeft` after support for 2.11 is dropped
378
386
val failed = Future .reduce(futures)(_ + _)
379
387
intercept[IllegalArgumentException ] {
380
388
Await .result(failed, timeout)
@@ -383,6 +391,7 @@ class FutureSpec {
383
391
384
392
@ Test def `shouldReduceThrowNSEEOnEmptyInput` () {
385
393
intercept[java.util.NoSuchElementException ] {
394
+ // TODO: change to `reduceLeft` after support for 2.11 is dropped
386
395
val emptyreduced = Future .reduce(List [Future [Int ]]())(_ + _)
387
396
Await .result(emptyreduced, defaultTimeout)
388
397
}
@@ -397,7 +406,7 @@ class FutureSpec {
397
406
}
398
407
}
399
408
400
- val oddFutures = List .fill(100 )(future { counter.incAndGet() }).iterator
409
+ val oddFutures = List .fill(100 )(Future { counter.incAndGet() }).iterator
401
410
val traversed = Future .sequence(oddFutures)
402
411
Await .result(traversed, defaultTimeout).sum mustBe (10000 )
403
412
@@ -413,11 +422,11 @@ class FutureSpec {
413
422
@ Test def `shouldBlockUntilResult` () {
414
423
val latch = new TestLatch
415
424
416
- val f = future {
425
+ val f = Future {
417
426
Await .ready(latch, 5 seconds)
418
427
5
419
428
}
420
- val f2 = future {
429
+ val f2 = Future {
421
430
val res = Await .result(f, Inf )
422
431
res + 9
423
432
}
@@ -430,7 +439,7 @@ class FutureSpec {
430
439
431
440
Await .result(f2, defaultTimeout) mustBe (14 )
432
441
433
- val f3 = future {
442
+ val f3 = Future {
434
443
Thread .sleep(100 )
435
444
5
436
445
}
@@ -443,7 +452,7 @@ class FutureSpec {
443
452
@ Test def `run callbacks async` () {
444
453
val latch = Vector .fill(10 )(new TestLatch )
445
454
446
- val f1 = future {
455
+ val f1 = Future {
447
456
latch(0 ).open()
448
457
Await .ready(latch(1 ), TestLatch .DefaultTimeout )
449
458
" Hello"
@@ -535,7 +544,7 @@ class FutureSpec {
535
544
536
545
@ Test def `should not throw when Await.ready` () {
537
546
val expected = try Success (5 / 0 ) catch { case a : ArithmeticException => Failure (a) }
538
- val f = async { await(future (5 )) / 0 }
547
+ val f = async { await(Future (5 )) / 0 }
539
548
Await .ready(f, defaultTimeout).value.get.toString mustBe expected.toString
540
549
}
541
550
}
0 commit comments