You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/04/01 02:51:47 UTC

[GitHub] [rocketmq] XiaoyiPeng commented on a change in pull request #3746: [ISSUE #3681]Add the command to check master-slave synchronization status.

XiaoyiPeng commented on a change in pull request #3746:
URL: https://github.com/apache/rocketmq/pull/3746#discussion_r840191185



##########
File path: tools/src/test/java/org/apache/rocketmq/tools/command/broker/GetMasterSlaveDiffCommandTest.java
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rocketmq.tools.command.broker;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.PosixParser;
+import org.apache.rocketmq.client.exception.MQBrokerException;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.protocol.body.ClusterInfo;
+import org.apache.rocketmq.common.protocol.route.BrokerData;
+import org.apache.rocketmq.remoting.exception.RemotingException;
+import org.apache.rocketmq.srvutil.ServerUtil;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+import org.apache.rocketmq.tools.command.SubCommandException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.internal.util.collections.Sets;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Set;
+
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+public class GetMasterSlaveDiffCommandTest {
+
+    private GetMasterSlaveDiffCommand cmd;
+
+    private static DefaultMQAdminExt defaultMQAdminExt;
+
+    private static final String CLUSTER_NAME = "DefaultCluster";
+
+    private static final String BROKER_NAME = "broker-a";
+
+    @Before
+    public void before() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQBrokerException,
+            InterruptedException, MQClientException {
+
+        ClusterInfo clusterInfo = new ClusterInfo();
+        HashMap<String, Set<String>> clusterMap = new HashMap<>(4);
+        clusterMap.put(CLUSTER_NAME, Sets.newSet(BROKER_NAME));
+        clusterInfo.setClusterAddrTable(clusterMap);
+
+        HashMap<Long, String> brokerMap = new HashMap<>(4);
+        brokerMap.put(0L, "127.0.0.1:10911");
+        BrokerData brokerData = new BrokerData(CLUSTER_NAME, BROKER_NAME, brokerMap);
+        HashMap<String, BrokerData> brokerAddrTable = new HashMap<>();
+        brokerAddrTable.put(BROKER_NAME, brokerData);
+        clusterInfo.setBrokerAddrTable(brokerAddrTable);
+
+        defaultMQAdminExt = new DefaultMQAdminExt();
+        defaultMQAdminExt = spy(defaultMQAdminExt);
+
+        cmd = new GetMasterSlaveDiffCommand();
+        Field field = cmd.getClass().getDeclaredField("defaultMQAdminExt");
+        field.setAccessible(true);
+        field.set(cmd, defaultMQAdminExt);
+
+        doReturn(clusterInfo).when(defaultMQAdminExt).examineBrokerClusterInfo();
+        doReturn(1024L).when(defaultMQAdminExt).getMasterSlaveDiff(anyString());
+    }
+
+    @After
+    public void after() {}
+
+    @Test
+    public void testExecute() throws SubCommandException, RemotingException, MQBrokerException, InterruptedException, MQClientException {
+        Options options = ServerUtil.buildCommandlineOptions(new Options());
+        String[] subargs = new String[] {"-b " + BROKER_NAME , "-c " + CLUSTER_NAME};
+        final CommandLine commandLine =
+            ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
+        cmd.execute(commandLine, options, null);

Review comment:
       Hi, @vongosling 
   Thanks for your review, in package `org.apache.rocketmq.tools.command.broker`, none of the classes has assert for cmd execute.
   For consistency of code style, I didn't add assert before
   
   But just now, I've added the assert for cmd execute, please review again. Thank you very much.
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org