Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,6 @@ public MessageExtBrokerInner convertMessage(MessageExt msgExt, boolean needRoll)
long tagsCodeValue =
MessageExtBrokerInner.tagsString2tagsCode(topicFilterType, msgInner.getTags());
msgInner.setTagsCode(tagsCodeValue);
msgInner.setPropertiesString(MessageDecoder.messageProperties2String(msgExt.getProperties()));

msgInner.setSysFlag(msgExt.getSysFlag());
msgInner.setBornTimestamp(msgExt.getBornTimestamp());
Expand All @@ -1270,6 +1269,9 @@ public MessageExtBrokerInner convertMessage(MessageExt msgExt, boolean needRoll)
MessageAccessor.clearProperty(msgInner, MessageConst.PROPERTY_REAL_TOPIC);
MessageAccessor.clearProperty(msgInner, MessageConst.PROPERTY_REAL_QUEUE_ID);
}
// Encode after the properties are finalized so that the wire data stays consistent
// with the property map, aligning with TimerMessageRocksDBStore#convertMessage.
msgInner.setPropertiesString(MessageDecoder.messageProperties2String(msgInner.getProperties()));
return msgInner;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,31 @@ private static PutMessageResult transformTimerMessage(TimerMessageStore timerMes
return null;
}

@Test
public void testConvertMessagePropertiesStringMatchesProperties() throws Exception {
final TimerMessageStore timerMessageStore = createTimerMessageStore(null, true);

MessageExtBrokerInner msgExt = buildMessage(3000, "TimerTest_testConvertMessage", false);
MessageAccessor.putProperty(msgExt, MessageConst.PROPERTY_REAL_TOPIC, msgExt.getTopic());
MessageAccessor.putProperty(msgExt, MessageConst.PROPERTY_REAL_QUEUE_ID, "0");
msgExt.setPropertiesString(MessageDecoder.messageProperties2String(msgExt.getProperties()));
msgExt.setTopic(TimerMessageStore.TIMER_TOPIC);

// delivered message: internal properties are cleared from both the map and the wire data
MessageExtBrokerInner delivered = timerMessageStore.convertMessage(msgExt, false);
assertEquals("TimerTest_testConvertMessage", delivered.getTopic());
assertFalse(delivered.getPropertiesString().contains(MessageConst.PROPERTY_REAL_TOPIC));
assertFalse(delivered.getPropertiesString().contains(MessageConst.PROPERTY_REAL_QUEUE_ID));
assertEquals(MessageDecoder.messageProperties2String(delivered.getProperties()), delivered.getPropertiesString());

// rolled message: keeps REAL_TOPIC and stays consistent between the map and the wire data
MessageExtBrokerInner rolled = timerMessageStore.convertMessage(msgExt, true);
assertEquals(TimerMessageStore.TIMER_TOPIC, rolled.getTopic());
assertTrue(rolled.getPropertiesString().contains(MessageConst.PROPERTY_REAL_TOPIC));
assertTrue(rolled.getPropertiesString().contains(MessageConst.PROPERTY_REAL_QUEUE_ID));
assertEquals(MessageDecoder.messageProperties2String(rolled.getProperties()), rolled.getPropertiesString());
}

@Test
public void testPutTimerMessage() throws Exception {
Assume.assumeFalse(MixAll.isWindows());
Expand Down
Loading