diff options
author | gjoranv <gv@yahoo-inc.com> | 2017-05-18 12:35:57 +0200 |
---|---|---|
committer | gjoranv <gv@yahoo-inc.com> | 2017-05-18 13:21:36 +0200 |
commit | f028bc8cca04f0e5bbacea85a33bbc9b41fd4306 (patch) | |
tree | 451027902429d5af937497680c3497d30cfd1dce /container-di | |
parent | 23fbcc166e867ead3a59cfd48139299664a946a3 (diff) |
Verify graph generation number.
+ Rename test component class, and fail if constructed,
to clarify intention of tests where it's being used.
+ Optimize imports.
Diffstat (limited to 'container-di')
-rw-r--r-- | container-di/src/main/scala/com/yahoo/container/di/ConfigRetriever.scala | 2 | ||||
-rw-r--r-- | container-di/src/test/scala/com/yahoo/container/di/ContainerTest.scala | 38 |
2 files changed, 22 insertions, 18 deletions
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 3df131b0d26..77e283721d5 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 @@ -81,7 +81,7 @@ final class ConfigRetriever(bootstrapKeys: Set[ConfigKeyT], componentSubscriber = subscribe(keys) } catch { case e: Throwable => - log.warning(s"Could not set up subscriptions for component configs: ${e.getMessage} - Config keys: $keys") + log.warning(s"Failed setting up subscriptions for component configs: ${e.getMessage} - Config keys: $keys") throw e } } diff --git a/container-di/src/test/scala/com/yahoo/container/di/ContainerTest.scala b/container-di/src/test/scala/com/yahoo/container/di/ContainerTest.scala index 8b612fd6a17..6cccd5c06a4 100644 --- a/container-di/src/test/scala/com/yahoo/container/di/ContainerTest.scala +++ b/container-di/src/test/scala/com/yahoo/container/di/ContainerTest.scala @@ -1,25 +1,27 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.di -import com.yahoo.component.AbstractComponent -import com.yahoo.config.di.IntConfig -import com.yahoo.config.test.TestConfig -import com.yahoo.container.bundle.MockBundle -import com.yahoo.container.di.ContainerTest._ -import com.yahoo.container.di.componentgraph.Provider import com.yahoo.container.di.componentgraph.core.ComponentGraphTest.{SimpleComponent, SimpleComponent2} +import com.yahoo.container.di.componentgraph.Provider import com.yahoo.container.di.componentgraph.core.{ComponentGraph, Node} -import com.yahoo.container.di.config.RestApiContext -import org.hamcrest.CoreMatchers._ -import org.junit.Assert._ import org.junit.{After, Before, Test} +import org.junit.Assert._ +import org.hamcrest.CoreMatchers._ +import com.yahoo.config.test.TestConfig +import com.yahoo.component.AbstractComponent +import ContainerTest._ import scala.collection.JavaConversions -import scala.concurrent.ExecutionContext.Implicits.global +import com.yahoo.config.di.IntConfig + +import scala.concurrent.{Await, Future, future} import scala.concurrent.duration._ -import scala.concurrent.{Await, Future} -import scala.language.postfixOps +import scala.concurrent.ExecutionContext.Implicits.global import scala.util.Try +import com.yahoo.container.di.config.RestApiContext +import com.yahoo.container.bundle.MockBundle + +import scala.language.postfixOps /** * @author tonytv @@ -116,7 +118,7 @@ class ContainerTest { } @Test - def previous_graph_is_retained_when_new_graph_throws_exception() { + def previous_graph_is_retained_when_new_graph_throws_exception_for_missing_config() { val simpleComponentEntry = ComponentEntry("simpleComponent", classOf[SimpleComponent]) writeBootstrapConfigs(Array(simpleComponentEntry)) @@ -125,7 +127,7 @@ class ContainerTest { val simpleComponent = currentGraph.getInstance(classOf[SimpleComponent]) - writeBootstrapConfigs("thrower", classOf[ComponentThrowingException]) + writeBootstrapConfigs("thrower", classOf[ComponentThrowingExceptionForMissingConfig]) dirConfigSource.writeConfig("test", """stringVal "myString" """) container.reloadConfig(2) try { @@ -134,12 +136,14 @@ class ContainerTest { } catch { case e: Exception => e.printStackTrace() } + assertEquals(1, currentGraph.generation) val componentTakingConfigEntry = ComponentEntry("componentTakingConfig", classOf[ComponentTakingConfig]) writeBootstrapConfigs(Array(simpleComponentEntry, componentTakingConfigEntry)) container.reloadConfig(3) currentGraph = container.runOnce(currentGraph) + assertEquals(3, currentGraph.generation) assertSame(simpleComponent, currentGraph.getInstance(classOf[SimpleComponent])) assertNotNull(currentGraph.getInstance(classOf[ComponentTakingConfig])) } @@ -152,7 +156,7 @@ class ContainerTest { val container = newContainer(dirConfigSource) var currentGraph = container.runOnce() - writeBootstrapConfigs("thrower", classOf[ComponentThrowingException]) + writeBootstrapConfigs("thrower", classOf[ComponentThrowingExceptionForMissingConfig]) container.reloadConfig(2) try { @@ -318,8 +322,8 @@ object ContainerTest { require(config != null) } - class ComponentThrowingException(config:IntConfig) extends AbstractComponent { - throw new RuntimeException("This component can never be created") + class ComponentThrowingExceptionForMissingConfig(intConfig: IntConfig) extends AbstractComponent { + fail("This component should never be created. Only used for tests where 'int' config is missing.") } class DestructableComponent extends AbstractComponent { |