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

fuyou 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 48ed89807 Use Mockito to directly throw TimeoutException through 
set-up (#5510)
48ed89807 is described below

commit 48ed8980719c14fde8ce145e5d585c6c0852920f
Author: Zhanhui Li <[email protected]>
AuthorDate: Sun Nov 13 17:45:49 2022 +0800

    Use Mockito to directly throw TimeoutException through set-up (#5510)
---
 .../org/apache/rocketmq/broker/BrokerOuterAPITest.java  | 17 ++++++-----------
 1 file changed, 6 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 d91775fe3..dab1a9147 100644
--- a/broker/src/test/java/org/apache/rocketmq/broker/BrokerOuterAPITest.java
+++ b/broker/src/test/java/org/apache/rocketmq/broker/BrokerOuterAPITest.java
@@ -32,6 +32,7 @@ import org.apache.rocketmq.broker.out.BrokerOuterAPI;
 import org.apache.rocketmq.common.BrokerConfig;
 import org.apache.rocketmq.common.BrokerIdentity;
 import org.apache.rocketmq.common.MixAll;
+import org.apache.rocketmq.remoting.exception.RemotingTimeoutException;
 import org.apache.rocketmq.remoting.netty.NettyClientConfig;
 import org.apache.rocketmq.remoting.netty.NettyRemotingClient;
 import org.apache.rocketmq.remoting.netty.NettyServerConfig;
@@ -51,6 +52,7 @@ import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
+import org.mockito.ArgumentMatchers;
 import org.mockito.Mock;
 import org.mockito.Spy;
 import org.mockito.invocation.InvocationOnMock;
@@ -64,6 +66,7 @@ import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.argThat;
 import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.AdditionalMatchers.or;
 import static org.mockito.Mockito.when;
 
 @RunWith(MockitoJUnitRunner.class)
@@ -194,17 +197,9 @@ public class BrokerOuterAPITest {
 
         
when(nettyRemotingClient.getAvailableNameSrvList()).thenReturn(Lists.asList(nameserver1,
 nameserver2, new String[] {nameserver3}));
         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;
-            });
+        
when(nettyRemotingClient.invokeSync(or(ArgumentMatchers.eq(nameserver1), 
ArgumentMatchers.eq(nameserver2)), any(RemotingCommand.class),
+            timeoutMillisCaptor.capture())).thenReturn(response);
+        when(nettyRemotingClient.invokeSync(ArgumentMatchers.eq(nameserver3), 
any(RemotingCommand.class), 
anyLong())).thenThrow(RemotingTimeoutException.class);
         List<RegisterBrokerResult> registerBrokerResultList = 
brokerOuterAPI.registerBrokerAll(clusterName, brokerAddr, brokerName, brokerId, 
"hasServerAddr", topicConfigSerializeWrapper, Lists.<String>newArrayList(), 
false, timeOut, false, true, new BrokerIdentity());
 
         assertEquals(2, registerBrokerResultList.size());

Reply via email to