You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "Hisoka-X (via GitHub)" <gi...@apache.org> on 2023/09/26 11:42:04 UTC

[GitHub] [seatunnel] Hisoka-X commented on a diff in pull request #5551: Throw IllegalArgumentException when find multiple connector jar for one pluginIdentifier

Hisoka-X commented on code in PR #5551:
URL: https://github.com/apache/seatunnel/pull/5551#discussion_r1337076183


##########
seatunnel-plugin-discovery/src/test/java/org/apache/seatunnel/plugin/discovery/seatunnel/SeaTunnelSourcePluginDiscoveryTest.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.seatunnel.plugin.discovery.seatunnel;
+
+import org.apache.seatunnel.common.config.Common;
+import org.apache.seatunnel.common.config.DeployMode;
+import org.apache.seatunnel.common.constants.PluginType;
+import org.apache.seatunnel.plugin.discovery.PluginIdentifier;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.google.common.collect.Lists;
+
+class SeaTunnelSourcePluginDiscoveryTest {
+
+
+    private static final String seatunnelHome = SeaTunnelSourcePluginDiscoveryTest.class.getResource("/duplicate").getPath();
+    private static final List<Path> pluginJars = Lists.newArrayList(
+        Paths.get(seatunnelHome + File.separator + "connectors" + File.separator + "connector-http-jira.jar"),
+        Paths.get(seatunnelHome + File.separator + "connectors" + File.separator + "connector-http.jar")
+    );
+
+    @BeforeEach
+    public void before() throws IOException {
+        Common.setDeployMode(DeployMode.CLIENT);
+        System.setProperty("SEATUNNEL_HOME", seatunnelHome);
+        // The file is created under target directory.
+        for (Path pluginJar : pluginJars) {
+            Files.createFile(pluginJar);
+        }
+    }
+
+    @Test
+    void getPluginBaseClass() throws IOException {
+        List<PluginIdentifier> pluginIdentifiers = Lists.newArrayList(
+            PluginIdentifier.of("seatunnel", PluginType.SOURCE.getType(), "HttpJira"),
+            PluginIdentifier.of("seatunnel", PluginType.SOURCE.getType(), "HttpBase")
+        );
+        SeaTunnelSourcePluginDiscovery seaTunnelSourcePluginDiscovery = new SeaTunnelSourcePluginDiscovery();
+        Assertions.assertThrows(IllegalArgumentException.class, () -> seaTunnelSourcePluginDiscovery.getPluginJarPaths(pluginIdentifiers));
+    }
+
+    @AfterEach
+    public void after() throws IOException {
+        for (Path pluginJar : pluginJars) {
+            Files.deleteIfExists(pluginJar);
+        }
+    }

Review Comment:
   Should revert `seatunnelHome`?



##########
seatunnel-plugin-discovery/src/main/java/org/apache/seatunnel/plugin/discovery/AbstractPluginDiscovery.java:
##########
@@ -328,16 +329,13 @@ protected Optional<URL> getPluginJarPath(PluginIdentifier pluginIdentifier) {
      * @return plugin jar path.
      */
     private Optional<URL> findPluginJarPath(PluginIdentifier pluginIdentifier) {
-        if (pluginConfig.isEmpty()) {
-            return Optional.empty();
-        }
         final String engineType = pluginIdentifier.getEngineType().toLowerCase();
         final String pluginType = pluginIdentifier.getPluginType().toLowerCase();
         final String pluginName = pluginIdentifier.getPluginName().toLowerCase();
-        if (!pluginConfig.hasPath(engineType)) {
+        if (pluginMappingConfig.isEmpty() || !pluginMappingConfig.hasPath(engineType)) {

Review Comment:
   Any reason for add `pluginMappingConfig.isEmpty()` condition? I think if `pluginMappingConfig.isEmpty()` is true, the `!pluginMappingConfig.hasPath(engineType)` is true too?



-- 
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: commits-unsubscribe@seatunnel.apache.org

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