Search in sources :

Example 1 with InMemoryWindowsStoreFactory

use of storm.trident.windowing.InMemoryWindowsStoreFactory 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 2 with InMemoryWindowsStoreFactory

use of storm.trident.windowing.InMemoryWindowsStoreFactory 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 3 with InMemoryWindowsStoreFactory

use of storm.trident.windowing.InMemoryWindowsStoreFactory 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 4 with InMemoryWindowsStoreFactory

use of storm.trident.windowing.InMemoryWindowsStoreFactory 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)

Example 5 with InMemoryWindowsStoreFactory

use of storm.trident.windowing.InMemoryWindowsStoreFactory in project jstorm by alibaba.

the class TridentWindowingInmemoryStoreTopology method test.

public static void test() {
    String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\.");
    String topologyName = className[className.length - 1];
    try {
        WindowsStoreFactory mapState = new InMemoryWindowsStoreFactory();
        List<? extends WindowConfig> list = Arrays.asList(SlidingCountWindow.of(1000, 100), TumblingCountWindow.of(1000), SlidingDurationWindow.of(new BaseWindowedBolt.Duration(6, TimeUnit.SECONDS), new BaseWindowedBolt.Duration(3, TimeUnit.SECONDS)), TumblingDurationWindow.of(new BaseWindowedBolt.Duration(3, TimeUnit.SECONDS)));
        for (WindowConfig windowConfig : list) {
            LocalCluster cluster = new LocalCluster();
            cluster.submitTopology("wordCounter", conf, buildTopology(mapState, windowConfig));
            Utils.sleep(60 * 1000);
            cluster.shutdown();
        }
        for (WindowConfig windowConfig : list) {
            String name = topologyName + "." + windowConfig.getWindowLength() + "." + windowConfig.getSlidingLength();
            JStormHelper.runTopology(buildTopology(mapState, windowConfig), name, conf, 60, new JStormHelper.CheckAckedFail(conf), isLocal);
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Assert.fail("Failed");
    }
}
Also used : WindowConfig(storm.trident.windowing.config.WindowConfig) LocalCluster(backtype.storm.LocalCluster) JStormHelper(com.alibaba.starter.utils.JStormHelper) InMemoryWindowsStoreFactory(storm.trident.windowing.InMemoryWindowsStoreFactory) WindowsStoreFactory(storm.trident.windowing.WindowsStoreFactory) InMemoryWindowsStoreFactory(storm.trident.windowing.InMemoryWindowsStoreFactory)

Aggregations

InMemoryWindowsStoreFactory (storm.trident.windowing.InMemoryWindowsStoreFactory)5 WindowsStoreFactory (storm.trident.windowing.WindowsStoreFactory)5 Fields (backtype.storm.tuple.Fields)4 Values (backtype.storm.tuple.Values)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Test (org.junit.Test)4 Stream (storm.trident.Stream)4 TridentTopology (storm.trident.TridentTopology)4 CountAsAggregator (storm.trident.testing.CountAsAggregator)4 Split (storm.trident.testing.Split)4 LocalCluster (backtype.storm.LocalCluster)1 JStormHelper (com.alibaba.starter.utils.JStormHelper)1 WindowConfig (storm.trident.windowing.config.WindowConfig)1