diff options
author | gjoranv <gv@yahoo-inc.com> | 2017-05-31 11:18:41 +0200 |
---|---|---|
committer | gjoranv <gv@yahoo-inc.com> | 2017-05-31 11:18:41 +0200 |
commit | 77ddf302a8f3ad82ff0eb2d0ef75a4b8f112785f (patch) | |
tree | 7f942bb1ab3545291d0d3c2ddf58fa506eee0726 | |
parent | a66b8e55fc81ae2e60301a35503c21baaf24d0ae (diff) |
Remove the timeout for component construction.
-rw-r--r-- | container-di/src/main/scala/com/yahoo/container/di/componentgraph/core/ComponentNode.scala | 31 | ||||
-rw-r--r-- | container-di/src/test/scala/com/yahoo/container/di/ContainerTest.scala | 28 |
2 files changed, 8 insertions, 51 deletions
diff --git a/container-di/src/main/scala/com/yahoo/container/di/componentgraph/core/ComponentNode.scala b/container-di/src/main/scala/com/yahoo/container/di/componentgraph/core/ComponentNode.scala index 477dfa40aad..242d4c97a79 100644 --- a/container-di/src/main/scala/com/yahoo/container/di/componentgraph/core/ComponentNode.scala +++ b/container-di/src/main/scala/com/yahoo/container/di/componentgraph/core/ComponentNode.scala @@ -95,27 +95,15 @@ class ComponentNode(componentId: ComponentId, case other => other } - val instanceFuture = Future { - try { - constructor.newInstance(actualArguments: _*) - } catch { - case e: InvocationTargetException => - throw removeStackTrace(ErrorOrComponentConstructorException(cutStackTraceAtConstructor(e.getCause), s"Error constructing $idAndType")) - } - } + val instance = + try { + constructor.newInstance(actualArguments: _*) + } catch { + case e: InvocationTargetException => + throw removeStackTrace(ErrorOrComponentConstructorException(cutStackTraceAtConstructor(e.getCause), s"Error constructing $idAndType")) + } - try { - val instance = Await.result(instanceFuture, ComponentConstructTimeout) - initId(instance) - } catch { - case constructorException: ComponentConstructorException => - throw constructorException - case _:TimeoutException => - throw new ComponentConstructorException(s"Timed out after $ComponentConstructTimeout while constructing component $idAndType.") - case e: InterruptedException => - Thread.currentThread().interrupt() - throw new RuntimeException(s"Interrupted while constructing component $idAndType", e) - } + initId(instance) } private def ErrorOrComponentConstructorException(cause: Throwable, message: String) : Throwable = { @@ -186,9 +174,6 @@ class ComponentNode(componentId: ComponentId, object ComponentNode { val log = Logger.getLogger(classOf[ComponentNode].getName) - // XXX: var for testing only. Do not reset in production code! - var ComponentConstructTimeout: FiniteDuration = 60 seconds - private def bestConstructor(clazz: Class[AnyRef]) = { val publicConstructors = clazz.getConstructors.asInstanceOf[Array[Constructor[AnyRef]]] 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 b7c3f94410b..9246f7e22c3 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 @@ -166,29 +166,6 @@ class ContainerTest { } @Test - def previous_graph_is_retained_when_new_graph_contains_component_that_times_out_in_ctor() { - ComponentNode.ComponentConstructTimeout = 1 second - val simpleComponentEntry = ComponentEntry("simpleComponent", classOf[SimpleComponent]) - - writeBootstrapConfigs(Array(simpleComponentEntry)) - val container = newContainer(dirConfigSource) - var currentGraph = container.runOnce() - - val simpleComponent = currentGraph.getInstance(classOf[SimpleComponent]) - - writeBootstrapConfigs("sleeper", classOf[ComponentThatSleepsInConstructor]) - container.reloadConfig(2) - try { - currentGraph = container.runOnce(currentGraph) - fail("Expected exception") - } catch { - case e: ComponentConstructorException => assertThat(e.getMessage, containsString("Timed out")) - case _: Throwable => fail("Expected ComponentConstructorException") - } - assertEquals(1, currentGraph.generation) - } - - @Test def previous_graph_is_retained_when_new_graph_throws_exception_for_missing_config() { val simpleComponentEntry = ComponentEntry("simpleComponent", classOf[SimpleComponent]) @@ -393,11 +370,6 @@ object ContainerTest { fail("This component should never be created. Only used for tests where 'int' config is missing.") } - class ComponentThatSleepsInConstructor() { - Thread.sleep(3 * ComponentNode.ComponentConstructTimeout.toMillis) - fail("The timeout mechanism for constructing components is broken.") - } - class DestructableComponent extends AbstractComponent { var deconstructed = false override def deconstruct() { |