未验证 提交 dc8609f1 编写于 作者: M Masahiro Sakamoto 提交者: GitHub

Implement toString() method for TopicMessageIdImpl class (#7807)

### Motivation

Currently, the `TopicMessageIdImpl` class does not override the `toString()` method. Therefore, even if the ID of a message received from a partitioned topic is output to the log, we can only know the ID of the Java object.
```java
LOG.info("Received: {} (ID: {})", new String(msg.getData()), msg.getMessageId());
```
```
15:57:17.759 [main] INFO  SampleConsumer - Received: msg0 (ID: org.apache.pulsar.client.impl.TopicMessageIdImpl@e35239b1)
15:57:17.760 [main] INFO  SampleConsumer - Received: msg1 (ID: org.apache.pulsar.client.impl.TopicMessageIdImpl@e3523a0e)
15:57:17.761 [main] INFO  SampleConsumer - Received: msg2 (ID: org.apache.pulsar.client.impl.TopicMessageIdImpl@e3523d72)
15:57:17.762 [main] INFO  SampleConsumer - Received: msg3 (ID: org.apache.pulsar.client.impl.TopicMessageIdImpl@e3524133)
15:57:17.762 [main] INFO  SampleConsumer - Received: msg4 (ID: org.apache.pulsar.client.impl.TopicMessageIdImpl@e3523dcf)
```

### Modifications

Added the `toString()` method to the `TopicMessageIdImpl` class. This method returns the result of converting the `MessageId` instance held internally to a string.
上级 855ee939
......@@ -215,6 +215,7 @@ public class MessageIdTest extends BrokerTestBase {
MessageId topicMessageId = consumer.receive().getMessageId();
MessageId messageId = ((TopicMessageIdImpl)topicMessageId).getInnerMessageId();
log.info("Message ID Received = " + messageId);
Assert.assertEquals(topicMessageId.toString(), messageId.toString());
Assert.assertTrue(messageIds.remove(messageId), "Failed to receive Message");
}
log.info("Message IDs = " + messageIds);
......@@ -257,6 +258,7 @@ public class MessageIdTest extends BrokerTestBase {
for (int i = 0; i < numberOfMessages; i++) {
MessageId topicMessageId = consumer.receive().getMessageId();
MessageId messageId = ((TopicMessageIdImpl)topicMessageId).getInnerMessageId();
Assert.assertEquals(topicMessageId.toString(), messageId.toString());
Assert.assertTrue(messageIds.remove(messageId), "Failed to receive Message");
}
log.info("Message IDs = " + messageIds);
......
......@@ -54,6 +54,11 @@ public class TopicMessageIdImpl implements MessageId {
return messageId;
}
@Override
public String toString() {
return messageId.toString();
}
@Override
public byte[] toByteArray() {
return messageId.toByteArray();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册