From 94f3b5a41b1af7054f59343c033d4df622af95ae Mon Sep 17 00:00:00 2001
From: what-a-good-jungle <353187194@qq.com>
Date: Thu, 5 Jul 2018 20:01:49 +0800
Subject: [PATCH] [ISSUE #353]Optimzation For Unit Test (#356)
---
.../apache/rocketmq/filter/ParserTest.java | 15 ++++++++------
pom.xml | 4 +++-
.../rocketmq/store/DefaultMessageStore.java | 2 +-
.../rocketmq/store/ConsumeQueueTest.java | 2 --
.../test/client/rmq/RMQAsyncSendProducer.java | 20 ++++++++++---------
.../test/client/rmq/RMQNormalProducer.java | 6 +++---
.../clientinterface/AbstractMQProducer.java | 4 ++--
.../test/clientinterface/MQProducer.java | 4 ++--
.../{SendResult.java => ResultWrapper.java} | 2 +-
9 files changed, 32 insertions(+), 27 deletions(-)
rename test/src/main/java/org/apache/rocketmq/test/sendresult/{SendResult.java => ResultWrapper.java} (98%)
diff --git a/filter/src/test/java/org/apache/rocketmq/filter/ParserTest.java b/filter/src/test/java/org/apache/rocketmq/filter/ParserTest.java
index 36ef2714..115632fa 100644
--- a/filter/src/test/java/org/apache/rocketmq/filter/ParserTest.java
+++ b/filter/src/test/java/org/apache/rocketmq/filter/ParserTest.java
@@ -84,14 +84,17 @@ public class ParserTest {
@Test
public void testParse_floatOverFlow() {
try {
- String str = "1";
- for (int i = 0; i < 2048; i++) {
- str += "111111111111111111111111111111111111111111111111111";
+ StringBuffer sb = new StringBuffer(210000);
+ sb.append("1");
+ for (int i = 0; i < 2048; i ++) {
+ sb.append("111111111111111111111111111111111111111111111111111");
}
- str += ".";
- for (int i = 0; i < 2048; i++) {
- str += "111111111111111111111111111111111111111111111111111";
+ sb.append(".");
+ for (int i = 0; i < 2048; i ++) {
+ sb.append("111111111111111111111111111111111111111111111111111");
}
+ String str = sb.toString();
+
SelectorParser.parse("a > " + str);
diff --git a/pom.xml b/pom.xml
index 6fe4f73f..72cd3496 100644
--- a/pom.xml
+++ b/pom.xml
@@ -157,7 +157,7 @@
-
+
true
@@ -315,6 +315,7 @@
maven-surefire-plugin
2.19.1
+ 1
1
true
@@ -333,6 +334,7 @@
maven-failsafe-plugin
2.19.1
+ 1
**/NormalMsgDelayIT.java
diff --git a/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java b/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java
index 4fc7412b..1ade7c28 100644
--- a/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java
+++ b/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java
@@ -247,7 +247,7 @@ public class DefaultMessageStore implements MessageStore {
try {
- Thread.sleep(1000 * 3);
+ Thread.sleep(1000);
} catch (InterruptedException e) {
log.error("shutdown Exception, ", e);
}
diff --git a/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueTest.java b/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueTest.java
index b7d38f8c..7e01b851 100644
--- a/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueTest.java
+++ b/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueTest.java
@@ -212,8 +212,6 @@ public class ConsumeQueueTest {
try {
try {
putMsg(master);
- // wait build consume queue
- Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
assertThat(Boolean.FALSE).isTrue();
diff --git a/test/src/main/java/org/apache/rocketmq/test/client/rmq/RMQAsyncSendProducer.java b/test/src/main/java/org/apache/rocketmq/test/client/rmq/RMQAsyncSendProducer.java
index 2f8af68b..9907cac8 100644
--- a/test/src/main/java/org/apache/rocketmq/test/client/rmq/RMQAsyncSendProducer.java
+++ b/test/src/main/java/org/apache/rocketmq/test/client/rmq/RMQAsyncSendProducer.java
@@ -26,10 +26,11 @@ import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.MessageQueueSelector;
import org.apache.rocketmq.client.producer.SendCallback;
+import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageQueue;
import org.apache.rocketmq.test.clientinterface.AbstractMQProducer;
-import org.apache.rocketmq.test.sendresult.SendResult;
+import org.apache.rocketmq.test.sendresult.ResultWrapper;
import org.apache.rocketmq.test.util.RandomUtil;
import org.apache.rocketmq.test.util.TestUtil;
@@ -39,20 +40,19 @@ public class RMQAsyncSendProducer extends AbstractMQProducer {
private String nsAddr = null;
private DefaultMQProducer producer = null;
private SendCallback sendCallback = null;
- private List successSendResult = Collections
- .synchronizedList(new ArrayList());
- private AtomicInteger exceptionMsgCount = new AtomicInteger(
- 0);
+ private List successSendResult = Collections.synchronizedList(new ArrayList());
+ private AtomicInteger exceptionMsgCount = new AtomicInteger(0);
private int msgSize = 0;
public RMQAsyncSendProducer(String nsAddr, String topic) {
super(topic);
this.nsAddr = nsAddr;
sendCallback = new SendCallback() {
- public void onSuccess(org.apache.rocketmq.client.producer.SendResult sendResult) {
+ @Override
+ public void onSuccess(SendResult sendResult) {
successSendResult.add(sendResult);
}
-
+ @Override
public void onException(Throwable throwable) {
exceptionMsgCount.getAndIncrement();
}
@@ -66,7 +66,7 @@ public class RMQAsyncSendProducer extends AbstractMQProducer {
return successSendResult.size();
}
- public List getSuccessSendResult() {
+ public List getSuccessSendResult() {
return successSendResult;
}
@@ -94,10 +94,12 @@ public class RMQAsyncSendProducer extends AbstractMQProducer {
}
}
- public SendResult send(Object msg, Object arg) {
+ @Override
+ public ResultWrapper send(Object msg, Object arg) {
return null;
}
+ @Override
public void shutdown() {
producer.shutdown();
}
diff --git a/test/src/main/java/org/apache/rocketmq/test/client/rmq/RMQNormalProducer.java b/test/src/main/java/org/apache/rocketmq/test/client/rmq/RMQNormalProducer.java
index 42949339..6bbec6cb 100644
--- a/test/src/main/java/org/apache/rocketmq/test/client/rmq/RMQNormalProducer.java
+++ b/test/src/main/java/org/apache/rocketmq/test/client/rmq/RMQNormalProducer.java
@@ -26,7 +26,7 @@ import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageQueue;
import org.apache.rocketmq.test.clientinterface.AbstractMQProducer;
-import org.apache.rocketmq.test.sendresult.SendResult;
+import org.apache.rocketmq.test.sendresult.ResultWrapper;
public class RMQNormalProducer extends AbstractMQProducer {
private static Logger logger = Logger.getLogger(RMQNormalProducer.class);
@@ -91,7 +91,7 @@ public class RMQNormalProducer extends AbstractMQProducer {
}
}
- public SendResult send(Object msg, Object orderKey) {
+ public ResultWrapper send(Object msg, Object orderKey) {
org.apache.rocketmq.client.producer.SendResult metaqResult = null;
Message message = (Message) msg;
try {
@@ -132,7 +132,7 @@ public class RMQNormalProducer extends AbstractMQProducer {
}
}
- public SendResult sendMQ(Message msg, MessageQueue mq) {
+ public ResultWrapper sendMQ(Message msg, MessageQueue mq) {
org.apache.rocketmq.client.producer.SendResult metaqResult = null;
try {
long start = System.currentTimeMillis();
diff --git a/test/src/main/java/org/apache/rocketmq/test/clientinterface/AbstractMQProducer.java b/test/src/main/java/org/apache/rocketmq/test/clientinterface/AbstractMQProducer.java
index 8201e631..df6abfc6 100644
--- a/test/src/main/java/org/apache/rocketmq/test/clientinterface/AbstractMQProducer.java
+++ b/test/src/main/java/org/apache/rocketmq/test/clientinterface/AbstractMQProducer.java
@@ -21,14 +21,14 @@ import java.util.Date;
import java.util.List;
import org.apache.rocketmq.common.message.MessageQueue;
import org.apache.rocketmq.test.client.rmq.RMQNormalProducer;
-import org.apache.rocketmq.test.sendresult.SendResult;
+import org.apache.rocketmq.test.sendresult.ResultWrapper;
import org.apache.rocketmq.test.util.RandomUtil;
import org.apache.rocketmq.test.util.TestUtil;
public abstract class AbstractMQProducer extends MQCollector implements MQProducer {
protected String topic = null;
- protected SendResult sendResult = new SendResult();
+ protected ResultWrapper sendResult = new ResultWrapper();
protected boolean startSuccess = false;
protected String producerGroupName = null;
protected String producerInstanceName = null;
diff --git a/test/src/main/java/org/apache/rocketmq/test/clientinterface/MQProducer.java b/test/src/main/java/org/apache/rocketmq/test/clientinterface/MQProducer.java
index 795457d1..e9ed0d3f 100644
--- a/test/src/main/java/org/apache/rocketmq/test/clientinterface/MQProducer.java
+++ b/test/src/main/java/org/apache/rocketmq/test/clientinterface/MQProducer.java
@@ -17,10 +17,10 @@
package org.apache.rocketmq.test.clientinterface;
-import org.apache.rocketmq.test.sendresult.SendResult;
+import org.apache.rocketmq.test.sendresult.ResultWrapper;
public interface MQProducer {
- SendResult send(Object msg, Object arg);
+ ResultWrapper send(Object msg, Object arg);
void setDebug();
diff --git a/test/src/main/java/org/apache/rocketmq/test/sendresult/SendResult.java b/test/src/main/java/org/apache/rocketmq/test/sendresult/ResultWrapper.java
similarity index 98%
rename from test/src/main/java/org/apache/rocketmq/test/sendresult/SendResult.java
rename to test/src/main/java/org/apache/rocketmq/test/sendresult/ResultWrapper.java
index d53ee7da..9fe31463 100644
--- a/test/src/main/java/org/apache/rocketmq/test/sendresult/SendResult.java
+++ b/test/src/main/java/org/apache/rocketmq/test/sendresult/ResultWrapper.java
@@ -17,7 +17,7 @@
package org.apache.rocketmq.test.sendresult;
-public class SendResult {
+public class ResultWrapper {
private boolean sendResult = false;
private String msgId = null;
private Exception sendException = null;
--
GitLab