support lazy init BaseMetadataStoreTest#etcdCluster
@@ -22,6 +22,7 @@ import static org.testng.Assert.assertTrue;
import io.etcd.jetcd.launcher.EtcdCluster;
import io.etcd.jetcd.launcher.EtcdClusterFactory;
import java.io.File;
+import java.net.URI;
import java.util.UUID;
import java.util.concurrent.CompletionException;
import java.util.function.Supplier;
@@ -41,9 +42,6 @@ public abstract class BaseMetadataStoreTest extends TestRetrySupport {
public final void setup() throws Exception {
incrementSetupNumber();
zks = new TestZKServer();
-
- etcdCluster = EtcdClusterFactory.buildCluster("test", 1, false);
- etcdCluster.start();
}
@AfterClass(alwaysRun = true)
@@ -57,6 +55,7 @@ public abstract class BaseMetadataStoreTest extends TestRetrySupport {
if (etcdCluster != null) {
etcdCluster.close();
+ etcdCluster = null;
}
}
@@ -77,11 +76,18 @@ public abstract class BaseMetadataStoreTest extends TestRetrySupport {
{"ZooKeeper", stringSupplier(() -> zks.getConnectionString())},
{"Memory", stringSupplier(() -> "memory:" + UUID.randomUUID())},
{"RocksDB", stringSupplier(() -> "rocksdb:" + createTempFolder())},
- {"Etcd", stringSupplier(() -> "etcd:" + etcdCluster.getClientEndpoints().stream().map(x -> x.toString())
- .collect(Collectors.joining(",")))},
+ {"Etcd", stringSupplier(() -> "etcd:" + getEtcdClusterConnectString())},
};
}
+ private synchronized String getEtcdClusterConnectString() {
+ if (etcdCluster == null) {
+ etcdCluster = EtcdClusterFactory.buildCluster("test", 1, false);
+ etcdCluster.start();
+ }
+ return etcdCluster.getClientEndpoints().stream().map(URI::toString).collect(Collectors.joining(","));
+ }
+
public static Supplier<String> stringSupplier(Supplier<String> supplier) {
return supplier;
}
