This is an automated email from the ASF dual-hosted git repository.
ShannonDing 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 557887a43a test(common): cover RoundQueue deduplication and FIFO
eviction (#11599)
557887a43a is described below
commit 557887a43aefadae298067299a804abc02efc20f
Author: xiaoyuxiao <[email protected]>
AuthorDate: Tue Nov 24 15:18:33 2026 +0800
test(common): cover RoundQueue deduplication and FIFO eviction (#11599)
---
.../rocketmq/common/queue/RoundQueueTest.java | 77 ++++++++++++++++++++++
1 file changed, 77 insertions(+)
diff --git
a/common/src/test/java/org/apache/rocketmq/common/queue/RoundQueueTest.java
b/common/src/test/java/org/apache/rocketmq/common/queue/RoundQueueTest.java
new file mode 100644
index 0000000000..4c2fed38a4
--- /dev/null
+++ b/common/src/test/java/org/apache/rocketmq/common/queue/RoundQueueTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.common.queue;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class RoundQueueTest {
+
+ @Test
+ public void testDuplicateValuesAreRejected() {
+ RoundQueue<String> queue = new RoundQueue<>(2);
+
+ assertTrue(queue.put(new String("first")));
+ assertFalse(queue.put(new String("first")));
+ assertTrue(queue.put("second"));
+ assertFalse(queue.put("first"));
+ assertFalse(queue.put("second"));
+ }
+
+ @Test
+ public void testCapacityOneEvictsPreviousValue() {
+ RoundQueue<String> queue = new RoundQueue<>(1);
+
+ assertTrue(queue.put("first"));
+ assertFalse(queue.put("first"));
+ assertTrue(queue.put("second"));
+ assertFalse(queue.put("second"));
+ assertTrue(queue.put("first"));
+ }
+
+ @Test
+ public void testFullQueueEvictsOldestValue() {
+ RoundQueue<String> queue = new RoundQueue<>(3);
+ assertTrue(queue.put("first"));
+ assertTrue(queue.put("second"));
+ assertTrue(queue.put("third"));
+
+ assertTrue(queue.put("fourth"));
+
+ assertFalse(queue.put("second"));
+ assertFalse(queue.put("third"));
+ assertFalse(queue.put("fourth"));
+ assertTrue(queue.put("first"));
+ }
+
+ @Test
+ public void testDuplicateDoesNotRefreshInsertionOrder() {
+ RoundQueue<String> queue = new RoundQueue<>(2);
+ assertTrue(queue.put("first"));
+ assertTrue(queue.put("second"));
+
+ assertFalse(queue.put("first"));
+ assertTrue(queue.put("third"));
+
+ assertFalse(queue.put("second"));
+ assertFalse(queue.put("third"));
+ assertTrue(queue.put("first"));
+ }
+}