diff options
author | Harald Musum <musum@verizonmedia.com> | 2021-07-08 22:22:07 +0200 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2021-07-08 22:22:07 +0200 |
commit | 9e4889d949f2b7b8163e22ed8b08a6804f728fd2 (patch) | |
tree | 7a3436b258c89628b4e91f8956f294c64ed34c90 /configserver/src/test/java/com/yahoo/vespa | |
parent | 3c06371c9393e9c2ebae773c350737db7c540f89 (diff) |
Use Curator instead of ConfigCurator, part 2
Diffstat (limited to 'configserver/src/test/java/com/yahoo/vespa')
2 files changed, 22 insertions, 15 deletions
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFileTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFileTest.java index a34c17dc909..c452e1cf0f3 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFileTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFileTest.java @@ -1,9 +1,10 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.zookeeper; import com.yahoo.config.application.api.ApplicationFile; import com.yahoo.config.application.api.ApplicationFileTest; import com.yahoo.path.Path; +import com.yahoo.text.Utf8; import com.yahoo.vespa.curator.mock.MockCurator; import org.junit.Rule; import org.junit.rules.TemporaryFolder; @@ -11,6 +12,7 @@ import org.junit.rules.TemporaryFolder; import java.io.File; import java.io.IOException; +import static com.yahoo.vespa.config.server.zookeeper.ConfigCurator.USERAPP_ZK_SUBPATH; import static org.junit.Assert.assertTrue; /** @@ -23,9 +25,9 @@ public class ZKApplicationFileTest extends ApplicationFileTest { private void feed(ConfigCurator zk, File dirToFeed) { assertTrue(dirToFeed.isDirectory()); - String appPath = "/0"; - ZKApplicationPackageTest.feedZooKeeper(zk, dirToFeed, appPath + ConfigCurator.USERAPP_ZK_SUBPATH, null, true); - zk.putData(appPath, ZKApplicationPackage.fileRegistryNode, "dummyfiles"); + Path appPath = Path.fromString("/0"); + ZKApplicationPackageTest.feedZooKeeper(zk.curator(), dirToFeed, appPath.append(USERAPP_ZK_SUBPATH), null, true); + zk.curator().set(appPath.append(ZKApplicationPackage.fileRegistryNode), Utf8.toBytes("dummyfiles")); } @Override diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackageTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackageTest.java index 458cdb82066..3f84646ad82 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackageTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackageTest.java @@ -14,6 +14,7 @@ import com.yahoo.config.provisioning.FlavorsConfig; import com.yahoo.io.IOUtils; import com.yahoo.path.Path; import com.yahoo.text.Utf8; +import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.mock.MockCurator; import org.junit.Before; import org.junit.Rule; @@ -31,6 +32,8 @@ import java.util.Set; import java.util.regex.Pattern; import static com.yahoo.config.provision.serialization.AllocatedHostsSerializer.toJson; +import static com.yahoo.vespa.config.server.zookeeper.ConfigCurator.META_ZK_PATH; +import static com.yahoo.vespa.config.server.zookeeper.ConfigCurator.USERAPP_ZK_SUBPATH; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -71,7 +74,7 @@ public class ZKApplicationPackageTest { @Test public void testBasicZKFeed() throws IOException { - feed(configCurator, new File(APP)); + feed(configCurator.curator(), new File(APP)); ZKApplicationPackage zkApp = new ZKApplicationPackage(configCurator, Path.fromString("/0")); assertTrue(Pattern.compile(".*<slobroks>.*",Pattern.MULTILINE+Pattern.DOTALL).matcher(IOUtils.readAll(zkApp.getServices())).matches()); assertTrue(Pattern.compile(".*<alias>.*",Pattern.MULTILINE+Pattern.DOTALL).matcher(IOUtils.readAll(zkApp.getHosts())).matches()); @@ -103,13 +106,14 @@ public class ZKApplicationPackageTest { assertEquals("mydisc", DeploymentSpec.fromXml(zkApp.getDeployment().get()).requireInstance("default").globalServiceId().get()); } - private void feed(ConfigCurator zk, File dirToFeed) throws IOException { + private void feed(Curator zk, File dirToFeed) throws IOException { assertTrue(dirToFeed.isDirectory()); - feedZooKeeper(zk, dirToFeed, "/0" + ConfigCurator.USERAPP_ZK_SUBPATH, null, true); + Path sessionPath = Path.fromString("/0"); + feedZooKeeper(zk, dirToFeed, sessionPath.append(USERAPP_ZK_SUBPATH), null, true); String metaData = "{\"deploy\":{\"user\":\"foo\",\"from\":\"bar\",\"timestamp\":1},\"application\":{\"id\":\"foo:foo:default\",\"checksum\":\"abc\",\"generation\":4,\"previousActiveGeneration\":3}}"; - zk.putData("/0", ConfigCurator.META_ZK_PATH, metaData); - zk.putData("/0/" + ZKApplicationPackage.fileRegistryNode + "/3.0.0", "dummyfiles"); - zk.putData("/0/" + ZKApplicationPackage.allocatedHostsNode, toJson(ALLOCATED_HOSTS)); + zk.set(sessionPath.append(META_ZK_PATH), Utf8.toBytes(metaData)); + zk.set(sessionPath.append(ZKApplicationPackage.fileRegistryNode).append("/3.0.0"), Utf8.toBytes("dummyfiles")); + zk.set(sessionPath.append(ZKApplicationPackage.allocatedHostsNode), toJson(ALLOCATED_HOSTS)); } private static class MockNodeFlavors extends NodeFlavors{ @@ -131,7 +135,7 @@ public class ZKApplicationPackageTest { * @param filenameFilter A FilenameFilter which decides which files in dir are fed to zookeeper * @param recurse recurse subdirectories */ - static void feedZooKeeper(ConfigCurator zk, File dir, String path, FilenameFilter filenameFilter, boolean recurse) { + static void feedZooKeeper(Curator zk, File dir, Path path, FilenameFilter filenameFilter, boolean recurse) { try { if (filenameFilter == null) { filenameFilter = acceptsAllFileNameFilter; @@ -141,12 +145,13 @@ public class ZKApplicationPackageTest { } for (File file : listFiles(dir, filenameFilter)) { if (file.getName().startsWith(".")) continue; //.svn , .git ... + Path filePath = path.append(file.getName()); if (file.isFile()) { - String contents = IOUtils.readFile(file); - zk.putData(path, file.getName(), contents); + byte[] contents = IOUtils.readFileBytes(file); + zk.set(filePath, contents); } else if (recurse && file.isDirectory()) { - zk.createNode(path, file.getName()); - feedZooKeeper(zk, file, path + '/' + file.getName(), filenameFilter, recurse); + zk.create(filePath); + feedZooKeeper(zk, file, filePath, filenameFilter, recurse); } } } |