This is an automated email from the ASF dual-hosted git repository.
nkurihar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new a186672 Fix implementation of equals() for MessageId (#2226)
a186672 is described below
commit a1866721d9e9aa85fb913bc6a0ea165ca0f7ab3d
Author: massakam <[email protected]>
AuthorDate: Wed Jul 25 19:53:08 2018 +0900
Fix implementation of equals() for MessageId (#2226)
---
.../pulsar/client/impl/BatchMessageIdImpl.java | 4 +++-
.../apache/pulsar/client/impl/MessageIdImpl.java | 8 ++++----
.../pulsar/client/impl/BatchMessageIdImplTest.java | 24 ++++++++++++++++++++++
3 files changed, 31 insertions(+), 5 deletions(-)
diff --git
a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/BatchMessageIdImpl.java
b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/BatchMessageIdImpl.java
index 78109c4..d66e242 100644
---
a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/BatchMessageIdImpl.java
+++
b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/BatchMessageIdImpl.java
@@ -92,7 +92,9 @@ public class BatchMessageIdImpl extends MessageIdImpl {
return ledgerId == other.ledgerId && entryId == other.entryId &&
partitionIndex == other.partitionIndex
&& batchIndex == other.batchIndex;
} else if (obj instanceof MessageIdImpl) {
- return batchIndex == NO_BATCH && obj.equals(this);
+ MessageIdImpl other = (MessageIdImpl) obj;
+ return ledgerId == other.ledgerId && entryId == other.entryId &&
partitionIndex == other.partitionIndex
+ && batchIndex == NO_BATCH;
}
return false;
}
diff --git
a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/MessageIdImpl.java
b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/MessageIdImpl.java
index 41cc9c9..3686b12 100644
---
a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/MessageIdImpl.java
+++
b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/MessageIdImpl.java
@@ -70,12 +70,12 @@ public class MessageIdImpl implements MessageId {
@Override
public boolean equals(Object obj) {
- if (obj instanceof MessageIdImpl) {
- MessageIdImpl other = (MessageIdImpl) obj;
- return ledgerId == other.ledgerId && entryId == other.entryId &&
partitionIndex == other.partitionIndex;
- } else if (obj instanceof BatchMessageIdImpl){
+ if (obj instanceof BatchMessageIdImpl) {
BatchMessageIdImpl other = (BatchMessageIdImpl) obj;
return other.equals(this);
+ } else if (obj instanceof MessageIdImpl) {
+ MessageIdImpl other = (MessageIdImpl) obj;
+ return ledgerId == other.ledgerId && entryId == other.entryId &&
partitionIndex == other.partitionIndex;
}
return false;
}
diff --git
a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/BatchMessageIdImplTest.java
b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/BatchMessageIdImplTest.java
index a3b5f72..af21fcf 100644
---
a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/BatchMessageIdImplTest.java
+++
b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/BatchMessageIdImplTest.java
@@ -44,4 +44,28 @@ public class BatchMessageIdImplTest {
Assert.assertTrue(batchMsgId1.hashCode() != batchMsgId2.hashCode());
}
+
+ @Test
+ public void equalsTest() {
+ BatchMessageIdImpl batchMsgId1 = new BatchMessageIdImpl(0, 0, 0, 0);
+ BatchMessageIdImpl batchMsgId2 = new BatchMessageIdImpl(1, 1, 1, 1);
+ BatchMessageIdImpl batchMsgId3 = new BatchMessageIdImpl(0, 0, 0, 1);
+ BatchMessageIdImpl batchMsgId4 = new BatchMessageIdImpl(0, 0, 0, -1);
+ MessageIdImpl msgId = new MessageIdImpl(0, 0, 0);
+
+ Assert.assertTrue(batchMsgId1.equals(batchMsgId1));
+ Assert.assertFalse(batchMsgId1.equals(batchMsgId2));
+ Assert.assertFalse(batchMsgId1.equals(batchMsgId3));
+ Assert.assertFalse(batchMsgId1.equals(batchMsgId4));
+ Assert.assertFalse(batchMsgId1.equals(msgId));
+
+ Assert.assertTrue(msgId.equals(msgId));
+ Assert.assertFalse(msgId.equals(batchMsgId1));
+ Assert.assertFalse(msgId.equals(batchMsgId2));
+ Assert.assertFalse(msgId.equals(batchMsgId3));
+ Assert.assertTrue(msgId.equals(batchMsgId4));
+
+ Assert.assertTrue(batchMsgId4.equals(msgId));
+ }
+
}