Commit 11c6e0f5 authored by Joerg Domaschka's avatar Joerg Domaschka

- adapter container tests to new class names.

- unified collection of exceptions thrown during container operaton.
parent 068907b5
......@@ -98,13 +98,13 @@ public final class ErrorAwareContainer<T extends ContainerLogic> implements Cont
}
@Override
public void awaitCreation() {
public void awaitCreation() throws ContainerException {
ContainerStatus stat = stateMachine.waitForEndOfCurrentTransition();
if(CreateTransitionAction.isSuccessfullEndState(stat)) {
return;
}
if(CreateTransitionAction.isKnownErrorState(stat)) {
throw new IllegalStateException(stateMachine.collectExceptions());
throw new ContainerException("container creation failed. container is now in error state: " + stat, stateMachine.collectExceptions());
}
}
......@@ -114,13 +114,13 @@ public final class ErrorAwareContainer<T extends ContainerLogic> implements Cont
}
@Override
public void awaitBootstrap() {
public void awaitBootstrap() throws ContainerException {
ContainerStatus stat = stateMachine.waitForEndOfCurrentTransition();
if(BootstrapTransitionAction.isSuccessfullEndState(stat)) {
return;
}
if(BootstrapTransitionAction.isKnownErrorState(stat)) {
throw new IllegalStateException(stateMachine.collectExceptions());
throw new ContainerException("container bootstrap failed. container is now in error state: " + stat, stateMachine.collectExceptions());
}
}
......@@ -130,14 +130,14 @@ public final class ErrorAwareContainer<T extends ContainerLogic> implements Cont
}
@Override
public void awaitInitialisation() {
public void awaitInitialisation() throws ContainerException {
stateMachine.waitForEndOfCurrentTransition();
ContainerStatus stat = stateMachine.waitForEndOfCurrentTransition();
if(InitTransitionAction.isSuccessfullEndState(stat)) {
return;
}
if(InitTransitionAction.isKnownErrorState(stat)) {
throw new IllegalStateException(stateMachine.collectExceptions());
throw new ContainerException("container initialisation failed. container is now in error state: " + stat, stateMachine.collectExceptions());
}
}
......@@ -147,14 +147,14 @@ public final class ErrorAwareContainer<T extends ContainerLogic> implements Cont
}
@Override
public void awaitDestruction() {
public void awaitDestruction() throws ContainerException {
stateMachine.waitForEndOfCurrentTransition();
ContainerStatus stat = stateMachine.waitForEndOfCurrentTransition();
if(DestroyTransitionAction.isSuccessfullEndState(stat)) {
return;
}
if(DestroyTransitionAction.isKnownErrorState(stat)) {
throw new IllegalStateException(stateMachine.collectExceptions());
throw new ContainerException("container deletion failed. container is now in error state: " + stat, stateMachine.collectExceptions());
}
}
......
......@@ -197,12 +197,27 @@ public final class ErrorAwareStateMachine<T extends Enum<?> & State > {
// will eventually be stored.
// endOfTransition = endOfTransition
}
}
public synchronized Throwable[] collectExceptions() {
Throwable[] t = collectedExceptions.toArray(new Throwable[collectedExceptions.size()]);
public synchronized Throwable collectExceptions() {
if(collectedExceptions.isEmpty())
throw new IllegalStateException("collectException shall only be called when something bad has actually happened.");
Throwable ret = collectedExceptions.pop();
while(!collectedExceptions.isEmpty()) {
Throwable up = collectedExceptions.pop();
ret = addAsLastCause(up, ret);
}
collectedExceptions.clear();
return ret;
}
private Throwable addAsLastCause(Throwable t, Throwable cause) {
assert t != null;
Throwable x = t;
while(x.getCause() != null)
x = x.getCause();
x.initCause(cause);
return t;
}
}
......@@ -8,14 +8,14 @@ import org.junit.Test;
import org.junit.BeforeClass;
import de.uniulm.omi.cloudiator.lance.lca.container.ComponentInstanceId;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerException;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerStatus;
import de.uniulm.omi.cloudiator.lance.lca.containers.dummy.DummyContainer;
import de.uniulm.omi.cloudiator.lance.lca.containers.dummy.DummyInterceptor;
import de.uniulm.omi.cloudiator.lance.lca.registry.RegistrationException;
import de.uniulm.omi.cloudiator.lance.lifecycle.LifecycleController;
import de.uniulm.omi.cloudiator.lance.lca.EnvContextWrapper;
import de.uniulm.omi.cloudiator.lance.container.standard.StandardContainer;
import de.uniulm.omi.cloudiator.lance.container.standard.ErrorAwareContainer;
public class ContainerLifecycleTest {
......@@ -41,12 +41,12 @@ public class ContainerLifecycleTest {
}
private StandardContainer<DummyContainer> linkControllers() {
private ErrorAwareContainer<DummyContainer> linkControllers() {
interceptor = new DummyInterceptor();
LifecycleController lcc = new LifecycleController(null, interceptor, core.accessor, null);
StandardContainer<DummyContainer> containerWrapper =
new StandardContainer<>(CoreElements.componentInstanceId, container,
ErrorAwareContainer<DummyContainer> containerWrapper =
new ErrorAwareContainer<>(CoreElements.componentInstanceId, container,
core.networkHandler, lcc, core.accessor);
return containerWrapper;
}
......@@ -55,16 +55,16 @@ public class ContainerLifecycleTest {
public void testNewContainer() {
assertNotNull(CoreElements.context);
init(false);
StandardContainer<DummyContainer> containerWrapper = linkControllers();
ErrorAwareContainer<DummyContainer> containerWrapper = linkControllers();
assertRightState(ContainerStatus.NEW, containerWrapper);
assertTrue(container.invocationCount() == 0);
}
@Test(expected=IllegalStateException.class)
public void testNewContainerWithoutRegistryInit() {
public void testNewContainerWithoutRegistryInit() throws ContainerException {
assertNotNull(CoreElements.context);
init(true);
StandardContainer<DummyContainer> containerWrapper = linkControllers();
ErrorAwareContainer<DummyContainer> containerWrapper = linkControllers();
containerWrapper.create();
containerWrapper.awaitCreation();
}
......@@ -84,12 +84,12 @@ public class ContainerLifecycleTest {
}
@Test
public void testContainerCreation() throws RegistrationException {
public void testContainerCreation() throws RegistrationException, ContainerException {
assertNotNull(CoreElements.context);
init(true);
core.fillRegistry();
StandardContainer<DummyContainer> containerWrapper = linkControllers();
ErrorAwareContainer<DummyContainer> containerWrapper = linkControllers();
containerWrapper.create();
containerWrapper.awaitCreation();
......@@ -112,12 +112,12 @@ public class ContainerLifecycleTest {
}
@Test
public void testContainerBootstrap() throws RegistrationException {
public void testContainerBootstrap() throws RegistrationException, ContainerException {
assertNotNull(CoreElements.context);
init(true);
core.fillRegistry();
StandardContainer<DummyContainer> containerWrapper = linkControllers();
ErrorAwareContainer<DummyContainer> containerWrapper = linkControllers();
containerWrapper.create();
containerWrapper.awaitCreation();
......@@ -148,12 +148,12 @@ public class ContainerLifecycleTest {
}
@Test
public void testContainerInit() throws RegistrationException {
public void testContainerInit() throws RegistrationException, ContainerException {
assertNotNull(CoreElements.context);
init(true);
core.fillRegistry();
StandardContainer<DummyContainer> containerWrapper = linkControllers();
ErrorAwareContainer<DummyContainer> containerWrapper = linkControllers();
LifecycleStoreCreator creator = new LifecycleStoreCreator();
creator.addDefaultStartDetector();
......@@ -201,7 +201,7 @@ public class ContainerLifecycleTest {
assertTrue(dumb.size() == compInstances);
}
private static void assertRightState(ContainerStatus stat, StandardContainer<DummyContainer> container) {
private static void assertRightState(ContainerStatus stat, ErrorAwareContainer<DummyContainer> container) {
for(ContainerStatus status : ContainerStatus.values()) {
if(status == stat)
assertTrue(status == container.getState());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment