use of org.apache.storm.tuple.Values 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);
}
use of org.apache.storm.tuple.Values in project storm by apache.
the class TestTridentTopology method buildTopology.
private StormTopology buildTopology() {
FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 3, new Values("the cow jumped over the moon"), new Values("the man went to the store and bought some candy"), new Values("four score and seven years ago"), new Values("how many apples can you eat"));
spout.setCycle(true);
TridentTopology topology = new TridentTopology();
topology.newStream("spout", spout).each(new Fields("sentence"), new Split(), new Fields("word")).partitionBy(new Fields("word")).name("abc").each(new Fields("word"), new StringLength(), new Fields("length")).partitionBy(new Fields("length")).name("def").aggregate(new Fields("length"), new Count(), new Fields("count")).partitionBy(new Fields("count")).name("ghi").aggregate(new Fields("count"), new Sum(), new Fields("sum"));
return topology.build();
}
use of org.apache.storm.tuple.Values in project storm by apache.
the class CountBolt method execute.
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
String word = tuple.getString(0);
Integer count = counts.get(word);
if (count == null)
count = 0;
count++;
counts.put(word, count);
collector.emit(new Values(word, count));
}
use of org.apache.storm.tuple.Values in project storm by apache.
the class IdBolt method execute.
@Override
public void execute(Tuple tuple) {
collector.emit(tuple, new Values(tuple.getValues()));
collector.ack(tuple);
}
use of org.apache.storm.tuple.Values in project storm by apache.
the class FileReadSpout method nextTuple.
@Override
public void nextTuple() {
if (ackEnabled) {
collector.emit(new Values(reader.nextLine()), count);
count++;
} else {
collector.emit(new Values(reader.nextLine()));
}
}
Aggregations