Unit test bolts and spouts individually

1,340 views
Skip to first unread message

Hussein B.

unread,
Sep 27, 2012, 4:08:06 PM9/27/12
to storm...@googlegroups.com
Hi,

I have a Storm topology that employs Kafka as the spout.

I want to start unit testing it (preferably with clojure.test or Midjie) .

What do we have at our hands?
It will be nice to unit test spouts and bolts individually and then of course use https://github.com/nathanmarz/storm/blob/master/src/clj/backtype/storm/testing.clj

Is it possible to unit test spouts and bolts individually?

Thanks for help and time

Nathan Marz

unread,
Sep 29, 2012, 3:27:03 PM9/29/12
to storm...@googlegroups.com
There's a Java-based testing API fo testing topologies as a whole: https://github.com/xumingming/storm-lib/blob/master/src/jvm/storm/TestingApiDemo.java

For testing individual spouts and bolts it's pretty easy to make your own output collector that captures tuples so you can test the output.
--
Twitter: @nathanmarz
http://nathanmarz.com

Hussein B.

unread,
Oct 1, 2012, 5:34:15 AM10/1/12
to storm...@googlegroups.com
> For testing individual spouts and bolts it's pretty easy to make your own output collector that captures tuples so you can test the output.
Not sure how to do that as I'm using Clojure DSL to code the topology

Nathan Marz

unread,
Oct 1, 2012, 3:33:32 PM10/1/12
to storm...@googlegroups.com
(OutputCollector. (reify IOutputCollector ...))

Hussein B.

unread,
Oct 2, 2012, 7:27:34 AM10/2/12
to storm...@googlegroups.com
Yes thanks but what I mean is how to pass the mocked OutputCollector (that you provided) to a bolt definition that is created with Clojure DSL?

(defbolt ....)

Thanks a lot!

Nathan Marz

unread,
Oct 2, 2012, 3:56:26 PM10/2/12
to storm...@googlegroups.com
(defbolt ...) creates an instance of IBolt. So you can just call .prepare and .execute on it

Hussein B.

unread,
Oct 3, 2012, 8:19:32 AM10/3/12
to storm...@googlegroups.com
I see.

But I think I have to create tuples too?

To create a tuple, I need to create TupleImpl which its constructor needs GeneralTopologyContext which in turns, its constructor is a long one that needs StormTopology instance and many other things.

Am I missing something?

Nathan Marz

unread,
Oct 3, 2012, 12:48:50 PM10/3/12
to storm...@googlegroups.com
Check out the function backtype.storm.testing/test-tuple
Reply all
Reply to author
Forward
0 new messages