diff options
author | Håkon Hallingstad <hakon@oath.com> | 2019-01-26 02:30:54 +0100 |
---|---|---|
committer | Håkon Hallingstad <hakon@oath.com> | 2019-01-26 02:30:54 +0100 |
commit | 5b51470fdf2eb245d509984047dc84ef3a7fae83 (patch) | |
tree | a310e85085feaf5624f826215af766dd4e704b42 /flags/src/test/java/com/yahoo | |
parent | 5d126afb33df13888c58e5b43a79c893c23fb65b (diff) |
Read override file flags from file only once for config server
Up until now, every lookup of a flag in the ConfigServerFlagSource would
1. try to read 2 flag files under /etc/vespa/flags, causing exceptions
because they are typically not set, and
2. then read flag from ZooKeeper through ZooKeeperFlagSource
Optimization was deliberately held off until later (now). This PR fixes (1).
Changes the ConfigServerFlagSource to:
1'. Read VESPA_HOME/var/vespa/flag.db once during component graph
construction. As before, if a flag is defined on file, the flag is not
looked up in ZK, which may be useful in emergencies.
2. As before.
Also, removes the last usages of FileFlagSource and its reading of flags in
/etc/vespa/flags.
Diffstat (limited to 'flags/src/test/java/com/yahoo')
-rw-r--r-- | flags/src/test/java/com/yahoo/vespa/flags/FileFlagSourceTest.java | 93 |
1 files changed, 0 insertions, 93 deletions
diff --git a/flags/src/test/java/com/yahoo/vespa/flags/FileFlagSourceTest.java b/flags/src/test/java/com/yahoo/vespa/flags/FileFlagSourceTest.java deleted file mode 100644 index e19436069b5..00000000000 --- a/flags/src/test/java/com/yahoo/vespa/flags/FileFlagSourceTest.java +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.flags; - -import com.yahoo.vespa.test.file.TestFileSystem; -import org.junit.Test; - -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.file.FileSystem; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Optional; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -public class FileFlagSourceTest { - private final FileSystem fileSystem = TestFileSystem.create(); - private final FileFlagSource source = new FileFlagSource(fileSystem); - private final FlagId id = new FlagId("foo"); - - @Test - public void testFeatureLikeFlags() throws IOException { - BooleanFlag booleanFlag = new UnboundBooleanFlag(id).bindTo(source); - BooleanFlag byDefaultTrue = new UnboundBooleanFlag(id, true).bindTo(source); - - assertFalse(booleanFlag.value()); - assertTrue(byDefaultTrue.value()); - - writeFlag(id.toString(), "true\n"); - - assertTrue(booleanFlag.value()); - assertTrue(byDefaultTrue.value()); - - writeFlag(id.toString(), "false\n"); - - assertFalse(booleanFlag.value()); - assertFalse(byDefaultTrue.value()); - } - - @Test - public void testIntegerLikeFlags() throws IOException { - IntFlag intFlag = new UnboundIntFlag(id, -1).bindTo(source); - LongFlag longFlag = new UnboundLongFlag(id, -2L).bindTo(source); - - assertFalse(fetch().isPresent()); - assertFalse(fetch().isPresent()); - assertEquals(-1, intFlag.value()); - assertEquals(-2L, longFlag.value()); - - writeFlag(id.toString(), "1\n"); - - assertTrue(fetch().isPresent()); - assertTrue(fetch().isPresent()); - assertEquals(1, intFlag.value()); - assertEquals(1L, longFlag.value()); - } - - @Test - public void testStringFlag() throws IOException { - StringFlag stringFlag = new UnboundStringFlag(id, "default").bindTo(source); - assertFalse(fetch().isPresent()); - assertEquals("default", stringFlag.value()); - - writeFlag(id.toString(), "\"1\\n\"\n"); - assertEquals("1\n", stringFlag.value()); - } - - @Test - public void parseFailure() throws IOException { - BooleanFlag booleanFlag = new UnboundBooleanFlag(id).bindTo(source); - writeFlag(booleanFlag.id().toString(), "garbage"); - - try { - booleanFlag.value(); - } catch (UncheckedIOException e) { - assertThat(e.getMessage(), containsString("garbage")); - } - } - - private Optional<RawFlag> fetch() { - return source.fetch(id, new FetchVector()); - } - - private void writeFlag(String flagId, String value) throws IOException { - Path featurePath = fileSystem.getPath(FileFlagSource.FLAGS_DIRECTORY).resolve(flagId); - Files.createDirectories(featurePath.getParent()); - Files.write(featurePath, value.getBytes()); - } -}
\ No newline at end of file |