If anyone is interested in the solution to this, I managed to find a way of
doing it. It's probably not the optimal solution, but here it goes.
Comments will be appreciated :)
it should "route the KeepAliveSignal and the NewActivity to proper flows" in
{
Given("A Flow with an ActivityFlexiRouter, a KeepAliveSignal and a
merger")
var keepAliveCounter = 0
var newTweetCounter = 0
val flow = Flow() { implicit b =>
import FlowGraph.Implicits._
val route = b.add(new ActivityFlexiRouter)
val merge = b.add(Merge[GnipActivity](2))
route.newActivityFlow ~> Flow[GnipActivity].map(x => {newTweetCounter
= newTweetCounter + 1; x}) ~> merge.in(0)
route.keepAliveSignalFlow ~> Flow[GnipActivity].map(x =>
{keepAliveCounter
= keepAliveCounter + 1; x}) ~> merge.in(1)
(route.in, merge.out)
}
When("the flow is materialized and run")
val (pub, sub) = TestSource.probe[GnipActivity]
.via(flow)
.toMat(TestSink.probe[GnipActivity])(Keep.both)
.run()
Then("the keep alive flow receives the element")
sub.request(4)
pub.sendNext(KeepAliveSignal)
pub.sendNext(KeepAliveSignal)
pub.sendNext(NewTweetActivity(Tweet("nId", "l", "b", DateTime.now(), 0L,
0L, None, None, "a", UUID.randomUUID()), Vector(),
TweetAuthor("nIdA", "aName", "img")))
pub.sendNext(KeepAliveSignal)
pub.sendNext(NewTweetActivity(Tweet("nId", "l", "b", DateTime.now(), 0L,
0L, None, None, "a", UUID.randomUUID()), Vector(),
TweetAuthor("nIdA", "aName", "img")))
Thread.sleep(300)
assert(keepAliveCounter == 3)
assert(newTweetCounter == 2)
}
On Thursday, August 20, 2015 at 9:49:50 AM UTC+2, Ivan Baisi wrote:
>
> I'm trying to test a FlexiRoute I've developed that dpeending on the type
> of element it receives, it routes it either the keep alive signal or the
> gnip activity to different flows. Here's the approach I'm trying:
>
> class ActivityFlexiRouterSpec extends FlatSpec with GivenWhenThen{
> implicit val system = ActorSystem("TEST")
> implicit val materializer =
> ActorMaterializer(ActorMaterializerSettings(system))
> behavior of "ActivityFlexiRouter"
>
> it should "route the KeepAliveSignal to the KeepAliveSignalFlow" in {
> Given("A FlowGraph an ActivityFlexiRouter and a KeepAliveSignal")
> val newFlowProbe = TestSink.probe[GnipActivity]
> val keepAliveFlowProbe = TestSubscriber.manualProbe[GnipActivity]
> val graph = FlowGraph.closed() { implicit b =>
> val route = b.add(new ActivityFlexiRouter)
>
> Source.single(KeepAliveSignal) ~> route.in
> route.newActivityFlow ~> newFlowProbe
> route.keepAliveSignalFlow ~> keepAliveFlowProbe
> }
>
> When("the graph is run")
> graph.run()
>
> Then("assert something")
> assert(keepAliveFlowProbe.)
> }
>
> }
>
> I must say neither of the newFlowProbe or keepAliveFlowProbe are working,
> but I wanted to give some idea of the couple of the things I've tried.
> Could anyone give me any hint on how to test this?
>
> Thanks!
>
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.