I'm testing a Flow with TestSource and TestSink

"TestSource/TestSink Example" should {
  "work" in {
    val (pub, sub) = TestSource.probe[MyClass]
    .via(myFlow[String])
    .toMat(TestSink.probe[String])(Keep.both)
    .run()
    sub.request(1)
    pub.sendNext(myData)
    val response = sub.expectNext()
    pub.sendComplete()
    sub.expectComplete()
    response.size shouldBe 1
  }
}

I want to also test it with a real Source. The reference doc has this 
example.

val sourceUnderTest = Source(1 to 4).filter(_ % 2 == 0).map(_ * 2)
sourceUnderTest
  .runWith(TestSink.probe[Int])
  .request(2)
  .expectNext(4, 8)
  .expectComplete()

If I change the first line from
val sourceUnderTest = Source(1 to 4).filter(_ % 2 == 0).map(_ * 2)
to
val sourceUnderTest = Source(1 to 4)
The test times out. Why do I need filter or map for the test to run?

What I want to do is replace TestSource with a real Source. I expected to 
drop references to "pub" and have just the TestSink subscriber using 
(Keep.right)
and then do assertions on the response. But this doesn't work.

val sourceUnderTest = Source.fromGraph(sourceGraph)

"Source/TestSink Example" should {
  "work" in {
    val sub = sourceUnderTest
    .via(myFlow[String])
    .toMat(TestSink.probe[String])(Keep.right)
    .run()
    sub.request(1)
    val response = sub.expectNext()
    response.size shouldBe 1
  }
}

How do I use the nice TestSource/TestSink format with a real Source?

Gary

-- 
>>>>>>>>>>      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 akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to