Search in sources :

Example 21 with Values

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

Example 22 with Values

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();
}
Also used : FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) StringLength(org.apache.storm.trident.testing.StringLength) Fields(org.apache.storm.tuple.Fields) Values(org.apache.storm.tuple.Values) Sum(org.apache.storm.trident.operation.builtin.Sum) Count(org.apache.storm.trident.operation.builtin.Count) Split(org.apache.storm.trident.testing.Split)

Example 23 with Values

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));
}
Also used : Values(org.apache.storm.tuple.Values)

Example 24 with Values

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);
}
Also used : Values(org.apache.storm.tuple.Values)

Example 25 with Values

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()));
    }
}
Also used : Values(org.apache.storm.tuple.Values)

Aggregations

Values (org.apache.storm.tuple.Values)206 Test (org.junit.Test)89 ArrayList (java.util.ArrayList)42 Fields (org.apache.storm.tuple.Fields)40 HashMap (java.util.HashMap)39 ChannelHandler (org.apache.storm.sql.runtime.ChannelHandler)26 TridentTopology (org.apache.storm.trident.TridentTopology)21 FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)14 Stream (org.apache.storm.trident.Stream)12 TupleImpl (org.apache.storm.tuple.TupleImpl)12 List (java.util.List)11 TestUtils (org.apache.storm.sql.TestUtils)11 TridentState (org.apache.storm.trident.TridentState)11 Tuple (org.apache.storm.tuple.Tuple)11 JSONObject (org.json.simple.JSONObject)10 Map (java.util.Map)9 Config (org.apache.storm.Config)9 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)9 GeneralTopologyContext (org.apache.storm.task.GeneralTopologyContext)8 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)8