Skip to content

Commit

Permalink
Fix get properties failed when the message metadata contains the same…
Browse files Browse the repository at this point in the history
… key, but with different values issue.
  • Loading branch information
horizonzy committed Feb 5, 2025
1 parent cdab2d6 commit ffbb581
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public Map<String, String> getProperties() {
(oldValue, newValue) -> newValue));
} else if (msgMetadata.getMetadata().getPropertiesCount() > 0) {
return msgMetadata.getMetadata().getPropertiesList().stream()
.collect(Collectors.toMap(KeyValue::getKey, KeyValue::getValue));
.collect(Collectors.toMap(KeyValue::getKey, KeyValue::getValue,
(oldValue, newValue) -> newValue));
} else {
return Collections.emptyMap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class RawMessageImplTest {
private static final String HARD_CODE_KEY_ID_VALUE = "__pfn_input_msg_id_value__";

@Test
public void testGetProperties() {
public void testGetMessageSingleMetadataProperties() {
ReferenceCountedMessageMetadata refCntMsgMetadata =
ReferenceCountedMessageMetadata.get(mock(ByteBuf.class));
SingleMessageMetadata singleMessageMetadata = new SingleMessageMetadata();
Expand All @@ -56,6 +56,24 @@ public void testGetProperties() {
assertEquals(HARD_CODE_KEY_ID_VALUE, properties.get(HARD_CODE_KEY_ID));
}

@Test
public void testGetMessageMetadataProperties() {
ReferenceCountedMessageMetadata refCntMsgMetadata =
ReferenceCountedMessageMetadata.get(mock(ByteBuf.class));

MessageMetadata messageMetadata = refCntMsgMetadata.getMetadata();
messageMetadata.addProperty().setKey(HARD_CODE_KEY).setValue(KEY_VALUE_FIRST);
messageMetadata.addProperty().setKey(HARD_CODE_KEY).setValue(KEY_VALUE_SECOND);
messageMetadata.addProperty().setKey(HARD_CODE_KEY_ID).setValue(HARD_CODE_KEY_ID_VALUE);

RawMessage msg = RawMessageImpl.get(refCntMsgMetadata, null, null, 0, 0, 0);
Map<String, String> properties = msg.getProperties();
assertEquals(properties.get(HARD_CODE_KEY), KEY_VALUE_SECOND);
assertEquals(properties.get(HARD_CODE_KEY_ID), HARD_CODE_KEY_ID_VALUE);
assertEquals(KEY_VALUE_SECOND, properties.get(HARD_CODE_KEY));
assertEquals(HARD_CODE_KEY_ID_VALUE, properties.get(HARD_CODE_KEY_ID));
}

@Test
public void testNonBatchedMessage() {
MessageMetadata messageMetadata = new MessageMetadata();
Expand Down

0 comments on commit ffbb581

Please sign in to comment.