use of org.apache.storm.streams.operations.aggregators.Count in project storm by apache.
the class StreamBuilderTest method testRepartition.
@Test
public void testRepartition() throws Exception {
Stream<String> stream = streamBuilder.newStream(newSpout(Utils.DEFAULT_STREAM_ID), new ValueMapper<>(0));
stream.repartition(3).filter(x -> true).repartition(2).filter(x -> true).aggregate(new Count<>());
StormTopology topology = streamBuilder.build();
assertEquals(1, topology.get_spouts_size());
SpoutSpec spout = topology.get_spouts().get("spout1");
assertEquals(4, topology.get_bolts_size());
Bolt bolt1 = topology.get_bolts().get("bolt1");
Bolt bolt2 = topology.get_bolts().get("bolt2");
Bolt bolt3 = topology.get_bolts().get("bolt3");
Bolt bolt4 = topology.get_bolts().get("bolt4");
assertEquals(1, spout.get_common().get_parallelism_hint());
assertEquals(1, bolt1.get_common().get_parallelism_hint());
assertEquals(3, bolt2.get_common().get_parallelism_hint());
assertEquals(2, bolt3.get_common().get_parallelism_hint());
assertEquals(2, bolt4.get_common().get_parallelism_hint());
}
use of org.apache.storm.streams.operations.aggregators.Count in project storm by apache.
the class WindowedProcessorBoltTest method testEmit.
@Test
public void testEmit() throws Exception {
Window<?, ?> window = TumblingWindows.of(BaseWindowedBolt.Count.of(2));
setUpWindowedProcessorBolt(new AggregateProcessor<>(new Count<>()), window);
bolt.execute(getMockTupleWindow(mockTuple1, mockTuple2, mockTuple3));
ArgumentCaptor<Values> values = ArgumentCaptor.forClass(Values.class);
ArgumentCaptor<String> os = ArgumentCaptor.forClass(String.class);
Mockito.verify(mockOutputCollector, Mockito.times(2)).emit(os.capture(), values.capture());
assertEquals("outputstream", os.getAllValues().get(0));
assertEquals(new Values(3L), values.getAllValues().get(0));
assertEquals("outputstream__punctuation", os.getAllValues().get(1));
assertEquals(new Values(WindowNode.PUNCTUATION), values.getAllValues().get(1));
}
Aggregations