rmetzger commented on a change in pull request #14879:
URL: https://github.com/apache/flink/pull/14879#discussion_r572048718



##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/declarative/MockStateWithExecutionGraphContext.java
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.runtime.scheduler.declarative;
+
+import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor;
+import 
org.apache.flink.runtime.concurrent.ManuallyTriggeredComponentMainThreadExecutor;
+import org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph;
+
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import java.util.function.Function;
+
+class MockStateWithExecutionGraphContext implements 
StateWithExecutionGraph.Context, AutoCloseable {
+
+    private final StateValidator<ArchivedExecutionGraph> 
finishedStateValidator =
+            new StateValidator<>("finished");
+
+    Function<State, Boolean> expectedStateChecker =
+            (ign) -> {
+                throw new UnsupportedOperationException("Remember to set me");
+            };
+
+    private final ManuallyTriggeredComponentMainThreadExecutor executor =
+            new ManuallyTriggeredComponentMainThreadExecutor();

Review comment:
       I'm not sure, doesn't 
`ComponentMainThreadExecutorServiceAdapter.forMainThread` change the semantics 
of the CompletableFuture *async methods, by executing them immediately, instead 
of executing them once the current operation is done?
   
   When using the proposed executor, the 
`ExecutingTest.testTransitionToFinishedOnSuspend()` will fail, because we 
transition into Finished state twice: Once in the EG termination future 
(usually executed asynchronously), and in StateWithExecutionGraph.suspend(). 
The async state transition is guarded by a check if the state is still the 
same, hence it will be ignored when the termination future is executed 
asynchronously.
   
   Using the `ManuallyTriggeredComponentMainThreadExecutor` allows us to 
guarantee that all async operations, which might potentially perform state 
transitions etc. happen before we do the final check of the state transitions 
in the close() method.
   
   We could of course also guard the transition to finished in suspend() with a 
state check, but that should not be necessary under the normal semantics.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to