You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "kanha-gupta (via GitHub)" <gi...@apache.org> on 2023/02/15 15:55:30 UTC

[GitHub] [shardingsphere] kanha-gupta commented on a diff in pull request #24007: Add test case for PluginLifecycleServiceManager

kanha-gupta commented on code in PR #24007:
URL: https://github.com/apache/shardingsphere/pull/24007#discussion_r1107313417


##########
agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/PluginLifecycleServiceManagerTest.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.shardingsphere.agent.core.plugin;
+
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLStreamHandlerFactory;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.jar.JarFile;
+import javax.management.loading.PrivateMLet;
+
+import net.bytebuddy.dynamic.loading.MultipleParentClassLoader;
+import org.apache.shardingsphere.agent.api.PluginConfiguration;
+import org.junit.Test;
+
+public final class PluginLifecycleServiceManagerTest {
+
+    @Test
+    public void assertInitPluginLifecycleService() {
+        Map<String, PluginConfiguration> pluginConfigs = new HashMap<>();
+        ArrayList<JarFile> pluginJars = new ArrayList<>();
+        PluginLifecycleServiceManager.init(pluginConfigs, pluginJars, new MultipleParentClassLoader(new ArrayList<>()),

Review Comment:
   Hey,I understand your concern. the init method for which this testFile is written uses final ClassLoader pluginClassLoader in the constructor & The best way I,ve figured out to put it into test is through using MultipleParentClassLoader because it is being used to load classes for plugins that may have dependencies on other libraries. By using a MultipleParentClassLoader, the plugins can be loaded in their own isolated classloader and their dependencies can be loaded in a separate classloader, which helps to prevent classpath conflicts.
   This was the reason i used it. I believe the reason it is never used in the project is because this is the first file which uses a method which have final ClassLoader pluginClassLoader in its constructor.There are no testfiles which test methods containing this configuration.
   I can implement it in a different way if this is not appropriate :) 



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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