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 /container-di | |
parent | 15f1b04fa8afc3b632a3a3c6dee560f487cfb8c6 (diff) |
Test no config when restart on redeploy
Diffstat (limited to 'container-di')
4 files changed, 39 insertions, 7 deletions
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 } + } |