Search in sources :

Example 71 with Config

use of org.apache.heron.api.Config in project heron by twitter.

the class WindowManagerTest method testTimeBasedWindowExpiry.

@Test
public void testTimeBasedWindowExpiry() throws Exception {
    EvictionPolicy<Integer, ?> evictionPolicy = new TimeEvictionPolicy<Integer>(Duration.ofMillis(100).toMillis());
    windowManager.setEvictionPolicy(evictionPolicy);
    /*
         * Don't wait for Timetrigger to fire since this could lead to timing issues in unit tests.
         * Set it to a large value and trigger manually.
          */
    TriggerPolicy<Integer, ?> triggerPolicy = new TimeTriggerPolicy<Integer>(Duration.ofDays(1).toMillis());
    triggerPolicy.setTriggerHandler(windowManager);
    triggerPolicy.setEvictionPolicy(evictionPolicy);
    triggerPolicy.setTopologyConfig(new Config());
    triggerPolicy.start();
    windowManager.setTriggerPolicy(triggerPolicy);
    long now = System.currentTimeMillis();
    // add 10 events
    for (int i : seq(1, 10)) {
        windowManager.add(i);
    }
    // simulate the time trigger by setting the reference time and invoking onTrigger() manually
    evictionPolicy.setContext(new DefaultEvictionContext(now + 60));
    windowManager.onTrigger();
    assertEquals(seq(1, 10), listener.onActivationEvents);
    assertTrue(listener.onActivationExpiredEvents.isEmpty());
    listener.clear();
    // wait so all events expire
    evictionPolicy.setContext(new DefaultEvictionContext(now + 120));
    windowManager.onTrigger();
    assertEquals(seq(1, 10), listener.onExpiryEvents);
    assertTrue(listener.onActivationEvents.isEmpty());
    listener.clear();
    evictionPolicy.setContext(new DefaultEvictionContext(now + 180));
    windowManager.onTrigger();
    assertTrue(listener.onActivationExpiredEvents.isEmpty());
    assertTrue(listener.onActivationEvents.isEmpty());
}
Also used : WatermarkTimeEvictionPolicy(org.apache.heron.api.windowing.evictors.WatermarkTimeEvictionPolicy) TimeEvictionPolicy(org.apache.heron.api.windowing.evictors.TimeEvictionPolicy) WatermarkTimeTriggerPolicy(org.apache.heron.api.windowing.triggers.WatermarkTimeTriggerPolicy) TimeTriggerPolicy(org.apache.heron.api.windowing.triggers.TimeTriggerPolicy) Config(org.apache.heron.api.Config) Test(org.junit.Test)

Example 72 with Config

use of org.apache.heron.api.Config in project heron by twitter.

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 : WatermarkTimeTriggerPolicy(org.apache.heron.api.windowing.triggers.WatermarkTimeTriggerPolicy) TimeTriggerPolicy(org.apache.heron.api.windowing.triggers.TimeTriggerPolicy) Config(org.apache.heron.api.Config) CountEvictionPolicy(org.apache.heron.api.windowing.evictors.CountEvictionPolicy) WatermarkCountEvictionPolicy(org.apache.heron.api.windowing.evictors.WatermarkCountEvictionPolicy) Test(org.junit.Test)

Example 73 with Config

use of org.apache.heron.api.Config in project heron by twitter.

the class ConfigUtils method translateConfig.

/**
 * Translate storm config to heron config for topology
 * @param stormConfig the storm config
 * @return a heron config
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Config translateConfig(Map stormConfig) {
    Config heronConfig;
    if (stormConfig != null) {
        heronConfig = new Config((Map<String, Object>) stormConfig);
    } else {
        heronConfig = new Config();
    }
    // Look at serialization stuff first
    doSerializationTranslation(heronConfig);
    // Now look at supported apis
    doStormTranslation(heronConfig);
    doTaskHooksTranslation(heronConfig);
    doTopologyLevelTranslation(heronConfig);
    return heronConfig;
}
Also used : Config(org.apache.heron.api.Config) Map(java.util.Map)

Example 74 with Config

use of org.apache.heron.api.Config in project heron by twitter.

the class ConfigUtils method translateComponentConfig.

/**
 * Translate storm config to heron config for components
 * @param stormConfig the storm config
 * @return a heron config
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Config translateComponentConfig(Map stormConfig) {
    Config heronConfig;
    if (stormConfig != null) {
        heronConfig = new Config((Map<String, Object>) stormConfig);
    } else {
        heronConfig = new Config();
    }
    doStormTranslation(heronConfig);
    return heronConfig;
}
Also used : Config(org.apache.heron.api.Config) Map(java.util.Map)

Aggregations

Config (org.apache.heron.api.Config)74 Test (org.junit.Test)35 TopologyBuilder (org.apache.heron.api.topology.TopologyBuilder)21 HashMap (java.util.HashMap)16 EcoTopologyDefinition (org.apache.heron.eco.definition.EcoTopologyDefinition)10 TreeMap (java.util.TreeMap)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 FileInputStream (java.io.FileInputStream)8 InputStream (java.io.InputStream)8 Fields (org.apache.heron.api.tuple.Fields)7 EcoParser (org.apache.heron.eco.parser.EcoParser)7 Map (java.util.Map)6 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)6 ByteAmount (org.apache.heron.common.basics.ByteAmount)6 Simulator (org.apache.heron.simulator.Simulator)6 LinkedList (java.util.LinkedList)5 List (java.util.List)5 TopologyContext (org.apache.heron.api.topology.TopologyContext)5 Tuple (org.apache.heron.api.tuple.Tuple)5 TestWordSpout (org.apache.heron.examples.api.spout.TestWordSpout)5