Repository navigation
test(mqtt): use real repositories in SubscribeTest and cover the session update - #8093
Merged
yuluo-yx merged 1 commit intoOct 24, 2026
Merged
Conversation
…ion update SubscribeTest mocked ChannelRepository and SessionRepository, and a mock answers null for every lookup. subscribe() therefore always took the "no session" branch: the client id was null, the session was null, and the code that stores the granted subscriptions on the session never ran. The three assertions only covered SUBACK, so a regression there would have gone unnoticed. The channel and session repositories are now real instances, the connected channel is registered in the channel repository, and a fourth test asserts that the subscriptions land on the session. SubscribeRepository and TopicRepository stay mocked, because subscribe() writes to the first and the second is only observed through verify(). This also supersedes apache#8089, which adds the same real instances but keeps the @mock fields with the same names and does not compile.
yuluo-yx
approved these changes
Oct 24, 2026
This was referenced Oct 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
SubscribeTestregisteredChannelRepositoryandSessionRepositoryas Mockito mocks:A mock answers
nullfor every lookup, so inSubscribe.subscribe():the branch that stores the granted subscriptions on the session never ran. All three tests only
looked at the SUBACK, so that half of
subscribe()had no coverage at all — and the mocks are alsowhy the null-key crash described in #8092 stayed invisible from this test class.
What this changes
ChannelRepositoryandSessionRepositoryare real instances; the connected channel is registeredin the channel repository, so
subscribe()resolves a real client id.testSubscribeStoresSubscriptionsInSessionasserts the subscription reaches the session.SubscribeRepositoryandTopicRepositorystay mocked:subscribe()writes to the first, and thesecond is only observed through
verify(topicRepository, never()).Verification
Full module: 147 tests, and the only errors are the three pre-existing
MqttTransportHandlerTestones described below — the same three that a cleanmasterproduceslocally, no new failure.
Notes
MqttTransportHandlerTestfails withSingleton.get(InflightRepository.class)returningnullwhen it does not run after a class that registers every repository (
MqttBootstrapServerTest).That is a pre-existing order dependency in a different test class; it is fixed in fix(mqtt): scope session state per instance and guard a missing client id #8092 together
with the repository scoping, not here.
@Mockfields with thesame names (
variable channelRepository is already defined in class) and does not compile.