@Override public Instant getWatermarkThatGuaranteesFiring(BoundedWindow window) { // This trigger will fire at least once when the first trigger in the sequence // fires at least once. return subTriggers.get(0).getWatermarkThatGuaranteesFiring(window); }
@Override public final OnceTrigger getContinuationTrigger() { Trigger continuation = super.getContinuationTrigger(); if (!(continuation instanceof OnceTrigger)) { throw new IllegalStateException("Continuation of a OnceTrigger must be a OnceTrigger"); } return (OnceTrigger) continuation; } }
/** * <b><i>For internal use only; no backwards-compatibility guarantees.</i></b> * * <p>Returns whether this performs the same triggering as the given {@link Trigger}. */ @Internal public boolean isCompatible(Trigger other) { if (!getClass().equals(other.getClass())) { return false; } if (subTriggers == null) { return other.subTriggers == null; } else if (other.subTriggers == null) { return false; } else if (subTriggers.size() != other.subTriggers.size()) { return false; } for (int i = 0; i < subTriggers.size(); i++) { if (!subTriggers.get(i).isCompatible(other.subTriggers.get(i))) { return false; } } return true; }
@Test public void testFromEndOfWindowToString() { Trigger trigger = AfterWatermark.pastEndOfWindow(); assertEquals("AfterWatermark.pastEndOfWindow()", trigger.toString()); }
@Override public boolean equals(Object object) { if (!(object instanceof WindowingStrategy)) { return false; } WindowingStrategy<?, ?> other = (WindowingStrategy<?, ?>) object; return isAllowedLatenessSpecified() == other.isAllowedLatenessSpecified() && isModeSpecified() == other.isModeSpecified() && isTimestampCombinerSpecified() == other.isTimestampCombinerSpecified() && getMode().equals(other.getMode()) && getAllowedLateness().equals(other.getAllowedLateness()) && getClosingBehavior().equals(other.getClosingBehavior()) && getOnTimeBehavior().equals(other.getOnTimeBehavior()) && getTrigger().equals(other.getTrigger()) && getTimestampCombiner().equals(other.getTimestampCombiner()) && getWindowFn().equals(other.getWindowFn()); }
case OR_FINALLY: return fromProto(triggerProto.getOrFinally().getMain()) .orFinally((OnceTrigger) fromProto(triggerProto.getOrFinally().getFinally())); case REPEAT: return Repeatedly.forever(fromProto(triggerProto.getRepeat().getSubtrigger()));
@Test public void testToString() { Trigger trigger = new ReshuffleTrigger<>(); assertEquals("ReshuffleTrigger()", trigger.toString()); } }
@Override public Instant getWatermarkThatGuaranteesFiring(BoundedWindow window) { // This trigger fires once the repeated trigger fires. return subTriggers.get(REPEATED).getWatermarkThatGuaranteesFiring(window); }
@Test public void testToString() { Trigger trigger = AfterPane.elementCountAtLeast(5); assertEquals("AfterPane.elementCountAtLeast(5)", trigger.toString()); } }
/** * Return a trigger to use after a {@link GroupByKey} to preserve the intention of this trigger. * Specifically, triggers that are time based and intended to provide speculative results should * continue providing speculative results. Triggers that fire once (or multiple times) should * continue firing once (or multiple times). * * <p>If this method is not overridden, its default implementation delegates its behavior to * {@link #getContinuationTrigger(List)} which is expected to be implemented by subclasses. */ public Trigger getContinuationTrigger() { if (subTriggers == null) { return getContinuationTrigger(null); } List<Trigger> subTriggerContinuations = new ArrayList<>(); for (Trigger subTrigger : subTriggers) { subTriggerContinuations.add(subTrigger.getContinuationTrigger()); } return getContinuationTrigger(subTriggerContinuations); }
if (!windowingStrategy.getTrigger().isCompatible(other.getTrigger())) { throw new IllegalStateException( "Inputs to Flatten had incompatible triggers: "
@Override public Instant getWatermarkThatGuaranteesFiring(BoundedWindow window) { // This trigger fires once either the trigger or the until trigger fires. Instant actualDeadline = subTriggers.get(ACTUAL).getWatermarkThatGuaranteesFiring(window); Instant untilDeadline = subTriggers.get(UNTIL).getWatermarkThatGuaranteesFiring(window); return actualDeadline.isBefore(untilDeadline) ? actualDeadline : untilDeadline; }
@Test public void testToString() { Trigger trigger = AfterProcessingTime.pastFirstElementInPane(); assertEquals("AfterProcessingTime.pastFirstElementInPane()", trigger.toString()); }
@Test public void testContinuation() throws Exception { Trigger trigger = AfterProcessingTime.pastFirstElementInPane(); Trigger repeatedly = Repeatedly.forever(trigger); assertEquals( Repeatedly.forever(trigger.getContinuationTrigger()), repeatedly.getContinuationTrigger()); assertEquals( Repeatedly.forever(trigger.getContinuationTrigger().getContinuationTrigger()), repeatedly.getContinuationTrigger().getContinuationTrigger()); }
/** Basic test of compatibility check between identical triggers. */ @Test public void testCompatibilityIdentical() throws Exception { Trigger t1 = AfterProcessingTime.pastFirstElementInPane().plusDelayOf(Duration.standardMinutes(1L)); Trigger t2 = AfterProcessingTime.pastFirstElementInPane().plusDelayOf(Duration.standardMinutes(1L)); assertTrue(t1.isCompatible(t2)); }
@Override public Instant getWatermarkThatGuaranteesFiring(BoundedWindow window) { // This trigger will fire after the earliest of its sub-triggers. Instant deadline = BoundedWindow.TIMESTAMP_MAX_VALUE; for (Trigger subTrigger : subTriggers) { Instant subDeadline = subTrigger.getWatermarkThatGuaranteesFiring(window); if (deadline.isAfter(subDeadline)) { deadline = subDeadline; } } return deadline; }
@Test public void testToString() { Trigger trigger = Repeatedly.forever( new StubTrigger() { @Override public String toString() { return "innerTrigger"; } }); assertEquals("Repeatedly.forever(innerTrigger)", trigger.toString()); } }
@Test public void testContinuation() throws Exception { assertEquals(underTest, underTest.getContinuationTrigger()); } }
public static <W extends BoundedWindow> WatermarkCallback onGuaranteedFiring( BoundedWindow window, WindowingStrategy<?, W> strategy, Runnable callback) { @SuppressWarnings("unchecked") Instant firingAfter = strategy.getTrigger().getWatermarkThatGuaranteesFiring((W) window); return new WatermarkCallback(firingAfter, callback); }
@Test public void testLateFiringsToString() { Trigger trigger = AfterWatermark.pastEndOfWindow().withLateFirings(StubTrigger.named("t1")); assertEquals("AfterWatermark.pastEndOfWindow().withLateFirings(t1)", trigger.toString()); }