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 <> 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 <> 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:
16:53:32.561 [stderr]	at backtype.storm.utils.Utils.javaSerialize(
16:53:32.561 [stderr]	at backtype.storm.topology.TopologyBuilder.createTopology(
16:53:32.561 [stderr]	at
16:53:32.561 [stderr]Caused by:
16:53:32.561 [stderr]	at
16:53:32.561 [stderr]	at
16:53:32.562 [stderr]	at
16:53:32.562 [stderr]	at
16:53:32.562 [stderr]	at
16:53:32.562 [stderr]	at
16:53:32.562 [stderr]	at backtype.storm.utils.Utils.javaSerialize(

So I have to do it like this to not get the Exception

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