Search in sources :

Example 51 with Config

use of com.twitter.heron.api.Config in project incubator-heron by apache.

the class WindowManagerTest method testExpireThreshold.

@Test
public void testExpireThreshold() throws Exception {
    int threshold = WindowManager.EXPIRE_EVENTS_THRESHOLD;
    int windowLength = 5;
    CountEvictionPolicy<Integer> countEvictionPolicy = new CountEvictionPolicy<Integer>(5);
    windowManager.setEvictionPolicy(countEvictionPolicy);
    TriggerPolicy<Integer, ?> triggerPolicy = new TimeTriggerPolicy<Integer>(Duration.ofHours(1).toMillis());
    triggerPolicy.setEvictionPolicy(countEvictionPolicy);
    triggerPolicy.setTriggerHandler(windowManager);
    triggerPolicy.setTopologyConfig(new Config());
    triggerPolicy.start();
    windowManager.setTriggerPolicy(triggerPolicy);
    for (int i : seq(1, 5)) {
        windowManager.add(i);
    }
    // nothing expired yet
    assertTrue(listener.onExpiryEvents.isEmpty());
    for (int i : seq(6, 10)) {
        windowManager.add(i);
    }
    for (int i : seq(11, threshold)) {
        windowManager.add(i);
    }
    // window should be compacted and events should be expired.
    assertEquals(seq(1, threshold - windowLength), listener.onExpiryEvents);
}
Also used : TimeTriggerPolicy(com.twitter.heron.api.windowing.triggers.TimeTriggerPolicy) WatermarkTimeTriggerPolicy(com.twitter.heron.api.windowing.triggers.WatermarkTimeTriggerPolicy) Config(com.twitter.heron.api.Config) CountEvictionPolicy(com.twitter.heron.api.windowing.evictors.CountEvictionPolicy) WatermarkCountEvictionPolicy(com.twitter.heron.api.windowing.evictors.WatermarkCountEvictionPolicy) Test(org.junit.Test)

Example 52 with Config

use of com.twitter.heron.api.Config in project incubator-heron by apache.

the class GeneralReduceByKeyAndWindowOperatorTest method getReduceByWindowOperator.

@SuppressWarnings({ "rawtypes", "unchecked" })
private GeneralReduceByKeyAndWindowOperator<String, KeyValue<String, Integer>, Integer> getReduceByWindowOperator(Integer identity) {
    GeneralReduceByKeyAndWindowOperator<String, KeyValue<String, Integer>, Integer> reduceByWindowOperator = new GeneralReduceByKeyAndWindowOperator<>(x -> x.getKey(), identity, (o, o2) -> o + o2.getValue());
    reduceByWindowOperator.prepare(new Config(), PowerMockito.mock(TopologyContext.class), new OutputCollector(new IOutputCollector() {

        @Override
        public void reportError(Throwable error) {
        }

        @Override
        public List<Integer> emit(String streamId, Collection<Tuple> anchors, List<Object> tuple) {
            emittedTuples.addAll(tuple);
            return null;
        }

        @Override
        public void emitDirect(int taskId, String streamId, Collection<Tuple> anchors, List<Object> tuple) {
        }

        @Override
        public void ack(Tuple input) {
        }

        @Override
        public void fail(Tuple input) {
        }
    }));
    return reduceByWindowOperator;
}
Also used : IOutputCollector(com.twitter.heron.api.bolt.IOutputCollector) OutputCollector(com.twitter.heron.api.bolt.OutputCollector) KeyValue(com.twitter.heron.streamlet.KeyValue) Config(com.twitter.heron.api.Config) IOutputCollector(com.twitter.heron.api.bolt.IOutputCollector) Collection(java.util.Collection) List(java.util.List) LinkedList(java.util.LinkedList) TopologyContext(com.twitter.heron.api.topology.TopologyContext) Tuple(com.twitter.heron.api.tuple.Tuple)

Example 53 with Config

use of com.twitter.heron.api.Config in project incubator-heron by apache.

the class ReduceByKeyAndWindowOperatorTest method getReduceByWindowOperator.

@SuppressWarnings({ "rawtypes", "unchecked" })
private ReduceByKeyAndWindowOperator<String, Integer, String> getReduceByWindowOperator() {
    ReduceByKeyAndWindowOperator<String, Integer, String> reduceByWindowOperator = new ReduceByKeyAndWindowOperator<>(x -> x, x -> 1, (o, o2) -> o + o2);
    reduceByWindowOperator.prepare(new Config(), PowerMockito.mock(TopologyContext.class), new OutputCollector(new IOutputCollector() {

        @Override
        public void reportError(Throwable error) {
        }

        @Override
        public List<Integer> emit(String streamId, Collection<Tuple> anchors, List<Object> tuple) {
            emittedTuples.addAll(tuple);
            return null;
        }

        @Override
        public void emitDirect(int taskId, String streamId, Collection<Tuple> anchors, List<Object> tuple) {
        }

        @Override
        public void ack(Tuple input) {
        }

        @Override
        public void fail(Tuple input) {
        }
    }));
    return reduceByWindowOperator;
}
Also used : IOutputCollector(com.twitter.heron.api.bolt.IOutputCollector) OutputCollector(com.twitter.heron.api.bolt.OutputCollector) Config(com.twitter.heron.api.Config) IOutputCollector(com.twitter.heron.api.bolt.IOutputCollector) Collection(java.util.Collection) List(java.util.List) LinkedList(java.util.LinkedList) TopologyContext(com.twitter.heron.api.topology.TopologyContext) Tuple(com.twitter.heron.api.tuple.Tuple)

Example 54 with Config

use of com.twitter.heron.api.Config in project incubator-heron by apache.

the class TopologyUtilsTest method testGetComponentParallelism.

@Test
public void testGetComponentParallelism() {
    int componentParallelism = 4;
    Config topologyConfig = new Config();
    Map<String, Integer> spouts = new HashMap<>();
    spouts.put("spout", componentParallelism);
    Map<String, Integer> bolts = new HashMap<>();
    bolts.put("bolt", componentParallelism);
    TopologyAPI.Topology topology = TopologyTests.createTopology("testTopology", topologyConfig, spouts, bolts);
    Map<String, Integer> componentParallelismMap = TopologyUtils.getComponentParallelism(topology);
    Assert.assertEquals(componentParallelism, componentParallelismMap.get("spout").intValue());
    Assert.assertEquals(componentParallelism, componentParallelismMap.get("bolt").intValue());
}
Also used : HashMap(java.util.HashMap) Config(com.twitter.heron.api.Config) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) Test(org.junit.Test)

Example 55 with Config

use of com.twitter.heron.api.Config in project incubator-heron by apache.

the class TopologyUtilsTest method testGetComponentCpuMapSomeCpuSpecified.

@Test
public void testGetComponentCpuMapSomeCpuSpecified() {
    int componentParallelism = 2;
    Config topologyConfig = new Config();
    Map<String, Integer> spouts = new HashMap<>();
    spouts.put("spout", componentParallelism);
    Map<String, Integer> bolts = new HashMap<>();
    bolts.put("bolt", componentParallelism);
    double spoutCpu = 2.0f;
    topologyConfig.setComponentCpu("spout", spoutCpu);
    // sort the component cpu map
    Map<String, Double> cpuMap = new TreeMap<>(TopologyUtils.getComponentCpuMapConfig(TopologyTests.createTopology("test", topologyConfig, spouts, bolts)));
    // Component cpu map sets only spout's cpu
    Assert.assertArrayEquals(new String[] { "spout" }, cpuMap.keySet().toArray());
    Assert.assertArrayEquals(new Double[] { spoutCpu }, cpuMap.values().toArray());
}
Also used : HashMap(java.util.HashMap) Config(com.twitter.heron.api.Config) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Aggregations

Config (com.twitter.heron.api.Config)80 Test (org.junit.Test)39 TopologyBuilder (com.twitter.heron.api.topology.TopologyBuilder)25 HashMap (java.util.HashMap)22 Fields (com.twitter.heron.api.tuple.Fields)14 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)12 EcoTopologyDefinition (com.twitter.heron.eco.definition.EcoTopologyDefinition)12 TreeMap (java.util.TreeMap)12 ByteAmount (com.twitter.heron.common.basics.ByteAmount)9 FileInputStream (java.io.FileInputStream)9 EcoParser (com.twitter.heron.eco.parser.EcoParser)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 InputStream (java.io.InputStream)8 Map (java.util.Map)6 TopologyArgParser (com.github.ashvina.common.TopologyArgParser)5 TopologyContext (com.twitter.heron.api.topology.TopologyContext)5 Tuple (com.twitter.heron.api.tuple.Tuple)5 TestTopologyBuilder (com.twitter.heron.integration_test.core.TestTopologyBuilder)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4