This is an automated email from the ASF dual-hosted git repository.
jinrongtong 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 d05ff5ef68 [ISSUE #8098] Fix parsing delay message type from property
d05ff5ef68 is described below
commit d05ff5ef6871839fc202612136bb21a24e67998a
Author: Liu Shengzhong <[email protected]>
AuthorDate: Tue May 7 10:44:26 2024 +0800
[ISSUE #8098] Fix parsing delay message type from property
---
.../common/attribute/TopicMessageType.java | 3 +-
.../common/attribute/TopicMessageTypeTest.java | 60 ++++++++++++++++++++++
2 files changed, 62 insertions(+), 1 deletion(-)
diff --git
a/common/src/main/java/org/apache/rocketmq/common/attribute/TopicMessageType.java
b/common/src/main/java/org/apache/rocketmq/common/attribute/TopicMessageType.java
index 9680acec74..5e581a34ee 100644
---
a/common/src/main/java/org/apache/rocketmq/common/attribute/TopicMessageType.java
+++
b/common/src/main/java/org/apache/rocketmq/common/attribute/TopicMessageType.java
@@ -50,7 +50,8 @@ public enum TopicMessageType {
return TopicMessageType.TRANSACTION;
} else if (messageProperty.get(MessageConst.PROPERTY_DELAY_TIME_LEVEL)
!= null
|| messageProperty.get(MessageConst.PROPERTY_TIMER_DELIVER_MS) !=
null
- || messageProperty.get(MessageConst.PROPERTY_TIMER_DELAY_SEC) !=
null) {
+ || messageProperty.get(MessageConst.PROPERTY_TIMER_DELAY_SEC) !=
null
+ || messageProperty.get(MessageConst.PROPERTY_TIMER_DELAY_MS) !=
null) {
return TopicMessageType.DELAY;
} else if (messageProperty.get(MessageConst.PROPERTY_SHARDING_KEY) !=
null) {
return TopicMessageType.FIFO;
diff --git
a/common/src/test/java/org/apache/rocketmq/common/attribute/TopicMessageTypeTest.java
b/common/src/test/java/org/apache/rocketmq/common/attribute/TopicMessageTypeTest.java
new file mode 100644
index 0000000000..67525ae808
--- /dev/null
+++
b/common/src/test/java/org/apache/rocketmq/common/attribute/TopicMessageTypeTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.attribute;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.rocketmq.common.message.MessageConst;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TopicMessageTypeTest {
+ @Test
+ public void testParseFromMessageProperty() {
+ Map<String, String> properties = new HashMap<>();
+
+ // TRANSACTION
+ properties.put(MessageConst.PROPERTY_TRANSACTION_PREPARED, "true");
+ Assert.assertEquals(TopicMessageType.TRANSACTION,
TopicMessageType.parseFromMessageProperty(properties));
+
+ // DELAY
+ properties.clear();
+ properties.put(MessageConst.PROPERTY_DELAY_TIME_LEVEL, "3");
+ Assert.assertEquals(TopicMessageType.DELAY,
TopicMessageType.parseFromMessageProperty(properties));
+
+ properties.clear();
+ properties.put(MessageConst.PROPERTY_TIMER_DELIVER_MS,
System.currentTimeMillis() + 10000 + "");
+ Assert.assertEquals(TopicMessageType.DELAY,
TopicMessageType.parseFromMessageProperty(properties));
+
+ properties.clear();
+ properties.put(MessageConst.PROPERTY_TIMER_DELAY_SEC, 10 + "");
+ Assert.assertEquals(TopicMessageType.DELAY,
TopicMessageType.parseFromMessageProperty(properties));
+
+ properties.clear();
+ properties.put(MessageConst.PROPERTY_TIMER_DELAY_MS, 10000 + "");
+ Assert.assertEquals(TopicMessageType.DELAY,
TopicMessageType.parseFromMessageProperty(properties));
+
+ // FIFO
+ properties.clear();
+ properties.put(MessageConst.PROPERTY_SHARDING_KEY, "sharding_key");
+ Assert.assertEquals(TopicMessageType.FIFO,
TopicMessageType.parseFromMessageProperty(properties));
+
+ // NORMAL
+ properties.clear();
+ Assert.assertEquals(TopicMessageType.NORMAL,
TopicMessageType.parseFromMessageProperty(properties));
+ }
+}