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 0dd48c39db [ISSUE #11402] Add unit tests for TopicSysFlag and 
SubscriptionSysFlag (#11404)
0dd48c39db is described below

commit 0dd48c39dbdfe0601200e31f441979f88d93ff99
Author: Untergang1 <[email protected]>
AuthorDate: Wed Oct 14 17:29:47 2026 +0800

    [ISSUE #11402] Add unit tests for TopicSysFlag and SubscriptionSysFlag 
(#11404)
---
 .../common/sysflag/SubscriptionSysFlagTest.java    | 53 ++++++++++++++
 .../rocketmq/common/sysflag/TopicSysFlagTest.java  | 84 ++++++++++++++++++++++
 2 files changed, 137 insertions(+)

diff --git 
a/common/src/test/java/org/apache/rocketmq/common/sysflag/SubscriptionSysFlagTest.java
 
b/common/src/test/java/org/apache/rocketmq/common/sysflag/SubscriptionSysFlagTest.java
new file mode 100644
index 0000000000..f84a4b2002
--- /dev/null
+++ 
b/common/src/test/java/org/apache/rocketmq/common/sysflag/SubscriptionSysFlagTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.sysflag;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class SubscriptionSysFlagTest {
+
+    private static final int UNIT = 0x1;
+
+    @Test
+    public void testBuildSysFlag() {
+        assertThat(SubscriptionSysFlag.buildSysFlag(false)).isEqualTo(0);
+        assertThat(SubscriptionSysFlag.buildSysFlag(true)).isEqualTo(UNIT);
+    }
+
+    @Test
+    public void testUnitFlag() {
+        int flag = SubscriptionSysFlag.setUnitFlag(0);
+        assertThat(SubscriptionSysFlag.hasUnitFlag(flag)).isTrue();
+        assertThat(SubscriptionSysFlag.setUnitFlag(flag)).isEqualTo(flag);
+
+        flag = SubscriptionSysFlag.clearUnitFlag(flag);
+        assertThat(SubscriptionSysFlag.hasUnitFlag(flag)).isFalse();
+        assertThat(flag).isEqualTo(0);
+        assertThat(SubscriptionSysFlag.clearUnitFlag(flag)).isEqualTo(flag);
+    }
+
+    @Test
+    public void testOtherBitsArePreserved() {
+        int otherBits = 0xFF0;
+
+        
assertThat(SubscriptionSysFlag.setUnitFlag(otherBits)).isEqualTo(otherBits | 
UNIT);
+        assertThat(SubscriptionSysFlag.clearUnitFlag(otherBits | 
UNIT)).isEqualTo(otherBits);
+        assertThat(SubscriptionSysFlag.hasUnitFlag(otherBits)).isFalse();
+    }
+}
diff --git 
a/common/src/test/java/org/apache/rocketmq/common/sysflag/TopicSysFlagTest.java 
b/common/src/test/java/org/apache/rocketmq/common/sysflag/TopicSysFlagTest.java
new file mode 100644
index 0000000000..6d9dd5a007
--- /dev/null
+++ 
b/common/src/test/java/org/apache/rocketmq/common/sysflag/TopicSysFlagTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.sysflag;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class TopicSysFlagTest {
+
+    private static final int UNIT = 0x1;
+    private static final int UNIT_SUB = 0x2;
+
+    @Test
+    public void testBuildSysFlag() {
+        assertThat(TopicSysFlag.buildSysFlag(false, false)).isEqualTo(0);
+        assertThat(TopicSysFlag.buildSysFlag(true, false)).isEqualTo(UNIT);
+        assertThat(TopicSysFlag.buildSysFlag(false, true)).isEqualTo(UNIT_SUB);
+        assertThat(TopicSysFlag.buildSysFlag(true, true)).isEqualTo(UNIT | 
UNIT_SUB);
+    }
+
+    @Test
+    public void testUnitFlag() {
+        int flag = TopicSysFlag.setUnitFlag(0);
+        assertThat(TopicSysFlag.hasUnitFlag(flag)).isTrue();
+        assertThat(TopicSysFlag.hasUnitSubFlag(flag)).isFalse();
+        assertThat(TopicSysFlag.setUnitFlag(flag)).isEqualTo(flag);
+
+        flag = TopicSysFlag.clearUnitFlag(flag);
+        assertThat(TopicSysFlag.hasUnitFlag(flag)).isFalse();
+        assertThat(flag).isEqualTo(0);
+        assertThat(TopicSysFlag.clearUnitFlag(flag)).isEqualTo(flag);
+    }
+
+    @Test
+    public void testUnitSubFlag() {
+        int flag = TopicSysFlag.setUnitSubFlag(0);
+        assertThat(TopicSysFlag.hasUnitSubFlag(flag)).isTrue();
+        assertThat(TopicSysFlag.hasUnitFlag(flag)).isFalse();
+        assertThat(TopicSysFlag.setUnitSubFlag(flag)).isEqualTo(flag);
+
+        flag = TopicSysFlag.clearUnitSubFlag(flag);
+        assertThat(TopicSysFlag.hasUnitSubFlag(flag)).isFalse();
+        assertThat(flag).isEqualTo(0);
+        assertThat(TopicSysFlag.clearUnitSubFlag(flag)).isEqualTo(flag);
+    }
+
+    @Test
+    public void testFlagsAreIndependent() {
+        int flag = TopicSysFlag.buildSysFlag(true, true);
+
+        int withoutUnit = TopicSysFlag.clearUnitFlag(flag);
+        assertThat(TopicSysFlag.hasUnitFlag(withoutUnit)).isFalse();
+        assertThat(TopicSysFlag.hasUnitSubFlag(withoutUnit)).isTrue();
+
+        int withoutUnitSub = TopicSysFlag.clearUnitSubFlag(flag);
+        assertThat(TopicSysFlag.hasUnitFlag(withoutUnitSub)).isTrue();
+        assertThat(TopicSysFlag.hasUnitSubFlag(withoutUnitSub)).isFalse();
+    }
+
+    @Test
+    public void testOtherBitsArePreserved() {
+        int otherBits = 0xFF0;
+
+        assertThat(TopicSysFlag.setUnitFlag(otherBits)).isEqualTo(otherBits | 
UNIT);
+        assertThat(TopicSysFlag.clearUnitFlag(otherBits | 
UNIT)).isEqualTo(otherBits);
+        assertThat(TopicSysFlag.setUnitSubFlag(otherBits)).isEqualTo(otherBits 
| UNIT_SUB);
+        assertThat(TopicSysFlag.clearUnitSubFlag(otherBits | 
UNIT_SUB)).isEqualTo(otherBits);
+    }
+}

Reply via email to