/** * Returns an {@code EvictionPolicy} instance which evicts elements after a count of given window length. * * @return */ @Override public EvictionPolicy<T, ?> getEvictionPolicy() { return new CountEvictionPolicy<>(windowConfig.getWindowLength()); } }
/** * Returns an {@code EvictionPolicy} instance which evicts elements after a count of given window length. * * @return */ @Override public EvictionPolicy<T, ?> getEvictionPolicy() { return new CountEvictionPolicy<>(windowConfig.getWindowLength()); } }
private EvictionPolicy<Tuple, ?> getEvictionPolicy(Count windowLengthCount, Duration windowLengthDuration) { if (windowLengthCount != null) { if (isTupleTs()) { return new WatermarkCountEvictionPolicy<>(windowLengthCount.value); } else { return new CountEvictionPolicy<>(windowLengthCount.value); } } else { if (isTupleTs()) { return new WatermarkTimeEvictionPolicy<>(windowLengthDuration.value, maxLagMs); } else { return new TimeEvictionPolicy<>(windowLengthDuration.value); } } }
@Test public void testExpireThreshold() throws Exception { int threshold = WindowManager.EXPIRE_EVENTS_THRESHOLD; int windowLength = 5; windowManager.setEvictionPolicy(new CountEvictionPolicy<Integer>(5)); TriggerPolicy<Integer, ?> triggerPolicy = new TimeTriggerPolicy<Integer>(new Duration(1, TimeUnit.HOURS).value, windowManager); 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); }
@Test public void testTumblingWindow() throws Exception { EvictionPolicy<Integer, ?> evictionPolicy = new CountEvictionPolicy<Integer>(3); windowManager.setEvictionPolicy(evictionPolicy); TriggerPolicy<Integer, ?> triggerPolicy = new CountTriggerPolicy<Integer>(3, windowManager, evictionPolicy); triggerPolicy.start(); windowManager.setTriggerPolicy(triggerPolicy); windowManager.add(1); windowManager.add(2); // nothing expired yet assertTrue(listener.onExpiryEvents.isEmpty()); windowManager.add(3); assertTrue(listener.onExpiryEvents.isEmpty()); assertEquals(seq(1, 3), listener.onActivationEvents); assertTrue(listener.onActivationExpiredEvents.isEmpty()); assertEquals(seq(1, 3), listener.onActivationNewEvents); listener.clear(); windowManager.add(4); windowManager.add(5); windowManager.add(6); assertEquals(seq(1, 3), listener.onExpiryEvents); assertEquals(seq(4, 6), listener.onActivationEvents); assertEquals(seq(1, 3), listener.onActivationExpiredEvents); assertEquals(seq(4, 6), listener.onActivationNewEvents); }
@Test public void testCountBasedWindow() throws Exception { EvictionPolicy<Integer, ?> evictionPolicy = new CountEvictionPolicy<Integer>(5); TriggerPolicy<Integer, ?> triggerPolicy = new CountTriggerPolicy<Integer>(2, windowManager, evictionPolicy); triggerPolicy.start();
/** * Returns an {@code EvictionPolicy} instance which evicts elements after a count of given window length. * * @return */ @Override public EvictionPolicy<T> getEvictionPolicy() { return new CountEvictionPolicy<>(windowConfig.getWindowLength()); } }
/** * Returns an {@code EvictionPolicy} instance which evicts elements after a count of given window length. * * @return */ @Override public EvictionPolicy<T> getEvictionPolicy() { return new CountEvictionPolicy<>(windowConfig.getWindowLength()); } }
private EvictionPolicy<Tuple> getEvictionPolicy(Count windowLengthCount, Duration windowLengthDuration) { if (windowLengthCount != null) { if (isTupleTs()) { return new WatermarkCountEvictionPolicy<>(windowLengthCount.value); } else { return new CountEvictionPolicy<>(windowLengthCount.value); } } else { if (isTupleTs()) { return new WatermarkTimeEvictionPolicy<>(windowLengthDuration.value, maxLagMs); } else { return new TimeEvictionPolicy<>(windowLengthDuration.value); } } }