You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@storm.apache.org by Max Bridgewater <ma...@gmail.com> on 2015/04/21 02:04:12 UTC

Unit testing bolts with non-serializable properties

Hi,

In my topology, I have a bolt that reads and writes to Solr. Everything
works well. The connection to solr is created in the prepare method, which
ensures that the solr client does not need to be serializable.

The problem I have is around unit testing the topology. In this process, I
mock the solr client (SolrJ) using Mockito and inject the resulting mock
class into the bolt. Something along the line of:

SolrClient client=mock(SolrClient);
mySolrBolt.setSolrClient(client);

Unfortunately, this doesn't work. I get NotSerializableException because
the Solr client is of course not serializable. My topology unit tests is
heavily inspired from testBasicTopology implemented in TestingApiDemo.


My question is: what is the recommended way to unit test topologies with
such bolts?

Thanks,
Max.

Re: Unit testing bolts with non-serializable properties

Posted by Max Bridgewater <ma...@gmail.com>.
Just to correct my statements above. The issue was somewhere else. In fact,
I was creating my bolt through anonymous. Something along the lines of:

MyBolt bot= new MyBolt(){

public SolrClient getSolrClient(){
     return mockedSolrClient;
}
}

The issue here is that eventhough MyBolt is serializable, the above
statement defines an anonymous class that is subsequently instantiated. And
because this anonymous class is not serializable, storm was rightfully
throwing NotSerializableException.

The solution I ended up with is to get rid of the anonymous class and
create a fully named help class, instantiate it and use it as bolt.

Thanks,
Max.



On Mon, Apr 20, 2015 at 6:04 PM, Max Bridgewater <ma...@gmail.com>
wrote:

> Hi,
>
> In my topology, I have a bolt that reads and writes to Solr. Everything
> works well. The connection to solr is created in the prepare method, which
> ensures that the solr client does not need to be serializable.
>
> The problem I have is around unit testing the topology. In this process, I
> mock the solr client (SolrJ) using Mockito and inject the resulting mock
> class into the bolt. Something along the line of:
>
> SolrClient client=mock(SolrClient);
> mySolrBolt.setSolrClient(client);
>
> Unfortunately, this doesn't work. I get NotSerializableException because
> the Solr client is of course not serializable. My topology unit tests is
> heavily inspired from testBasicTopology implemented in TestingApiDemo.
>
>
> My question is: what is the recommended way to unit test topologies with
> such bolts?
>
> Thanks,
> Max.
>