summaryrefslogtreecommitdiffstats
path: root/container-di
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-05-30 11:39:26 +0200
committerJon Bratseth <bratseth@oath.com>2018-05-30 11:39:26 +0200
commit4919fb84be7edc03f7c7feb0080ff0c5f705f654 (patch)
tree4eb3d1a1032c6a329b05acc05af4acc4eb0594e8 /container-di
parent9bfecc00be5716933ec305aa9161f68c4dca4200 (diff)
Run reconfigurer thread even when restartOnRedeploy is true
Diffstat (limited to 'container-di')
-rw-r--r--container-di/src/main/scala/com/yahoo/container/di/Container.scala16
-rw-r--r--container-di/src/test/java/demo/ContainerTestBase.java5
-rw-r--r--container-di/src/test/scala/com/yahoo/container/di/ContainerTest.scala40
3 files changed, 30 insertions, 31 deletions
diff --git a/container-di/src/main/scala/com/yahoo/container/di/Container.scala b/container-di/src/main/scala/com/yahoo/container/di/Container.scala
index 5ea6422ddad..0ef01e5aa3d 100644
--- a/container-di/src/main/scala/com/yahoo/container/di/Container.scala
+++ b/container-di/src/main/scala/com/yahoo/container/di/Container.scala
@@ -44,9 +44,9 @@ class Container(
var leastGeneration = -1L
@throws(classOf[InterruptedException])
- def runOnce(
- oldGraph: ComponentGraph = new ComponentGraph,
- fallbackInjector: GuiceInjector = Guice.createInjector()): ComponentGraph = {
+ def getNewConfigGraph(oldGraph: ComponentGraph = new ComponentGraph,
+ fallbackInjector: GuiceInjector = Guice.createInjector(),
+ restartOnRedeploy: Boolean = false): ComponentGraph = {
def deconstructObsoleteComponents(oldGraph: ComponentGraph, newGraph: ComponentGraph) {
val oldComponents = new IdentityHashMap[AnyRef, AnyRef]()
@@ -56,7 +56,8 @@ class Container(
}
try {
- val newGraph = createNewGraph(oldGraph, fallbackInjector)
+ val newGraph = getConfigAndCreateGraph(oldGraph, fallbackInjector)
+ if (restartOnRedeploy) return oldGraph // wait for restart to cause reconfig instead
newGraph.reuseNodes(oldGraph)
constructComponents(newGraph)
deconstructObsoleteComponents(oldGraph, newGraph)
@@ -113,10 +114,11 @@ class Container(
}
}
- final def createNewGraph(graph: ComponentGraph = new ComponentGraph,
- fallbackInjector: Injector): ComponentGraph = {
+ final def getConfigAndCreateGraph(graph: ComponentGraph = new ComponentGraph,
+ fallbackInjector: Injector): ComponentGraph = {
val snapshot = configurer.getConfigs(graph.configKeys, leastGeneration)
+
log.log(DEBUG,
"""createNewGraph:
|graph.configKeys = %s
@@ -138,7 +140,7 @@ class Container(
|previous generation: %d"""
.format(getBootstrapGeneration, getComponentsGeneration, previousConfigGeneration).stripMargin)
installBundles(configs)
- createNewGraph(
+ getConfigAndCreateGraph(
createComponentsGraph(configs, getBootstrapGeneration,fallbackInjector),
fallbackInjector)
case ComponentsConfigs(configs) =>
diff --git a/container-di/src/test/java/demo/ContainerTestBase.java b/container-di/src/test/java/demo/ContainerTestBase.java
index 426033ea101..d413a61759b 100644
--- a/container-di/src/test/java/demo/ContainerTestBase.java
+++ b/container-di/src/test/java/demo/ContainerTestBase.java
@@ -12,12 +12,9 @@ import com.yahoo.container.di.Osgi;
import com.yahoo.container.di.componentgraph.core.ComponentGraph;
import org.junit.Before;
import org.osgi.framework.Bundle;
-import scala.collection.*;
-import scala.collection.immutable.*;
import scala.collection.immutable.Set;
import java.util.Collection;
-import java.util.List;
/**
* @author tonytv
@@ -62,7 +59,7 @@ public class ContainerTestBase extends ContainerTest {
throw new UnsupportedOperationException("getBundle not supported.");
}
});
- componentGraph = container.runOnce(componentGraph, Guice.createInjector());
+ componentGraph = container.getNewConfigGraph(componentGraph, Guice.createInjector(), false);
} catch (Exception e) {
throw new RuntimeException(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 8e7fbde3f5e..83645a8b35c 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
@@ -44,7 +44,7 @@ class ContainerTest {
val container = newContainer(dirConfigSource)
- val component = createComponentTakingConfig(container.runOnce())
+ val component = createComponentTakingConfig(container.getNewConfigGraph())
assertThat(component.config.stringVal(), is("myString"))
container.shutdownConfigurer()
@@ -57,7 +57,7 @@ class ContainerTest {
val container = newContainer(dirConfigSource)
- val componentGraph = container.runOnce()
+ val componentGraph = container.getNewConfigGraph()
val component = createComponentTakingConfig(componentGraph)
assertThat(component.config.stringVal(), is("original"))
@@ -66,7 +66,7 @@ class ContainerTest {
dirConfigSource.writeConfig("test", """stringVal "reconfigured" """)
container.reloadConfig(2)
- val newComponentGraph = container.runOnce(componentGraph)
+ val newComponentGraph = container.getNewConfigGraph(componentGraph)
val component2 = createComponentTakingConfig(newComponentGraph)
assertThat(component2.config.stringVal(), is("reconfigured"))
@@ -80,7 +80,7 @@ class ContainerTest {
val container = newContainer(dirConfigSource)
- val graph = container.runOnce()
+ val graph = container.getNewConfigGraph()
val component = createComponentTakingConfig(graph)
assertThat(component.getId.toString, is("id1"))
@@ -89,7 +89,7 @@ class ContainerTest {
("id2", classOf[ComponentTakingConfig])))
container.reloadConfig(2)
- val newGraph = container.runOnce(graph)
+ val newGraph = container.getNewConfigGraph(graph)
assertThat(ComponentGraph.getNode(newGraph, "id1"), notNullValue(classOf[Node]))
assertThat(ComponentGraph.getNode(newGraph, "id2"), notNullValue(classOf[Node]))
@@ -107,12 +107,12 @@ class ContainerTest {
val container = newContainer(dirConfigSource)
- val oldGraph = container.runOnce()
+ val oldGraph = container.getNewConfigGraph()
val componentToDestruct = oldGraph.getInstance(classOf[DestructableComponent])
writeBootstrapConfigs("id2", classOf[DestructableComponent])
container.reloadConfig(2)
- container.runOnce(oldGraph)
+ container.getNewConfigGraph(oldGraph)
assertTrue(componentToDestruct.deconstructed)
}
@@ -123,7 +123,7 @@ class ContainerTest {
val container = newContainer(dirConfigSource)
var currentGraph: ComponentGraph = null
try {
- currentGraph = container.runOnce()
+ currentGraph = container.getNewConfigGraph()
fail("Expected to log and die.")
} catch {
case _: Throwable => fail("Expected to log and die")
@@ -136,14 +136,14 @@ class ContainerTest {
writeBootstrapConfigs(Array(simpleComponentEntry))
val container = newContainer(dirConfigSource)
- var currentGraph = container.runOnce()
+ var currentGraph = container.getNewConfigGraph()
val simpleComponent = currentGraph.getInstance(classOf[SimpleComponent])
writeBootstrapConfigs("thrower", classOf[ComponentThrowingExceptionInConstructor])
container.reloadConfig(2)
try {
- currentGraph = container.runOnce(currentGraph)
+ currentGraph = container.getNewConfigGraph(currentGraph)
fail("Expected exception")
} catch {
case _: ComponentConstructorException => // Expected, do nothing
@@ -156,7 +156,7 @@ class ContainerTest {
dirConfigSource.writeConfig("test", """stringVal "myString" """)
writeBootstrapConfigs(Array(simpleComponentEntry, componentTakingConfigEntry))
container.reloadConfig(3)
- currentGraph = container.runOnce(currentGraph)
+ currentGraph = container.getNewConfigGraph(currentGraph)
assertEquals(3, currentGraph.generation)
assertSame(simpleComponent, currentGraph.getInstance(classOf[SimpleComponent]))
@@ -169,7 +169,7 @@ class ContainerTest {
writeBootstrapConfigs(Array(simpleComponentEntry))
val container = newContainer(dirConfigSource)
- var currentGraph = container.runOnce()
+ var currentGraph = container.getNewConfigGraph()
val simpleComponent = currentGraph.getInstance(classOf[SimpleComponent])
@@ -177,7 +177,7 @@ class ContainerTest {
dirConfigSource.writeConfig("test", """stringVal "myString" """)
container.reloadConfig(2)
try {
- currentGraph = container.runOnce(currentGraph)
+ currentGraph = container.getNewConfigGraph(currentGraph)
fail("Expected exception")
} catch {
case _: IllegalArgumentException => // Expected, do nothing
@@ -192,20 +192,20 @@ class ContainerTest {
writeBootstrapConfigs("myId", classOf[ComponentTakingConfig])
val container = newContainer(dirConfigSource)
- var currentGraph = container.runOnce()
+ var currentGraph = container.getNewConfigGraph()
writeBootstrapConfigs("thrower", classOf[ComponentThrowingExceptionForMissingConfig])
container.reloadConfig(2)
try {
- currentGraph = container.runOnce(currentGraph)
+ currentGraph = container.getNewConfigGraph(currentGraph)
fail("expected exception")
} catch {
case e: Exception =>
}
val newGraph = Future {
- currentGraph = container.runOnce(currentGraph)
+ currentGraph = container.getNewConfigGraph(currentGraph)
currentGraph
}
@@ -230,7 +230,7 @@ class ContainerTest {
dirConfigSource.writeConfig("jersey-injection", """inject[0]" """)
val container = newContainer(dirConfigSource)
- val componentGraph = container.runOnce()
+ val componentGraph = container.getNewConfigGraph()
val restApiContext = componentGraph.getInstance(clazz)
assertNotNull(restApiContext)
@@ -278,7 +278,7 @@ class ContainerTest {
dirConfigSource.writeConfig("jersey-injection", injectionConfig)
val container = newContainer(dirConfigSource)
- val componentGraph = container.runOnce()
+ val componentGraph = container.getNewConfigGraph()
val restApiContext = componentGraph.getInstance(restApiClass)
}
@@ -328,12 +328,12 @@ class ContainerTest {
val container = newContainer(dirConfigSource, deconstructor)
- val oldGraph = container.runOnce()
+ val oldGraph = container.getNewConfigGraph()
val destructableEntity = oldGraph.getInstance(classOf[DestructableEntity])
writeBootstrapConfigs("id2", classOf[DestructableProvider])
container.reloadConfig(2)
- container.runOnce(oldGraph)
+ container.getNewConfigGraph(oldGraph)
assertTrue(destructableEntity.deconstructed)
}