Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a backtype.storm.tuple.Tuple for testing purposes?

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.

like image 618
gak Avatar asked Mar 27 '13 02:03

gak


1 Answers

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;
    }
}
like image 126
gak Avatar answered Oct 03 '22 00:10

gak