void-ptr974 opened a new pull request, #25857:
URL: https://github.com/apache/pulsar/pull/25857

   Fixes #25837
   
   ### Motivation
   
   `ConsumerImpl.hasMessageAvailable()` can throw 
`UnsupportedOperationException: Unknown MessageId type: null` when it is called 
before any message has been dequeued from a consumer created through 
`newConsumer().subscribe()`.
   
   `hasMessageAvailable` is not part of the `Consumer` public interface, but 
`ConsumerImpl` exposes it as a public implementation method. In this state, 
`startMessageId` can be `null`, and the existing comparison path eventually 
calls `MessageIdAdv.compareTo(null)`.
   
   ### Modifications
   
   - Handle the initial `startMessageId == null` state by querying the broker 
for the last message id response and comparing it with the subscription 
mark-delete position.
   - Extract the mark-delete comparison logic so the existing latest/timestamp 
path and the null-start path share the same behavior.
   - Use `FutureUtil.unwrapCompletionException(...)` when propagating failures 
from `hasMessageAvailableAsync()`.
   - Add a regression test that calls both async and sync 
`ConsumerImpl.hasMessageAvailable` before the first receive.
   
   ### Verifying this change
   
   This change added tests and can be verified as follows:
   
   - Added 
`SimpleProducerConsumerTest.testConsumerImplHasMessageAvailableDoesNotThrowBeforeReceive`.
   - Ran:
   
   ```bash
   ./gradlew :pulsar-broker:test --tests 
org.apache.pulsar.client.api.SimpleProducerConsumerTest.testConsumerImplHasMessageAvailableDoesNotThrowBeforeReceive
 --no-configuration-cache --rerun-tasks
   ```
   
   ### Does this pull request potentially affect one of the following parts:
   
   - [ ] Dependencies (add or upgrade a dependency)
   - [ ] The public API
   - [ ] The schema
   - [ ] The default values of configurations
   - [ ] The threading model
   - [ ] The binary protocol
   - [ ] The REST endpoints
   - [ ] The admin CLI options
   - [ ] The metrics
   - [ ] Anything that affects deployment


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to