Search in sources :

Example 1 with Split

use of storm.trident.testing.Split in project jstorm by alibaba.

the class TridentWindowingInmemoryStoreTopology method buildTopology.

public static StormTopology buildTopology(WindowsStoreFactory windowStore, WindowConfig windowConfig) throws Exception {
    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"), new Values("to be or not to be the person"));
    spout.setCycle(true);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout).parallelismHint(16).each(new Fields("sentence"), new Split(), new Fields("word")).window(windowConfig, windowStore, new Fields("word"), new CountAsAggregator(), new Fields("count")).peek(new Consumer() {

        @Override
        public void accept(TridentTuple input) {
            LOG.info("Received tuple: [{}]", input);
        }
    });
    return topology.build();
}
Also used : FixedBatchSpout(storm.trident.testing.FixedBatchSpout) Fields(backtype.storm.tuple.Fields) Consumer(storm.trident.operation.Consumer) TridentTopology(storm.trident.TridentTopology) CountAsAggregator(storm.trident.testing.CountAsAggregator) Values(backtype.storm.tuple.Values) Stream(storm.trident.Stream) Split(storm.trident.testing.Split) TridentTuple(storm.trident.tuple.TridentTuple)

Example 2 with Split

use of storm.trident.testing.Split in project jstorm by alibaba.

the class TridentTumblingCountWindowTest method testTridentTumblingCountWindow.

@Test
public void testTridentTumblingCountWindow() {
    WindowsStoreFactory windowsStoreFactory = new InMemoryWindowsStoreFactory();
    FixedLimitBatchSpout spout = new FixedLimitBatchSpout(SPOUT_LIMIT, new Fields("sentence"), SPOUT_BATCH_SIZE, 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"), new Values("to be or not to be the person"));
    TridentTopology tridentTopology = new TridentTopology();
    Stream stream = tridentTopology.newStream("spout1", spout).parallelismHint(16).each(new Fields("sentence"), new Split(), new Fields("word")).window(windowConfig, windowsStoreFactory, new Fields("word"), new CountAsAggregator(), new Fields("count")).peek(new ValidateConsumer());
    Map config = new HashMap();
    config.put(Config.TOPOLOGY_NAME, "TridentTumblingCountWindowTest");
    JStormUnitTestRunner.submitTopology(tridentTopology.build(), null, 120, null);
}
Also used : Fields(backtype.storm.tuple.Fields) TridentTopology(storm.trident.TridentTopology) CountAsAggregator(storm.trident.testing.CountAsAggregator) HashMap(java.util.HashMap) Values(backtype.storm.tuple.Values) InMemoryWindowsStoreFactory(storm.trident.windowing.InMemoryWindowsStoreFactory) Stream(storm.trident.Stream) Split(storm.trident.testing.Split) HashMap(java.util.HashMap) Map(java.util.Map) WindowsStoreFactory(storm.trident.windowing.WindowsStoreFactory) InMemoryWindowsStoreFactory(storm.trident.windowing.InMemoryWindowsStoreFactory) Test(org.junit.Test)

Example 3 with Split

use of storm.trident.testing.Split in project jstorm by alibaba.

the class TridentTumblingDurationWindowTest method testTridentTumblingDurationWindow.

@Test
public void testTridentTumblingDurationWindow() {
    WindowsStoreFactory windowsStoreFactory = new InMemoryWindowsStoreFactory();
    FixedLimitBatchSpout spout = new FixedLimitBatchSpout(SPOUT_LIMIT, new Fields("sentence"), SPOUT_BATCH_SIZE, 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"), new Values("to be or not to be the person"));
    TridentTopology tridentTopology = new TridentTopology();
    Stream stream = tridentTopology.newStream("spout1", spout).parallelismHint(16).each(new Fields("sentence"), new Split(), new Fields("word")).window(windowConfig, windowsStoreFactory, new Fields("word"), new CountAsAggregator(), new Fields("count")).peek(new ValidateConsumer());
    Map config = new HashMap();
    config.put(Config.TOPOLOGY_NAME, "TridentTumblingDurationWindowTest");
    JStormUnitTestRunner.submitTopology(tridentTopology.build(), null, 120, null);
}
Also used : Fields(backtype.storm.tuple.Fields) TridentTopology(storm.trident.TridentTopology) CountAsAggregator(storm.trident.testing.CountAsAggregator) HashMap(java.util.HashMap) Values(backtype.storm.tuple.Values) InMemoryWindowsStoreFactory(storm.trident.windowing.InMemoryWindowsStoreFactory) Stream(storm.trident.Stream) Split(storm.trident.testing.Split) HashMap(java.util.HashMap) Map(java.util.Map) WindowsStoreFactory(storm.trident.windowing.WindowsStoreFactory) InMemoryWindowsStoreFactory(storm.trident.windowing.InMemoryWindowsStoreFactory) Test(org.junit.Test)

Example 4 with Split

use of storm.trident.testing.Split in project jstorm by alibaba.

the class TridentSlidingCountWindowTest method testTridentSlidingCountWindow.

@Test
public void testTridentSlidingCountWindow() {
    WindowsStoreFactory windowsStoreFactory = new InMemoryWindowsStoreFactory();
    FixedLimitBatchSpout spout = new FixedLimitBatchSpout(SPOUT_LIMIT, new Fields("sentence"), SPOUT_BATCH_SIZE, 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"), new Values("to be or not to be the person"));
    TridentTopology tridentTopology = new TridentTopology();
    Stream stream = tridentTopology.newStream("spout1", spout).parallelismHint(16).each(new Fields("sentence"), new Split(), new Fields("word")).window(windowConfig, windowsStoreFactory, new Fields("word"), new CountAsAggregator(), new Fields("count")).peek(new ValidateConsumer());
    Map config = new HashMap();
    config.put(Config.TOPOLOGY_NAME, "TridentSlidingCountWindowTest");
    JStormUnitTestRunner.submitTopology(tridentTopology.build(), null, 120, null);
}
Also used : Fields(backtype.storm.tuple.Fields) TridentTopology(storm.trident.TridentTopology) CountAsAggregator(storm.trident.testing.CountAsAggregator) HashMap(java.util.HashMap) Values(backtype.storm.tuple.Values) InMemoryWindowsStoreFactory(storm.trident.windowing.InMemoryWindowsStoreFactory) Stream(storm.trident.Stream) Split(storm.trident.testing.Split) HashMap(java.util.HashMap) Map(java.util.Map) WindowsStoreFactory(storm.trident.windowing.WindowsStoreFactory) InMemoryWindowsStoreFactory(storm.trident.windowing.InMemoryWindowsStoreFactory) Test(org.junit.Test)

Example 5 with Split

use of storm.trident.testing.Split in project jstorm by alibaba.

the class TridentSlidingDurationWindowTest method testTridentSlidingDurationWindow.

@Test
public void testTridentSlidingDurationWindow() {
    WindowsStoreFactory windowsStoreFactory = new InMemoryWindowsStoreFactory();
    FixedLimitBatchSpout spout = new FixedLimitBatchSpout(SPOUT_LIMIT, new Fields("sentence"), SPOUT_BATCH_SIZE, 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"), new Values("to be or not to be the person"));
    TridentTopology tridentTopology = new TridentTopology();
    Stream stream = tridentTopology.newStream("spout1", spout).parallelismHint(16).each(new Fields("sentence"), new Split(), new Fields("word")).window(windowConfig, windowsStoreFactory, new Fields("word"), new CountAsAggregator(), new Fields("count")).peek(new ValidateConsumer());
    Map config = new HashMap();
    config.put(Config.TOPOLOGY_NAME, "TridentSlidingDurationWindowTest");
    JStormUnitTestRunner.submitTopology(tridentTopology.build(), null, 120, null);
}
Also used : Fields(backtype.storm.tuple.Fields) TridentTopology(storm.trident.TridentTopology) CountAsAggregator(storm.trident.testing.CountAsAggregator) HashMap(java.util.HashMap) Values(backtype.storm.tuple.Values) InMemoryWindowsStoreFactory(storm.trident.windowing.InMemoryWindowsStoreFactory) Stream(storm.trident.Stream) Split(storm.trident.testing.Split) HashMap(java.util.HashMap) Map(java.util.Map) WindowsStoreFactory(storm.trident.windowing.WindowsStoreFactory) InMemoryWindowsStoreFactory(storm.trident.windowing.InMemoryWindowsStoreFactory) Test(org.junit.Test)

Aggregations

Fields (backtype.storm.tuple.Fields)5 Values (backtype.storm.tuple.Values)5 Stream (storm.trident.Stream)5 TridentTopology (storm.trident.TridentTopology)5 CountAsAggregator (storm.trident.testing.CountAsAggregator)5 Split (storm.trident.testing.Split)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Test (org.junit.Test)4 InMemoryWindowsStoreFactory (storm.trident.windowing.InMemoryWindowsStoreFactory)4 WindowsStoreFactory (storm.trident.windowing.WindowsStoreFactory)4 Consumer (storm.trident.operation.Consumer)1 FixedBatchSpout (storm.trident.testing.FixedBatchSpout)1 TridentTuple (storm.trident.tuple.TridentTuple)1