question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MessageId#compare is not symmetric (MessageIdImpl, BatchMessageIdImpl)

See original GitHub issue

Describe the bug Given to MessageIds, 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:closed
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
racorncommented, Feb 28, 2020

Yes, I could, but I am not sure how MessageIdImpl and BatchMessageIdImpl should compare?

It seems to me that the asymmetry was introduced by purpose with #1285, the code reads as

} else if (o instanceof MessageIdImpl) {
    int res = super.compareTo(o);
    if (res == 0 && batchIndex > NO_BATCH) {
        return 1;
    } else {
        return res;
    }
}

But as it is now, it breaks the Comparable contract, and that makes it confusing for user of the client API.

0reactions
tisonkuncommented, Dec 9, 2022

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found