storm-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Noppanit Charassinvichai <noppani...@gmail.com>
Subject Re: How to write unit test if I can't pass object to the bolt?
Date Thu, 01 Sep 2016 12:50:21 GMT
That actually works. I wonder if it's a common pattern for Storm Bolt to do
this? IMO, I like to inject things either from the method or constructor.

Thanks a lot.

On Wed, 31 Aug 2016 at 22:31 Zachary Smith <tud20772@temple.edu> wrote:

> Can't you do something like this ala mockito:
>
> @InjectMocks private KinesisInsertBolt underTest = new KinesisInsertBolt();
>
> @Mock private AmazonKinesisClient amazonKinesisClient;
>
>
> On Wed, Aug 31, 2016 at 9:50 PM, Noppanit Charassinvichai <
> noppanit.c@gmail.com> wrote:
>
>> I'm writing a Bolt where a bolt will send data to Kinesis. The library is
>> AmazonClient. If I initialize AmazonClient outside of prepare() method I
>> will get this error
>>
>> *16:53:32.561* [stderr]Exception in thread "main" java.lang.RuntimeException: java.io.NotSerializableException:
com.amazonaws.services.kinesis.AmazonKinesisClient*16:53:32.561* [stderr]	at backtype.storm.utils.Utils.javaSerialize(Utils.java:109)*16:53:32.561*
[stderr]	at backtype.storm.topology.TopologyBuilder.createTopology(TopologyBuilder.java:107)*16:53:32.561*
[stderr]	at io.conde.data.SparrowFirehoseTopology.main(SparrowFirehoseTopology.java:93)*16:53:32.561*
[stderr]Caused by: java.io.NotSerializableException: com.amazonaws.services.kinesis.AmazonKinesisClient*16:53:32.561*
[stderr]	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)*16:53:32.561*
[stderr]	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)*16:53:32.562*
[stderr]	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)*16:53:32.562*
[stderr]	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)*16:53:32.562*
[stderr]	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)*16:53:32.562*
[stderr]	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)*16:53:32.562*
[stderr]	at backtype.storm.utils.Utils.javaSerialize(Utils.java:105)
>>
>>
>>
>> So I have to do it like this to not get the Exception
>>
>> @Override
>> public void prepare(Map map, TopologyContext topologyContext, OutputCollector outputCollector)
{
>>     this.amazonKinesisClient = new AmazonKinesisClient(new CustomCredentialsProviderChain(),
new ClientConfiguration());
>>     this.random = new Random();
>>     this.outputCollector = outputCollector;
>>     this.decoder = Charset.forName("UTF-8").newDecoder();
>> }
>>
>> But then I won't be able to inject that and unit test that properly. How
>> do I overcome this? I'm using Storm 0.10
>>
>>
>>
>

Mime
View raw message