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:47 UTC
[pulsar] 01/02: [fix][broker] Fix create ns (#17864)
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")