Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE in PersistentStickyKeyDispatcherMultipleConsumers #8969

Merged
merged 1 commit into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected void sendMessagesToConsumers(ReadType readType, List<Entry> entries) {
Consumer consumer = current.getKey();
List<Entry> entriesWithSameKey = current.getValue();
int entriesWithSameKeyCount = entriesWithSameKey.size();
final int availablePermits = Math.max(consumer.getAvailablePermits(), 0);
final int availablePermits = consumer == null ? 0 : Math.max(consumer.getAvailablePermits(), 0);
int maxMessagesForC = Math.min(entriesWithSameKeyCount, availablePermits);
int messagesForC = getRestrictedMaxEntriesForConsumer(consumer, entriesWithSameKey,
maxMessagesForC, readType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,35 @@ public void testSendMarkerMessage() {
Assert.assertEquals(allTotalMessagesCaptor.get(0).intValue(), 5);
}

@Test(timeOut = 10000)
public void testSendMessage() {
KeySharedMeta keySharedMeta = KeySharedMeta.newBuilder().setKeySharedMode(PulsarApi.KeySharedMode.STICKY).build();
PersistentStickyKeyDispatcherMultipleConsumers persistentDispatcher = new PersistentStickyKeyDispatcherMultipleConsumers(
topicMock, cursorMock, subscriptionMock, configMock, keySharedMeta);
try {
PulsarApi.IntRange.newBuilder().setStart(0).setEnd(9).build();
keySharedMeta = PulsarApi.KeySharedMeta.newBuilder().setKeySharedMode(PulsarApi.KeySharedMode.STICKY)
.addHashRanges(PulsarApi.IntRange.newBuilder().setStart(0).setEnd(9).build()).build();
Consumer consumerMock = mock(Consumer.class);
doReturn(keySharedMeta).when(consumerMock).getKeySharedMeta();
persistentDispatcher.addConsumer(consumerMock);
persistentDispatcher.consumerFlow(consumerMock, 1000);
} catch (Exception e) {
fail("Failed to add mock consumer", e);
}

List<Entry> entries = new ArrayList<>();
entries.add(EntryImpl.create(1, 1, createMessage("message1", 1)));
entries.add(EntryImpl.create(1, 2, createMessage("message2", 2)));

try {
//Should success,see issue #8960
persistentDispatcher.readEntriesComplete(entries, PersistentStickyKeyDispatcherMultipleConsumers.ReadType.Normal);
} catch (Exception e) {
fail("Failed to readEntriesComplete.", e);
}
}

@Test
public void testSkipRedeliverTemporally() {
final Consumer slowConsumerMock = mock(Consumer.class);
Expand Down