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);
}
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);
}
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);
}
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();
}
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();
}
Aggregations