You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2021/09/01 18:29:49 UTC

[pulsar] branch master updated: [Tests] Fix BaseMetadataStoreTest retries (#11778)

This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 499713c  [Tests] Fix BaseMetadataStoreTest retries (#11778)
499713c is described below

commit 499713cd7f2eae48caf0ec45d8d97c57940f9789
Author: Lari Hotari <lh...@users.noreply.github.com>
AuthorDate: Wed Sep 1 21:29:06 2021 +0300

    [Tests] Fix BaseMetadataStoreTest retries (#11778)
    
    * [Tests] Fix BaseMetadataStoreTest retries
    
    - A Supplier<String> must be used for the Zookeeper connection string parameter.
    
    - The retried test run will use the same arguments as the failed attempt.
      The Zookeeper test server gets restarted by TestRetrySupport before a retry.
      The new connection string won't be available to the test method unless a
      Supplier<String> lambda is used for providing the value.
    
    * Make @Before*/@After* annotated methods public and final on abstract base class
    
    - prevents possible future issues. overriding a base class method that has annotations
      leads to inconsistent behavior in the case when the overridden method doesn't specify the
      annotations. It's better to add hook methods when hooks are needed.
---
 .../metadata/BacklogQuotaCompatibilityTest.java    | 40 ++++++------
 .../pulsar/metadata/BaseMetadataStoreTest.java     | 18 ++++--
 .../org/apache/pulsar/metadata/CounterTest.java    |  8 +--
 .../apache/pulsar/metadata/LeaderElectionTest.java | 50 +++++++++------
 .../apache/pulsar/metadata/LockManagerTest.java    | 35 +++++-----
 .../apache/pulsar/metadata/MetadataCacheTest.java  | 74 +++++++++++-----------
 .../pulsar/metadata/MetadataStoreExtendedTest.java |  9 ++-
 .../apache/pulsar/metadata/MetadataStoreTest.java  | 40 ++++++------
 8 files changed, 147 insertions(+), 127 deletions(-)

diff --git a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/BacklogQuotaCompatibilityTest.java b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/BacklogQuotaCompatibilityTest.java
index cc92b60..a3a155e 100644
--- a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/BacklogQuotaCompatibilityTest.java
+++ b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/BacklogQuotaCompatibilityTest.java
@@ -18,37 +18,39 @@
  */
 package org.apache.pulsar.metadata;
 
+import static org.testng.Assert.assertEquals;
 import com.fasterxml.jackson.databind.type.TypeFactory;
+import java.io.IOException;
 import org.apache.pulsar.common.policies.data.BacklogQuota;
 import org.apache.pulsar.common.policies.data.Policies;
 import org.apache.pulsar.metadata.cache.impl.JSONMetadataSerdeSimpleType;
 import org.testng.annotations.Test;
 
-import java.io.IOException;
-
-import static org.testng.Assert.assertEquals;
-
 public class BacklogQuotaCompatibilityTest {
 
     @Test
     public void testBackwardCompatibility() throws IOException {
-        String oldPolicyStr = "{\"auth_policies\":{\"namespace_auth\":{},\"destination_auth\":{}," +
-                "\"subscription_auth_roles\":{}},\"replication_clusters\":[],\"backlog_quota_map\":" +
-                "{\"destination_storage\":{\"limit\":1001,\"policy\":\"consumer_backlog_eviction\"}}," +
-                "\"clusterDispatchRate\":{},\"topicDispatchRate\":{},\"subscriptionDispatchRate\":{}," +
-                "\"replicatorDispatchRate\":{},\"clusterSubscribeRate\":{},\"publishMaxMessageRate\":{}," +
-                "\"latency_stats_sample_rate\":{},\"subscription_expiration_time_minutes\":0,\"deleted\":false," +
-                "\"encryption_required\":false,\"subscription_auth_mode\":\"None\"," +
-                "\"max_consumers_per_subscription\":0,\"offload_threshold\":-1," +
-                "\"schema_auto_update_compatibility_strategy\":\"Full\",\"schema_compatibility_strategy\":" +
-                "\"UNDEFINED\",\"is_allow_auto_update_schema\":true,\"schema_validation_enforced\":false," +
-                "\"subscription_types_enabled\":[]}\n";
+        String oldPolicyStr = "{\"auth_policies\":{\"namespace_auth\":{},\"destination_auth\":{},"
+                + "\"subscription_auth_roles\":{}},\"replication_clusters\":[],\"backlog_quota_map\":"
+                + "{\"destination_storage\":{\"limit\":1001,\"policy\":\"consumer_backlog_eviction\"}},"
+                + "\"clusterDispatchRate\":{},\"topicDispatchRate\":{},\"subscriptionDispatchRate\":{},"
+                + "\"replicatorDispatchRate\":{},\"clusterSubscribeRate\":{},\"publishMaxMessageRate\":{},"
+                + "\"latency_stats_sample_rate\":{},\"subscription_expiration_time_minutes\":0,\"deleted\":false,"
+                + "\"encryption_required\":false,\"subscription_auth_mode\":\"None\","
+                + "\"max_consumers_per_subscription\":0,\"offload_threshold\":-1,"
+                + "\"schema_auto_update_compatibility_strategy\":\"Full\",\"schema_compatibility_strategy\":"
+                + "\"UNDEFINED\",\"is_allow_auto_update_schema\":true,\"schema_validation_enforced\":false,"
+                + "\"subscription_types_enabled\":[]}\n";
 
-        JSONMetadataSerdeSimpleType jsonMetadataSerdeSimpleType = new JSONMetadataSerdeSimpleType(TypeFactory.defaultInstance().constructSimpleType(Policies.class, null));
+        JSONMetadataSerdeSimpleType jsonMetadataSerdeSimpleType = new JSONMetadataSerdeSimpleType(
+                TypeFactory.defaultInstance().constructSimpleType(Policies.class, null));
         Policies policies = (Policies) jsonMetadataSerdeSimpleType.deserialize(oldPolicyStr.getBytes());
-        assertEquals(policies.backlog_quota_map.get(BacklogQuota.BacklogQuotaType.destination_storage).getLimitSize(), 1001);
-        assertEquals(policies.backlog_quota_map.get(BacklogQuota.BacklogQuotaType.destination_storage).getLimitTime(), 0);
-        assertEquals(policies.backlog_quota_map.get(BacklogQuota.BacklogQuotaType.destination_storage).getPolicy(), BacklogQuota.RetentionPolicy.consumer_backlog_eviction);
+        assertEquals(policies.backlog_quota_map.get(BacklogQuota.BacklogQuotaType.destination_storage).getLimitSize(),
+                1001);
+        assertEquals(policies.backlog_quota_map.get(BacklogQuota.BacklogQuotaType.destination_storage).getLimitTime(),
+                0);
+        assertEquals(policies.backlog_quota_map.get(BacklogQuota.BacklogQuotaType.destination_storage).getPolicy(),
+                BacklogQuota.RetentionPolicy.consumer_backlog_eviction);
     }
 
 }
diff --git a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/BaseMetadataStoreTest.java b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/BaseMetadataStoreTest.java
index afd6f3a..1911725 100644
--- a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/BaseMetadataStoreTest.java
+++ b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/BaseMetadataStoreTest.java
@@ -20,6 +20,7 @@ package org.apache.pulsar.metadata;
 
 import static org.testng.Assert.assertTrue;
 import java.util.concurrent.CompletionException;
+import java.util.function.Supplier;
 import org.apache.pulsar.tests.TestRetrySupport;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
@@ -30,26 +31,35 @@ public abstract class BaseMetadataStoreTest extends TestRetrySupport {
 
     @BeforeClass(alwaysRun = true)
     @Override
-    protected void setup() throws Exception {
+    public final void setup() throws Exception {
         incrementSetupNumber();
         zks = new TestZKServer();
     }
 
     @AfterClass(alwaysRun = true)
     @Override
-    protected void cleanup() throws Exception {
+    public final void cleanup() throws Exception {
         markCurrentSetupNumberCleaned();
         zks.close();
     }
 
     @DataProvider(name = "impl")
     public Object[][] implementations() {
+        // A Supplier<String> must be used for the Zookeeper connection string parameter. The retried test run will
+        // use the same arguments as the failed attempt.
+        // The Zookeeper test server gets restarted by TestRetrySupport before the retry.
+        // The new connection string won't be available to the test method unless a
+        // Supplier<String> lambda is used for providing the value.
         return new Object[][] {
-                { "ZooKeeper", zks.getConnectionString() },
-                { "Memory", "memory://local" },
+                { "ZooKeeper", stringSupplier(() -> zks.getConnectionString()) },
+                { "Memory", stringSupplier(() -> "memory://local") },
         };
     }
 
+    public static Supplier<String> stringSupplier(Supplier<String> supplier) {
+        return supplier;
+    }
+
     protected String newKey() {
         return "/key-" + System.nanoTime();
     }
diff --git a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/CounterTest.java b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/CounterTest.java
index 0612d8f..dcf9159 100644
--- a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/CounterTest.java
+++ b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/CounterTest.java
@@ -19,9 +19,8 @@
 package org.apache.pulsar.metadata;
 
 import static org.testng.Assert.assertNotEquals;
-
+import java.util.function.Supplier;
 import lombok.Cleanup;
-
 import org.apache.pulsar.metadata.api.MetadataStoreConfig;
 import org.apache.pulsar.metadata.api.coordination.CoordinationService;
 import org.apache.pulsar.metadata.api.extended.MetadataStoreExtended;
@@ -31,9 +30,10 @@ import org.testng.annotations.Test;
 public class CounterTest extends BaseMetadataStoreTest {
 
     @Test(dataProvider = "impl")
-    public void basicTest(String provider, String url) throws Exception {
+    public void basicTest(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStoreExtended store = MetadataStoreExtended.create(url, MetadataStoreConfig.builder().build());
+        MetadataStoreExtended store = MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
 
         @Cleanup
         CoordinationService cs1 = new CoordinationServiceImpl(store);
diff --git a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/LeaderElectionTest.java b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/LeaderElectionTest.java
index fac83ff..8412c71 100644
--- a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/LeaderElectionTest.java
+++ b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/LeaderElectionTest.java
@@ -19,15 +19,13 @@
 package org.apache.pulsar.metadata;
 
 import static org.testng.Assert.assertEquals;
-
 import java.util.EnumSet;
 import java.util.Optional;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingDeque;
 import java.util.concurrent.TimeUnit;
-
+import java.util.function.Supplier;
 import lombok.Cleanup;
-
 import org.apache.pulsar.common.util.ObjectMapperFactory;
 import org.apache.pulsar.metadata.api.MetadataCache;
 import org.apache.pulsar.metadata.api.MetadataStoreConfig;
@@ -42,9 +40,10 @@ import org.testng.annotations.Test;
 public class LeaderElectionTest extends BaseMetadataStoreTest {
 
     @Test(dataProvider = "impl")
-    public void basicTest(String provider, String url) throws Exception {
+    public void basicTest(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStoreExtended store = MetadataStoreExtended.create(url, MetadataStoreConfig.builder().build());
+        MetadataStoreExtended store = MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
 
         @Cleanup
         CoordinationService coordinationService = new CoordinationServiceImpl(store);
@@ -74,16 +73,18 @@ public class LeaderElectionTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void multipleMembers(String provider, String url) throws Exception {
+    public void multipleMembers(String provider, Supplier<String> urlSupplier) throws Exception {
         if (provider.equals("Memory")) {
             // There are no multiple session in local mem provider
             return;
         }
 
         @Cleanup
-        MetadataStoreExtended store1 = MetadataStoreExtended.create(url, MetadataStoreConfig.builder().build());
+        MetadataStoreExtended store1 = MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
         @Cleanup
-        MetadataStoreExtended store2 = MetadataStoreExtended.create(url, MetadataStoreConfig.builder().build());
+        MetadataStoreExtended store2 = MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
 
 
         @Cleanup
@@ -129,9 +130,10 @@ public class LeaderElectionTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void leaderNodeIsDeletedExternally(String provider, String url) throws Exception {
+    public void leaderNodeIsDeletedExternally(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStoreExtended store = MetadataStoreExtended.create(url, MetadataStoreConfig.builder().build());
+        MetadataStoreExtended store = MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
 
         @Cleanup
         CoordinationService coordinationService = new CoordinationServiceImpl(store);
@@ -156,9 +158,10 @@ public class LeaderElectionTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void closeAll(String provider, String url) throws Exception {
+    public void closeAll(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStoreExtended store = MetadataStoreExtended.create(url, MetadataStoreConfig.builder().build());
+        MetadataStoreExtended store = MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
         MetadataCache<String> cache = store.getMetadataCache(String.class);
 
         CoordinationService cs = new CoordinationServiceImpl(store);
@@ -185,9 +188,10 @@ public class LeaderElectionTest extends BaseMetadataStoreTest {
 
 
     @Test(dataProvider = "impl")
-    public void revalidateLeaderWithinSameSession(String provider, String url) throws Exception {
+    public void revalidateLeaderWithinSameSession(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStoreExtended store = MetadataStoreExtended.create(url, MetadataStoreConfig.builder().build());
+        MetadataStoreExtended store = MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
 
         String path = newKey();
 
@@ -209,12 +213,15 @@ public class LeaderElectionTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void revalidateLeaderWithDifferentSessionsSameValue(String provider, String url) throws Exception {
+    public void revalidateLeaderWithDifferentSessionsSameValue(String provider, Supplier<String> urlSupplier)
+            throws Exception {
         @Cleanup
-        MetadataStoreExtended store = MetadataStoreExtended.create(url, MetadataStoreConfig.builder().build());
+        MetadataStoreExtended store = MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
 
         @Cleanup
-        MetadataStoreExtended store2 = MetadataStoreExtended.create(url, MetadataStoreConfig.builder().build());
+        MetadataStoreExtended store2 = MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
 
         String path = newKey();
 
@@ -237,17 +244,20 @@ public class LeaderElectionTest extends BaseMetadataStoreTest {
 
 
     @Test(dataProvider = "impl")
-    public void revalidateLeaderWithDifferentSessionsDifferentValue(String provider, String url) throws Exception {
+    public void revalidateLeaderWithDifferentSessionsDifferentValue(String provider, Supplier<String> urlSupplier)
+            throws Exception {
         if (provider.equals("Memory")) {
             // There are no multiple sessions for the local memory provider
             return;
         }
 
         @Cleanup
-        MetadataStoreExtended store = MetadataStoreExtended.create(url, MetadataStoreConfig.builder().build());
+        MetadataStoreExtended store = MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
 
         @Cleanup
-        MetadataStoreExtended store2 = MetadataStoreExtended.create(url, MetadataStoreConfig.builder().build());
+        MetadataStoreExtended store2 = MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
 
         String path = newKey();
 
diff --git a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/LockManagerTest.java b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/LockManagerTest.java
index e256950..dbcdc4f 100644
--- a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/LockManagerTest.java
+++ b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/LockManagerTest.java
@@ -20,8 +20,6 @@ package org.apache.pulsar.metadata;
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.fail;
-
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -31,13 +29,10 @@ import java.util.Optional;
 import java.util.concurrent.CompletionException;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
-
+import java.util.function.Supplier;
 import lombok.Cleanup;
-
-import org.apache.pulsar.common.util.ObjectMapperFactory;
 import org.apache.pulsar.metadata.api.MetadataCache;
 import org.apache.pulsar.metadata.api.MetadataStoreConfig;
-import org.apache.pulsar.metadata.api.MetadataStoreException;
 import org.apache.pulsar.metadata.api.MetadataStoreException.LockBusyException;
 import org.apache.pulsar.metadata.api.coordination.CoordinationService;
 import org.apache.pulsar.metadata.api.coordination.LockManager;
@@ -50,9 +45,10 @@ import org.testng.annotations.Test;
 public class LockManagerTest extends BaseMetadataStoreTest {
 
     @Test(dataProvider = "impl")
-    public void acquireLocks(String provider, String url) throws Exception {
+    public void acquireLocks(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStoreExtended store = MetadataStoreExtended.create(url, MetadataStoreConfig.builder().build());
+        MetadataStoreExtended store = MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
 
         @Cleanup
         CoordinationService coordinationService = new CoordinationServiceImpl(store);
@@ -98,9 +94,10 @@ public class LockManagerTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void cleanupOnClose(String provider, String url) throws Exception {
+    public void cleanupOnClose(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStoreExtended store = MetadataStoreExtended.create(url, MetadataStoreConfig.builder().build());
+        MetadataStoreExtended store = MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
 
         @Cleanup
         CoordinationService coordinationService = new CoordinationServiceImpl(store);
@@ -127,9 +124,10 @@ public class LockManagerTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void updateValue(String provider, String url) throws Exception {
+    public void updateValue(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStoreExtended store = MetadataStoreExtended.create(url, MetadataStoreConfig.builder().build());
+        MetadataStoreExtended store = MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
 
         MetadataCache<String> cache = store.getMetadataCache(String.class);
 
@@ -149,9 +147,10 @@ public class LockManagerTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void revalidateLockWithinSameSession(String provider, String url) throws Exception {
+    public void revalidateLockWithinSameSession(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStoreExtended store = MetadataStoreExtended.create(url, MetadataStoreConfig.builder().build());
+        MetadataStoreExtended store = MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
 
         @Cleanup
         CoordinationService cs2 = new CoordinationServiceImpl(store);
@@ -180,16 +179,18 @@ public class LockManagerTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void revalidateLockOnDifferentSession(String provider, String url) throws Exception {
+    public void revalidateLockOnDifferentSession(String provider, Supplier<String> urlSupplier) throws Exception {
         if (provider.equals("Memory")) {
             // Local memory provider doesn't really have the concept of multiple sessions
             return;
         }
 
         @Cleanup
-        MetadataStoreExtended store1 = MetadataStoreExtended.create(url, MetadataStoreConfig.builder().build());
+        MetadataStoreExtended store1 = MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
         @Cleanup
-        MetadataStoreExtended store2 = MetadataStoreExtended.create(url, MetadataStoreConfig.builder().build());
+        MetadataStoreExtended store2 = MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
 
         @Cleanup
         CoordinationService cs1 = new CoordinationServiceImpl(store1);
diff --git a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataCacheTest.java b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataCacheTest.java
index 53e8292..3e13fe2 100644
--- a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataCacheTest.java
+++ b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataCacheTest.java
@@ -24,7 +24,6 @@ import static org.testng.Assert.assertNotSame;
 import static org.testng.Assert.assertSame;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
-
 import com.fasterxml.jackson.core.type.TypeReference;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
@@ -35,9 +34,8 @@ import java.util.Optional;
 import java.util.TreeMap;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CompletionException;
-import java.util.concurrent.ExecutionException;
 import java.util.concurrent.atomic.AtomicReference;
-
+import java.util.function.Supplier;
 import lombok.AllArgsConstructor;
 import lombok.Cleanup;
 import lombok.Data;
@@ -73,9 +71,9 @@ public class MetadataCacheTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void emptyCacheTest(String provider, String url) throws Exception {
+    public void emptyCacheTest(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStore store = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
 
         MetadataCache<MyClass> objCache = store.getMetadataCache(MyClass.class);
 
@@ -103,20 +101,20 @@ public class MetadataCacheTest extends BaseMetadataStoreTest {
     @DataProvider(name = "zk")
     public Object[][] zkimplementations() {
         return new Object[][] {
-            { "ZooKeeper", zks.getConnectionString() },
+            { "ZooKeeper", stringSupplier(() -> zks.getConnectionString()) },
         };
     }
 
     @Test(dataProvider = "zk")
-    public void crossStoreAddDelete(String provider, String url) throws Exception {
+    public void crossStoreAddDelete(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStore store1 = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store1 = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
 
         @Cleanup
-        MetadataStore store2 = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store2 = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
 
         @Cleanup
-        MetadataStore store3 = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store3 = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
 
         MetadataCache<MyClass> objCache1 = store1.getMetadataCache(MyClass.class);
         MetadataCache<MyClass> objCache2 = store2.getMetadataCache(MyClass.class);
@@ -137,7 +135,8 @@ public class MetadataCacheTest extends BaseMetadataStoreTest {
         multiStoreAddDelete(allCaches, 1, 1, "add cache1 del cache1");
     }
 
-    private void multiStoreAddDelete(List<MetadataCache<MyClass>> caches, int addOn, int delFrom, String testName) throws InterruptedException {
+    private void multiStoreAddDelete(List<MetadataCache<MyClass>> caches, int addOn, int delFrom, String testName)
+            throws InterruptedException {
         MetadataCache<MyClass> addCache = caches.get(addOn);
         MetadataCache<MyClass> delCache = caches.get(delFrom);
 
@@ -172,13 +171,13 @@ public class MetadataCacheTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "zk")
-    public void crossStoreUpdates(String provider, String url) throws Exception {
+    public void crossStoreUpdates(String provider, Supplier<String> urlSupplier) throws Exception {
         String testName = "cross store updates";
         @Cleanup
-        MetadataStore store1 = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store1 = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
 
         @Cleanup
-        MetadataStore store2 = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store2 = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
 
         MetadataCacheImpl<MyClass> objCache1 = (MetadataCacheImpl<MyClass>) store1.getMetadataCache(MyClass.class);
 
@@ -194,7 +193,7 @@ public class MetadataCacheTest extends BaseMetadataStoreTest {
                         log.error("Got exception {}", e.getMessage());
                     }
                 });
-            };
+            }
         });
 
         String key1 = "/test-key1";
@@ -211,15 +210,15 @@ public class MetadataCacheTest extends BaseMetadataStoreTest {
         });
 
         MyClass value2 = new MyClass(testName, 2);
-        objCache1.readModifyUpdate(key1, (oldData) -> {return value2;}).join();
+        objCache1.readModifyUpdate(key1, (oldData) -> value2).join();
 
         Awaitility.await().ignoreNoExceptions().untilAsserted(() ->assertEquals(storeObj.get(), value2));
     }
 
     @Test(dataProvider = "impl")
-    public void insertionDeletionWitGenericType(String provider, String url) throws Exception {
+    public void insertionDeletionWitGenericType(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStore store = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
 
         MetadataCache<Map<String, String>> objCache = store.getMetadataCache(new TypeReference<Map<String, String>>() {
         });
@@ -243,9 +242,9 @@ public class MetadataCacheTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void insertionDeletion(String provider, String url) throws Exception {
+    public void insertionDeletion(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStore store = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
         MetadataCache<MyClass> objCache = store.getMetadataCache(MyClass.class);
 
         String key1 = newKey();
@@ -278,9 +277,9 @@ public class MetadataCacheTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void insertionOutsideCache(String provider, String url) throws Exception {
+    public void insertionOutsideCache(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStore store = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
         MetadataCache<MyClass> objCache = store.getMetadataCache(MyClass.class);
 
         String key1 = newKey();
@@ -296,9 +295,9 @@ public class MetadataCacheTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void insertionOutsideCacheWithGenericType(String provider, String url) throws Exception {
+    public void insertionOutsideCacheWithGenericType(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStore store = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
         MetadataCache<Map<String, String>> objCache = store.getMetadataCache(new TypeReference<Map<String, String>>() {
         });
 
@@ -314,9 +313,9 @@ public class MetadataCacheTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void invalidJsonContent(String provider, String url) throws Exception {
+    public void invalidJsonContent(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStore store = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
 
         MetadataCache<MyClass> objCache = store.getMetadataCache(MyClass.class);
 
@@ -334,9 +333,9 @@ public class MetadataCacheTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void testReadCloned(String provider, String url) throws Exception {
+    public void testReadCloned(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStore store = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
 
         MetadataCache<Policies> objCache = store.getMetadataCache(Policies.class);
         String path = "/testReadCloned-policies";
@@ -372,9 +371,9 @@ public class MetadataCacheTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void testCloneInReadModifyUpdateOrCreate(String provider, String url) throws Exception {
+    public void testCloneInReadModifyUpdateOrCreate(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStore store = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
 
         MetadataCache<Policies> objCache = store.getMetadataCache(Policies.class);
         String path = "/testCloneInReadModifyUpdateOrCreate-policies";
@@ -411,9 +410,9 @@ public class MetadataCacheTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void readModifyUpdate(String provider, String url) throws Exception {
+    public void readModifyUpdate(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStore store = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
 
         MetadataCache<MyClass> objCache = store.getMetadataCache(MyClass.class);
 
@@ -472,15 +471,16 @@ public class MetadataCacheTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void getWithStats(String provider, String url) throws Exception {
+    public void getWithStats(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStore store = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
         MetadataCache<MyClass> objCache = store.getMetadataCache(MyClass.class);
 
         String key1 = newKey();
 
         MyClass value1 = new MyClass("a", 1);
-        Stat stat1 = store.put(key1, ObjectMapperFactory.getThreadLocal().writeValueAsBytes(value1), Optional.of(-1L)).join();
+        Stat stat1 = store.put(key1, ObjectMapperFactory.getThreadLocal().writeValueAsBytes(value1), Optional.of(-1L))
+                .join();
 
         CacheGetResult<MyClass> res = objCache.getWithStats(key1).join().get();
         assertEquals(res.getValue(), value1);
@@ -488,9 +488,9 @@ public class MetadataCacheTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void cacheWithCustomSerde(String provider, String url) throws Exception {
+    public void cacheWithCustomSerde(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStore store = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
 
         // Simple serde that convert numbers to ascii
         MetadataCache<Integer> objCache = store.getMetadataCache(new MetadataSerde<Integer>() {
diff --git a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataStoreExtendedTest.java b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataStoreExtendedTest.java
index 1249ade..eae9c1d 100644
--- a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataStoreExtendedTest.java
+++ b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataStoreExtendedTest.java
@@ -21,12 +21,10 @@ package org.apache.pulsar.metadata;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotEquals;
 import static org.testng.Assert.assertNotNull;
-
 import java.util.EnumSet;
 import java.util.Optional;
-
+import java.util.function.Supplier;
 import lombok.Cleanup;
-
 import org.apache.pulsar.metadata.api.MetadataStoreConfig;
 import org.apache.pulsar.metadata.api.Stat;
 import org.apache.pulsar.metadata.api.extended.CreateOption;
@@ -36,11 +34,12 @@ import org.testng.annotations.Test;
 public class MetadataStoreExtendedTest extends BaseMetadataStoreTest {
 
     @Test(dataProvider = "impl")
-    public void sequentialKeys(String provider, String url) throws Exception {
+    public void sequentialKeys(String provider, Supplier<String> urlSupplier) throws Exception {
         final String basePath = "/my/path";
 
         @Cleanup
-        MetadataStoreExtended store = MetadataStoreExtended.create(url, MetadataStoreConfig.builder().build());
+        MetadataStoreExtended store = MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
 
         Stat stat1 = store.put(basePath, "value-1".getBytes(), Optional.of(-1L), EnumSet.of(CreateOption.Sequential))
                 .join();
diff --git a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataStoreTest.java b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataStoreTest.java
index 4fdcb59..34a1373 100644
--- a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataStoreTest.java
+++ b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataStoreTest.java
@@ -23,7 +23,6 @@ import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
-
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -32,9 +31,8 @@ import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.CompletionException;
 import java.util.concurrent.LinkedBlockingDeque;
 import java.util.concurrent.TimeUnit;
-
+import java.util.function.Supplier;
 import lombok.Cleanup;
-
 import org.apache.pulsar.metadata.api.GetResult;
 import org.apache.pulsar.metadata.api.MetadataStore;
 import org.apache.pulsar.metadata.api.MetadataStoreConfig;
@@ -50,9 +48,9 @@ import org.testng.annotations.Test;
 public class MetadataStoreTest extends BaseMetadataStoreTest {
 
     @Test(dataProvider = "impl")
-    public void emptyStoreTest(String provider, String url) throws Exception {
+    public void emptyStoreTest(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStore store = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
 
         assertFalse(store.exists("/non-existing-key").join());
         assertFalse(store.exists("/non-existing-key/child").join());
@@ -78,9 +76,9 @@ public class MetadataStoreTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void insertionTestWithExpectedVersion(String provider, String url) throws Exception {
+    public void insertionTestWithExpectedVersion(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStore store = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
 
         String key1 = newKey();
 
@@ -136,15 +134,15 @@ public class MetadataStoreTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void getChildrenTest(String provider, String url) throws Exception {
+    public void getChildrenTest(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStore store = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
 
         String key = newKey();
-        int N = 10;
+        int n = 10;
         List<String> expectedChildren = new ArrayList<>();
 
-        for (int i = 0; i < N; i++) {
+        for (int i = 0; i < n; i++) {
             store.put(key + "/c-" + i, new byte[0], Optional.empty()).join();
 
             expectedChildren.add("c-" + i);
@@ -153,7 +151,7 @@ public class MetadataStoreTest extends BaseMetadataStoreTest {
         assertEquals(store.getChildren(key).join(), expectedChildren);
 
         // Nested children
-        for (int i = 0; i < N; i++) {
+        for (int i = 0; i < n; i++) {
             store.put(key + "/c-0/cc-" + i, new byte[0], Optional.empty()).join();
         }
 
@@ -161,15 +159,15 @@ public class MetadataStoreTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void deletionTest(String provider, String url) throws Exception {
+    public void deletionTest(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStore store = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
 
         String key = newKey();
-        int N = 10;
+        int n = 10;
         List<String> expectedChildren = new ArrayList<>();
 
-        for (int i = 0; i < N; i++) {
+        for (int i = 0; i < n; i++) {
             store.put(key + "/c-" + i, new byte[0], Optional.empty()).join();
 
             expectedChildren.add("c-" + i);
@@ -182,7 +180,7 @@ public class MetadataStoreTest extends BaseMetadataStoreTest {
             assertException(e, MetadataStoreException.class);
         }
 
-        for (int i = 0; i < N; i++) {
+        for (int i = 0; i < n; i++) {
             try {
                 store.delete(key + "/c-" + i, Optional.of(1L)).join();
                 fail("The key has children");
@@ -195,9 +193,9 @@ public class MetadataStoreTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void emptyKeyTest(String provider, String url) throws Exception {
+    public void emptyKeyTest(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStore store = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
 
         try {
             store.delete("", Optional.empty()).join();
@@ -236,9 +234,9 @@ public class MetadataStoreTest extends BaseMetadataStoreTest {
     }
 
     @Test(dataProvider = "impl")
-    public void notificationListeners(String provider, String url) throws Exception {
+    public void notificationListeners(String provider, Supplier<String> urlSupplier) throws Exception {
         @Cleanup
-        MetadataStore store = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
+        MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
 
         BlockingQueue<Notification> notifications = new LinkedBlockingDeque<>();
         store.registerListener(n -> {