Search in sources :

Example 6 with Stream

use of storm.trident.Stream 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 7 with Stream

use of storm.trident.Stream 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 8 with Stream

use of storm.trident.Stream 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 9 with Stream

use of storm.trident.Stream in project jstorm by alibaba.

the class TridentMinMaxOfDevicesTopology method buildVehiclesTopology.

/**
     * Creates a topology which demonstrates min/max operations on tuples of
     * stream which contain vehicle and driver fields with values
     * {@link TridentMinMaxOfDevicesTopology.Vehicle} and
     * {@link TridentMinMaxOfDevicesTopology.Driver} respectively.
     */
public static StormTopology buildVehiclesTopology() {
    Fields driverField = new Fields(Driver.FIELD_NAME);
    Fields vehicleField = new Fields(Vehicle.FIELD_NAME);
    Fields allFields = new Fields(Vehicle.FIELD_NAME, Driver.FIELD_NAME);
    FixedBatchSpout spout = new FixedBatchSpout(allFields, 10, Vehicle.generateVehicles(20));
    spout.setCycle(true);
    TridentTopology topology = new TridentTopology();
    Stream vehiclesStream = topology.newStream("spout1", spout).each(allFields, new Debug("##### vehicles"));
    Stream slowVehiclesStream = vehiclesStream.min(new SpeedComparator()).each(vehicleField, new Debug("#### slowest vehicle"));
    Stream slowDriversStream = slowVehiclesStream.project(driverField).each(driverField, new Debug("##### slowest driver"));
    vehiclesStream.max(new SpeedComparator()).each(vehicleField, new Debug("#### fastest vehicle")).project(driverField).each(driverField, new Debug("##### fastest driver"));
    vehiclesStream.max(new EfficiencyComparator()).each(vehicleField, new Debug("#### efficient vehicle"));
    return topology.build();
}
Also used : FixedBatchSpout(storm.trident.testing.FixedBatchSpout) Fields(backtype.storm.tuple.Fields) TridentTopology(storm.trident.TridentTopology) Stream(storm.trident.Stream) Debug(storm.trident.operation.builtin.Debug)

Example 10 with Stream

use of storm.trident.Stream in project jstorm by alibaba.

the class TridentMinMaxOfVehiclesTopology method buildVehiclesTopology.

/**
     * Creates a topology which demonstrates min/max operations on tuples of
     * stream which contain vehicle and driver fields with values
     * {@link TridentMinMaxOfVehiclesTopology.Vehicle} and
     * {@link TridentMinMaxOfVehiclesTopology.Driver} respectively.
     */
public static StormTopology buildVehiclesTopology() {
    Fields driverField = new Fields(Driver.FIELD_NAME);
    Fields vehicleField = new Fields(Vehicle.FIELD_NAME);
    Fields allFields = new Fields(Vehicle.FIELD_NAME, Driver.FIELD_NAME);
    FixedBatchSpout spout = new FixedBatchSpout(allFields, 10, Vehicle.generateVehicles(20));
    spout.setCycle(true);
    TridentTopology topology = new TridentTopology();
    Stream vehiclesStream = topology.newStream("spout1", spout).each(allFields, new Debug("##### vehicles"));
    Stream slowVehiclesStream = vehiclesStream.min(new SpeedComparator()).each(vehicleField, new Debug("#### slowest vehicle"));
    Stream slowDriversStream = slowVehiclesStream.project(driverField).each(driverField, new Debug("##### slowest driver"));
    vehiclesStream.max(new SpeedComparator()).each(vehicleField, new Debug("#### fastest vehicle")).project(driverField).each(driverField, new Debug("##### fastest driver"));
    vehiclesStream.minBy(Vehicle.FIELD_NAME, new EfficiencyComparator()).each(vehicleField, new Debug("#### least efficient vehicle"));
    vehiclesStream.maxBy(Vehicle.FIELD_NAME, new EfficiencyComparator()).each(vehicleField, new Debug("#### most efficient vehicle"));
    return topology.build();
}
Also used : FixedBatchSpout(storm.trident.testing.FixedBatchSpout) Fields(backtype.storm.tuple.Fields) TridentTopology(storm.trident.TridentTopology) Stream(storm.trident.Stream) Debug(storm.trident.operation.builtin.Debug)

Aggregations

Fields (backtype.storm.tuple.Fields)12 Stream (storm.trident.Stream)12 TridentTopology (storm.trident.TridentTopology)10 Values (backtype.storm.tuple.Values)7 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Debug (storm.trident.operation.builtin.Debug)5 CountAsAggregator (storm.trident.testing.CountAsAggregator)5 Split (storm.trident.testing.Split)5 InMemoryWindowsStoreFactory (storm.trident.windowing.InMemoryWindowsStoreFactory)4 WindowsStoreFactory (storm.trident.windowing.WindowsStoreFactory)4 FixedBatchSpout (storm.trident.testing.FixedBatchSpout)3 Aggregator (storm.trident.operation.Aggregator)2 CombinerAggregator (storm.trident.operation.CombinerAggregator)2 ReducerAggregator (storm.trident.operation.ReducerAggregator)2 GroupedAggregator (storm.trident.operation.impl.GroupedAggregator)2 ArrayList (java.util.ArrayList)1 RandomNumberGeneratorSpout (org.apache.storm.starter.spout.RandomNumberGeneratorSpout)1 Consumer (storm.trident.operation.Consumer)1