use of org.apache.storm.streams.operations.StateUpdater in project storm by apache.
the class StatefulProcessorBoltTest method testEmitAndAck.
@Test
public void testEmitAndAck() throws Exception {
setUpStatefulProcessorBolt(new UpdateStateByKeyProcessor<>(new StateUpdater<Object, Long>() {
@Override
public Long init() {
return 0L;
}
@Override
public Long apply(Long state, Object value) {
return state + 1;
}
}));
bolt.execute(mockTuple1);
ArgumentCaptor<Collection> anchor = ArgumentCaptor.forClass(Collection.class);
ArgumentCaptor<Values> values = ArgumentCaptor.forClass(Values.class);
ArgumentCaptor<String> os = ArgumentCaptor.forClass(String.class);
Mockito.verify(mockOutputCollector).emit(os.capture(), anchor.capture(), values.capture());
assertEquals("outputstream", os.getValue());
assertArrayEquals(new Object[] { mockTuple1 }, anchor.getValue().toArray());
assertEquals(new Values("k", 1L), values.getValue());
Mockito.verify(mockOutputCollector, Mockito.times(1)).ack(mockTuple1);
Mockito.verify(mockKeyValueState, Mockito.times(1)).put("k", 1L);
}
Aggregations