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