[
https://issues.apache.org/jira/browse/FLINK-9902?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16550542#comment-16550542
]
ASF GitHub Bot commented on FLINK-9902:
---------------------------------------
Github user StefanRRichter commented on a diff in the pull request:
https://github.com/apache/flink/pull/6376#discussion_r203981882
--- Diff:
flink-tests/src/test/java/org/apache/flink/test/checkpointing/utils/ValidatingSink.java
---
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.test.checkpointing.utils;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.streaming.api.TimeCharacteristic;
+import org.apache.flink.streaming.api.checkpoint.ListCheckpointed;
+import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
+import org.apache.flink.test.util.SuccessException;
+
+import javax.annotation.Nonnull;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Generalized sink for validation of window checkpointing IT cases.
+ */
+public class ValidatingSink<T> extends RichSinkFunction<T>
+ implements ListCheckpointed<HashMap<Long, Integer>> {
+
+ /**
+ * Function to check if the window counts are as expected.
+ */
+ @FunctionalInterface
+ public interface ResultChecker extends Serializable {
+ boolean checkResult(Map<Long, Integer> windowCounts);
+ }
+
+ /**
+ * Function that updates the window counts from an update event.
+ *
+ * @param <T> type of the update event.
+ */
+ public interface CountUpdater<T> extends Serializable {
+ void updateCount(T update, Map<Long, Integer> windowCounts);
+ }
+
+ @Nonnull
+ private final ResultChecker resultChecker;
+
+ @Nonnull
+ private final CountUpdater<T> countUpdater;
+
+ @Nonnull
+ private final HashMap<Long, Integer> windowCounts;
+
+ private final boolean usingProcessingTime;
+
+ public ValidatingSink(
+ @Nonnull CountUpdater<T> countUpdater,
+ @Nonnull ResultChecker resultChecker) {
+ this(countUpdater, resultChecker, TimeCharacteristic.EventTime);
+ }
+
+ public ValidatingSink(
+ @Nonnull CountUpdater<T> countUpdater,
+ @Nonnull ResultChecker resultChecker,
+ @Nonnull TimeCharacteristic timeCharacteristic) {
+
+ this.resultChecker = resultChecker;
+ this.countUpdater = countUpdater;
+ this.usingProcessingTime = TimeCharacteristic.ProcessingTime ==
timeCharacteristic;
+ this.windowCounts = new HashMap<>();
+ }
+
+ @Override
+ public void open(Configuration parameters) throws Exception {
+ // this sink can only work with DOP 1
+ assertEquals(1,
getRuntimeContext().getNumberOfParallelSubtasks());
+ if (usingProcessingTime &&
resultChecker.checkResult(windowCounts)) {
--- End diff --
Was also not 100% sure if this is needed. My reason was that in theory we
could have restored from a checkpoint of a completed job that will not emit
events, and we will not get into `close()` unless we somehow fire a
`SuccessException`.
> Improve and refactor window checkpointing IT cases
> --------------------------------------------------
>
> Key: FLINK-9902
> URL: https://issues.apache.org/jira/browse/FLINK-9902
> Project: Flink
> Issue Type: Test
> Components: State Backends, Checkpointing
> Affects Versions: 1.6.0
> Reporter: Stefan Richter
> Assignee: Stefan Richter
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.6.0, 1.7.0
>
>
> Windowing IT cases currently have a lot of duplicated code that could be
> unified and deduplicated. Furthermore, the test will also not fail on
> problems with timer snapshots because either there are no timers in the
> snapshot or all timers will still be re-inserted before they trigger. We can
> cover timers as well if we change this.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)