This is an automated email from the ASF dual-hosted git repository.
duhengforever 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 d5c8800 add tests for AllocateMessageQueueAveragely (#3811)
d5c8800 is described below
commit d5c88001252c64dc273fea0e07932ef007513d22
Author: yuz10 <[email protected]>
AuthorDate: Mon Feb 7 23:51:02 2022 +0800
add tests for AllocateMessageQueueAveragely (#3811)
---
.../AllocateMessageQueueAveragelyTest.java | 57 ++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git
a/client/src/test/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueAveragelyTest.java
b/client/src/test/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueAveragelyTest.java
new file mode 100644
index 0000000..b486106
--- /dev/null
+++
b/client/src/test/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueAveragelyTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.client.consumer.rebalance;
+
+import junit.framework.TestCase;
+import org.apache.rocketmq.common.message.MessageQueue;
+import org.junit.Assert;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class AllocateMessageQueueAveragelyTest extends TestCase {
+
+ public void testAllocateMessageQueueAveragely() {
+ List<String> consumerIdList = createConsumerIdList(4);
+ List<MessageQueue> messageQueueList = createMessageQueueList(10);
+ int[] results = new int[consumerIdList.size()];
+ for (int i = 0; i < consumerIdList.size(); i++) {
+ List<MessageQueue> result = new
AllocateMessageQueueAveragely().allocate("", consumerIdList.get(i),
messageQueueList, consumerIdList);
+ results[i] = result.size();
+ }
+ Assert.assertArrayEquals(new int[]{3, 3, 2, 2}, results);
+ }
+
+ private List<String> createConsumerIdList(int size) {
+ List<String> consumerIdList = new ArrayList<String>(size);
+ for (int i = 0; i < size; i++) {
+ consumerIdList.add("CID_PREFIX" + i);
+ }
+ return consumerIdList;
+ }
+
+ private List<MessageQueue> createMessageQueueList(int size) {
+ List<MessageQueue> messageQueueList = new
ArrayList<MessageQueue>(size);
+ for (int i = 0; i < size; i++) {
+ MessageQueue mq = new MessageQueue("topic", "brokerName", i);
+ messageQueueList.add(mq);
+ }
+ return messageQueueList;
+ }
+
+
+}