MessageId#compare is not symmetric (MessageIdImpl, BatchMessageIdImpl)
See original GitHub issueDescribe the bug
Given to MessageId
s, of which one happens to be a MessageIdImpl
and the other is a BatchMessageIdImpl
, the compare method is not symmetric.
To Reproduce
import static org.assertj.core.api.Assertions.assertThat;
@Test
public void shouldBeSymmetric() {
MessageIdImpl simpleMessageId = new MessageIdImpl(1, 2, 3);
BatchMessageIdImpl batchMessageId = new BatchMessageIdImpl(1, 2, 3, 0);
assertThat(simpleMessageId.compareTo(batchMessageId)).isEqualTo(batchMessageId.compareTo(simpleMessageId));
}
Expected behavior MessageId#compare should be symmetric
Additional context Pulsar 2.5.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
BatchMessageIdImpl (Pulsar Client Java 2.2.0 API)
public class BatchMessageIdImpl extends MessageIdImpl ... BatchMessageIdImpl(long ledgerId, long entryId, int partitionIndex, int batchIndex).
Read more >org.apache.pulsar.client.impl.BatchMessageIdImpl java code ...
Clear the internal receiver queue and returns the message id of what was the 1st message in the queue that was * not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, I could, but I am not sure how
MessageIdImpl
andBatchMessageIdImpl
should compare?It seems to me that the asymmetry was introduced by purpose with #1285, the code reads as
But as it is now, it breaks the
Comparable
contract, and that makes it confusing for user of the client API.@racorn Anyway, the compare logic for both classes is correct now 😃
Some code quality improvements can be made, and you’re welcome to give it a review or suggest a test case to cover this issue. See https://github.com/apache/pulsar/pull/18843.