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:18:46 UTC

[pulsar] branch branch-2.11 updated (0b5f31dbf34 -> 00d2516addc)

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

technoboy pushed a change to branch branch-2.11
in repository https://gitbox.apache.org/repos/asf/pulsar.git


    from 0b5f31dbf34 [fix][txn] Fix PendingAckHandleImpl when `pendingAckStoreProvider.checkInitializedBefore` failed (#18859)
     new 4294a0f73c8 [fix][broker] Fix create ns (#17864)
     new 00d2516addc [fix][broker] Ignore the exception of creating namespace (#18837)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../main/java/org/apache/pulsar/PulsarStandalone.java  | 10 +++++-----
 .../java/org/apache/pulsar/PulsarStandaloneTest.java   | 18 ++++++++++++++++--
 .../pulsar/tests/integration/standalone/SmokeTest.java | 14 ++++++++++++++
 .../topologies/PulsarStandaloneTestBase.java           |  3 +++
 4 files changed, 38 insertions(+), 7 deletions(-)


[pulsar] 02/02: [fix][broker] Ignore the exception of creating namespace (#18837)

Posted by te...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 00d2516addc1f15a6d17c9d645a14ae24ade7c9d
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 22e4070d053..b5cc3462691 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java
@@ -392,7 +392,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 efa4d2b4862..f62ce1c5e46 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;
@@ -32,6 +33,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;
@@ -60,7 +62,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);
@@ -94,6 +96,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 5d142297a91..9fb90f172c5 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 85d7b46c711..1261e76c0ba 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();
+    }
 }


[pulsar] 01/02: [fix][broker] Fix create ns (#17864)

Posted by te...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 4294a0f73c87173f1f76c8a004f116cc8d570f39
Author: Zixuan Liu <no...@gmail.com>
AuthorDate: Sat Oct 8 11:19:06 2022 +0800

    [fix][broker] Fix create ns (#17864)
    
    Signed-off-by: Zixuan Liu <no...@gmail.com>
---
 .../src/main/java/org/apache/pulsar/PulsarStandalone.java     |  6 +-----
 .../src/test/java/org/apache/pulsar/PulsarStandaloneTest.java | 11 ++++++++++-
 2 files changed, 11 insertions(+), 6 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 8c5f9e899b2..22e4070d053 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java
@@ -25,7 +25,6 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.Sets;
 import java.io.File;
 import java.nio.file.Paths;
-import java.util.Collections;
 import java.util.Optional;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.bookkeeper.conf.ServerConfiguration;
@@ -40,7 +39,6 @@ import org.apache.pulsar.common.naming.NamespaceName;
 import org.apache.pulsar.common.naming.TopicName;
 import org.apache.pulsar.common.partition.PartitionedTopicMetadata;
 import org.apache.pulsar.common.policies.data.ClusterData;
-import org.apache.pulsar.common.policies.data.Policies;
 import org.apache.pulsar.common.policies.data.TenantInfo;
 import org.apache.pulsar.functions.instance.state.PulsarMetadataStateStoreProviderImpl;
 import org.apache.pulsar.functions.worker.WorkerConfig;
@@ -394,9 +392,7 @@ public class PulsarStandalone implements AutoCloseable {
         }
 
         if (!nsr.namespaceExists(ns)) {
-            Policies nsp = new Policies();
-            nsp.replication_clusters = Collections.singleton(config.getClusterName());
-            nsr.createPolicies(ns, nsp);
+            broker.getAdminClient().namespaces().createNamespace(ns.toString());
         }
     }
 
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 f4c34bbc96c..efa4d2b4862 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/PulsarStandaloneTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/PulsarStandaloneTest.java
@@ -30,6 +30,8 @@ import java.io.File;
 import java.util.List;
 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.common.naming.NamespaceName;
 import org.apache.pulsar.broker.PulsarService;
 import org.apache.pulsar.broker.ServiceConfiguration;
@@ -66,12 +68,18 @@ public class PulsarStandaloneTest {
         when(resources.getTenantResources()).thenReturn(tr);
         when(resources.getNamespaceResources()).thenReturn(nsr);
 
+        Namespaces namespaces = mock(Namespaces.class);
+        doNothing().when(namespaces).createNamespace(any());
+        PulsarAdmin admin = mock(PulsarAdmin.class);
+        when(admin.namespaces()).thenReturn(namespaces);
+
         PulsarService broker = mock(PulsarService.class);
         when(broker.getPulsarResources()).thenReturn(resources);
         when(broker.getWebServiceAddress()).thenReturn("pulsar://localhost:8080");
         when(broker.getWebServiceAddressTls()).thenReturn(null);
         when(broker.getBrokerServiceUrl()).thenReturn("pulsar://localhost:6650");
         when(broker.getBrokerServiceUrlTls()).thenReturn(null);
+        when(broker.getAdminClient()).thenReturn(admin);
 
         ServiceConfiguration config = new ServiceConfiguration();
         config.setClusterName(cluster);
@@ -84,7 +92,8 @@ public class PulsarStandaloneTest {
         standalone.createNameSpace(cluster, tenant, ns);
         verify(cr, times(1)).createCluster(eq(cluster), any());
         verify(tr, times(1)).createTenant(eq(tenant), any());
-        verify(nsr, times(1)).createPolicies(eq(ns), any());
+        verify(admin, times(1)).namespaces();
+        verify(admin.namespaces(), times(1)).createNamespace(eq(ns.toString()));
     }
 
     @Test(groups = "broker")