poorbarcode commented on code in PR #17609:
URL: https://github.com/apache/pulsar/pull/17609#discussion_r969861170
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicAutoCreationTest.java:
##########
@@ -85,4 +105,76 @@ public void testPartitionedTopicAutoCreation() throws
PulsarAdminException, Puls
producer.close();
}
+
+
+ @Test
+ public void
testPartitionedTopicAutoCreationForbiddenDuringNamespaceDeletion()
+ throws Exception {
+ final String namespaceName = "my-property/my-ns";
+ final String topic = "persistent://" + namespaceName +
"/test-partitioned-topi-auto-creation-"
+ + UUID.randomUUID().toString();
+
+ pulsar.getPulsarResources().getNamespaceResources()
+ .setPolicies(NamespaceName.get(namespaceName), old -> {
+ old.deleted = true;
+ return old;
+ });
+
+
+ LookupService original = Whitebox.getInternalState(pulsarClient,
"lookup");
+ try {
+
+ // we want to skip the "lookup" phase, because it is blocked by
the HTTP API
+ LookupService mockLookup = mock(LookupService.class);
+ Whitebox.setInternalState(pulsarClient, "lookup", mockLookup);
+ when(mockLookup.getPartitionedTopicMetadata(any())).thenAnswer(i
-> {
+ return CompletableFuture.completedFuture(new
PartitionedTopicMetadata(0));
+ });
+ when(mockLookup.getBroker(any())).thenAnswer(i -> {
+ InetSocketAddress brokerAddress =
+ new InetSocketAddress(pulsar.getAdvertisedAddress(),
pulsar.getBrokerListenPort().get());
+ return
CompletableFuture.completedFuture(Pair.of(brokerAddress, brokerAddress));
+ });
+
+ // Creating a producer and creating a Consumer may trigger
automatic topic
+ // creation, let's try to create a Producer and a Consumer
+ try (Producer<byte[]> producer = pulsarClient.newProducer()
+ .sendTimeout(1, TimeUnit.SECONDS)
+ .topic(topic)
+ .create();) {
+ } catch (PulsarClientException.LookupException expected) {
+ }
+
+ try (Consumer<byte[]> consumer = pulsarClient.newConsumer()
+ .topic(topic)
+ .subscriptionName("test")
+ .subscribe();) {
+ } catch (PulsarClientException.LookupException expected) {
Review Comment:
Same as above
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicAutoCreationTest.java:
##########
@@ -85,4 +105,76 @@ public void testPartitionedTopicAutoCreation() throws
PulsarAdminException, Puls
producer.close();
}
+
+
+ @Test
+ public void
testPartitionedTopicAutoCreationForbiddenDuringNamespaceDeletion()
+ throws Exception {
+ final String namespaceName = "my-property/my-ns";
+ final String topic = "persistent://" + namespaceName +
"/test-partitioned-topi-auto-creation-"
+ + UUID.randomUUID().toString();
+
+ pulsar.getPulsarResources().getNamespaceResources()
+ .setPolicies(NamespaceName.get(namespaceName), old -> {
+ old.deleted = true;
+ return old;
+ });
+
+
+ LookupService original = Whitebox.getInternalState(pulsarClient,
"lookup");
+ try {
+
+ // we want to skip the "lookup" phase, because it is blocked by
the HTTP API
+ LookupService mockLookup = mock(LookupService.class);
+ Whitebox.setInternalState(pulsarClient, "lookup", mockLookup);
+ when(mockLookup.getPartitionedTopicMetadata(any())).thenAnswer(i
-> {
+ return CompletableFuture.completedFuture(new
PartitionedTopicMetadata(0));
+ });
+ when(mockLookup.getBroker(any())).thenAnswer(i -> {
+ InetSocketAddress brokerAddress =
+ new InetSocketAddress(pulsar.getAdvertisedAddress(),
pulsar.getBrokerListenPort().get());
+ return
CompletableFuture.completedFuture(Pair.of(brokerAddress, brokerAddress));
+ });
+
+ // Creating a producer and creating a Consumer may trigger
automatic topic
+ // creation, let's try to create a Producer and a Consumer
+ try (Producer<byte[]> producer = pulsarClient.newProducer()
+ .sendTimeout(1, TimeUnit.SECONDS)
+ .topic(topic)
+ .create();) {
+ } catch (PulsarClientException.LookupException expected) {
Review Comment:
Should we add validation to make sure the exception is what we expect? When
I run this test, the exception is "Namespace bundle for topic (%s) not served
by this instance" which should not be what we expected.
--
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]