提交 e7b9169b 编写于 作者: Q qqeasonchen

optimize unit test

上级 0c47fcf7
...@@ -27,8 +27,8 @@ import java.util.concurrent.CountDownLatch; ...@@ -27,8 +27,8 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.apache.rocketmq.client.ClientConfig; import org.apache.rocketmq.client.ClientConfig;
import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.client.exception.MQClientException;
...@@ -319,24 +319,25 @@ public class DefaultMQProducerTest { ...@@ -319,24 +319,25 @@ public class DefaultMQProducerTest {
@Test @Test
public void testRequestMessage() throws RemotingException, RequestTimeoutException, MQClientException, InterruptedException, MQBrokerException { public void testRequestMessage() throws RemotingException, RequestTimeoutException, MQClientException, InterruptedException, MQBrokerException {
when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(createTopicRoute()); when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(createTopicRoute());
final AtomicBoolean finish = new AtomicBoolean(false);
new Thread(new Runnable() { new Thread(new Runnable() {
@Override public void run() { @Override public void run() {
boolean flag = true; ConcurrentHashMap<String, RequestResponseFuture> responseMap = RequestFutureTable.getRequestFutureTable();
ConcurrentHashMap<String, RequestResponseFuture> responseMap = null;
while (flag) {
responseMap = RequestFutureTable.getRequestFutureTable();
if (responseMap != null) {
flag = false;
}
}
assertThat(responseMap).isNotNull(); assertThat(responseMap).isNotNull();
for (Map.Entry<String, RequestResponseFuture> entry : responseMap.entrySet()) { while (!finish.get()) {
RequestResponseFuture future = entry.getValue(); try {
future.putResponseMessage(message); Thread.sleep(10);
} catch (InterruptedException e) {
}
for (Map.Entry<String, RequestResponseFuture> entry : responseMap.entrySet()) {
RequestResponseFuture future = entry.getValue();
future.putResponseMessage(message);
}
} }
} }
}).start(); }).start();
Message result = producer.request(message, 3 * 1000L); Message result = producer.request(message, 3 * 1000L);
finish.getAndSet(true);
assertThat(result.getTopic()).isEqualTo("FooBar"); assertThat(result.getTopic()).isEqualTo("FooBar");
assertThat(result.getBody()).isEqualTo(new byte[] {'a'}); assertThat(result.getBody()).isEqualTo(new byte[] {'a'});
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册