diff options
author | Harald Musum <musum@verizonmedia.com> | 2021-07-08 22:03:04 +0200 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2021-07-08 22:03:04 +0200 |
commit | 3c06371c9393e9c2ebae773c350737db7c540f89 (patch) | |
tree | ad0442747c9cdd0ba593dc74abebe70011dc6f9b /configserver/src/test/java/com | |
parent | b019e9c524760e781f194df12c6f6b34e7445491 (diff) |
Use Curator instead of ConfigCurator, part 1
Diffstat (limited to 'configserver/src/test/java/com')
2 files changed, 47 insertions, 39 deletions
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClientTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClientTest.java index e20363af4e9..4acf0ea6603 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClientTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClientTest.java @@ -14,8 +14,9 @@ import com.yahoo.config.provision.AllocatedHosts; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.HostSpec; import com.yahoo.path.Path; -import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; +import com.yahoo.text.Utf8; import com.yahoo.vespa.config.server.zookeeper.ZKApplicationPackage; +import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.mock.MockCurator; import org.junit.Before; import org.junit.Rule; @@ -31,6 +32,10 @@ import java.util.Map; import java.util.Optional; import static com.yahoo.config.provision.serialization.AllocatedHostsSerializer.fromJson; +import static com.yahoo.vespa.config.server.zookeeper.ConfigCurator.DEFCONFIGS_ZK_SUBPATH; +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 com.yahoo.vespa.config.server.zookeeper.ConfigCurator.USER_DEFCONFIGS_ZK_SUBPATH; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; @@ -46,13 +51,13 @@ public class ZooKeeperClientTest { @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); - private ConfigCurator zk; - private final String appPath = "/1"; + private Curator zk; + private final Path appPath = Path.fromString("/1"); @Before public void setupZK() throws IOException { - zk = ConfigCurator.create(new MockCurator()); - ZooKeeperClient zkc = new ZooKeeperClient(zk, new BaseDeployLogger(), Path.fromString(appPath)); + zk = new MockCurator(); + ZooKeeperClient zkc = new ZooKeeperClient(zk, new BaseDeployLogger(), appPath); ApplicationPackage app = FilesApplicationPackage.fromFileWithDeployData(new File("src/test/apps/zkfeed"), new DeployData("foo", "/bar/baz", @@ -81,30 +86,30 @@ public class ZooKeeperClientTest { @Test public void testInitZooKeeper() { - ConfigCurator zk = ConfigCurator.create(new MockCurator()); + Curator zk = new MockCurator(); BaseDeployLogger logger = new BaseDeployLogger(); long generation = 1L; ZooKeeperClient zooKeeperClient = new ZooKeeperClient(zk, logger, Path.fromString("/1")); zooKeeperClient.initialize(); - String appPath = "/"; + Path appPath = Path.fromString("/"); assertThat(zk.getChildren(appPath).size(), is(1)); - assertTrue(zk.exists("/" + generation)); - String currentAppPath = appPath + generation; - assertTrue(zk.exists(currentAppPath, ConfigCurator.DEFCONFIGS_ZK_SUBPATH.replaceFirst("/", ""))); + Path currentAppPath = appPath.append(String.valueOf(generation)); + assertTrue(zk.exists(currentAppPath)); + assertTrue(zk.exists(currentAppPath.append(DEFCONFIGS_ZK_SUBPATH.replaceFirst("/", "")))); assertThat(zk.getChildren(currentAppPath).size(), is(4)); } @Test public void testFeedDefFilesToZooKeeper() { - String defsPath = appPath + ConfigCurator.DEFCONFIGS_ZK_SUBPATH; - assertTrue(zk.exists(appPath, ConfigCurator.DEFCONFIGS_ZK_SUBPATH.replaceFirst("/", ""))); + Path defsPath = appPath.append(DEFCONFIGS_ZK_SUBPATH); + assertTrue(zk.exists(appPath.append(DEFCONFIGS_ZK_SUBPATH.replaceFirst("/", "")))); List<String> children = zk.getChildren(defsPath); assertEquals(defsPath + " children", 1, children.size()); Collections.sort(children); assertThat(children.get(0), is("a.b.test2")); - assertTrue(zk.exists(appPath, ConfigCurator.USER_DEFCONFIGS_ZK_SUBPATH.replaceFirst("/", ""))); - String userDefsPath = appPath + ConfigCurator.USER_DEFCONFIGS_ZK_SUBPATH; + assertTrue(zk.exists(appPath.append(USER_DEFCONFIGS_ZK_SUBPATH.replaceFirst("/", "")))); + Path userDefsPath = appPath.append(USER_DEFCONFIGS_ZK_SUBPATH); children = zk.getChildren(userDefsPath); assertThat(children.size(), is(1)); Collections.sort(children); @@ -113,8 +118,9 @@ public class ZooKeeperClientTest { @Test public void testFeedAppMetaDataToZooKeeper() { - assertTrue(zk.exists(appPath, ConfigCurator.META_ZK_PATH)); - ApplicationMetaData metaData = ApplicationMetaData.fromJsonString(zk.getData(appPath, ConfigCurator.META_ZK_PATH)); + assertTrue(zk.exists(appPath.append(META_ZK_PATH))); + ApplicationMetaData metaData = ApplicationMetaData.fromJsonString( + Utf8.toString(zk.getData(appPath.append(META_ZK_PATH)).get())); assertTrue(metaData.getChecksum().length() > 0); assertTrue(metaData.isInternalRedeploy()); assertThat(metaData.getDeployedByUser(), is("foo")); @@ -126,34 +132,34 @@ public class ZooKeeperClientTest { @Test public void testVersionedFileRegistry() { - String fileRegPath = appPath + "/" + ZKApplicationPackage.fileRegistryNode; + Path fileRegPath = appPath.append(ZKApplicationPackage.fileRegistryNode); assertTrue(zk.exists(fileRegPath)); - assertTrue(zk.exists(fileRegPath + "/1.2.3")); - assertTrue(zk.exists(fileRegPath + "/3.2.1")); + assertTrue(zk.exists(fileRegPath.append("/1.2.3"))); + assertTrue(zk.exists(fileRegPath.append("/3.2.1"))); // assertNull("Data at " + fileRegPath, zk.getData(fileRegPath)); Not null any more .. hm } @Test public void include_dirs_are_written_to_ZK() { - assertTrue(zk.exists(appPath + ConfigCurator.USERAPP_ZK_SUBPATH + "/" + "dir1", "default.xml")); - assertTrue(zk.exists(appPath + ConfigCurator.USERAPP_ZK_SUBPATH + "/nested/" + "dir2", "chain2.xml")); - assertTrue(zk.exists(appPath + ConfigCurator.USERAPP_ZK_SUBPATH + "/nested/" + "dir2", "chain3.xml")); + assertTrue(zk.exists(appPath.append(USERAPP_ZK_SUBPATH).append("dir1").append("default.xml"))); + assertTrue(zk.exists(appPath.append(USERAPP_ZK_SUBPATH).append("nested").append("dir2").append("chain2.xml"))); + assertTrue(zk.exists(appPath.append(USERAPP_ZK_SUBPATH).append("nested").append("dir2").append("chain3.xml"))); } @Test public void search_chain_dir_written_to_ZK() { - assertTrue(zk.exists(appPath().append("search").append("chains").append("dir1").append("default.xml").getAbsolute())); - assertTrue(zk.exists(appPath().append("search").append("chains").append("dir2").append("chain2.xml").getAbsolute())); - assertTrue(zk.exists(appPath().append("search").append("chains").append("dir2").append("chain3.xml").getAbsolute())); + assertTrue(zk.exists(appPath().append("search").append("chains").append("dir1").append("default.xml"))); + assertTrue(zk.exists(appPath().append("search").append("chains").append("dir2").append("chain2.xml"))); + assertTrue(zk.exists(appPath().append("search").append("chains").append("dir2").append("chain3.xml"))); } private Path appPath() { - return Path.fromString(appPath).append(ConfigCurator.USERAPP_ZK_SUBPATH); + return appPath.append(USERAPP_ZK_SUBPATH); } @Test public void testWritingHostNamesToZooKeeper() throws IOException { - ConfigCurator zk = ConfigCurator.create(new MockCurator()); + Curator zk = new MockCurator(); BaseDeployLogger logger = new BaseDeployLogger(); Path app = Path.fromString("/1"); ZooKeeperClient zooKeeperClient = new ZooKeeperClient(zk, logger, app); @@ -163,9 +169,9 @@ public class ZooKeeperClientTest { ImmutableSet<HostSpec> hosts = ImmutableSet.of(host1, host2); zooKeeperClient.write(AllocatedHosts.withHosts(hosts)); Path hostsPath = app.append(ZKApplicationPackage.allocatedHostsNode); - assertTrue(zk.exists(hostsPath.getAbsolute())); + assertTrue(zk.exists(hostsPath)); - AllocatedHosts deserialized = fromJson(zk.getBytes(hostsPath.getAbsolute())); + AllocatedHosts deserialized = fromJson(zk.getData(hostsPath).get()); assertEquals(hosts, deserialized.getHosts()); } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperDeployerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperDeployerTest.java index 641fbe5bf41..ebbb10c2d2a 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperDeployerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperDeployerTest.java @@ -1,15 +1,16 @@ -// 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.deploy; +import com.yahoo.component.Version; import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.config.application.api.DeployLogger; -import com.yahoo.config.model.application.provider.*; +import com.yahoo.config.model.application.provider.FilesApplicationPackage; +import com.yahoo.config.model.application.provider.MockFileRegistry; import com.yahoo.config.provision.AllocatedHosts; -import com.yahoo.component.Version; import com.yahoo.io.IOUtils; import com.yahoo.path.Path; +import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.mock.MockCurator; -import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -33,7 +34,7 @@ public class ZooKeeperDeployerTest { @Test public void require_that_deployer_is_initialized() throws IOException { - ConfigCurator zkfacade = ConfigCurator.create(new MockCurator()); + Curator curator = new MockCurator(); File serverdbDir = folder.newFolder("serverdb"); File defsDir = new File(serverdbDir, "serverdefs"); try { @@ -42,21 +43,22 @@ public class ZooKeeperDeployerTest { e.printStackTrace(); fail(); } - deploy(FilesApplicationPackage.fromFile(new File("src/test/apps/content")), zkfacade, Path.fromString("/1")); - deploy(FilesApplicationPackage.fromFile(new File("src/test/apps/content")), zkfacade, Path.fromString("/2")); + deploy(FilesApplicationPackage.fromFile(new File("src/test/apps/content")), curator, Path.fromString("/1")); + deploy(FilesApplicationPackage.fromFile(new File("src/test/apps/content")), curator, Path.fromString("/2")); } - public void deploy(ApplicationPackage applicationPackage, ConfigCurator configCurator, Path appPath) throws IOException { + public void deploy(ApplicationPackage applicationPackage, Curator curator, Path appPath) throws IOException { MockDeployLogger logger = new MockDeployLogger(); - ZooKeeperClient client = new ZooKeeperClient(configCurator, logger, appPath); + ZooKeeperClient client = new ZooKeeperClient(curator, logger, appPath); ZooKeeperDeployer deployer = new ZooKeeperDeployer(client); deployer.deploy(applicationPackage, Collections.singletonMap(new Version(1, 0, 0), new MockFileRegistry()), AllocatedHosts.withHosts(Collections.emptySet())); - assertTrue(configCurator.exists(appPath.getAbsolute())); + assertTrue(curator.exists(appPath)); } private static class MockDeployLogger implements DeployLogger { @Override public void log(Level level, String message) { } } + } |