This is an automated email from the ASF dual-hosted git repository.
penghui pushed a commit to branch branch-2.11
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.11 by this push:
new 53f1cb29d52 [fix][broker] Fix create ns (#18755)
53f1cb29d52 is described below
commit 53f1cb29d52a4b11c1479bb6e70afb17c5d46bad
Author: Zixuan Liu <[email protected]>
AuthorDate: Thu Dec 8 14:33:37 2022 +0800
[fix][broker] Fix create ns (#18755)
---
.../main/java/org/apache/pulsar/PulsarStandalone.java | 6 +-----
.../java/org/apache/pulsar/PulsarStandaloneTest.java | 19 +++++++++++--------
2 files changed, 12 insertions(+), 13 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..b9f7f648802 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/PulsarStandaloneTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/PulsarStandaloneTest.java
@@ -30,13 +30,15 @@ import java.io.File;
import java.util.List;
import org.apache.bookkeeper.conf.ServerConfiguration;
import org.apache.bookkeeper.util.IOUtils;
-import org.apache.pulsar.common.naming.NamespaceName;
import org.apache.pulsar.broker.PulsarService;
import org.apache.pulsar.broker.ServiceConfiguration;
import org.apache.pulsar.broker.resources.ClusterResources;
import org.apache.pulsar.broker.resources.NamespaceResources;
import org.apache.pulsar.broker.resources.PulsarResources;
import org.apache.pulsar.broker.resources.TenantResources;
+import org.apache.pulsar.client.admin.Namespaces;
+import org.apache.pulsar.client.admin.PulsarAdmin;
+import org.apache.pulsar.common.naming.NamespaceName;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -48,43 +50,44 @@ public class PulsarStandaloneTest {
final String cluster = "cluster1";
final String tenant = "tenant1";
final NamespaceName ns = NamespaceName.get(tenant, "ns1");
-
ClusterResources cr = mock(ClusterResources.class);
when(cr.clusterExists(cluster)).thenReturn(false).thenReturn(true);
doNothing().when(cr).createCluster(eq(cluster), any());
-
TenantResources tr = mock(TenantResources.class);
when(tr.tenantExists(tenant)).thenReturn(false).thenReturn(true);
doNothing().when(tr).createTenant(eq(tenant), any());
-
NamespaceResources nsr = mock(NamespaceResources.class);
when(nsr.namespaceExists(ns)).thenReturn(false).thenReturn(true);
doNothing().when(nsr).createPolicies(eq(ns), any());
-
PulsarResources resources = mock(PulsarResources.class);
when(resources.getClusterResources()).thenReturn(cr);
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);
-
PulsarStandalone standalone = new PulsarStandalone();
standalone.setBroker(broker);
standalone.setConfig(config);
-
standalone.createNameSpace(cluster, tenant, ns);
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")