use of org.joda.time.ReadableInstant in project beam by apache.
the class WindowFnTestUtils method validateGetOutputTimestamps.
/**
* Verifies that later-ending merged windows from any of the timestamps hold up output of
* earlier-ending windows, using the provided {@link WindowFn} and {@link TimestampCombiner}.
*
* <p>Given a list of lists of timestamps, where each list is expected to merge into a single
* window with end times in ascending order, assigns and merges windows for each list (as though
* each were a separate key/user session). Then combines each timestamp in the list according to
* the provided {@link TimestampCombiner}.
*
* <p>Verifies that a overlapping windows do not hold each other up via the watermark.
*/
public static <T, W extends IntervalWindow> void validateGetOutputTimestamps(WindowFn<T, W> windowFn, TimestampCombiner timestampCombiner, List<List<Long>> timestampsPerWindow) throws Exception {
// Assign windows to each timestamp, then merge them, storing the merged windows in
// a list in corresponding order to timestampsPerWindow
final List<W> windows = new ArrayList<>();
for (List<Long> timestampsForWindow : timestampsPerWindow) {
final Set<W> windowsToMerge = new HashSet<>();
for (long timestamp : timestampsForWindow) {
windowsToMerge.addAll(WindowFnTestUtils.<T, W>assignedWindows(windowFn, timestamp));
}
windowFn.mergeWindows(windowFn.new MergeContext() {
@Override
public Collection<W> windows() {
return windowsToMerge;
}
@Override
public void merge(Collection<W> toBeMerged, W mergeResult) throws Exception {
windows.add(mergeResult);
}
});
}
// Map every list of input timestamps to an output timestamp
final List<Instant> combinedOutputTimestamps = new ArrayList<>();
for (int i = 0; i < timestampsPerWindow.size(); ++i) {
List<Long> timestampsForWindow = timestampsPerWindow.get(i);
W window = windows.get(i);
List<Instant> outputInstants = new ArrayList<>();
for (long inputTimestamp : timestampsForWindow) {
outputInstants.add(assignOutputTime(timestampCombiner, new Instant(inputTimestamp), window));
}
combinedOutputTimestamps.add(combineOutputTimes(timestampCombiner, outputInstants));
}
// Consider windows in increasing order of max timestamp; ensure the output timestamp is after
// the max timestamp of the previous
@Nullable W earlierEndingWindow = null;
for (int i = 0; i < windows.size(); ++i) {
W window = windows.get(i);
ReadableInstant outputTimestamp = combinedOutputTimestamps.get(i);
if (earlierEndingWindow != null) {
assertThat(outputTimestamp, greaterThan((ReadableInstant) earlierEndingWindow.maxTimestamp()));
}
earlierEndingWindow = window;
}
}
use of org.joda.time.ReadableInstant in project beam by apache.
the class LateDataUtilsTest method garbageCollectionTimeAfterEndOfGlobalWindowWithLateness.
@Test
public void garbageCollectionTimeAfterEndOfGlobalWindowWithLateness() {
FixedWindows windowFn = FixedWindows.of(Duration.standardMinutes(5));
Duration allowedLateness = Duration.millis(Long.MAX_VALUE);
WindowingStrategy<?, ?> strategy = WindowingStrategy.globalDefault().withWindowFn(windowFn).withAllowedLateness(allowedLateness);
IntervalWindow window = windowFn.assignWindow(new Instant(-100));
assertThat(window.maxTimestamp().plus(allowedLateness), Matchers.<ReadableInstant>greaterThan(GlobalWindow.INSTANCE.maxTimestamp()));
assertThat(LateDataUtils.garbageCollectionTime(window, strategy), equalTo(GlobalWindow.INSTANCE.maxTimestamp()));
}
Aggregations