This repository has been archived by the owner on Mar 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
202 additions
and
4 deletions.
There are no files selected for viewing
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
75 changes: 73 additions & 2 deletions
75
src/test/scala/reactor/core/scala/publisher/SParallelFluxTest.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,87 @@ | ||
package reactor.core.scala.publisher | ||
|
||
import org.mockito.Mockito.{spy, times, verify} | ||
import org.scalatest.{FreeSpec, Matchers} | ||
import reactor.core.publisher.{ParallelFlux => JParallelFlux, Flux => JFlux} | ||
import reactor.core.publisher.{Flux => JFlux, ParallelFlux => JParallelFlux} | ||
import reactor.core.scheduler.Schedulers | ||
import reactor.test.StepVerifier | ||
|
||
class SParallelFluxTest extends FreeSpec with Matchers { | ||
"SParallelFlux" - { | ||
val data = Seq(1, 2, 3) | ||
val flux = Flux.just(data.head, data.tail: _*) | ||
val fluxParallel: SParallelFlux[Int] = flux.parallel() | ||
".asJava should convert as Java ParallelFlux" in { | ||
Flux.just(1, 2, 3).parallel().asJava shouldBe a[JParallelFlux[Int]] | ||
fluxParallel.asJava shouldBe a[JParallelFlux[Int]] | ||
} | ||
|
||
".apply should convert Java ParallelFlux into SParallelFlux" in { | ||
SParallelFlux(JFlux.just(1, 2, 3).parallel()).asJava shouldBe a[JParallelFlux[Int]] | ||
} | ||
|
||
".filter should filter elements" in { | ||
StepVerifier.create(fluxParallel.filter((i: Int) => i % 2 == 0)) | ||
.expectNext(2) | ||
.verifyComplete() | ||
} | ||
|
||
".map should map from T to U" in { | ||
val expected = data.map(_.toString) | ||
StepVerifier.create(fluxParallel.map(i => i.toString)) | ||
.expectNextMatches((i: String) => expected.contains(i)) | ||
.expectNextMatches((i: String) => expected.contains(i)) | ||
.expectNextMatches((i: String) => expected.contains(i)) | ||
.verifyComplete() | ||
} | ||
|
||
".reduce should aggregate the values" - { | ||
"without initial supplier" in { | ||
val mono = fluxParallel.reduce(_ + _) | ||
StepVerifier.create(mono) | ||
.expectNext(6) | ||
.verifyComplete() | ||
} | ||
"with initial value should aggregate the values with initial one" ignore { | ||
val parallelFlux = fluxParallel.reduce[String](() => "0", (agg, v) => s"$agg-${v.toString}") | ||
StepVerifier.create(parallelFlux) | ||
.expectNext("0-1") | ||
.expectNext("0-2") | ||
.expectNext("0-3") | ||
.expectNext("0") | ||
.expectNext("0") | ||
.expectNext("0") | ||
.expectNext("0") | ||
.expectNext("0") | ||
.expectNext("0") | ||
.expectNext("0") | ||
.expectNext("0") | ||
.expectNext("0") | ||
.expectNext("0") | ||
.expectNext("0") | ||
.expectNext("0") | ||
.expectNext("0") | ||
.verifyComplete() | ||
} | ||
} | ||
|
||
".sequential should merge the rails" in { | ||
val expected = data.map(_.toString) | ||
StepVerifier.create(fluxParallel.map(i => i.toString).sequential()) | ||
.expectNextMatches((i: String) => expected.contains(i)) | ||
.expectNextMatches((i: String) => expected.contains(i)) | ||
.expectNextMatches((i: String) => expected.contains(i)) | ||
.verifyComplete() | ||
} | ||
|
||
".runOn should run on different thread" in { | ||
val scheduler = spy(Schedulers.parallel()) | ||
StepVerifier.create(flux.parallel(2).runOn(scheduler)) | ||
.expectNextMatches((i: Int) => data.contains(i)) | ||
.expectNextMatches((i: Int) => data.contains(i)) | ||
.expectNextMatches((i: Int) => data.contains(i)) | ||
.verifyComplete() | ||
|
||
verify(scheduler, times(2)).createWorker() | ||
} | ||
} | ||
} |