!str #15977 Rename and change types in the new DSL

* Cleaned up type signatures
* Changed names of Source/Sink/ProcessorFlow to Tap/Drain/Pipe
* Introduced new Source/Sink/Flow
* Made all Pipe types package private
* Changed the TypeGraph DSL to work on Flow/Sink/Source
This commit is contained in:
Björn Antonsson 2014-10-02 17:32:08 +02:00
parent afa1a6fd44
commit a6ab82f992
63 changed files with 1858 additions and 1675 deletions

View file

@ -25,17 +25,17 @@ class FlowGraphCompileSpec extends AkkaSpec {
}
}
val f1 = FlowFrom[String].transform("f1", op[String, String])
val f2 = FlowFrom[String].transform("f2", op[String, String])
val f3 = FlowFrom[String].transform("f3", op[String, String])
val f4 = FlowFrom[String].transform("f4", op[String, String])
val f5 = FlowFrom[String].transform("f5", op[String, String])
val f6 = FlowFrom[String].transform("f6", op[String, String])
val f1 = Flow[String].transform("f1", op[String, String])
val f2 = Flow[String].transform("f2", op[String, String])
val f3 = Flow[String].transform("f3", op[String, String])
val f4 = Flow[String].transform("f4", op[String, String])
val f5 = Flow[String].transform("f5", op[String, String])
val f6 = Flow[String].transform("f6", op[String, String])
val in1 = IterableSource(List("a", "b", "c"))
val in2 = IterableSource(List("d", "e", "f"))
val out1 = PublisherSink[String]
val out2 = FutureSink[String]
val in1 = IterableTap(List("a", "b", "c"))
val in2 = IterableTap(List("d", "e", "f"))
val out1 = PublisherDrain[String]
val out2 = FutureDrain[String]
"FlowGraph" should {
"build simple merge" in {
@ -97,7 +97,7 @@ class FlowGraphCompileSpec extends AkkaSpec {
val merge = Merge[String]
val bcast1 = Broadcast[String]
val bcast2 = Broadcast[String]
val feedbackLoopBuffer = FlowFrom[String].buffer(10, OverflowStrategy.dropBuffer)
val feedbackLoopBuffer = Flow[String].buffer(10, OverflowStrategy.dropBuffer)
b.
addEdge(in1, f1, merge).
addEdge(merge, f2, bcast1).
@ -116,7 +116,7 @@ class FlowGraphCompileSpec extends AkkaSpec {
val merge = Merge[String]
val bcast1 = Broadcast[String]
val bcast2 = Broadcast[String]
val feedbackLoopBuffer = FlowFrom[String].buffer(10, OverflowStrategy.dropBuffer)
val feedbackLoopBuffer = Flow[String].buffer(10, OverflowStrategy.dropBuffer)
import FlowGraphImplicits._
in1 ~> f1 ~> merge ~> f2 ~> bcast1 ~> f3 ~> out1
bcast1 ~> feedbackLoopBuffer ~> bcast2 ~> f5 ~> merge
@ -145,13 +145,13 @@ class FlowGraphCompileSpec extends AkkaSpec {
val m9 = Merge[String]
val m10 = Merge[String]
val m11 = Merge[String]
val in3 = IterableSource(List("b"))
val in5 = IterableSource(List("b"))
val in7 = IterableSource(List("a"))
val out2 = PublisherSink[String]
val out9 = PublisherSink[String]
val out10 = PublisherSink[String]
def f(s: String) = FlowFrom[String].transform(s, op[String, String])
val in3 = IterableTap(List("b"))
val in5 = IterableTap(List("b"))
val in7 = IterableTap(List("a"))
val out2 = PublisherDrain[String]
val out9 = PublisherDrain[String]
val out10 = PublisherDrain[String]
def f(s: String) = Flow[String].transform(s, op[String, String])
import FlowGraphImplicits._
in7 ~> f("a") ~> b7 ~> f("b") ~> m11 ~> f("c") ~> b11 ~> f("d") ~> out2
@ -164,53 +164,53 @@ class FlowGraphCompileSpec extends AkkaSpec {
}.run()
}
"attachSource and attachSink" in {
"attachTap and attachDrain" in {
val mg = FlowGraph { b
val merge = Merge[String]
val undefinedSrc1 = UndefinedSource[String]
val undefinedSrc2 = UndefinedSource[String]
val undefinedSink1 = UndefinedSink[String]
val undefinedSrc1 = UndefinedTap[String]
val undefinedSrc2 = UndefinedTap[String]
val undefinedDrain1 = UndefinedDrain[String]
b.
addEdge(undefinedSrc1, f1, merge).
addEdge(UndefinedSource[String]("src2"), f2, merge).
addEdge(merge, f3, undefinedSink1)
addEdge(UndefinedTap[String]("src2"), f2, merge).
addEdge(merge, f3, undefinedDrain1)
b.attachSource(undefinedSrc1, in1)
b.attachSource(UndefinedSource[String]("src2"), in2)
b.attachSink(undefinedSink1, out1)
b.attachTap(undefinedSrc1, in1)
b.attachTap(UndefinedTap[String]("src2"), in2)
b.attachDrain(undefinedDrain1, out1)
}.run()
out1.publisher(mg) should not be (null)
}
"build partial flow graphs" in {
val undefinedSrc1 = UndefinedSource[String]
val undefinedSrc2 = UndefinedSource[String]
val undefinedSink1 = UndefinedSink[String]
val undefinedSrc1 = UndefinedTap[String]
val undefinedSrc2 = UndefinedTap[String]
val undefinedDrain1 = UndefinedDrain[String]
val bcast = Broadcast[String]
val partial1 = PartialFlowGraph { implicit b
import FlowGraphImplicits._
val merge = Merge[String]
undefinedSrc1 ~> f1 ~> merge ~> f2 ~> bcast ~> f3 ~> undefinedSink1
undefinedSrc1 ~> f1 ~> merge ~> f2 ~> bcast ~> f3 ~> undefinedDrain1
undefinedSrc2 ~> f4 ~> merge
}
partial1.undefinedSources should be(Set(undefinedSrc1, undefinedSrc2))
partial1.undefinedSinks should be(Set(undefinedSink1))
partial1.undefinedTaps should be(Set(undefinedSrc1, undefinedSrc2))
partial1.undefinedDrains should be(Set(undefinedDrain1))
val partial2 = PartialFlowGraph(partial1) { implicit b
import FlowGraphImplicits._
b.attachSource(undefinedSrc1, in1)
b.attachSource(undefinedSrc2, in2)
bcast ~> f5 ~> UndefinedSink[String]("sink2")
b.attachTap(undefinedSrc1, in1)
b.attachTap(undefinedSrc2, in2)
bcast ~> f5 ~> UndefinedDrain[String]("drain2")
}
partial2.undefinedSources should be(Set.empty)
partial2.undefinedSinks should be(Set(undefinedSink1, UndefinedSink[String]("sink2")))
partial2.undefinedTaps should be(Set.empty)
partial2.undefinedDrains should be(Set(undefinedDrain1, UndefinedDrain[String]("drain2")))
FlowGraph(partial2) { implicit b
b.attachSink(undefinedSink1, out1)
b.attachSink(UndefinedSink[String]("sink2"), out2)
b.attachDrain(undefinedDrain1, out1)
b.attachDrain(UndefinedDrain[String]("drain2"), out2)
}.run()
}
@ -225,22 +225,13 @@ class FlowGraphCompileSpec extends AkkaSpec {
}.run()
}
"use FlowWithSource and FlowWithSink" in {
FlowGraph { implicit b
val bcast = Broadcast[String]
import FlowGraphImplicits._
f1.withSource(in1) ~> bcast ~> f2.withSink(out1)
bcast ~> f3.withSink(out2)
}.run()
}
"chain input and output ports" in {
FlowGraph { implicit b
val zip = Zip[Int, String]
val out = PublisherSink[(Int, String)]
val out = PublisherDrain[(Int, String)]
import FlowGraphImplicits._
FlowFrom(List(1, 2, 3)) ~> zip.left ~> out
FlowFrom(List("a", "b", "c")) ~> zip.right
Source(List(1, 2, 3)) ~> zip.left ~> out
Source(List("a", "b", "c")) ~> zip.right
}.run()
}
@ -248,10 +239,10 @@ class FlowGraphCompileSpec extends AkkaSpec {
FlowGraph { implicit b
val zip = Zip[Int, String]
val unzip = Unzip[Int, String]
val out = PublisherSink[(Int, String)]
val out = PublisherDrain[(Int, String)]
import FlowGraphImplicits._
FlowFrom(List(1 -> "a", 2 -> "b", 3 -> "c")) ~> unzip.in
unzip.left ~> FlowFrom[Int].map(_ * 2) ~> zip.left
Source(List(1 -> "a", 2 -> "b", 3 -> "c")) ~> unzip.in
unzip.left ~> Flow[Int].map(_ * 2) ~> zip.left
unzip.right ~> zip.right
zip.out ~> out
}.run()
@ -262,15 +253,15 @@ class FlowGraphCompileSpec extends AkkaSpec {
FlowGraph { implicit b
val zip = Zip[Int, String]
val unzip = Unzip[Int, String]
val wrongOut = PublisherSink[(Int, Int)]
val whatever = PublisherSink[Any]
val wrongOut = PublisherDrain[(Int, Int)]
val whatever = PublisherDrain[Any]
import FlowGraphImplicits._
"FlowFrom(List(1, 2, 3)) ~> zip.left ~> wrongOut" shouldNot compile
"""FlowFrom(List("a", "b", "c")) ~> zip.left""" shouldNot compile
"""FlowFrom(List("a", "b", "c")) ~> zip.out""" shouldNot compile
"Flow(List(1, 2, 3)) ~> zip.left ~> wrongOut" shouldNot compile
"""Flow(List("a", "b", "c")) ~> zip.left""" shouldNot compile
"""Flow(List("a", "b", "c")) ~> zip.out""" shouldNot compile
"zip.left ~> zip.right" shouldNot compile
"FlowFrom(List(1, 2, 3)) ~> zip.left ~> wrongOut" shouldNot compile
"""FlowFrom(List(1 -> "a", 2 -> "b", 3 -> "c")) ~> unzip.in ~> whatever""" shouldNot compile
"Flow(List(1, 2, 3)) ~> zip.left ~> wrongOut" shouldNot compile
"""Flow(List(1 -> "a", 2 -> "b", 3 -> "c")) ~> unzip.in ~> whatever""" shouldNot compile
}
}.getMessage should include("empty")
}
@ -298,50 +289,50 @@ class FlowGraphCompileSpec extends AkkaSpec {
}
"build with variance" in {
val out = SubscriberSink(SubscriberProbe[Fruit]())
val out = SubscriberDrain(SubscriberProbe[Fruit]())
FlowGraph { b
val merge = Merge[Fruit]
b.
addEdge(FlowFrom[Fruit](() Some(new Apple)), merge).
addEdge(FlowFrom[Apple](() Some(new Apple)), merge).
addEdge(merge, FlowFrom[Fruit].map(identity), out)
addEdge(Source[Fruit](() Some(new Apple)), merge).
addEdge(Source[Apple](() Some(new Apple)), merge).
addEdge(merge, Flow[Fruit].map(identity), out)
}
}
"build with implicits and variance" in {
PartialFlowGraph { implicit b
val inA = PublisherSource(PublisherProbe[Fruit]())
val inB = PublisherSource(PublisherProbe[Apple]())
val outA = SubscriberSink(SubscriberProbe[Fruit]())
val outB = SubscriberSink(SubscriberProbe[Fruit]())
val inA = PublisherTap(PublisherProbe[Fruit]())
val inB = PublisherTap(PublisherProbe[Apple]())
val outA = SubscriberDrain(SubscriberProbe[Fruit]())
val outB = SubscriberDrain(SubscriberProbe[Fruit]())
val merge = Merge[Fruit]
val unzip = Unzip[Int, String]
val whatever = PublisherSink[Any]
val whatever = PublisherDrain[Any]
import FlowGraphImplicits._
FlowFrom[Fruit](() Some(new Apple)) ~> merge
FlowFrom[Apple](() Some(new Apple)) ~> merge
Source[Fruit](() Some(new Apple)) ~> merge
Source[Apple](() Some(new Apple)) ~> merge
inA ~> merge
inB ~> merge
inA ~> FlowFrom[Fruit].map(identity) ~> merge
inB ~> FlowFrom[Apple].map(identity) ~> merge
UndefinedSource[Apple] ~> merge
UndefinedSource[Apple] ~> FlowFrom[Fruit].map(identity) ~> merge
UndefinedSource[Apple] ~> FlowFrom[Apple].map(identity) ~> merge
merge ~> FlowFrom[Fruit].map(identity) ~> outA
inA ~> Flow[Fruit].map(identity) ~> merge
inB ~> Flow[Apple].map(identity) ~> merge
UndefinedTap[Apple] ~> merge
UndefinedTap[Apple] ~> Flow[Fruit].map(identity) ~> merge
UndefinedTap[Apple] ~> Flow[Apple].map(identity) ~> merge
merge ~> Flow[Fruit].map(identity) ~> outA
FlowFrom[Apple](() Some(new Apple)) ~> Broadcast[Apple] ~> merge
FlowFrom[Apple](() Some(new Apple)) ~> Broadcast[Apple] ~> outB
FlowFrom[Apple](() Some(new Apple)) ~> Broadcast[Apple] ~> UndefinedSink[Fruit]
Source[Apple](() Some(new Apple)) ~> Broadcast[Apple] ~> merge
Source[Apple](() Some(new Apple)) ~> Broadcast[Apple] ~> outB
Source[Apple](() Some(new Apple)) ~> Broadcast[Apple] ~> UndefinedDrain[Fruit]
inB ~> Broadcast[Apple] ~> merge
FlowFrom(List(1 -> "a", 2 -> "b", 3 -> "c")) ~> unzip.in
Source(List(1 -> "a", 2 -> "b", 3 -> "c")) ~> unzip.in
unzip.right ~> whatever
unzip.left ~> UndefinedSink[Any]
unzip.left ~> UndefinedDrain[Any]
"UndefinedSource[Fruit] ~> FlowFrom[Apple].map(identity) ~> merge" shouldNot compile
"UndefinedSource[Fruit] ~> Broadcast[Apple]" shouldNot compile
"UndefinedTap[Fruit] ~> Flow[Apple].map(identity) ~> merge" shouldNot compile
"UndefinedTap[Fruit] ~> Broadcast[Apple]" shouldNot compile
"merge ~> Broadcast[Apple]" shouldNot compile
"merge ~> FlowFrom[Fruit].map(identity) ~> Broadcast[Apple]" shouldNot compile
"merge ~> Flow[Fruit].map(identity) ~> Broadcast[Apple]" shouldNot compile
"inB ~> merge ~> Broadcast[Apple]" shouldNot compile
"inA ~> Broadcast[Apple]" shouldNot compile
}