diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java index 4429a081d41a4..b4444c44b14e1 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java @@ -393,7 +393,11 @@ void createNameSpace(String cluster, String publicTenant, NamespaceName ns) thro } if (!nsr.namespaceExists(ns)) { - broker.getAdminClient().namespaces().createNamespace(ns.toString()); + try { + broker.getAdminClient().namespaces().createNamespace(ns.toString()); + } catch (Exception e) { + log.warn("Failed to create the default namespace {}: {}", ns, e.getMessage()); + } } } diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/PulsarStandaloneTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/PulsarStandaloneTest.java index 357a8e1bd4b0f..3cbf8a555c090 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/PulsarStandaloneTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/PulsarStandaloneTest.java @@ -21,6 +21,7 @@ import static org.apache.commons.io.FileUtils.cleanDirectory; import static org.mockito.Mockito.any; import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -33,6 +34,7 @@ import org.apache.bookkeeper.util.IOUtils; import org.apache.pulsar.client.admin.Namespaces; import org.apache.pulsar.client.admin.PulsarAdmin; +import org.apache.pulsar.client.admin.PulsarAdminException; import org.apache.pulsar.common.naming.NamespaceName; import org.apache.pulsar.broker.PulsarService; import org.apache.pulsar.broker.ServiceConfiguration; @@ -61,7 +63,7 @@ public void testCreateNameSpace() throws Exception { doNothing().when(tr).createTenant(eq(tenant), any()); NamespaceResources nsr = mock(NamespaceResources.class); - when(nsr.namespaceExists(ns)).thenReturn(false).thenReturn(true); + when(nsr.namespaceExists(ns)).thenReturn(false).thenReturn(true).thenReturn(false); doNothing().when(nsr).createPolicies(eq(ns), any()); PulsarResources resources = mock(PulsarResources.class); @@ -95,6 +97,9 @@ public void testCreateNameSpace() throws Exception { verify(tr, times(1)).createTenant(eq(tenant), any()); verify(admin, times(1)).namespaces(); verify(admin.namespaces(), times(1)).createNamespace(eq(ns.toString())); + + doThrow(new PulsarAdminException("No permission")).when(namespaces).createNamespace(any()); + standalone.createNameSpace(cluster, tenant, ns); } @Test(groups = "broker") diff --git a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/standalone/SmokeTest.java b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/standalone/SmokeTest.java index b435ecf9649aa..38065d05f5443 100644 --- a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/standalone/SmokeTest.java +++ b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/standalone/SmokeTest.java @@ -18,7 +18,12 @@ */ package org.apache.pulsar.tests.integration.standalone; +import static org.testng.Assert.assertEquals; import java.util.function.Supplier; +import lombok.Cleanup; +import org.apache.pulsar.client.admin.PulsarAdmin; +import org.apache.pulsar.client.admin.PulsarAdminException; +import org.apache.pulsar.client.api.PulsarClientException; import org.apache.pulsar.tests.integration.suites.PulsarStandaloneTestSuite; import org.testng.annotations.Test; @@ -29,4 +34,13 @@ public void testPublishAndConsume(Supplier serviceUrl, boolean isPersist super.testPublishAndConsume(serviceUrl.get(), isPersistent); } + @Test + public void testGetBundleRange() throws PulsarClientException, PulsarAdminException { + @Cleanup + PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(getHttpServiceUrl()).build(); + + String topic = "test-get-topic-bundle-range"; + admin.topics().createNonPartitionedTopic(topic); + assertEquals(admin.lookups().getBundleRange(topic), "0xc0000000_0xffffffff"); + } } diff --git a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/topologies/PulsarStandaloneTestBase.java b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/topologies/PulsarStandaloneTestBase.java index 411b5217501cf..ee3048b50f700 100644 --- a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/topologies/PulsarStandaloneTestBase.java +++ b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/topologies/PulsarStandaloneTestBase.java @@ -121,4 +121,7 @@ protected void dumpFunctionLogs(String name) { } } + protected String getHttpServiceUrl() { + return container.getHttpServiceUrl(); + } }