zentol commented on a change in pull request #18692:
URL: https://github.com/apache/flink/pull/18692#discussion_r805899247



##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/highavailability/AbstractHaJobRunITCase.java
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.highavailability;
+
+import org.apache.flink.api.common.JobStatus;
+import org.apache.flink.api.common.time.Deadline;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.HighAvailabilityOptions;
+import org.apache.flink.core.fs.FileSystem;
+import org.apache.flink.core.plugin.PluginManager;
+import org.apache.flink.core.testutils.AllCallbackWrapper;
+import org.apache.flink.core.testutils.EachCallbackWrapper;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.jobgraph.JobGraphTestUtils;
+import org.apache.flink.runtime.minicluster.MiniCluster;
+import org.apache.flink.runtime.minicluster.RpcServiceSharing;
+import org.apache.flink.runtime.testutils.MiniClusterExtension;
+import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
+import org.apache.flink.runtime.zookeeper.ZooKeeperExtension;
+import org.apache.flink.testutils.TestingUtils;
+import org.apache.flink.util.TestLoggerExtension;
+import org.apache.flink.util.concurrent.FutureUtils;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import javax.annotation.Nullable;
+
+import java.time.Duration;
+import java.util.concurrent.TimeUnit;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * {@code AbstractHaJobRunITCase} runs a job storing in HA mode and provides 
{@code abstract}
+ * methods for initializing a specific {@link FileSystem}.
+ */
+@ExtendWith(TestLoggerExtension.class)
+public abstract class AbstractHaJobRunITCase {
+
+    @RegisterExtension
+    private static final AllCallbackWrapper<ZooKeeperExtension> 
ZOOKEEPER_EXTENSION =
+            new AllCallbackWrapper<>(new ZooKeeperExtension());
+
+    @RegisterExtension
+    public final EachCallbackWrapper<MiniClusterExtension> 
miniClusterExtension =
+            new EachCallbackWrapper<>(
+                    new MiniClusterExtension(
+                            new MiniClusterResourceConfiguration.Builder()
+                                    .setNumberTaskManagers(1)
+                                    .setNumberSlotsPerTaskManager(1)
+                                    
.setRpcServiceSharing(RpcServiceSharing.DEDICATED)
+                                    .setConfiguration(getFlinkConfiguration())
+                                    .build()));
+
+    private Configuration getFlinkConfiguration() {
+        Configuration config = new Configuration();
+        config.set(HighAvailabilityOptions.HA_MODE, "ZOOKEEPER");
+        config.set(
+                HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM,
+                ZOOKEEPER_EXTENSION.getCustomExtension().getConnectString());
+
+        config.set(HighAvailabilityOptions.HA_STORAGE_PATH, 
createHAStoragePath());
+
+        updateConfiguration(config);
+
+        FileSystem.initialize(config, loadPluginManager());
+        initializeStorageBackend(config);
+
+        return config;
+    }
+
+    /**
+     * Should return the path to the HA storage which will be injected into 
the Flink configuration.
+     *
+     * @see HighAvailabilityOptions#HA_STORAGE_PATH
+     */
+    protected abstract String createHAStoragePath();
+
+    /**
+     * Updates the passed {@link Configuration} to point to the {@link 
FileSystem} that's subject to
+     * test.
+     */
+    protected abstract void updateConfiguration(Configuration config);
+
+    /** Runs any additional initialization that are necessary before running 
the actual test. */
+    protected void initializeStorageBackend(Configuration config) {}
+
+    @Nullable
+    protected PluginManager loadPluginManager() {
+        // by default, no PluginManager is loaded
+        return null;
+    }
+
+    @Test
+    public void testJobExecutionInHaMode() throws Exception {
+        final MiniCluster flinkCluster = 
miniClusterExtension.getCustomExtension().getMiniCluster();
+
+        final JobGraph jobGraph = JobGraphTestUtils.singleNoOpJobGraph();
+
+        flinkCluster.runDetached(jobGraph);

Review comment:
       Although I'm curious for what event you'd be waiting on. The handler 
doesn't give you more information than running the job, does it?
   If you'd disable restarts and run the job non-detached we could simplify the 
test a bit.




-- 
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.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to