Skip to content

Commit

Permalink
[ROCKETMQ-76] Expose IntegrationTestBase to be used by other integrat…
Browse files Browse the repository at this point in the history
…ion projects closes apache#52
  • Loading branch information
shroman authored and dongeforever committed Jun 6, 2017
1 parent e0d4a50 commit 3401296
Showing 9 changed files with 55 additions and 28 deletions.
16 changes: 16 additions & 0 deletions test/pom.xml
Original file line number Diff line number Diff line change
@@ -47,4 +47,20 @@
<version>0.30</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ public static boolean createTopic(String nameSrvAddr, String clusterName, String
while (!createResult) {
createResult = checkTopicExist(mqAdminExt, topic);
if (System.currentTimeMillis() - startTime < waitTimeSec * 1000) {
TestUtils.waitForMonment(100);
TestUtils.waitForMoment(100);
} else {
log.error(String.format("timeout,but create topic[%s] failed!", topic));
break;
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
import java.util.concurrent.TimeUnit;

public class TestUtils {
public static void waitForMonment(long time) {
public static void waitForMoment(long time) {
try {
Thread.sleep(time);
} catch (InterruptedException var3) {
17 changes: 1 addition & 16 deletions test/src/test/java/org/apache/rocketmq/test/base/BaseConf.java
Original file line number Diff line number Diff line change
@@ -42,7 +42,6 @@ public class BaseConf {
protected static int brokerNum;
protected static int waitTime = 5;
protected static int consumeTime = 1 * 60 * 1000;
protected static int topicCreateTime = 30 * 1000;
protected static NamesrvController namesrvController;
protected static BrokerController brokerController1;
protected static BrokerController brokerController2;
@@ -66,22 +65,8 @@ public BaseConf() {
}

public static String initTopic() {
long startTime = System.currentTimeMillis();
String topic = MQRandomUtils.getRandomTopic();
boolean createResult = false;
while (true) {
createResult = MQAdmin.createTopic(nsAddr, clusterName, topic, 8);
if (createResult) {
break;
} else if (System.currentTimeMillis() - startTime > topicCreateTime) {
Assert.fail(String.format("topic[%s] is created failed after:%d ms", topic,
System.currentTimeMillis() - startTime));
break;
} else {
TestUtils.waitForMonment(500);
continue;
}
}
IntegrationTestBase.initTopic(topic, nsAddr, clusterName);

return topic;
}
Original file line number Diff line number Diff line change
@@ -30,18 +30,23 @@
import org.apache.rocketmq.remoting.netty.NettyClientConfig;
import org.apache.rocketmq.remoting.netty.NettyServerConfig;
import org.apache.rocketmq.store.config.MessageStoreConfig;
import org.apache.rocketmq.test.util.MQAdmin;
import org.apache.rocketmq.test.util.TestUtils;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class IntegrationTestBase {
public static Logger logger = LoggerFactory.getLogger(IntegrationTestBase.class);

protected static final String SEP = File.separator;
protected static final String BROKER_NAME_PREFIX = "TestBrokerName_";
protected static final AtomicInteger BROKER_INDEX = new AtomicInteger(0);
protected static final List<File> TMPE_FILES = new ArrayList<>();
protected static final List<BrokerController> BROKER_CONTROLLERS = new ArrayList<>();
protected static final List<NamesrvController> NAMESRV_CONTROLLERS = new ArrayList<>();
public static Logger logger = LoggerFactory.getLogger(IntegrationTestBase.class);
protected static int topicCreateTime = 30 * 1000;

protected static Random random = new Random();

static {
@@ -125,6 +130,27 @@ public static BrokerController createAndStartBroker(String nsAddr) {
return brokerController;
}

public static boolean initTopic(String topic, String nsAddr, String clusterName) {
long startTime = System.currentTimeMillis();
boolean createResult;

while (true) {
createResult = MQAdmin.createTopic(nsAddr, clusterName, topic, 8);
if (createResult) {
break;
} else if (System.currentTimeMillis() - startTime > topicCreateTime) {
Assert.fail(String.format("topic[%s] is created failed after:%d ms", topic,
System.currentTimeMillis() - startTime));
break;
} else {
TestUtils.waitForMoment(500);
continue;
}
}

return createResult;
}

public static void deleteFile(File file) {
if (!file.exists()) {
return;
Original file line number Diff line number Diff line change
@@ -78,10 +78,10 @@ public void testConsumerStartWithInterval() {
RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, tag,
new RMQNormalListner(originMsgDCName, msgBodyDCName));
producer.send(tag, msgSize, 100);
TestUtils.waitForMonment(5);
TestUtils.waitForMoment(5);
RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), tag,
new RMQNormalListner(originMsgDCName, msgBodyDCName));
TestUtils.waitForMonment(5);
TestUtils.waitForMoment(5);

consumer1.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
@@ -102,10 +102,10 @@ public void testConsumerStartTwoAndCrashOnsAfterWhile() {
new RMQNormalListner(originMsgDCName, msgBodyDCName));

producer.send(tag, msgSize, 100);
TestUtils.waitForMonment(5);
TestUtils.waitForMoment(5);
consumer2.shutdown();
mqClients.remove(1);
TestUtils.waitForMonment(5);
TestUtils.waitForMoment(5);

consumer1.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
Original file line number Diff line number Diff line change
@@ -112,7 +112,7 @@ public void onException(Throwable throwable) {
int checkNum = 50;
while (!sendFail && checkNum > 0) {
checkNum--;
TestUtils.waitForMonment(100);
TestUtils.waitForMoment(100);
}
producer.shutdown();
assertThat(sendFail).isEqualTo(true);
@@ -141,7 +141,7 @@ public void onException(Throwable throwable) {
int checkNum = 50;
while (sendFail && checkNum > 0) {
checkNum--;
TestUtils.waitForMonment(100);
TestUtils.waitForMoment(100);
}
producer.shutdown();
assertThat(sendFail).isEqualTo(false);
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ public void testQueryMsg() {
MessageExt recvMsg = (MessageExt) consumer.getListner().getFirstMsg();
MessageExt queryMsg = null;
try {
TestUtils.waitForMonment(3000);
TestUtils.waitForMoment(3000);
queryMsg = producer.getProducer().viewMessage(((MessageClientExt) recvMsg).getOffsetMsgId());
} catch (Exception e) {
}
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ public void testQueryMsg() {

List<MessageExt> queryMsgs = null;
try {
TestUtils.waitForMonment(500 * 3);
TestUtils.waitForMoment(500 * 3);
queryMsgs = producer.getProducer().queryMessage(topic, key, msgSize, begin - 5000,
System.currentTimeMillis() + 5000).getMessageList();
} catch (Exception e) {
@@ -89,7 +89,7 @@ public void testQueryMax() {
i--;
queryMsgs = producer.getProducer().queryMessage(topic, key, msgSize, begin - 15000,
System.currentTimeMillis() + 15000).getMessageList();
TestUtils.waitForMonment(1000);
TestUtils.waitForMoment(1000);

if (i == 0 || (queryMsgs != null && queryMsgs.size() == max)) {
break;

0 comments on commit 3401296

Please sign in to comment.