Search in sources :

Example 1 with CountEvictionPolicy

use of com.twitter.heron.api.windowing.evictors.CountEvictionPolicy 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)

Aggregations

Config (com.twitter.heron.api.Config)1 CountEvictionPolicy (com.twitter.heron.api.windowing.evictors.CountEvictionPolicy)1 WatermarkCountEvictionPolicy (com.twitter.heron.api.windowing.evictors.WatermarkCountEvictionPolicy)1 TimeTriggerPolicy (com.twitter.heron.api.windowing.triggers.TimeTriggerPolicy)1 WatermarkTimeTriggerPolicy (com.twitter.heron.api.windowing.triggers.WatermarkTimeTriggerPolicy)1 Test (org.junit.Test)1