diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-06-01 18:16:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-06-01 18:16:44 +0200 |
commit | 9dce270f8ce9f964410e0acd6a6f1421e97205d7 (patch) | |
tree | 1b7b4ae94d28e4d4d3c818868cafbec2e37f07aa | |
parent | 15f1b04fa8afc3b632a3a3c6dee560f487cfb8c6 (diff) |
Test no config when restart on redeploy
7 files changed, 46 insertions, 12 deletions
diff --git a/config/src/main/java/com/yahoo/config/subscription/ConfigSource.java b/config/src/main/java/com/yahoo/config/subscription/ConfigSource.java index 886d8994d15..d0eda9d27cc 100644 --- a/config/src/main/java/com/yahoo/config/subscription/ConfigSource.java +++ b/config/src/main/java/com/yahoo/config/subscription/ConfigSource.java @@ -3,9 +3,8 @@ package com.yahoo.config.subscription; /** * A type of source of config - * @author vegardh - * @since 5.1 * + * @author vegardh */ public interface ConfigSource { diff --git a/config/src/main/java/com/yahoo/config/subscription/ConfigSourceSet.java b/config/src/main/java/com/yahoo/config/subscription/ConfigSourceSet.java index bb8d5a87916..c799186435c 100755 --- a/config/src/main/java/com/yahoo/config/subscription/ConfigSourceSet.java +++ b/config/src/main/java/com/yahoo/config/subscription/ConfigSourceSet.java @@ -14,10 +14,10 @@ import java.util.logging.Logger; * Two sets are said to be equal if they contain the same sources, independent of order, * upper/lower-casing and whitespaces. * - * @author <a href="gv@yahoo-inc.com">G. Voldengen</a> + * @author gjoranv */ -public class ConfigSourceSet implements ConfigSource -{ +public class ConfigSourceSet implements ConfigSource { + private static final Logger log = Logger.getLogger(ConfigSourceSet.class.getName()); private final Set<String> sources = new LinkedHashSet<>(); @@ -124,4 +124,5 @@ public class ConfigSourceSet implements ConfigSource } return sourceSet; } + } diff --git a/config/src/main/java/com/yahoo/config/subscription/ConfigSubscriber.java b/config/src/main/java/com/yahoo/config/subscription/ConfigSubscriber.java index 9e3a08eaf2c..80b76e7c919 100644 --- a/config/src/main/java/com/yahoo/config/subscription/ConfigSubscriber.java +++ b/config/src/main/java/com/yahoo/config/subscription/ConfigSubscriber.java @@ -221,6 +221,7 @@ public class ConfigSubscriber { /** * Acquire a snapshot of all configs with the same generation within a timeout. + * * @param timeoutInMillis timeout to wait in milliseconds * @param requireChange if set, at least one config have to change * @return true, if a new config generation has been found for all configs (additionally requires @@ -250,6 +251,7 @@ public class ConfigSubscriber { } throwIfExceptionSet(subscription); ConfigSubscription.ConfigState<? extends ConfigInstance> config = subscription.getConfigState(); + System.out.println("Subscription " + subscription + " of class " + subscription.getClass()); if (currentGen == null) currentGen = config.getGeneration(); if ( ! currentGen.equals(config.getGeneration())) allGenerationsTheSame = false; allGenerationsChanged = allGenerationsChanged && config.isGenerationChanged(); diff --git a/container-di/src/main/scala/com/yahoo/container/di/CloudSubscriberFactory.scala b/container-di/src/main/scala/com/yahoo/container/di/CloudSubscriberFactory.scala index e38ff9d4491..0f3fab93e80 100644 --- a/container-di/src/main/scala/com/yahoo/container/di/CloudSubscriberFactory.scala +++ b/container-di/src/main/scala/com/yahoo/container/di/CloudSubscriberFactory.scala @@ -16,9 +16,8 @@ import scala.language.existentials /** * @author Tony Vaagenes */ +class CloudSubscriberFactory(configSource: ConfigSource) extends SubscriberFactory { -class CloudSubscriberFactory(configSource: ConfigSource) extends SubscriberFactory -{ private var testGeneration: Option[Long] = None private val activeSubscribers = new java.util.WeakHashMap[CloudSubscriber, Int]() @@ -82,7 +81,7 @@ object CloudSubscriberFactory { case e: IllegalArgumentException => numExceptions += 1 log.log(Level.WARNING, "Got exception from the config system (please ignore the exception if you just removed " - + "a component from your application that used the mentioned config): ", e) + + "a component from your application that used the mentioned config): ", e) if (numExceptions >= 5) throw new IllegalArgumentException("Failed retrieving the next config generation.", e) } diff --git a/container-di/src/main/scala/com/yahoo/container/di/ConfigRetriever.scala b/container-di/src/main/scala/com/yahoo/container/di/ConfigRetriever.scala index 0d829b0456d..aad9e17acb2 100644 --- a/container-di/src/main/scala/com/yahoo/container/di/ConfigRetriever.scala +++ b/container-di/src/main/scala/com/yahoo/container/di/ConfigRetriever.scala @@ -27,7 +27,7 @@ final class ConfigRetriever(bootstrapKeys: Set[ConfigKeyT], private var componentSubscriber: Subscriber = subscribe(Set()) private var componentSubscriberKeys: Set[ConfigKeyT] = Set() - + /** Loop forever until we get config */ @tailrec final def getConfigs(componentConfigKeys: Set[ConfigKeyT], leastGeneration: Long, restartOnRedeploy: Boolean = false): ConfigSnapshot = { require(componentConfigKeys intersect bootstrapKeys isEmpty) @@ -41,6 +41,20 @@ final class ConfigRetriever(bootstrapKeys: Set[ConfigKeyT], } } + + /** Try to get config just once */ + final def getConfigsOnce(componentConfigKeys: Set[ConfigKeyT], leastGeneration: Long, restartOnRedeploy: Boolean = false): Option[ConfigSnapshot] = { + require(componentConfigKeys intersect bootstrapKeys isEmpty) + log.log(DEBUG, "getConfigsOnce: " + componentConfigKeys) + + setupComponentSubscriber(componentConfigKeys ++ bootstrapKeys) + + getConfigsOptional(leastGeneration, restartOnRedeploy) match { + case Some(snapshot) => resetComponentSubscriberIfBootstrap(snapshot); Some(snapshot) + case None => None; + } + } + private def getConfigsOptional(leastGeneration: Long, restartOnRedeploy: Boolean): Option[ConfigSnapshot] = { val newestComponentGeneration = componentSubscriber.waitNextGeneration() log.log(DEBUG, s"getConfigsOptional: new component generation: $newestComponentGeneration") diff --git a/container-di/src/test/scala/com/yahoo/container/di/ConfigRetrieverTest.scala b/container-di/src/test/scala/com/yahoo/container/di/ConfigRetrieverTest.scala index 93618f90e92..7f1d9a73a82 100644 --- a/container-di/src/test/scala/com/yahoo/container/di/ConfigRetrieverTest.scala +++ b/container-di/src/test/scala/com/yahoo/container/di/ConfigRetrieverTest.scala @@ -18,11 +18,13 @@ import scala.collection.JavaConverters._ * @author tonytv */ class ConfigRetrieverTest { + var dirConfigSource: DirConfigSource = null @Before def setup() { dirConfigSource = new DirConfigSource("ConfigRetrieverTest-") } + @After def cleanup() { dirConfigSource.cleanup() } @Test @@ -49,6 +51,22 @@ class ConfigRetrieverTest { } } + @Test + def require_no_reconfig_when_restart_on_redeploy() { + // TODO + writeConfigs() + val retriever = createConfigRetriever() + val bootstrapConfigs = retriever.getConfigs(Set(), 0) + + val testConfigKey = new ConfigKey(classOf[TestConfig], dirConfigSource.configId) + val componentsConfigs = retriever.getConfigsOnce(Set(testConfigKey), 0, true) + + componentsConfigs match { + case Some(snapshot) => fail("Expected no configs") + case _ => // ok + } + } + @Test(expected = classOf[IllegalArgumentException]) @Ignore def require_exception_upon_modified_components_keys_without_bootstrap() { diff --git a/container-di/src/test/scala/com/yahoo/container/di/DirConfigSource.scala b/container-di/src/test/scala/com/yahoo/container/di/DirConfigSource.scala index 5afa1bc418e..4f80b25a247 100644 --- a/container-di/src/test/scala/com/yahoo/container/di/DirConfigSource.scala +++ b/container-di/src/test/scala/com/yahoo/container/di/DirConfigSource.scala @@ -7,14 +7,12 @@ import java.util.Random import org.junit.rules.TemporaryFolder import com.yahoo.config.subscription.{ConfigSource, ConfigSourceSet} -// TODO: Make this a junit rule. Does not yet work. Look out for junit updates -// (@Rule def configSourceRule = dirConfigSource) - /** * @author tonytv * @author gjoranv */ class DirConfigSource(val testSourcePrefix: String) { + private val tempFolder = createTemporaryFolder() val configSource : ConfigSource = new ConfigSourceSet(testSourcePrefix + new Random().nextLong) @@ -32,9 +30,11 @@ class DirConfigSource(val testSourcePrefix: String) { def cleanup() { tempFolder.delete() } + } private object DirConfigSource { + def printFile(f: File, content: String) { var out: OutputStream = new FileOutputStream(f) out.write(content.getBytes("UTF-8")) @@ -46,4 +46,5 @@ private object DirConfigSource { folder.create() folder } + } |