You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by te...@apache.org on 2022/12/12 13:06:11 UTC

[pulsar] branch master updated: [fix][broker] Ignore the exception of creating namespace (#18837)

This is an automated email from the ASF dual-hosted git repository.

technoboy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new bdbb118b399 [fix][broker] Ignore the exception of creating namespace (#18837)
bdbb118b399 is described below

commit bdbb118b399e287ae6d1a779484324663bf61633
Author: Zixuan Liu <no...@gmail.com>
AuthorDate: Mon Dec 12 21:05:59 2022 +0800

    [fix][broker] Ignore the exception of creating namespace (#18837)
---
 .../src/main/java/org/apache/pulsar/PulsarStandalone.java  |  6 +++++-
 .../test/java/org/apache/pulsar/PulsarStandaloneTest.java  |  7 ++++++-
 .../pulsar/tests/integration/standalone/SmokeTest.java     | 14 ++++++++++++++
 .../integration/topologies/PulsarStandaloneTestBase.java   |  3 +++
 4 files changed, 28 insertions(+), 2 deletions(-)

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 4429a081d41..b4444c44b14 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 @@ public class PulsarStandalone implements AutoCloseable {
         }
 
         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 357a8e1bd4b..3cbf8a555c0 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 @@ package org.apache.pulsar;
 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.conf.ServerConfiguration;
 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 class PulsarStandaloneTest {
         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 class PulsarStandaloneTest {
         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 b435ecf9649..38065d05f54 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 class SmokeTest extends PulsarStandaloneTestSuite {
         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 411b5217501..ee3048b50f7 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 @@ public abstract class PulsarStandaloneTestBase extends PulsarTestBase {
         }
     }
 
+    protected String getHttpServiceUrl() {
+        return container.getHttpServiceUrl();
+    }
 }