From b92b2451796e93e518b283a662bb2a587cc3b2c6 Mon Sep 17 00:00:00 2001 From: rdhabalia Date: Thu, 13 Apr 2017 11:13:36 -0700 Subject: [PATCH 1/2] fix import into AdminApiTest and introduce disable-namespaceBundle unit test --- .../pulsar/broker/service/BrokerService.java | 2 +- .../pulsar/broker/admin/AdminApiTest.java | 1 + .../broker/service/BrokerServiceTest.java | 30 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/pulsar-broker/src/main/java/com/yahoo/pulsar/broker/service/BrokerService.java b/pulsar-broker/src/main/java/com/yahoo/pulsar/broker/service/BrokerService.java index 7af1b51e69380..b03c14dd1bd2d 100644 --- a/pulsar-broker/src/main/java/com/yahoo/pulsar/broker/service/BrokerService.java +++ b/pulsar-broker/src/main/java/com/yahoo/pulsar/broker/service/BrokerService.java @@ -439,7 +439,7 @@ public PulsarClient getReplicationClient(String cluster) { * @return CompletableFuture * @throws RuntimeException */ - private CompletableFuture createPersistentTopic(final String topic) throws RuntimeException { + protected CompletableFuture createPersistentTopic(final String topic) throws RuntimeException { checkTopicNsOwnership(topic); final CompletableFuture topicFuture = new CompletableFuture<>(); diff --git a/pulsar-broker/src/test/java/com/yahoo/pulsar/broker/admin/AdminApiTest.java b/pulsar-broker/src/test/java/com/yahoo/pulsar/broker/admin/AdminApiTest.java index ccb832f9614cc..e98dd09e72e28 100644 --- a/pulsar-broker/src/test/java/com/yahoo/pulsar/broker/admin/AdminApiTest.java +++ b/pulsar-broker/src/test/java/com/yahoo/pulsar/broker/admin/AdminApiTest.java @@ -57,6 +57,7 @@ import com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest; import com.yahoo.pulsar.broker.namespace.NamespaceEphemeralData; import com.yahoo.pulsar.broker.namespace.NamespaceService; +import com.yahoo.pulsar.broker.service.BrokerService; import com.yahoo.pulsar.client.admin.PulsarAdmin; import com.yahoo.pulsar.client.admin.PulsarAdminException; import com.yahoo.pulsar.client.admin.PulsarAdminException.ConflictException; diff --git a/pulsar-broker/src/test/java/com/yahoo/pulsar/broker/service/BrokerServiceTest.java b/pulsar-broker/src/test/java/com/yahoo/pulsar/broker/service/BrokerServiceTest.java index 059cc167020fb..56fcb412ab409 100644 --- a/pulsar-broker/src/test/java/com/yahoo/pulsar/broker/service/BrokerServiceTest.java +++ b/pulsar-broker/src/test/java/com/yahoo/pulsar/broker/service/BrokerServiceTest.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -728,4 +729,33 @@ public void testLookupThrottlingForClientByClient() throws Exception { // ok as throttling set to 0 } } + + @Test + public void testTopicLoadingOnDisableNamespaceBundle() throws Exception { + final String namespace = "prop/use/disableBundle"; + admin.namespaces().createNamespace(namespace); + + // own namespace bundle + final String topicName = "persistent://" + namespace + "/my-topic"; + DestinationName destination = DestinationName.get(topicName); + Producer producer = pulsarClient.createProducer(topicName); + producer.close(); + + // disable namespace-bundle + NamespaceBundle bundle = pulsar.getNamespaceService().getBundle(destination); + pulsar.getNamespaceService().getOwnershipCache().updateBundleState(bundle, false); + + // try to create topic which should fail as bundle is disable + CompletableFuture futureResult = pulsar.getBrokerService().createPersistentTopic(topicName); + + try { + futureResult.get(); + fail("Topic creation should fail due to disable bundle"); + } catch (Exception e) { + if (!(e.getCause() instanceof BrokerServiceException.ServiceUnitNotReadyException)) { + fail("Topic creation should fail with ServiceUnitNotReadyException"); + } + + } + } } \ No newline at end of file From cf3fe7a2a303cc8bd756bb72b3480ce2ed318dc3 Mon Sep 17 00:00:00 2001 From: rdhabalia Date: Thu, 13 Apr 2017 16:54:23 -0700 Subject: [PATCH 2/2] move namespaceTest from AdminApiTest because it init multiple broker and accessing bundleCache can be from different broker which fails test --- .../pulsar/broker/admin/AdminApiTest.java | 30 ----------------- .../pulsar/broker/admin/NamespacesTest.java | 33 +++++++++++++++++++ 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/pulsar-broker/src/test/java/com/yahoo/pulsar/broker/admin/AdminApiTest.java b/pulsar-broker/src/test/java/com/yahoo/pulsar/broker/admin/AdminApiTest.java index e98dd09e72e28..2645c4b57f56f 100644 --- a/pulsar-broker/src/test/java/com/yahoo/pulsar/broker/admin/AdminApiTest.java +++ b/pulsar-broker/src/test/java/com/yahoo/pulsar/broker/admin/AdminApiTest.java @@ -1698,34 +1698,4 @@ public void failed(Throwable e) { assertEquals(uriStats.get().subscriptions.size(), 1); } - /** - * Verifies that deleteNamespace cleans up policies(global,local), bundle cache and bundle ownership - * - * @throws Exception - */ - @Test - public void testDeleteNamespace() throws Exception { - - final String namespace = "prop-xyz/use/deleteNs"; - admin.namespaces().createNamespace(namespace, 100); - assertEquals(admin.namespaces().getPolicies(namespace).bundles.numBundles, 100); - - // (1) Force topic creation and namespace being loaded - final String topicName = "persistent://" + namespace + "/my-topic"; - DestinationName destination = DestinationName.get(topicName); - - Producer producer = pulsarClient.createProducer(topicName); - producer.close(); - NamespaceBundle bundle1 = pulsar.getNamespaceService().getBundle(destination); - // (2) Delete topic - admin.persistentTopics().delete(topicName); - // (3) Delete ns - admin.namespaces().deleteNamespace(namespace); - // (4) check bundle - NamespaceBundle bundle2 = pulsar.getNamespaceService().getBundle(destination); - assertNotEquals(bundle1.getBundleRange(), bundle2.getBundleRange()); - // returns full bundle if policies not present - assertEquals("0x00000000_0xffffffff", bundle2.getBundleRange()); - - } } diff --git a/pulsar-broker/src/test/java/com/yahoo/pulsar/broker/admin/NamespacesTest.java b/pulsar-broker/src/test/java/com/yahoo/pulsar/broker/admin/NamespacesTest.java index 54f50ffa9077a..ad29904c3ad2d 100644 --- a/pulsar-broker/src/test/java/com/yahoo/pulsar/broker/admin/NamespacesTest.java +++ b/pulsar-broker/src/test/java/com/yahoo/pulsar/broker/admin/NamespacesTest.java @@ -24,6 +24,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; @@ -63,6 +64,7 @@ import com.yahoo.pulsar.broker.web.PulsarWebResource; import com.yahoo.pulsar.broker.web.RestException; import com.yahoo.pulsar.client.admin.PulsarAdminException; +import com.yahoo.pulsar.client.api.Producer; import com.yahoo.pulsar.common.naming.DestinationName; import com.yahoo.pulsar.common.naming.NamespaceBundle; import com.yahoo.pulsar.common.naming.NamespaceBundles; @@ -1063,6 +1065,37 @@ public void testIsLeader() throws Exception { assertTrue(namespaces.isLeaderBroker()); } + /** + * Verifies that deleteNamespace cleans up policies(global,local), bundle cache and bundle ownership + * + * @throws Exception + */ + @Test + public void testDeleteNamespace() throws Exception { + + final String namespace = this.testProperty + "/use/deleteNs"; + admin.namespaces().createNamespace(namespace, 100); + assertEquals(admin.namespaces().getPolicies(namespace).bundles.numBundles, 100); + + // (1) Force topic creation and namespace being loaded + final String topicName = "persistent://" + namespace + "/my-topic"; + DestinationName destination = DestinationName.get(topicName); + + Producer producer = pulsarClient.createProducer(topicName); + producer.close(); + NamespaceBundle bundle1 = pulsar.getNamespaceService().getBundle(destination); + // (2) Delete topic + admin.persistentTopics().delete(topicName); + // (3) Delete ns + admin.namespaces().deleteNamespace(namespace); + // (4) check bundle + NamespaceBundle bundle2 = pulsar.getNamespaceService().getBundle(destination); + assertNotEquals(bundle1.getBundleRange(), bundle2.getBundleRange()); + // returns full bundle if policies not present + assertEquals("0x00000000_0xffffffff", bundle2.getBundleRange()); + + } + private void mockWebUrl(URL localWebServiceUrl, NamespaceName namespace) throws Exception { doReturn(localWebServiceUrl).when(nsSvc).getWebServiceUrl(Mockito.argThat(new Matcher() { @Override