Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] [common] Fix RawMessageImpl.getProperties() failed when the message metadata contains the same key but with different values #23927

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 @@ -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
Loading