Skip to content

Commit

Permalink
[ISSUE apache#353]Optimzation For Unit Test (apache#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellojungle authored and vongosling committed Jul 5, 2018
1 parent 650f46b commit 94f3b5a
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 27 deletions.
15 changes: 9 additions & 6 deletions filter/src/test/java/org/apache/rocketmq/filter/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,17 @@ public void testParse_decimalOverFlow() {
@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);

Expand Down
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
</executions>
<configuration>
<rules>
<banCircularDependencies />
<banCircularDependencies/>
</rules>
<fail>true</fail>
</configuration>
Expand Down Expand Up @@ -315,6 +315,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<skipAfterFailureCount>1</skipAfterFailureCount>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
</configuration>
Expand All @@ -333,6 +334,7 @@
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<skipAfterFailureCount>1</skipAfterFailureCount>
<excludes>
<exclude>**/NormalMsgDelayIT.java</exclude>
</excludes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public void shutdown() {

try {

Thread.sleep(1000 * 3);
Thread.sleep(1000);
} catch (InterruptedException e) {
log.error("shutdown Exception, ", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ public void dispatch(DispatchRequest request) {
try {
try {
putMsg(master);
// wait build consume queue
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
assertThat(Boolean.FALSE).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
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;

Expand All @@ -39,20 +40,19 @@ public class RMQAsyncSendProducer extends AbstractMQProducer {
private String nsAddr = null;
private DefaultMQProducer producer = null;
private SendCallback sendCallback = null;
private List<org.apache.rocketmq.client.producer.SendResult> successSendResult = Collections
.synchronizedList(new ArrayList<org.apache.rocketmq.client.producer.SendResult>());
private AtomicInteger exceptionMsgCount = new AtomicInteger(
0);
private List<SendResult> successSendResult = Collections.synchronizedList(new ArrayList<SendResult>());
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();
}
Expand All @@ -66,7 +66,7 @@ public int getSuccessMsgCount() {
return successSendResult.size();
}

public List<org.apache.rocketmq.client.producer.SendResult> getSuccessSendResult() {
public List<SendResult> getSuccessSendResult() {
return successSendResult;
}

Expand Down Expand Up @@ -94,10 +94,12 @@ private void start() {
}
}

public SendResult send(Object msg, Object arg) {
@Override
public ResultWrapper send(Object msg, Object arg) {
return null;
}

@Override
public void shutdown() {
producer.shutdown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
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);
Expand Down Expand Up @@ -91,7 +91,7 @@ public void start() {
}
}

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 {
Expand Down Expand Up @@ -132,7 +132,7 @@ public void send(List<Object> msgs, MessageQueue mq) {
}
}

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 94f3b5a

Please sign in to comment.