You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by li...@apache.org on 2022/09/05 03:29:19 UTC

[rocketmq] branch develop updated: Fix BrokerOuterAPITest#test_register_timeout (#4978)

This is an automated email from the ASF dual-hosted git repository.

lizhanhui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git


The following commit(s) were added to refs/heads/develop by this push:
     new b2f30272c Fix BrokerOuterAPITest#test_register_timeout (#4978)
b2f30272c is described below

commit b2f30272c85ac422aa6b119452b2de92b9b85dda
Author: Aaron Ai <ya...@gmail.com>
AuthorDate: Mon Sep 5 11:29:13 2022 +0800

    Fix BrokerOuterAPITest#test_register_timeout (#4978)
---
 .../apache/rocketmq/broker/BrokerOuterAPITest.java  | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/broker/src/test/java/org/apache/rocketmq/broker/BrokerOuterAPITest.java b/broker/src/test/java/org/apache/rocketmq/broker/BrokerOuterAPITest.java
index 5db36eafb..845e445bf 100644
--- a/broker/src/test/java/org/apache/rocketmq/broker/BrokerOuterAPITest.java
+++ b/broker/src/test/java/org/apache/rocketmq/broker/BrokerOuterAPITest.java
@@ -47,6 +47,7 @@ import org.apache.rocketmq.store.MessageStore;
 import org.apache.rocketmq.store.config.MessageStoreConfig;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.Spy;
 import org.mockito.invocation.InvocationOnMock;
@@ -189,19 +190,17 @@ public class BrokerOuterAPITest {
         TopicConfigSerializeWrapper topicConfigSerializeWrapper = new TopicConfigSerializeWrapper();
 
         when(nettyRemotingClient.getAvailableNameSrvList()).thenReturn(Lists.asList(nameserver1, nameserver2, new String[] {nameserver3}));
-        when(nettyRemotingClient.invokeSync(anyString(), any(RemotingCommand.class), anyLong())).thenAnswer(new Answer<RemotingCommand>() {
-            @Override
-            public RemotingCommand answer(InvocationOnMock invocation) throws Throwable {
-                if (invocation.getArgument(0) == nameserver1) {
-                    return response;
-                } else if (invocation.getArgument(0) == nameserver2) {
-                    return response;
-                } else if (invocation.getArgument(0) == nameserver3) {
-                    TimeUnit.MILLISECONDS.sleep(timeOut + 20);
-                    return response;
-                }
+        final ArgumentCaptor<Long> timeoutMillisCaptor = ArgumentCaptor.forClass(Long.class);
+        final ArgumentCaptor<String> namesrvCaptor = ArgumentCaptor.forClass(String.class);
+        when(nettyRemotingClient.invokeSync(namesrvCaptor.capture(), any(RemotingCommand.class),
+            timeoutMillisCaptor.capture())).thenAnswer((Answer<RemotingCommand>) invocation -> {
+            final String namesrv = namesrvCaptor.getValue();
+            if (nameserver1.equals(namesrv) || nameserver2.equals(namesrv)) {
                 return response;
             }
+            long delayTimeMillis = 1000;
+            TimeUnit.MILLISECONDS.sleep(timeoutMillisCaptor.getValue() + delayTimeMillis);
+            return response;
         });
         List<RegisterBrokerResult> registerBrokerResultList = brokerOuterAPI.registerBrokerAll(clusterName, brokerAddr, brokerName, brokerId, "hasServerAddr", topicConfigSerializeWrapper, Lists.<String>newArrayList(), false, timeOut, false, true, new BrokerIdentity());