[Bugfix] fixed bug where controllers aren't properly stopped

- this occurred for controllers which had dependencies of other
dependencies
This commit is contained in:
Robert von Burg 2015-01-20 20:08:58 +01:00
parent 72abd2a175
commit 99887642a6
3 changed files with 34 additions and 13 deletions

View File

@ -45,7 +45,7 @@ public class ComponentController {
return this.component;
}
public String getComponentName() {
public String getName() {
return this.component.getName();
}

View File

@ -27,6 +27,7 @@ import li.strolch.runtime.configuration.StrolchConfigurationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.eitchnet.utils.dbc.DBC;
import ch.eitchnet.utils.helper.StringHelper;
public class ComponentDependencyAnalyzer {
@ -63,7 +64,7 @@ public class ComponentDependencyAnalyzer {
private Set<ComponentController> collectAllUpstreamDependencies(ComponentController controller) {
Set<ComponentController> upstreamDependencies = new HashSet<>(controller.getUpstreamDependencies());
for (ComponentController upstream : upstreamDependencies) {
for (ComponentController upstream : controller.getUpstreamDependencies()) {
upstreamDependencies.addAll(collectAllUpstreamDependencies(upstream));
}
@ -72,6 +73,15 @@ public class ComponentDependencyAnalyzer {
public Set<ComponentController> collectDirectUpstreamDependencies(Set<ComponentController> controllers) {
// assert no upstream is in this list
for (ComponentController controller : controllers) {
Set<ComponentController> upstreamDependencies = collectAllUpstreamDependencies(controller);
for (ComponentController upstream : upstreamDependencies) {
DBC.INTERIM.assertFalse("Upstream " + upstream.getName() + " is one of the input controllers!",
controllers.contains(upstream));
}
}
Set<ComponentController> directUpstreamDependencies = new HashSet<>();
// collect all direct upstream dependencies
@ -92,7 +102,7 @@ public class ComponentDependencyAnalyzer {
private Set<ComponentController> collectAllDownstreamDependencies(ComponentController controller) {
Set<ComponentController> downstreamDependencies = new HashSet<>(controller.getDownstreamDependencies());
for (ComponentController downstream : downstreamDependencies) {
for (ComponentController downstream : controller.getDownstreamDependencies()) {
downstreamDependencies.addAll(collectAllDownstreamDependencies(downstream));
}
@ -101,6 +111,15 @@ public class ComponentDependencyAnalyzer {
public Set<ComponentController> collectDirectDownstreamDependencies(Set<ComponentController> controllers) {
// assert no downstream is in this list
for (ComponentController controller : controllers) {
Set<ComponentController> downstreamDependencies = collectAllUpstreamDependencies(controller);
for (ComponentController downstream : downstreamDependencies) {
DBC.INTERIM.assertFalse("Downstream " + downstream.getName() + " is one of the input controllers!",
controllers.contains(downstream));
}
}
Set<ComponentController> directDownstreamDependencies = new HashSet<>();
// collect all direct downstream dependencies

View File

@ -38,6 +38,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import ch.eitchnet.utils.dbc.DBC.DbcException;
@SuppressWarnings("nls")
public class ControllerDependencyTest {
@ -201,9 +203,8 @@ public class ControllerDependencyTest {
this.strolchConfiguration = ConfigurationParser.parseConfiguration("dev", rootPathF);
for (ComponentController controller : this.controllerMap.values()) {
ComponentConfiguration componentConfiguration = new ComponentConfiguration(
this.strolchConfiguration.getRuntimeConfiguration(), controller.getComponentName(), null, null,
null, null);
this.strolchConfiguration.addConfiguration(controller.getComponentName(), componentConfiguration);
this.strolchConfiguration.getRuntimeConfiguration(), controller.getName(), null, null, null, null);
this.strolchConfiguration.addConfiguration(controller.getName(), componentConfiguration);
}
}
@ -411,7 +412,7 @@ public class ControllerDependencyTest {
.collectDirectUpstreamDependencies(controllers);
assertEquals(1, directUpstreamDependencies.size());
assertTrue(directUpstreamDependencies.contains(this.conA));
assertTrue(directUpstreamDependencies.contains(this.conB));
}
@Test
@ -448,17 +449,18 @@ public class ControllerDependencyTest {
Set<ComponentController> controllers = new HashSet<>();
controllers.add(this.conB1);
controllers.add(this.conC1);
Set<ComponentController> directUpstreamDependencies = dependencyAnalyzer
.collectDirectUpstreamDependencies(controllers);
assertEquals(1, directUpstreamDependencies.size());
assertTrue(directUpstreamDependencies.contains(this.conA1));
assertTrue(directUpstreamDependencies.contains(this.conC1));
}
@Test
public void shouldCollectUpstreamDependencies4() {
public void shouldNotCollectUpstreamDependencies4() {
thrown.expect(DbcException.class);
thrown.expectMessage("Upstream C1 is one of the input controllers!");
assertModel();
ComponentDependencyAnalyzer dependencyAnalyzer = new ComponentDependencyAnalyzer(this.strolchConfiguration,
@ -489,7 +491,7 @@ public class ControllerDependencyTest {
.collectDirectUpstreamDependencies(controllers);
assertEquals(1, directUpstreamDependencies.size());
assertTrue(directUpstreamDependencies.contains(this.conA1));
assertTrue(directUpstreamDependencies.contains(this.conC1));
}
//
@ -532,7 +534,7 @@ public class ControllerDependencyTest {
.collectDirectUpstreamDependencies(controllers);
assertEquals(1, directUpstreamDependencies.size());
assertTrue(directUpstreamDependencies.contains(this.conA2));
assertTrue(directUpstreamDependencies.contains(this.conB2));
}
// +-> A2
@ -590,7 +592,7 @@ public class ControllerDependencyTest {
assertEquals(ComponentState.UNDEFINED, controller.getState());
ComponentConfiguration componentConfiguration = this.strolchConfiguration
.getComponentConfiguration(controller.getComponentName());
.getComponentConfiguration(controller.getName());
controller.getComponent().setup(componentConfiguration);
}