Search in sources :

Example 1 with StateUpdater

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);
}
Also used : Values(org.apache.storm.tuple.Values) Collection(java.util.Collection) StateUpdater(org.apache.storm.streams.operations.StateUpdater) Test(org.junit.Test)

Aggregations

Collection (java.util.Collection)1 StateUpdater (org.apache.storm.streams.operations.StateUpdater)1 Values (org.apache.storm.tuple.Values)1 Test (org.junit.Test)1