This is an automated email from the ASF dual-hosted git repository.
zhoubo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-connect.git
The following commit(s) were added to refs/heads/master by this push:
new ddc334b [ISSUE #220] Add unit test(controller module) (#236)
ddc334b is described below
commit ddc334bd969b981e492a2ad8ea66d894e889ad15
Author: Oliver <[email protected]>
AuthorDate: Mon Aug 15 14:28:43 2022 +0800
[ISSUE #220] Add unit test(controller module) (#236)
* Add controller module unit test
* Upgrade reflections to 0.10.2
---
pom.xml | 2 +-
.../isolation/DelegatingClassLoader.java | 16 +-
.../runtime/connectorwrapper/NameServerMocker.java | 66 +++++++
.../connectorwrapper/ServerResponseMocker.java | 218 +++++++++++++++++++++
.../DistributedConnectControllerTest.java | 83 ++++++++
.../distributed/TestConfigManagementService.java | 82 ++++++++
.../isolation/PluginClassLoaderTest.java | 52 +++++
.../runtime/controller/isolation/PluginTest.java | 41 ++++
.../controller/isolation/PluginUtilsTest.java | 62 ++++++
.../controller/isolation/PluginWrapperTest.java | 42 ++++
.../controller/isolation/TestFileSystem.java | 80 ++++++++
.../runtime/controller/isolation/TestPath.java | 138 +++++++++++++
.../StandaloneConnectControllerTest.java | 74 +++++++
13 files changed, 940 insertions(+), 16 deletions(-)
diff --git a/pom.xml b/pom.xml
index 26d5f2c..c4b4e16 100644
--- a/pom.xml
+++ b/pom.xml
@@ -50,7 +50,7 @@
<slf4j.version>1.7.7</slf4j.version>
<logback.version>1.2.9</logback.version>
<commons.cli.version>1.2</commons.cli.version>
- <reflections.version>0.9.12</reflections.version>
+ <reflections.version>0.10.2</reflections.version>
<guava.version>22.0</guava.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
diff --git
a/rocketmq-connect-runtime/src/main/java/org/apache/rocketmq/connect/runtime/controller/isolation/DelegatingClassLoader.java
b/rocketmq-connect-runtime/src/main/java/org/apache/rocketmq/connect/runtime/controller/isolation/DelegatingClassLoader.java
index 6153222..6cf7761 100644
---
a/rocketmq-connect-runtime/src/main/java/org/apache/rocketmq/connect/runtime/controller/isolation/DelegatingClassLoader.java
+++
b/rocketmq-connect-runtime/src/main/java/org/apache/rocketmq/connect/runtime/controller/isolation/DelegatingClassLoader.java
@@ -298,7 +298,7 @@ public class DelegatingClassLoader extends URLClassLoader {
builder.setClassLoaders(new ClassLoader[]{loader});
builder.addUrls(urls);
builder.setScanners(new SubTypesScanner());
- builder.useParallelExecutor();
+ builder.setParallel(true);
Reflections reflections = new InternalReflections(builder);
return new PluginScanResult(
@@ -413,20 +413,6 @@ public class DelegatingClassLoader extends URLClassLoader {
public InternalReflections(Configuration configuration) {
super(configuration);
}
-
- // When Reflections is used for parallel scans, it has a bug where it
propagates ReflectionsException
- // as RuntimeException. Override the scan behavior to emulate the
singled-threaded logic.
- @Override
- protected void scan(URL url) {
- try {
- super.scan(url);
- } catch (ReflectionsException e) {
- Logger log = Reflections.log;
- if (log != null && log.isWarnEnabled()) {
- log.warn("could not create Vfs.Dir from url. ignoring the
exception and continuing", e);
- }
- }
- }
}
}
diff --git
a/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/connectorwrapper/NameServerMocker.java
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/connectorwrapper/NameServerMocker.java
new file mode 100644
index 0000000..12d74bf
--- /dev/null
+++
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/connectorwrapper/NameServerMocker.java
@@ -0,0 +1,66 @@
+/*
+ * 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.rocketmq.connect.runtime.connectorwrapper;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import org.apache.rocketmq.common.MixAll;
+import org.apache.rocketmq.common.protocol.route.BrokerData;
+import org.apache.rocketmq.common.protocol.route.TopicRouteData;
+
+/**
+ * tools class
+ */
+public class NameServerMocker {
+
+ /**
+ * use the specified port to start the nameserver
+ *
+ * @param nameServerPort nameServer port
+ * @param brokerPort broker port
+ * @return ServerResponseMocker
+ */
+ public static ServerResponseMocker startByDefaultConf(int nameServerPort,
int brokerPort) {
+ return startByDefaultConf(nameServerPort, brokerPort, null);
+ }
+
+ /**
+ * use the specified port to start the nameserver
+ *
+ * @param nameServerPort nameServer port
+ * @param brokerPort broker port
+ * @param extMap extend config
+ * @return ServerResponseMocker
+ */
+ public static ServerResponseMocker startByDefaultConf(int nameServerPort,
int brokerPort,
+ HashMap<String,
String> extMap) {
+
+ System.setProperty(MixAll.NAMESRV_ADDR_PROPERTY, "127.0.0.1:" +
nameServerPort);
+ TopicRouteData topicRouteData = new TopicRouteData();
+ List<BrokerData> dataList = new ArrayList<>();
+ HashMap<Long, String> brokerAddress = new HashMap<>();
+ brokerAddress.put(1L, "127.0.0.1:" + brokerPort);
+ BrokerData brokerData = new BrokerData("mockCluster",
"mockBrokerName", brokerAddress);
+ brokerData.setBrokerName("mockBrokerName");
+ dataList.add(brokerData);
+ topicRouteData.setBrokerDatas(dataList);
+ // start name server
+ return ServerResponseMocker.startServer(nameServerPort,
topicRouteData.encode(), extMap);
+ }
+
+}
diff --git
a/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/connectorwrapper/ServerResponseMocker.java
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/connectorwrapper/ServerResponseMocker.java
new file mode 100644
index 0000000..f9d4fc1
--- /dev/null
+++
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/connectorwrapper/ServerResponseMocker.java
@@ -0,0 +1,218 @@
+/*
+ * 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.rocketmq.connect.runtime.connectorwrapper;
+
+import com.alibaba.fastjson.JSON;
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.ChannelDuplexHandler;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.SimpleChannelInboundHandler;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.timeout.IdleStateHandler;
+import io.netty.util.concurrent.Future;
+import java.net.InetSocketAddress;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import org.apache.rocketmq.common.DataVersion;
+import org.apache.rocketmq.common.MixAll;
+import org.apache.rocketmq.common.protocol.RequestCode;
+import org.apache.rocketmq.common.protocol.body.ClusterInfo;
+import org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper;
+import org.apache.rocketmq.common.protocol.route.BrokerData;
+import org.apache.rocketmq.common.subscription.SubscriptionGroupConfig;
+import org.apache.rocketmq.remoting.netty.NettyDecoder;
+import org.apache.rocketmq.remoting.netty.NettyEncoder;
+import org.apache.rocketmq.remoting.protocol.RemotingCommand;
+import org.apache.rocketmq.remoting.protocol.RemotingSysResponseCode;
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ * mock server response for command
+ */
+public abstract class ServerResponseMocker {
+
+ private final NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup();
+
+ @Before
+ public void before() {
+ start();
+ }
+
+ @After
+ public void shutdown() {
+ if (eventLoopGroup.isShutdown()) {
+ return;
+ }
+ Future<?> future = eventLoopGroup.shutdownGracefully();
+ try {
+ future.get();
+ } catch (InterruptedException | ExecutionException e) {
+ e.printStackTrace();
+ }
+ }
+
+ protected abstract int getPort();
+
+ protected abstract byte[] getBody();
+
+ public void start() {
+ start(null);
+ }
+
+ public void start(HashMap<String, String> extMap) {
+ ServerBootstrap serverBootstrap = new ServerBootstrap();
+ serverBootstrap.group(eventLoopGroup)
+ .channel(NioServerSocketChannel.class)
+ .option(ChannelOption.SO_BACKLOG, 1024)
+ .option(ChannelOption.SO_REUSEADDR, true)
+ .option(ChannelOption.SO_KEEPALIVE, false)
+ .childOption(ChannelOption.TCP_NODELAY, true)
+ .childOption(ChannelOption.SO_SNDBUF, 65535)
+ .childOption(ChannelOption.SO_RCVBUF, 65535)
+ .localAddress(new InetSocketAddress(getPort()))
+ .childHandler(new ChannelInitializer<SocketChannel>() {
+ @Override
+ public void initChannel(SocketChannel ch) throws Exception
{
+ ch.pipeline()
+ .addLast(eventLoopGroup,
+ new NettyEncoder(),
+ new NettyDecoder(),
+ new IdleStateHandler(0, 0, 120),
+ new ChannelDuplexHandler(),
+ new NettyServerHandler(extMap)
+ );
+ }
+ });
+ try {
+ ChannelFuture sync = serverBootstrap.bind().sync();
+ InetSocketAddress addr = (InetSocketAddress)
sync.channel().localAddress();
+ } catch (InterruptedException e1) {
+ throw new RuntimeException("this.serverBootstrap.bind().sync()
InterruptedException", e1);
+ }
+ }
+
+ @ChannelHandler.Sharable
+ private class NettyServerHandler extends
SimpleChannelInboundHandler<RemotingCommand> {
+ private HashMap<String, String> extMap;
+
+ public NettyServerHandler(HashMap<String, String> extMap) {
+ this.extMap = extMap;
+ }
+
+ @Override
+ protected void channelRead0(ChannelHandlerContext ctx, RemotingCommand
msg) throws Exception {
+ String remark = "mock data";
+ final RemotingCommand response =
+
RemotingCommand.createResponseCommand(RemotingSysResponseCode.SUCCESS, remark);
+ response.setOpaque(msg.getOpaque());
+ response.setBody(getBody());
+
+ switch (msg.getCode()) {
+ case RequestCode.GET_BROKER_CLUSTER_INFO: {
+ final ClusterInfo clusterInfo = buildClusterInfo();
+ response.setBody(JSON.toJSONBytes(clusterInfo));
+ break;
+ }
+
+ case RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG: {
+ final SubscriptionGroupWrapper wrapper =
buildSubscriptionGroupWrapper();
+ response.setBody(JSON.toJSONBytes(wrapper));
+ break;
+ }
+ default:
+ break;
+ }
+
+ if (extMap != null && extMap.size() > 0) {
+ response.setExtFields(extMap);
+ }
+ ctx.writeAndFlush(response);
+ }
+ }
+
+ public static ServerResponseMocker startServer(int port, byte[] body) {
+ return startServer(port, body, null);
+ }
+
+
+ public static ServerResponseMocker startServer(int port, byte[] body,
HashMap<String, String> extMap) {
+ ServerResponseMocker mocker = new ServerResponseMocker() {
+ @Override
+ protected int getPort() {
+ return port;
+ }
+
+ @Override
+ protected byte[] getBody() {
+ return body;
+ }
+ };
+ mocker.start(extMap);
+ // add jvm hook, close connection when jvm down
+ Runtime.getRuntime().addShutdownHook(new Thread(mocker::shutdown));
+ return mocker;
+ }
+
+ private ClusterInfo buildClusterInfo() {
+ ClusterInfo clusterInfo = new ClusterInfo();
+ HashMap<String, Set<String>> clusterAddrTable = new HashMap<>();
+ Set<String> brokerNames = new HashSet<>();
+ brokerNames.add("mockBrokerName");
+ clusterAddrTable.put("mockCluster", brokerNames);
+ clusterInfo.setClusterAddrTable(clusterAddrTable);
+ HashMap<String, BrokerData> brokerAddrTable = new HashMap<String,
BrokerData>();
+
+ //build brokerData
+ BrokerData brokerData = new BrokerData();
+ brokerData.setBrokerName("mockBrokerName");
+ brokerData.setCluster("mockCluster");
+
+ //build brokerAddrs
+ HashMap<Long, String> brokerAddrs = new HashMap<Long, String>();
+ brokerAddrs.put(MixAll.MASTER_ID, "127.0.0.1:10911");
+
+ brokerData.setBrokerAddrs(brokerAddrs);
+ brokerAddrTable.put("master", brokerData);
+ clusterInfo.setBrokerAddrTable(brokerAddrTable);
+ return clusterInfo;
+ }
+
+ private SubscriptionGroupWrapper buildSubscriptionGroupWrapper() {
+ SubscriptionGroupWrapper subscriptionGroupWrapper = new
SubscriptionGroupWrapper();
+ ConcurrentHashMap<String, SubscriptionGroupConfig> subscriptions = new
ConcurrentHashMap<>();
+ SubscriptionGroupConfig subscriptionGroupConfig = new
SubscriptionGroupConfig();
+ subscriptionGroupConfig.setConsumeBroadcastEnable(true);
+ subscriptionGroupConfig.setBrokerId(0);
+ subscriptionGroupConfig.setGroupName("Consumer-group-one");
+ subscriptions.put("Consumer-group-one", subscriptionGroupConfig);
+ subscriptionGroupWrapper.setSubscriptionGroupTable(subscriptions);
+ DataVersion dataVersion = new DataVersion();
+ dataVersion.nextVersion();
+ subscriptionGroupWrapper.setDataVersion(dataVersion);
+ return subscriptionGroupWrapper;
+ }
+}
diff --git
a/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/distributed/DistributedConnectControllerTest.java
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/distributed/DistributedConnectControllerTest.java
new file mode 100644
index 0000000..2a203e4
--- /dev/null
+++
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/distributed/DistributedConnectControllerTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.rocketmq.connect.runtime.controller.distributed;
+
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.TimeUnit;
+import org.apache.rocketmq.connect.runtime.config.ConnectConfig;
+import org.apache.rocketmq.connect.runtime.connectorwrapper.NameServerMocker;
+import
org.apache.rocketmq.connect.runtime.connectorwrapper.ServerResponseMocker;
+import
org.apache.rocketmq.connect.runtime.connectorwrapper.testimpl.TestPositionManageServiceImpl;
+import org.apache.rocketmq.connect.runtime.controller.isolation.Plugin;
+import org.apache.rocketmq.connect.runtime.service.ClusterManagementService;
+import
org.apache.rocketmq.connect.runtime.service.ClusterManagementServiceImpl;
+import org.apache.rocketmq.connect.runtime.service.ConfigManagementService;
+import org.apache.rocketmq.connect.runtime.service.PositionManagementService;
+import org.assertj.core.api.Assertions;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class DistributedConnectControllerTest {
+
+ private DistributedConnectController distributedConnectController;
+
+ @Mock
+ private Plugin plugin;
+
+ private DistributedConfig distributedConfig = new DistributedConfig();
+
+ private ClusterManagementService clusterManagementService = new
ClusterManagementServiceImpl();
+
+ private ConfigManagementService configManagementService = new
TestConfigManagementService();
+
+ private PositionManagementService positionManagementService = new
TestPositionManageServiceImpl();
+
+ private ConnectConfig connectConfig = new ConnectConfig();
+
+ private ServerResponseMocker nameServerMocker;
+
+ private ServerResponseMocker brokerMocker;
+
+ @Before
+ public void before() throws InterruptedException {
+ nameServerMocker = NameServerMocker.startByDefaultConf(9876, 10911);
+ brokerMocker = ServerResponseMocker.startServer(10911, "Hello
World".getBytes(StandardCharsets.UTF_8));
+ connectConfig.setNamesrvAddr("127.0.0.1:9876");
+ clusterManagementService.initialize(connectConfig);
+ distributedConnectController = new
DistributedConnectController(plugin, distributedConfig,
clusterManagementService,
+ configManagementService, positionManagementService);
+ }
+
+ @After
+ public void after() {
+ distributedConnectController.shutdown();
+ nameServerMocker.shutdown();
+ brokerMocker.shutdown();
+ }
+
+ @Test
+ public void startTest() {
+ Assertions.assertThatCode(() ->
distributedConnectController.start()).doesNotThrowAnyException();
+ }
+
+}
diff --git
a/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/distributed/TestConfigManagementService.java
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/distributed/TestConfigManagementService.java
new file mode 100644
index 0000000..7a62144
--- /dev/null
+++
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/distributed/TestConfigManagementService.java
@@ -0,0 +1,82 @@
+/*
+ * 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.rocketmq.connect.runtime.controller.distributed;
+
+import io.openmessaging.connector.api.component.connector.Connector;
+import java.util.List;
+import java.util.Map;
+import org.apache.rocketmq.connect.runtime.common.ConnectKeyValue;
+import org.apache.rocketmq.connect.runtime.config.ConnectConfig;
+import org.apache.rocketmq.connect.runtime.controller.isolation.Plugin;
+import org.apache.rocketmq.connect.runtime.service.ConfigManagementService;
+import org.apache.rocketmq.connect.runtime.service.StagingMode;
+
+public class TestConfigManagementService implements ConfigManagementService {
+ @Override public void start() {
+
+ }
+
+ @Override public void stop() {
+
+ }
+
+ @Override public Map<String, ConnectKeyValue> getConnectorConfigs() {
+ return null;
+ }
+
+ @Override public Map<String, ConnectKeyValue>
getConnectorConfigsIncludeDeleted() {
+ return null;
+ }
+
+ @Override public String putConnectorConfig(String connectorName,
ConnectKeyValue configs) throws Exception {
+ return null;
+ }
+
+ @Override public void removeConnectorConfig(String connectorName) {
+
+ }
+
+ @Override public void recomputeTaskConfigs(String connectorName, Connector
connector, Long currentTimestamp,
+ ConnectKeyValue configs) {
+
+ }
+
+ @Override public Map<String, List<ConnectKeyValue>> getTaskConfigs() {
+ return null;
+ }
+
+ @Override public void persist() {
+
+ }
+
+ @Override public void registerListener(ConnectorConfigUpdateListener
listener) {
+
+ }
+
+ @Override public void initialize(ConnectConfig connectConfig, Plugin
plugin) {
+
+ }
+
+ @Override public Plugin getPlugin() {
+ return null;
+ }
+
+ @Override public StagingMode getStagingMode() {
+ return null;
+ }
+}
diff --git
a/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/isolation/PluginClassLoaderTest.java
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/isolation/PluginClassLoaderTest.java
new file mode 100644
index 0000000..7456257
--- /dev/null
+++
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/isolation/PluginClassLoaderTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.rocketmq.connect.runtime.controller.isolation;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import org.assertj.core.api.Assertions;
+import org.junit.Before;
+import org.junit.Test;
+
+public class PluginClassLoaderTest {
+
+ private PluginClassLoader pluginClassLoader;
+
+ private URL url = new URL("http://www.baidu.com");
+
+ private URL[] urls = new URL[]{};
+
+ public PluginClassLoaderTest() throws MalformedURLException {
+ }
+
+ @Before
+ public void before() {
+ pluginClassLoader = new PluginClassLoader(url, urls);
+ }
+
+ @Test
+ public void loadClassTest() throws ClassNotFoundException {
+ Assertions.assertThatCode(() ->
pluginClassLoader.loadClass("org.apache.rocketmq.connect.runtime.connectorwrapper.testimpl.TestConnector"))
+ .doesNotThrowAnyException();
+ }
+
+
+
+
+
+}
diff --git
a/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/isolation/PluginTest.java
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/isolation/PluginTest.java
new file mode 100644
index 0000000..1eb8536
--- /dev/null
+++
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/isolation/PluginTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.rocketmq.connect.runtime.controller.isolation;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.assertj.core.api.Assertions;
+import org.junit.Before;
+import org.junit.Test;
+
+public class PluginTest {
+
+ private Plugin plugin;
+
+ @Before
+ public void before() {
+ List<String> pluginPaths = new ArrayList<>();
+ pluginPaths.add("src/test/java/org/apache/rocketmq/connect/runtime");
+ plugin = new Plugin(pluginPaths);
+ }
+
+ @Test
+ public void initLoadersTest() {
+ Assertions.assertThatCode(() ->
plugin.initLoaders()).doesNotThrowAnyException();
+ }
+}
diff --git
a/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/isolation/PluginUtilsTest.java
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/isolation/PluginUtilsTest.java
new file mode 100644
index 0000000..381cfa4
--- /dev/null
+++
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/isolation/PluginUtilsTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.rocketmq.connect.runtime.controller.isolation;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import org.junit.Test;
+
+public class PluginUtilsTest {
+
+ private Path path = new TestPath();
+
+ private static final String PATH =
"src/test/java/org/apache/rocketmq/connect/runtime";
+
+ @Test
+ public void isArchiveTest() {
+ final boolean archive = PluginUtils.isArchive(path);
+ assert archive == false;
+ }
+
+ @Test
+ public void isClassFileTest() {
+ final boolean file = PluginUtils.isClassFile(path);
+ assert file == false;
+ }
+
+ @Test
+ public void pluginLocationsTest() throws IOException {
+ final List<Path> paths =
PluginUtils.pluginLocations(Paths.get(PATH).toAbsolutePath());
+ assert paths.size() > 0;
+ }
+
+ @Test
+ public void pluginUrlsTest() throws IOException {
+ final List<Path> paths =
PluginUtils.pluginUrls(Paths.get(PATH).toAbsolutePath());
+ assert paths.size() == 0;
+ }
+
+ @Test
+ public void shouldNotLoadInIsolationTest() {
+ final boolean flag = PluginUtils.shouldNotLoadInIsolation(PATH);
+ assert flag == false;
+
+ }
+}
diff --git
a/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/isolation/PluginWrapperTest.java
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/isolation/PluginWrapperTest.java
new file mode 100644
index 0000000..c2a754c
--- /dev/null
+++
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/isolation/PluginWrapperTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.rocketmq.connect.runtime.controller.isolation;
+
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+public class PluginWrapperTest {
+
+ private PluginWrapper pluginWrapper = new
PluginWrapper(TestPath.class,"1.0", TestPath.class.getClassLoader());
+
+ @Test
+ public void getClassLoaderTest() {
+ Assertions.assertThat(pluginWrapper.getClassLoader()).isNotNull();
+ }
+
+ @Test
+ public void fromTest() {
+ final PluginType from = PluginType.from(PluginType.SOURCE.getClass());
+ Assertions.assertThat(from).isNotNull();
+
+ Assertions.assertThat(PluginType.SOURCE.simpleName()).isNotEmpty();
+
+ Assertions.assertThat(PluginType.SOURCE.toString()).isNotEmpty();
+
+ }
+}
diff --git
a/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/isolation/TestFileSystem.java
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/isolation/TestFileSystem.java
new file mode 100644
index 0000000..30e673a
--- /dev/null
+++
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/isolation/TestFileSystem.java
@@ -0,0 +1,80 @@
+/*
+ * 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.rocketmq.connect.runtime.controller.isolation;
+
+import java.io.IOException;
+import java.nio.file.FileStore;
+import java.nio.file.FileSystem;
+import java.nio.file.Path;
+import java.nio.file.PathMatcher;
+import java.nio.file.WatchService;
+import java.nio.file.attribute.UserPrincipalLookupService;
+import java.nio.file.spi.FileSystemProvider;
+import java.util.Set;
+import org.jetbrains.annotations.NotNull;
+import sun.nio.fs.MacOSXFileSystemProvider;
+
+public class TestFileSystem extends FileSystem {
+ @Override public FileSystemProvider provider() {
+ return new MacOSXFileSystemProvider();
+ }
+
+ @Override public void close() throws IOException {
+
+ }
+
+ @Override public boolean isOpen() {
+ return false;
+ }
+
+ @Override public boolean isReadOnly() {
+ return false;
+ }
+
+ @Override public String getSeparator() {
+ return null;
+ }
+
+ @Override public Iterable<Path> getRootDirectories() {
+ return null;
+ }
+
+ @Override public Iterable<FileStore> getFileStores() {
+ return null;
+ }
+
+ @Override public Set<String> supportedFileAttributeViews() {
+ return null;
+ }
+
+ @NotNull @Override public Path getPath(@NotNull String first, @NotNull
String... more) {
+ return null;
+ }
+
+ @Override public PathMatcher getPathMatcher(String syntaxAndPattern) {
+ return null;
+ }
+
+ @Override public UserPrincipalLookupService
getUserPrincipalLookupService() {
+ return null;
+ }
+
+ @Override public WatchService newWatchService() throws IOException {
+ return null;
+ }
+}
diff --git
a/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/isolation/TestPath.java
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/isolation/TestPath.java
new file mode 100644
index 0000000..7b70c7b
--- /dev/null
+++
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/isolation/TestPath.java
@@ -0,0 +1,138 @@
+/*
+ * 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.rocketmq.connect.runtime.controller.isolation;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.FileSystem;
+import java.nio.file.LinkOption;
+import java.nio.file.Path;
+import java.nio.file.WatchEvent;
+import java.nio.file.WatchKey;
+import java.nio.file.WatchService;
+import java.util.Iterator;
+import org.jetbrains.annotations.NotNull;
+
+public class TestPath implements Path {
+ @NotNull @Override public FileSystem getFileSystem() {
+ return new TestFileSystem();
+ }
+
+ @Override public boolean isAbsolute() {
+ return false;
+ }
+
+ @Override public Path getRoot() {
+ return null;
+ }
+
+ @Override public Path getFileName() {
+ return null;
+ }
+
+ @Override public Path getParent() {
+ return null;
+ }
+
+ @Override public int getNameCount() {
+ return 0;
+ }
+
+ @NotNull @Override public Path getName(int index) {
+ return null;
+ }
+
+ @NotNull @Override public Path subpath(int beginIndex, int endIndex) {
+ return null;
+ }
+
+ @Override public boolean startsWith(@NotNull Path other) {
+ return false;
+ }
+
+ @Override public boolean startsWith(@NotNull String other) {
+ return false;
+ }
+
+ @Override public boolean endsWith(@NotNull Path other) {
+ return false;
+ }
+
+ @Override public boolean endsWith(@NotNull String other) {
+ return false;
+ }
+
+ @NotNull @Override public Path normalize() {
+ return null;
+ }
+
+ @NotNull @Override public Path resolve(@NotNull Path other) {
+ return null;
+ }
+
+ @NotNull @Override public Path resolve(@NotNull String other) {
+ return null;
+ }
+
+ @NotNull @Override public Path resolveSibling(@NotNull Path other) {
+ return null;
+ }
+
+ @NotNull @Override public Path resolveSibling(@NotNull String other) {
+ return null;
+ }
+
+ @NotNull @Override public Path relativize(@NotNull Path other) {
+ return null;
+ }
+
+ @NotNull @Override public URI toUri() {
+ return null;
+ }
+
+ @NotNull @Override public Path toAbsolutePath() {
+ return null;
+ }
+
+ @NotNull @Override public Path toRealPath(@NotNull LinkOption... options)
throws IOException {
+ return null;
+ }
+
+ @NotNull @Override public File toFile() {
+ return null;
+ }
+
+ @NotNull @Override public WatchKey register(@NotNull WatchService watcher,
@NotNull WatchEvent.Kind<?>[] events,
+ WatchEvent.Modifier... modifiers) throws IOException {
+ return null;
+ }
+
+ @NotNull @Override
+ public WatchKey register(@NotNull WatchService watcher, @NotNull
WatchEvent.Kind<?>... events) throws IOException {
+ return null;
+ }
+
+ @NotNull @Override public Iterator<Path> iterator() {
+ return null;
+ }
+
+ @Override public int compareTo(@NotNull Path other) {
+ return 0;
+ }
+}
diff --git
a/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/standalone/StandaloneConnectControllerTest.java
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/standalone/StandaloneConnectControllerTest.java
new file mode 100644
index 0000000..7652f3f
--- /dev/null
+++
b/rocketmq-connect-runtime/src/test/java/org/apache/rocketmq/connect/runtime/controller/standalone/StandaloneConnectControllerTest.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.rocketmq.connect.runtime.controller.standalone;
+
+import java.nio.charset.StandardCharsets;
+import org.apache.rocketmq.connect.runtime.connectorwrapper.NameServerMocker;
+import
org.apache.rocketmq.connect.runtime.connectorwrapper.ServerResponseMocker;
+import
org.apache.rocketmq.connect.runtime.connectorwrapper.testimpl.TestPositionManageServiceImpl;
+import
org.apache.rocketmq.connect.runtime.controller.distributed.TestConfigManagementService;
+import org.apache.rocketmq.connect.runtime.controller.isolation.Plugin;
+import org.apache.rocketmq.connect.runtime.service.ClusterManagementService;
+import
org.apache.rocketmq.connect.runtime.service.ClusterManagementServiceImpl;
+import org.apache.rocketmq.connect.runtime.service.ConfigManagementService;
+import org.apache.rocketmq.connect.runtime.service.PositionManagementService;
+import org.assertj.core.api.Assertions;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class StandaloneConnectControllerTest {
+
+ private StandaloneConnectController standaloneConnectController;
+
+ @Mock
+ private Plugin plugin;
+
+ private StandaloneConfig standaloneConfig = new StandaloneConfig();
+
+ private ClusterManagementService clusterManagementService = new
ClusterManagementServiceImpl();
+
+ private ConfigManagementService configManagementService = new
TestConfigManagementService();
+
+ private PositionManagementService positionManagementService = new
TestPositionManageServiceImpl();
+
+ @Before
+ public void before() {
+ NameServerMocker.startByDefaultConf(9876, 10911);
+ ServerResponseMocker.startServer(10911, "Hello
World".getBytes(StandardCharsets.UTF_8));
+ standaloneConfig.setNamesrvAddr("127.0.0.1:9876");
+ standaloneConfig.setHttpPort(10001);
+ clusterManagementService.initialize(standaloneConfig);
+ standaloneConnectController = new StandaloneConnectController(plugin,
standaloneConfig, clusterManagementService,
+ configManagementService, positionManagementService);
+ }
+
+ @After
+ public void after() {
+ standaloneConnectController.shutdown();
+ }
+
+ @Test
+ public void startTest() {
+ Assertions.assertThatCode(() ->
standaloneConnectController.start()).doesNotThrowAnyException();
+ }
+}