You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ch...@apache.org on 2022/09/15 09:14:19 UTC

[flink-connector-elasticsearch] branch main updated: [hotfix] Deduplicate TestUtils

This is an automated email from the ASF dual-hosted git repository.

chesnay pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/flink-connector-elasticsearch.git


The following commit(s) were added to refs/heads/main by this push:
     new 94ab432  [hotfix] Deduplicate TestUtils
94ab432 is described below

commit 94ab432a550f4c9bb1188800e8b3e2a7a16a8f59
Author: Chesnay Schepler <ch...@apache.org>
AuthorDate: Thu Sep 15 10:22:43 2022 +0200

    [hotfix] Deduplicate TestUtils
---
 .../org/apache/flink/tests/util/TestUtils.java     | 85 ----------------------
 .../streaming/tests/Elasticsearch6SinkE2ECase.java | 10 ++-
 .../streaming/tests/Elasticsearch7SinkE2ECase.java | 10 ++-
 3 files changed, 12 insertions(+), 93 deletions(-)

diff --git a/flink-connector-elasticsearch-e2e-tests/flink-connector-elasticsearch-e2e-tests-common/src/main/java/org/apache/flink/tests/util/TestUtils.java b/flink-connector-elasticsearch-e2e-tests/flink-connector-elasticsearch-e2e-tests-common/src/main/java/org/apache/flink/tests/util/TestUtils.java
deleted file mode 100644
index 980aaa9..0000000
--- a/flink-connector-elasticsearch-e2e-tests/flink-connector-elasticsearch-e2e-tests-common/src/main/java/org/apache/flink/tests/util/TestUtils.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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.tests.util;
-
-import org.apache.flink.test.parameters.ParameterProperty;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.List;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-/** General test utilities. */
-public enum TestUtils {
-    ;
-
-    private static final ParameterProperty<Path> MODULE_DIRECTORY =
-            new ParameterProperty<>("moduleDir", Paths::get);
-
-    /**
-     * Searches for a resource file matching the given regex in the given directory. This method is
-     * primarily intended to be used for the initialization of static {@link Path} fields for
-     * resource file(i.e. jar, config file) that reside in the modules {@code target} directory.
-     *
-     * @param resourceNameRegex regex pattern to match against
-     * @return Path pointing to the matching jar
-     * @throws RuntimeException if none or multiple resource files could be found
-     */
-    public static Path getResource(final String resourceNameRegex) {
-        // if the property is not set then we are most likely running in the IDE, where the working
-        // directory is the
-        // module of the test that is currently running, which is exactly what we want
-        Path moduleDirectory = MODULE_DIRECTORY.get(Paths.get("").toAbsolutePath());
-
-        try (Stream<Path> dependencyResources = Files.walk(moduleDirectory)) {
-            final List<Path> matchingResources =
-                    dependencyResources
-                            .filter(
-                                    jar ->
-                                            Pattern.compile(resourceNameRegex)
-                                                    .matcher(jar.toAbsolutePath().toString())
-                                                    .find())
-                            .collect(Collectors.toList());
-            switch (matchingResources.size()) {
-                case 0:
-                    throw new RuntimeException(
-                            new FileNotFoundException(
-                                    String.format(
-                                            "No resource file could be found that matches the pattern %s. "
-                                                    + "This could mean that the test module must be rebuilt via maven.",
-                                            resourceNameRegex)));
-                case 1:
-                    return matchingResources.get(0);
-                default:
-                    throw new RuntimeException(
-                            new IOException(
-                                    String.format(
-                                            "Multiple resource files were found matching the pattern %s. Matches=%s",
-                                            resourceNameRegex, matchingResources)));
-            }
-        } catch (final IOException ioe) {
-            throw new RuntimeException("Could not search for resource resource files.", ioe);
-        }
-    }
-}
diff --git a/flink-connector-elasticsearch-e2e-tests/flink-connector-elasticsearch6-e2e-tests/src/test/java/org/apache/flink/streaming/tests/Elasticsearch6SinkE2ECase.java b/flink-connector-elasticsearch-e2e-tests/flink-connector-elasticsearch6-e2e-tests/src/test/java/org/apache/flink/streaming/tests/Elasticsearch6SinkE2ECase.java
index c4d401e..bc8a86e 100644
--- a/flink-connector-elasticsearch-e2e-tests/flink-connector-elasticsearch6-e2e-tests/src/test/java/org/apache/flink/streaming/tests/Elasticsearch6SinkE2ECase.java
+++ b/flink-connector-elasticsearch-e2e-tests/flink-connector-elasticsearch6-e2e-tests/src/test/java/org/apache/flink/streaming/tests/Elasticsearch6SinkE2ECase.java
@@ -19,7 +19,7 @@ package org.apache.flink.streaming.tests;
 
 import org.apache.flink.connector.elasticsearch.test.DockerImageVersions;
 import org.apache.flink.connector.testframe.junit.annotations.TestContext;
-import org.apache.flink.tests.util.TestUtils;
+import org.apache.flink.test.resources.ResourceTestUtils;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -44,15 +44,17 @@ public class Elasticsearch6SinkE2ECase
             new Elasticsearch6SinkExternalContextFactory(
                     elasticsearch.getContainer(),
                     Arrays.asList(
-                            TestUtils.getResource("dependencies/elasticsearch6-end-to-end-test.jar")
+                            ResourceTestUtils.getResource(
+                                            "dependencies/elasticsearch6-end-to-end-test.jar")
                                     .toAbsolutePath()
                                     .toUri()
                                     .toURL(),
-                            TestUtils.getResource("dependencies/flink-connector-test-utils.jar")
+                            ResourceTestUtils.getResource(
+                                            "dependencies/flink-connector-test-utils.jar")
                                     .toAbsolutePath()
                                     .toUri()
                                     .toURL(),
-                            TestUtils.getResource(
+                            ResourceTestUtils.getResource(
                                             "dependencies/flink-connector-elasticsearch-test-utils.jar")
                                     .toAbsolutePath()
                                     .toUri()
diff --git a/flink-connector-elasticsearch-e2e-tests/flink-connector-elasticsearch7-e2e-tests/src/test/java/org/apache/flink/streaming/tests/Elasticsearch7SinkE2ECase.java b/flink-connector-elasticsearch-e2e-tests/flink-connector-elasticsearch7-e2e-tests/src/test/java/org/apache/flink/streaming/tests/Elasticsearch7SinkE2ECase.java
index 0b4f19d..235b1ef 100644
--- a/flink-connector-elasticsearch-e2e-tests/flink-connector-elasticsearch7-e2e-tests/src/test/java/org/apache/flink/streaming/tests/Elasticsearch7SinkE2ECase.java
+++ b/flink-connector-elasticsearch-e2e-tests/flink-connector-elasticsearch7-e2e-tests/src/test/java/org/apache/flink/streaming/tests/Elasticsearch7SinkE2ECase.java
@@ -19,7 +19,7 @@ package org.apache.flink.streaming.tests;
 
 import org.apache.flink.connector.elasticsearch.test.DockerImageVersions;
 import org.apache.flink.connector.testframe.junit.annotations.TestContext;
-import org.apache.flink.tests.util.TestUtils;
+import org.apache.flink.test.resources.ResourceTestUtils;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -44,15 +44,17 @@ public class Elasticsearch7SinkE2ECase
             new Elasticsearch7SinkExternalContextFactory(
                     elasticsearch.getContainer(),
                     Arrays.asList(
-                            TestUtils.getResource("dependencies/elasticsearch7-end-to-end-test.jar")
+                            ResourceTestUtils.getResource(
+                                            "dependencies/elasticsearch7-end-to-end-test.jar")
                                     .toAbsolutePath()
                                     .toUri()
                                     .toURL(),
-                            TestUtils.getResource("dependencies/flink-connector-test-utils.jar")
+                            ResourceTestUtils.getResource(
+                                            "dependencies/flink-connector-test-utils.jar")
                                     .toAbsolutePath()
                                     .toUri()
                                     .toURL(),
-                            TestUtils.getResource(
+                            ResourceTestUtils.getResource(
                                             "dependencies/flink-connector-elasticsearch-test-utils.jar")
                                     .toAbsolutePath()
                                     .toUri()