Search in sources :

Example 6 with KeyValueState

use of org.apache.storm.state.KeyValueState in project storm by apache.

the class StatefulWindowedBoltExecutorTest method testExecute.

@Test
public void testExecute() throws Exception {
    mockStormConf.put(Config.TOPOLOGY_BOLTS_MESSAGE_ID_FIELD_NAME, "msgid");
    mockStormConf.put(Config.TOPOLOGY_BOLTS_WINDOW_LENGTH_COUNT, 5);
    mockStormConf.put(Config.TOPOLOGY_BOLTS_SLIDING_INTERVAL_COUNT, 5);
    KeyValueState<TaskStream, WindowState> mockState;
    mockState = Mockito.mock(KeyValueState.class);
    executor.prepare(mockStormConf, mockTopologyContext, mockOutputCollector, mockState);
    executor.initState(null);
    List<Tuple> tuples = getMockTuples(5);
    for (Tuple tuple : tuples) {
        executor.execute(tuple);
    }
    Mockito.verify(mockBolt, Mockito.times(1)).execute(getTupleWindow(tuples));
    WindowState expectedState = new WindowState(Long.MIN_VALUE, 4);
    Mockito.verify(mockState, Mockito.times(1)).put(Mockito.any(TaskStream.class), Mockito.eq(expectedState));
}
Also used : WindowState(org.apache.storm.topology.StatefulWindowedBoltExecutor.WindowState) TaskStream(org.apache.storm.topology.StatefulWindowedBoltExecutor.TaskStream) KeyValueState(org.apache.storm.state.KeyValueState) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Aggregations

KeyValueState (org.apache.storm.state.KeyValueState)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 Values (org.apache.storm.tuple.Values)4 TaskStream (org.apache.storm.topology.StatefulWindowedBoltExecutor.TaskStream)2 WindowState (org.apache.storm.topology.StatefulWindowedBoltExecutor.WindowState)2 Tuple (org.apache.storm.tuple.Tuple)2 GlobalStreamId (org.apache.storm.generated.GlobalStreamId)1 Grouping (org.apache.storm.generated.Grouping)1