You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "gaoyunhaii (via GitHub)" <gi...@apache.org> on 2023/04/06 00:58:51 UTC

[GitHub] [flink] gaoyunhaii commented on a diff in pull request #21736: [FLINK-27518][tests] Refactor migration tests to support version update automatically

gaoyunhaii commented on code in PR #21736:
URL: https://github.com/apache/flink/pull/21736#discussion_r1159187859


##########
flink-test-utils-parent/flink-migration-test-utils/src/main/java/org/apache/flink/test/migration/MigrationTestsSnapshotGenerator.java:
##########
@@ -0,0 +1,253 @@
+/*
+ * 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.migration;
+
+import org.apache.flink.FlinkVersion;
+import org.apache.flink.test.util.MigrationTest;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * This class aims to generate the snapshots for all the state migration tests. A migration test
+ * should implement {@link MigrationTest} interface and its name should match {@code
+ * *(Test|ITCase)(.java|.scala)}. For scala tests, we also require the class name is the same with
+ * the containing filename.
+ */
+public class MigrationTestsSnapshotGenerator {
+
+    private static final Logger LOG =
+            LoggerFactory.getLogger(MigrationTestsSnapshotGenerator.class);
+
+    private static final String DEFAULT_PATH_PREFIXES = "src/test/java,src/test/scala";
+
+    private static final Option OPTION_HELP =
+            Option.builder()
+                    .longOpt("help")
+                    .required(false)
+                    .hasArg(false)
+                    .desc("print this help information.")
+                    .build();
+
+    private static final Option OPTION_DIR =
+            Option.builder()
+                    .longOpt("dir")
+                    .required()
+                    .hasArg()
+                    .desc("The root directory for scanning. Required.")
+                    .build();
+
+    private static final Option OPTION_VERSION =
+            Option.builder()
+                    .longOpt("version")
+                    .required()
+                    .hasArg()
+                    .desc("The version to generate. Required.")
+                    .build();
+
+    private static final Option OPTION_PREFIXES =
+            Option.builder()
+                    .longOpt("prefixes")
+                    .required(false)
+                    .hasArg()
+                    .desc(
+                            "The prefix paths to scan under the root directory, separated by \",\". Default to \""
+                                    + DEFAULT_PATH_PREFIXES
+                                    + "\"")
+                    .build();
+
+    private static final Option OPTION_CLASSES =
+            Option.builder()
+                    .longOpt("classes")
+                    .required(false)
+                    .hasArg()
+                    .desc(
+                            "The specified qualified class name to generate test data, "
+                                    + "separated by \",\". This option has a higher priority than the prefix option.")
+                    .build();
+
+    private static final Pattern VERSION_PATTERN = Pattern.compile("v?([0-9]+)[._]([0-9]+)");
+
+    private static final String CLASS_NAME_GROUP = "className";
+    private static final Pattern CLASS_NAME_PATTERN =
+            Pattern.compile("(?<" + CLASS_NAME_GROUP + ">[a-zA-Z0-9]*(Test|ITCase))(.java|.scala)");
+
+    public static void main(String[] args) {
+        for (String s : args) {
+            if (s.equals("--" + OPTION_HELP.getLongOpt())) {
+                HelpFormatter helpFormatter = new HelpFormatter();
+                helpFormatter.setOptionComparator(null);
+                helpFormatter.printHelp(
+                        "java " + MigrationTestsSnapshotGenerator.class.getName(), createOptions());
+                return;
+            }
+        }

Review Comment:
   It might not work since during the parameter parsing, the commons-cli will look for the required parameters and throws exception if the required parameters is not found. 
   
   I then added the explicit comments for this issue. 



-- 
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-unsubscribe@flink.apache.org

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