|
41 | 41 | import com.google.common.collect.Lists; |
42 | 42 | import com.google.common.collect.Sets; |
43 | 43 | import java.lang.reflect.Field; |
| 44 | +import java.net.URI; |
44 | 45 | import java.net.URL; |
| 46 | +import java.net.http.HttpClient; |
| 47 | +import java.net.http.HttpRequest; |
| 48 | +import java.net.http.HttpResponse; |
45 | 49 | import java.nio.charset.StandardCharsets; |
46 | 50 | import java.time.Clock; |
47 | 51 | import java.util.ArrayList; |
|
137 | 141 | import org.apache.pulsar.common.policies.data.PartitionedTopicStats; |
138 | 142 | import org.apache.pulsar.common.policies.data.PersistencePolicies; |
139 | 143 | import org.apache.pulsar.common.policies.data.PersistentTopicInternalStats; |
| 144 | +import org.apache.pulsar.common.policies.data.Policies; |
140 | 145 | import org.apache.pulsar.common.policies.data.RetentionPolicies; |
141 | 146 | import org.apache.pulsar.common.policies.data.SubscriptionStats; |
142 | 147 | import org.apache.pulsar.common.policies.data.TenantInfoImpl; |
@@ -1739,6 +1744,36 @@ public void testCreateNamespaceWithNoClusters() throws PulsarAdminException { |
1739 | 1744 | Collections.singletonList(localCluster)); |
1740 | 1745 | } |
1741 | 1746 |
|
| 1747 | + @Test |
| 1748 | + public void testCreateNamespaceWithEmptyReplicationClustersByHttp() throws Exception { |
| 1749 | + String localCluster = pulsar.getConfiguration().getClusterName(); |
| 1750 | + String namespacePart = newUniqueName("ns"); |
| 1751 | + String namespace = defaultTenant + "/" + namespacePart; |
| 1752 | + |
| 1753 | + // Create namespace with "allowed_cluster", and the param "replication_clusters" is empty. |
| 1754 | + HttpClient httpClient = HttpClient.newHttpClient(); |
| 1755 | + URI adminV2Uri = URI.create(brokerUrl.toString()).resolve("/admin/v2/"); |
| 1756 | + String namespaceRequestBody = "{\"allowed_clusters\": [\"" + localCluster + "\"]}"; |
| 1757 | + HttpRequest createNamespaceRequest = |
| 1758 | + HttpRequest.newBuilder(adminV2Uri.resolve("namespaces/" + namespace)) |
| 1759 | + .header("Content-Type", "application/json") |
| 1760 | + .PUT(HttpRequest.BodyPublishers.ofString(namespaceRequestBody)) |
| 1761 | + .build(); |
| 1762 | + HttpResponse<String> createNamespaceResponse = httpClient.send(createNamespaceRequest, |
| 1763 | + HttpResponse.BodyHandlers.ofString()); |
| 1764 | + assertEquals(createNamespaceResponse.statusCode(), Status.NO_CONTENT.getStatusCode(), |
| 1765 | + "Failed to create namespace by HTTP: " + createNamespaceResponse.body()); |
| 1766 | + |
| 1767 | + // Verify: replication_clusters is not empty. |
| 1768 | + Awaitility.await().untilAsserted(() -> { |
| 1769 | + Policies policies = admin.namespaces().getPolicies(namespace); |
| 1770 | + assertEquals(policies.replication_clusters.size(), 1); |
| 1771 | + assertEquals(policies.allowed_clusters.size(), 1); |
| 1772 | + assertTrue(policies.replication_clusters.contains(localCluster)); |
| 1773 | + assertTrue(policies.allowed_clusters.contains(localCluster)); |
| 1774 | + }); |
| 1775 | + } |
| 1776 | + |
1742 | 1777 | @Test(timeOut = 30000) |
1743 | 1778 | public void testConsumerStatsLastTimestamp() throws PulsarClientException, PulsarAdminException, |
1744 | 1779 | InterruptedException { |
|
0 commit comments