use of org.apache.storm.topology.StatefulWindowedBoltExecutor.TaskStream in project storm by apache.
the class StatefulWindowedBoltExecutorTest method testRecovery.
@Test
public void testRecovery() 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);
Map<GlobalStreamId, Grouping> mockMap = Mockito.mock(Map.class);
Mockito.when(mockTopologyContext.getThisSources()).thenReturn(mockMap);
Mockito.when(mockTopologyContext.getComponentTasks(Mockito.anyString())).thenReturn(Collections.singletonList(1));
Mockito.when(mockMap.keySet()).thenReturn(Collections.singleton(new GlobalStreamId("a", "s")));
WindowState mockWindowState = new WindowState(4, 4);
Mockito.when(mockState.get(Mockito.any(TaskStream.class))).thenReturn(mockWindowState);
executor.prepare(mockStormConf, mockTopologyContext, mockOutputCollector, mockState);
executor.initState(null);
List<Tuple> tuples = getMockTuples(10);
for (Tuple tuple : tuples) {
executor.execute(tuple);
}
WindowState expectedState = new WindowState(4, 9);
Mockito.verify(mockState, Mockito.times(1)).put(Mockito.any(TaskStream.class), Mockito.eq(expectedState));
}
use of org.apache.storm.topology.StatefulWindowedBoltExecutor.TaskStream 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));
}
Aggregations