Stream Testkit expectNextType ?

17 views
Skip to first unread message

Derek Wyatt

unread,
Apr 7, 2016, 3:59:53 PM4/7/16
to Akka User List
Hi guys,

I've been writing some tests for my stream code and have run up against a situation where I would like to have expectNextType.  I've implemented this myself with a pimp, but I'm wondering if there's a better way?

  implicit class ProbeExtension[T](val p: Probe[T]) {
    def expectNextType[A](implicit t: ClassTag[A]): p.Self = {
      p.expectNextPF {
        case a: A =>
        case x => fail(s"Expected a $t type but got a ${x.getClass.getName}")
      }
      p
    }
  }

This is mostly useful when the 'A' in question is a derivation of Try[_].  I tend to write expectNextType[Failure[_]] in these cases.  And, just to give some context as to why I would want to do that: My flow components might return a Try, which I then pass through a special handling / logging flow, which transforms them to a List that is composed with a mapConcat. So...

val flowReturningTry: Flow[T, Try[U], NotUsed] = ...
val handlingAndLogging: Flow[Try[U], U, NotUsed] = Flow[Try[U]].mapConcat { /* List(u) or List(), depending on the Try */ }
val composed: Flow[T, U, NotUsed] = flowReturningTry.mapConcat(handlingAndLogging)

Now, when testing flowReturningTry in isolation, the expectNextType is useful.

Cheers and thanks,
Derek

Patrik Nordwall

unread,
Apr 8, 2016, 12:12:26 PM4/8/16
to akka...@googlegroups.com
Hi Derek,
Sounds like a great addition. Will you take a stab at it?
/Patrik

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



--

Patrik Nordwall
Akka Tech Lead
Lightbend -  Reactive apps on the JVM
Twitter: @patriknw

Derek Wyatt

unread,
Apr 10, 2016, 8:02:41 AM4/10/16
to akka...@googlegroups.com
Alright. I'll play around with these over the next few days and send you a PR.

You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/ySk9lP-TZQU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

Patrik Nordwall

unread,
Apr 11, 2016, 4:53:29 AM4/11/16
to akka...@googlegroups.com
Thanks, Derek
Reply all
Reply to author
Forward
0 new messages