Search in sources :

Example 1 with WindowState

use of org.apache.storm.topology.StatefulWindowedBoltExecutor.WindowState 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));
}
Also used : WindowState(org.apache.storm.topology.StatefulWindowedBoltExecutor.WindowState) TaskStream(org.apache.storm.topology.StatefulWindowedBoltExecutor.TaskStream) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) KeyValueState(org.apache.storm.state.KeyValueState) Grouping(org.apache.storm.generated.Grouping) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 2 with WindowState

use of org.apache.storm.topology.StatefulWindowedBoltExecutor.WindowState 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)2 TaskStream (org.apache.storm.topology.StatefulWindowedBoltExecutor.TaskStream)2 WindowState (org.apache.storm.topology.StatefulWindowedBoltExecutor.WindowState)2 Tuple (org.apache.storm.tuple.Tuple)2 Test (org.junit.Test)2 GlobalStreamId (org.apache.storm.generated.GlobalStreamId)1 Grouping (org.apache.storm.generated.Grouping)1