I'm new to Storm and am trying to work out how to write a bolt test that tests the execute(Tuple tuple)
method in a subclassed BaseRichBolt
.
The issue is it appears that Tuple
is immutable and I don't see any methods or builders to create a new Tuple. How can I create my own Tuple
, or how can I test a bolt with test input?
I'm actually using Scala, not Java, but the answer should be easily translatable.
Mocking the Tuple object is a good solution from the storm-starter project. It's straightforward:
package storm.starter.tools;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import backtype.storm.Constants;
import backtype.storm.tuple.Tuple;
public final class MockTupleHelpers {
private MockTupleHelpers() {
}
public static Tuple mockTickTuple() {
return mockTuple(Constants.SYSTEM_COMPONENT_ID, Constants.SYSTEM_TICK_STREAM_ID);
}
public static Tuple mockTuple(String componentId, String streamId) {
Tuple tuple = mock(Tuple.class);
when(tuple.getSourceComponent()).thenReturn(componentId);
when(tuple.getSourceStreamId()).thenReturn(streamId);
return tuple;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With