From e85b38c2931c8f25252134e8f456493a08402567 Mon Sep 17 00:00:00 2001 From: fengyubiao Date: Thu, 11 Aug 2022 23:40:44 +0800 Subject: [PATCH 1/3] [fix][flaky-test]AdminApi2Test.testDeleteTenant --- .../pulsar/broker/admin/AdminApi2Test.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java index 410ad097f6a3e..8a509e577540b 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java @@ -19,6 +19,7 @@ package org.apache.pulsar.broker.admin; import static org.apache.commons.lang3.StringUtils.isBlank; +import static org.apache.pulsar.common.naming.SystemTopicNames.NAMESPACE_EVENTS_LOCAL_NAME; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -44,6 +45,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.TreeSet; import java.util.UUID; import java.util.concurrent.TimeUnit; import javax.ws.rs.NotAcceptableException; @@ -1367,6 +1369,15 @@ public void testDeleteTenant() throws Exception { admin.topics().deletePartitionedTopic(topic); assertTrue(admin.topics().getList(namespace).isEmpty()); + // Wait for system topic create finish. + Awaitility.await().until(() -> { + if (!pulsar.getConfiguration().isSystemTopicEnabled()) { + return true; + } + TreeSet topicsCreated = queryTopicsByNamespace(namespace); + return topicsCreated.contains(String.format("persistent://%s/%s", namespace, NAMESPACE_EVENTS_LOCAL_NAME)); + }); + // delete namespace admin.namespaces().deleteNamespace(namespace, false); assertFalse(admin.namespaces().getNamespaces(tenant).contains(namespace)); @@ -1386,6 +1397,18 @@ public void testDeleteTenant() throws Exception { assertFalse(pulsar.getLocalMetadataStore().exists(bundleDataPath).join()); } + private TreeSet queryTopicsByNamespace(String namespace){ + NamespaceName namespaceName = NamespaceName.get(namespace); + TreeSet topics = new TreeSet<>(); + topics.addAll(pulsar.getNamespaceService() + .getListOfPersistentTopics(NamespaceName.get(namespace)).join()); + topics.addAll(pulsar.getPulsarResources().getNamespaceResources().getPartitionedTopicResources() + .listPartitionedTopicsAsync(namespaceName, TopicDomain.persistent).join()); + topics.addAll(pulsar.getPulsarResources().getNamespaceResources().getPartitionedTopicResources() + .listPartitionedTopicsAsync(namespaceName, TopicDomain.non_persistent).join()); + return topics; + } + @Test public void testDeleteNamespace() throws Exception { pulsar.getConfiguration().setForceDeleteNamespaceAllowed(false); From 8b7d14bed73ba228c2fd2ba5520cf513de003d2a Mon Sep 17 00:00:00 2001 From: fengyubiao Date: Fri, 12 Aug 2022 10:20:06 +0800 Subject: [PATCH 2/3] append partitioned topic wait --- .../pulsar/broker/admin/AdminApi2Test.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java index 8a509e577540b..7098067a3f8c5 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java @@ -1338,6 +1338,7 @@ public void testPreciseBacklog() throws PulsarClientException, PulsarAdminExcept @Test public void testDeleteTenant() throws Exception { + int partitionCount = 10; pulsar.getConfiguration().setForceDeleteNamespaceAllowed(false); String tenant = "test-tenant-1"; @@ -1355,9 +1356,16 @@ public void testDeleteTenant() throws Exception { // create topic String topic = namespace + "/test-topic-1"; - admin.topics().createPartitionedTopic(topic, 10); + admin.topics().createPartitionedTopic(topic, partitionCount); assertFalse(admin.topics().getList(namespace).isEmpty()); + // Wait for topics create finish. + Awaitility.await().until(() -> { + TreeSet topicsCreated = queryPersistentTopicsByNamespace(namespace); + String topicNamePrefix = String.format("persistent://%s/%s", namespace, "test-topic-1"); + return topicsCreated.stream().filter(s -> s.startsWith(topicNamePrefix)).count() == partitionCount + 1; + }); + try { admin.namespaces().deleteNamespace(namespace, false); fail("should have failed due to namespace not empty"); @@ -1374,7 +1382,7 @@ public void testDeleteTenant() throws Exception { if (!pulsar.getConfiguration().isSystemTopicEnabled()) { return true; } - TreeSet topicsCreated = queryTopicsByNamespace(namespace); + TreeSet topicsCreated = queryPersistentTopicsByNamespace(namespace); return topicsCreated.contains(String.format("persistent://%s/%s", namespace, NAMESPACE_EVENTS_LOCAL_NAME)); }); @@ -1397,15 +1405,13 @@ public void testDeleteTenant() throws Exception { assertFalse(pulsar.getLocalMetadataStore().exists(bundleDataPath).join()); } - private TreeSet queryTopicsByNamespace(String namespace){ + private TreeSet queryPersistentTopicsByNamespace(String namespace){ NamespaceName namespaceName = NamespaceName.get(namespace); TreeSet topics = new TreeSet<>(); topics.addAll(pulsar.getNamespaceService() .getListOfPersistentTopics(NamespaceName.get(namespace)).join()); topics.addAll(pulsar.getPulsarResources().getNamespaceResources().getPartitionedTopicResources() .listPartitionedTopicsAsync(namespaceName, TopicDomain.persistent).join()); - topics.addAll(pulsar.getPulsarResources().getNamespaceResources().getPartitionedTopicResources() - .listPartitionedTopicsAsync(namespaceName, TopicDomain.non_persistent).join()); return topics; } From 1272533813efcbb24436b147a958bca48b54b4b2 Mon Sep 17 00:00:00 2001 From: fengyubiao Date: Fri, 12 Aug 2022 17:05:20 +0800 Subject: [PATCH 3/3] change Modifications: disabled systemTopic feature --- .../pulsar/broker/admin/AdminApi2Test.java | 44 ++++++------------- .../pulsar/broker/admin/AdminApiTest.java | 1 + 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java index 7098067a3f8c5..b3072a693ee81 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java @@ -19,7 +19,6 @@ package org.apache.pulsar.broker.admin; import static org.apache.commons.lang3.StringUtils.isBlank; -import static org.apache.pulsar.common.naming.SystemTopicNames.NAMESPACE_EVENTS_LOCAL_NAME; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -45,7 +44,6 @@ import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.TreeSet; import java.util.UUID; import java.util.concurrent.TimeUnit; import javax.ws.rs.NotAcceptableException; @@ -1338,7 +1336,13 @@ public void testPreciseBacklog() throws PulsarClientException, PulsarAdminExcept @Test public void testDeleteTenant() throws Exception { - int partitionCount = 10; + // Disabled conf: systemTopicEnabled. see: https://github.com/apache/pulsar/pull/17070 + boolean originalSystemTopicEnabled = conf.isSystemTopicEnabled(); + if (originalSystemTopicEnabled) { + internalCleanup(); + conf.setSystemTopicEnabled(false); + setup(); + } pulsar.getConfiguration().setForceDeleteNamespaceAllowed(false); String tenant = "test-tenant-1"; @@ -1356,16 +1360,9 @@ public void testDeleteTenant() throws Exception { // create topic String topic = namespace + "/test-topic-1"; - admin.topics().createPartitionedTopic(topic, partitionCount); + admin.topics().createPartitionedTopic(topic, 10); assertFalse(admin.topics().getList(namespace).isEmpty()); - // Wait for topics create finish. - Awaitility.await().until(() -> { - TreeSet topicsCreated = queryPersistentTopicsByNamespace(namespace); - String topicNamePrefix = String.format("persistent://%s/%s", namespace, "test-topic-1"); - return topicsCreated.stream().filter(s -> s.startsWith(topicNamePrefix)).count() == partitionCount + 1; - }); - try { admin.namespaces().deleteNamespace(namespace, false); fail("should have failed due to namespace not empty"); @@ -1377,15 +1374,6 @@ public void testDeleteTenant() throws Exception { admin.topics().deletePartitionedTopic(topic); assertTrue(admin.topics().getList(namespace).isEmpty()); - // Wait for system topic create finish. - Awaitility.await().until(() -> { - if (!pulsar.getConfiguration().isSystemTopicEnabled()) { - return true; - } - TreeSet topicsCreated = queryPersistentTopicsByNamespace(namespace); - return topicsCreated.contains(String.format("persistent://%s/%s", namespace, NAMESPACE_EVENTS_LOCAL_NAME)); - }); - // delete namespace admin.namespaces().deleteNamespace(namespace, false); assertFalse(admin.namespaces().getNamespaces(tenant).contains(namespace)); @@ -1403,16 +1391,12 @@ public void testDeleteTenant() throws Exception { assertFalse(pulsar.getLocalMetadataStore().exists(partitionedTopicPath).join()); assertFalse(pulsar.getLocalMetadataStore().exists(localPoliciesPath).join()); assertFalse(pulsar.getLocalMetadataStore().exists(bundleDataPath).join()); - } - - private TreeSet queryPersistentTopicsByNamespace(String namespace){ - NamespaceName namespaceName = NamespaceName.get(namespace); - TreeSet topics = new TreeSet<>(); - topics.addAll(pulsar.getNamespaceService() - .getListOfPersistentTopics(NamespaceName.get(namespace)).join()); - topics.addAll(pulsar.getPulsarResources().getNamespaceResources().getPartitionedTopicResources() - .listPartitionedTopicsAsync(namespaceName, TopicDomain.persistent).join()); - return topics; + // Reset conf: systemTopicEnabled + if (originalSystemTopicEnabled) { + internalCleanup(); + conf.setSystemTopicEnabled(true); + setup(); + } } @Test diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java index ece5f8d830213..329f4ba4cdebd 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java @@ -2919,6 +2919,7 @@ public MockedPulsarService(ServiceConfiguration conf) { @Override protected void setup() throws Exception { super.conf.setLoadManagerClassName(conf.getLoadManagerClassName()); + super.conf.setSystemTopicEnabled(conf.isSystemTopicEnabled()); super.internalSetup(); }