提交 0846c3c6 编写于 作者: C chenzlalvin

[RIP-21] submodule test

上级 f3990857
...@@ -20,6 +20,7 @@ package org.apache.rocketmq.test.util; ...@@ -20,6 +20,7 @@ package org.apache.rocketmq.test.util;
import java.util.HashMap; import java.util.HashMap;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ForkJoinPool;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.rocketmq.common.admin.TopicStatsTable; import org.apache.rocketmq.common.admin.TopicStatsTable;
import org.apache.rocketmq.common.protocol.body.ClusterInfo; import org.apache.rocketmq.common.protocol.body.ClusterInfo;
...@@ -60,7 +61,7 @@ public class MQAdmin { ...@@ -60,7 +61,7 @@ public class MQAdmin {
} }
} }
mqAdminExt.shutdown(); ForkJoinPool.commonPool().execute(mqAdminExt::shutdown);
return createResult; return createResult;
} }
...@@ -99,7 +100,7 @@ public class MQAdmin { ...@@ -99,7 +100,7 @@ public class MQAdmin {
createResult = false; createResult = false;
e.printStackTrace(); e.printStackTrace();
} }
mqAdminExt.shutdown(); ForkJoinPool.commonPool().execute(mqAdminExt::shutdown);
return createResult; return createResult;
} }
...@@ -113,7 +114,7 @@ public class MQAdmin { ...@@ -113,7 +114,7 @@ public class MQAdmin {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
mqAdminExt.shutdown(); ForkJoinPool.commonPool().execute(mqAdminExt::shutdown);
return clusterInfo; return clusterInfo;
} }
...@@ -159,7 +160,7 @@ public class MQAdmin { ...@@ -159,7 +160,7 @@ public class MQAdmin {
createResult = false; createResult = false;
e.printStackTrace(); e.printStackTrace();
} }
mqAdminExt.shutdown(); ForkJoinPool.commonPool().execute(mqAdminExt::shutdown);
} }
} }
...@@ -17,13 +17,23 @@ ...@@ -17,13 +17,23 @@
package org.apache.rocketmq.test.base; package org.apache.rocketmq.test.base;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.broker.BrokerController;
import org.apache.rocketmq.client.consumer.MQPullConsumer;
import org.apache.rocketmq.client.consumer.MQPushConsumer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.MQProducer;
import org.apache.rocketmq.client.producer.TransactionListener; import org.apache.rocketmq.client.producer.TransactionListener;
import org.apache.rocketmq.common.MQVersion; import org.apache.rocketmq.common.MQVersion;
import org.apache.rocketmq.common.protocol.route.BrokerData;
import org.apache.rocketmq.namesrv.NamesrvController; import org.apache.rocketmq.namesrv.NamesrvController;
import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.remoting.protocol.RemotingCommand;
import org.apache.rocketmq.test.client.rmq.RMQAsyncSendProducer; import org.apache.rocketmq.test.client.rmq.RMQAsyncSendProducer;
...@@ -36,21 +46,28 @@ import org.apache.rocketmq.test.factory.ConsumerFactory; ...@@ -36,21 +46,28 @@ import org.apache.rocketmq.test.factory.ConsumerFactory;
import org.apache.rocketmq.test.listener.AbstractListener; import org.apache.rocketmq.test.listener.AbstractListener;
import org.apache.rocketmq.test.util.MQAdmin; import org.apache.rocketmq.test.util.MQAdmin;
import org.apache.rocketmq.test.util.MQRandomUtils; import org.apache.rocketmq.test.util.MQRandomUtils;
import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
import org.apache.rocketmq.tools.admin.MQAdminExt;
import static org.awaitility.Awaitility.await;
public class BaseConf { public class BaseConf {
public static String nsAddr; public final static String nsAddr;
protected static String broker1Name; protected final static String broker1Name;
protected static String broker2Name; protected final static String broker2Name;
protected static String clusterName; protected final static String clusterName;
protected static int brokerNum; protected final static int brokerNum;
protected static int waitTime = 5; protected final static int waitTime = 5;
protected static int consumeTime = 2 * 60 * 1000; protected final static int consumeTime = 2 * 60 * 1000;
protected static NamesrvController namesrvController; protected final static int QUEUE_NUMBERS = 8;
protected static BrokerController brokerController1; protected final static NamesrvController namesrvController;
protected static BrokerController brokerController2; protected final static BrokerController brokerController1;
protected static List<Object> mqClients = new ArrayList<Object>(); protected final static BrokerController brokerController2;
protected static boolean debug = false; protected final static List<BrokerController> brokerControllerList;
private static Logger log = Logger.getLogger(BaseConf.class); protected final static Map<String, BrokerController> brokerControllerMap;
protected final static List<Object> mqClients = new ArrayList<Object>();
protected final static boolean debug = false;
private final static Logger log = Logger.getLogger(BaseConf.class);
static { static {
System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION)); System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION));
...@@ -62,14 +79,32 @@ public class BaseConf { ...@@ -62,14 +79,32 @@ public class BaseConf {
broker1Name = brokerController1.getBrokerConfig().getBrokerName(); broker1Name = brokerController1.getBrokerConfig().getBrokerName();
broker2Name = brokerController2.getBrokerConfig().getBrokerName(); broker2Name = brokerController2.getBrokerConfig().getBrokerName();
brokerNum = 2; brokerNum = 2;
brokerControllerList = ImmutableList.of(brokerController1, brokerController2);
brokerControllerMap = brokerControllerList.stream().collect(Collectors.toMap(input -> input.getBrokerConfig().getBrokerName(), Function.identity()));
} }
public BaseConf() { public BaseConf() {
} }
// This method can't be placed in the static block of BaseConf, which seems to lead to a strange dead lock.
public static void waitBrokerRegistered(final String nsAddr, final String clusterName) {
final DefaultMQAdminExt mqAdminExt = new DefaultMQAdminExt(500);
mqAdminExt.setNamesrvAddr(nsAddr);
try {
mqAdminExt.start();
await().atMost(30, TimeUnit.SECONDS).until(() -> {
List<BrokerData> brokerDatas = mqAdminExt.examineTopicRouteInfo(clusterName).getBrokerDatas();
return brokerDatas.size() == brokerNum;
});
} catch (MQClientException e) {
log.error("init failed, please check BaseConf");
}
ForkJoinPool.commonPool().execute(mqAdminExt::shutdown);
}
public static String initTopic() { public static String initTopic() {
String topic = MQRandomUtils.getRandomTopic(); String topic = "tt-" + MQRandomUtils.getRandomTopic();
IntegrationTestBase.initTopic(topic, nsAddr, clusterName); IntegrationTestBase.initTopic(topic, nsAddr, clusterName);
return topic; return topic;
...@@ -157,18 +192,26 @@ public class BaseConf { ...@@ -157,18 +192,26 @@ public class BaseConf {
} }
public static void shutdown() { public static void shutdown() {
try { ImmutableList<Object> mqClients = ImmutableList.copyOf(BaseConf.mqClients);
for (Object mqClient : mqClients) { BaseConf.mqClients.clear();
shutdown(mqClients);
}
public static void shutdown(List<Object> mqClients) {
mqClients.forEach(mqClient -> ForkJoinPool.commonPool().execute(() -> {
if (mqClient instanceof AbstractMQProducer) { if (mqClient instanceof AbstractMQProducer) {
((AbstractMQProducer) mqClient).shutdown(); ((AbstractMQProducer) mqClient).shutdown();
} else if (mqClient instanceof AbstractMQConsumer) {
} else {
((AbstractMQConsumer) mqClient).shutdown(); ((AbstractMQConsumer) mqClient).shutdown();
} } else if (mqClient instanceof MQAdminExt) {
} ((MQAdminExt) mqClient).shutdown();
} catch (Exception e) { } else if (mqClient instanceof MQProducer) {
e.printStackTrace(); ((MQProducer) mqClient).shutdown();
} } else if (mqClient instanceof MQPullConsumer) {
((MQPullConsumer) mqClient).shutdown();
} else if (mqClient instanceof MQPushConsumer) {
((MQPushConsumer) mqClient).shutdown();
}
}));
} }
} }
...@@ -47,7 +47,7 @@ public class IntegrationTestBase { ...@@ -47,7 +47,7 @@ public class IntegrationTestBase {
protected static final List<BrokerController> BROKER_CONTROLLERS = new ArrayList<>(); protected static final List<BrokerController> BROKER_CONTROLLERS = new ArrayList<>();
protected static final List<NamesrvController> NAMESRV_CONTROLLERS = new ArrayList<>(); protected static final List<NamesrvController> NAMESRV_CONTROLLERS = new ArrayList<>();
protected static int topicCreateTime = 30 * 1000; protected static int topicCreateTime = 30 * 1000;
protected static final int COMMIT_LOG_SIZE = 1024 * 1024 * 100; public static volatile int COMMIT_LOG_SIZE = 1024 * 1024 * 100;
protected static final int INDEX_NUM = 1000; protected static final int INDEX_NUM = 1000;
private static final AtomicInteger port = new AtomicInteger(40000); private static final AtomicInteger port = new AtomicInteger(40000);
...@@ -183,7 +183,7 @@ public class IntegrationTestBase { ...@@ -183,7 +183,7 @@ public class IntegrationTestBase {
} }
public static boolean initTopic(String topic, String nsAddr, String clusterName) { public static boolean initTopic(String topic, String nsAddr, String clusterName) {
return initTopic(topic, nsAddr, clusterName, 8); return initTopic(topic, nsAddr, clusterName, BaseConf.QUEUE_NUMBERS);
} }
public static void deleteFile(File file) { public static void deleteFile(File file) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册