-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[feat][broker] PIP-145: Notifications for faster topic discovery #16062
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a9dbf26
PIP-145: Notifications for faster topic discovery
1f4d9ad
Fix checkstyle violation
577c717
Fix cpp client compile error
3a97b69
Remove unused code, remove failed watchers
a177ade
Rename command Unwatch, extract fields from command to avoid concurre…
da7d5c4
Fix cpp client compile error
c71bb64
Fix cpp client compile error
78471b6
Merge remote-tracking branch 'apache/master' into PIP-145-Part2
merlimat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
109 changes: 109 additions & 0 deletions
109
...ar-broker-common/src/test/java/org/apache/pulsar/broker/resources/TopicResourcesTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.pulsar.broker.resources; | ||
|
|
||
| import org.apache.pulsar.common.naming.NamespaceName; | ||
| import org.apache.pulsar.metadata.api.MetadataStore; | ||
| import org.apache.pulsar.metadata.api.Notification; | ||
| import org.apache.pulsar.metadata.api.NotificationType; | ||
| import org.testng.annotations.BeforeMethod; | ||
| import org.testng.annotations.Test; | ||
| import static org.mockito.Mockito.any; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.verifyNoInteractions; | ||
| import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
| import java.util.function.BiConsumer; | ||
|
|
||
| public class TopicResourcesTest { | ||
|
|
||
| private MetadataStore metadataStore; | ||
| private TopicResources topicResources; | ||
|
|
||
| @BeforeMethod | ||
| public void setup() { | ||
| metadataStore = mock(MetadataStore.class); | ||
| topicResources = new TopicResources(metadataStore); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConstructorRegistersAsListener() { | ||
| verify(metadataStore).registerListener(any()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testListenerInvokedWhenTopicCreated() { | ||
| BiConsumer<String, NotificationType> listener = mock(BiConsumer.class); | ||
| topicResources.registerPersistentTopicListener(NamespaceName.get("tenant/namespace"), listener); | ||
| topicResources.handleNotification(new Notification(NotificationType.Created, "/managed-ledgers/tenant/namespace/persistent/topic")); | ||
| verify(listener).accept("persistent://tenant/namespace/topic", NotificationType.Created); | ||
| } | ||
|
|
||
| @Test | ||
| public void testListenerInvokedWhenTopicV1Created() { | ||
| BiConsumer<String, NotificationType> listener = mock(BiConsumer.class); | ||
| topicResources.registerPersistentTopicListener(NamespaceName.get("tenant/cluster/namespace"), listener); | ||
| topicResources.handleNotification(new Notification(NotificationType.Created, "/managed-ledgers/tenant/cluster/namespace/persistent/topic")); | ||
| verify(listener).accept("persistent://tenant/cluster/namespace/topic", NotificationType.Created); | ||
| } | ||
|
|
||
| @Test | ||
| public void testListenerInvokedWhenTopicDeleted() { | ||
| BiConsumer<String, NotificationType> listener = mock(BiConsumer.class); | ||
| topicResources.registerPersistentTopicListener(NamespaceName.get("tenant/namespace"), listener); | ||
| topicResources.handleNotification(new Notification(NotificationType.Deleted, "/managed-ledgers/tenant/namespace/persistent/topic")); | ||
| verify(listener).accept("persistent://tenant/namespace/topic", NotificationType.Deleted); | ||
| } | ||
|
|
||
| @Test | ||
| public void testListenerNotInvokedWhenSubscriptionCreated() { | ||
| BiConsumer<String, NotificationType> listener = mock(BiConsumer.class); | ||
| topicResources.registerPersistentTopicListener(NamespaceName.get("tenant/namespace"), listener); | ||
| topicResources.handleNotification(new Notification(NotificationType.Created, "/managed-ledgers/tenant/namespace/persistent/topic/subscription")); | ||
| verifyNoInteractions(listener); | ||
| } | ||
|
|
||
| @Test | ||
| public void testListenerNotInvokedWhenTopicCreatedInOtherNamespace() { | ||
| BiConsumer<String, NotificationType> listener = mock(BiConsumer.class); | ||
| topicResources.registerPersistentTopicListener(NamespaceName.get("tenant/namespace"), listener); | ||
| topicResources.handleNotification(new Notification(NotificationType.Created, "/managed-ledgers/tenant/namespace2/persistent/topic")); | ||
| verifyNoInteractions(listener); | ||
| } | ||
|
|
||
| @Test | ||
| public void testListenerNotInvokedWhenTopicModified() { | ||
| BiConsumer<String, NotificationType> listener = mock(BiConsumer.class); | ||
| topicResources.registerPersistentTopicListener(NamespaceName.get("tenant/namespace"), listener); | ||
| topicResources.handleNotification(new Notification(NotificationType.Modified, "/managed-ledgers/tenant/namespace/persistent/topic")); | ||
| verifyNoInteractions(listener); | ||
| } | ||
|
|
||
| @Test | ||
| public void testListenerNotInvokedAfterDeregistered() { | ||
| BiConsumer<String, NotificationType> listener = mock(BiConsumer.class); | ||
| topicResources.registerPersistentTopicListener(NamespaceName.get("tenant/namespace"), listener); | ||
| topicResources.handleNotification(new Notification(NotificationType.Created, "/managed-ledgers/tenant/namespace/persistent/topic")); | ||
| verify(listener).accept("persistent://tenant/namespace/topic", NotificationType.Created); | ||
| topicResources.deregisterPersistentTopicListener(listener); | ||
| topicResources.handleNotification(new Notification(NotificationType.Created, "/managed-ledgers/tenant/namespace/persistent/topic2")); | ||
| verifyNoMoreInteractions(listener); | ||
| } | ||
|
|
||
| } |
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could have this as part of
NamespaceNamewhere we can store the compiled pattern.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would improve performance indeed. The only problem I'd have with it is that we'd be referring to a relatively low-level detail (the managed ledger path) in a very general and high-level class. To me, it feels like breaking encapsulation/abstraction.
What do you think about caching the patterns in this class instead? Something along the lines of
NamespaceName.cache.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
TopicNamewe already havegetPersistenceName()which is kind of similar. On one hand I agree that it's not directly related to the logical name, though it was a way to ensure all the naming related ops are in a single place with no duplicated approaches.