From 0ae3e4a002fdf168d3bed86fca470401bb2a2508 Mon Sep 17 00:00:00 2001 From: shesheng Date: Wed, 30 May 2018 17:01:32 +0800 Subject: [PATCH] fix RMQAsyncSend Thread-safe bugs --- .../apache/rocketmq/test/client/rmq/RMQAsyncSendProducer.java | 4 +++- .../client/producer/async/AsyncSendWithMessageQueueIT.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) 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 4a2ce2b7..2f8af68b 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 @@ -18,6 +18,7 @@ package org.apache.rocketmq.test.client.rmq; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import org.apache.log4j.Logger; @@ -38,7 +39,8 @@ public class RMQAsyncSendProducer extends AbstractMQProducer { private String nsAddr = null; private DefaultMQProducer producer = null; private SendCallback sendCallback = null; - private List successSendResult = new ArrayList(); + private List successSendResult = Collections + .synchronizedList(new ArrayList()); private AtomicInteger exceptionMsgCount = new AtomicInteger( 0); private int msgSize = 0; diff --git a/test/src/test/java/org/apache/rocketmq/test/client/producer/async/AsyncSendWithMessageQueueIT.java b/test/src/test/java/org/apache/rocketmq/test/client/producer/async/AsyncSendWithMessageQueueIT.java index 3efc5317..21472854 100644 --- a/test/src/test/java/org/apache/rocketmq/test/client/producer/async/AsyncSendWithMessageQueueIT.java +++ b/test/src/test/java/org/apache/rocketmq/test/client/producer/async/AsyncSendWithMessageQueueIT.java @@ -68,7 +68,7 @@ public class AsyncSendWithMessageQueueIT extends BaseConf { producer.clearMsg(); consumer.clearMsg(); - + producer.getSuccessSendResult().clear(); mq = new MessageQueue(topic, broker2Name, queueId); producer.asyncSend(msgSize, mq); producer.waitForResponse(10 * 1000); -- GitLab