aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@est.tech>2019-11-05 14:37:09 +0000
committera.sreekumar <ajith.sreekumar@est.tech>2019-11-14 12:15:55 +0000
commit40a1f22ff8d28e78b6512c0a10d454b37f015fdb (patch)
tree8d92efb03c45615bf8697db4adcee558a80eb9e7 /core
parent8c95a09fd412c89b1eaf7d0658005ffba24025bd (diff)
Retaining context in APEX Engine based on policies received in PdpUpdate
Change-Id: I73fad5bf76ed6b4979f5ab76013f204ea82da30b Issue-ID: POLICY-2215 Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
Diffstat (limited to 'core')
-rw-r--r--core/core-engine/pom.xml5
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/context/ApexInternalContext.java27
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/ApexEngine.java5
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java7
-rw-r--r--core/core-engine/src/test/java/org/onap/policy/apex/core/engine/context/ApexInternalContextTest.java34
-rw-r--r--core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java313
6 files changed, 125 insertions, 266 deletions
diff --git a/core/core-engine/pom.xml b/core/core-engine/pom.xml
index fff6d528c..b86fd50ec 100644
--- a/core/core-engine/pom.xml
+++ b/core/core-engine/pom.xml
@@ -63,6 +63,11 @@
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<profiles>
diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/context/ApexInternalContext.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/context/ApexInternalContext.java
index 3d6a72451..0589e8311 100644
--- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/context/ApexInternalContext.java
+++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/context/ApexInternalContext.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,14 +22,12 @@
package org.onap.policy.apex.core.engine.context;
import com.google.common.collect.Maps;
-
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.Set;
import java.util.TreeMap;
-
import org.onap.policy.apex.context.ContextAlbum;
import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.context.Distributor;
@@ -113,13 +112,24 @@ public class ApexInternalContext implements AxConceptGetter<ContextAlbum> {
* in the new model.
*
* @param newPolicyModel The new incoming Apex model to use for context
+ * @param isSubsequentInstance if the current worker instance being updated is not the first one
* @throws ContextException On errors on context setting
*/
- public void update(final AxPolicyModel newPolicyModel) throws ContextException {
+ public void update(final AxPolicyModel newPolicyModel, boolean isSubsequentInstance) throws ContextException {
if (newPolicyModel == null) {
throw new ContextException("internal context update failed, supplied model is null");
}
-
+ // context is shared between all the engine instances
+ // during model update context album only needs to be updated for the first instance.
+ // remaining engine instances can just copy the context
+ if (isSubsequentInstance) {
+ contextAlbums.clear();
+ for (AxArtifactKey contextAlbumKey : ModelService.getModel(AxContextAlbums.class).getAlbumsMap().keySet()) {
+ contextAlbums.put(contextAlbumKey, contextDistributor.createContextAlbum(contextAlbumKey));
+ }
+ key = newPolicyModel.getKey();
+ return;
+ }
// Get the differences between the existing context and the new context
final KeyedMapDifference<AxArtifactKey, AxContextAlbum> contextDifference =
new ContextComparer().compare(ModelService.getModel(AxContextAlbums.class), newPolicyModel.getAlbums());
@@ -143,11 +153,11 @@ public class ApexInternalContext implements AxConceptGetter<ContextAlbum> {
+ newContextAlbum.getItemSchema().getId() + "\" on incoming model");
}
}
-
+
// Remove maps that are no longer used
for (final Entry<AxArtifactKey, AxContextAlbum> removedContextAlbumEntry : contextDifference.getLeftOnly()
.entrySet()) {
- contextDistributor.removeContextAlbum(removedContextAlbumEntry.getValue());
+ contextDistributor.removeContextAlbum(removedContextAlbumEntry.getKey());
contextAlbums.remove(removedContextAlbumEntry.getKey());
}
@@ -156,6 +166,11 @@ public class ApexInternalContext implements AxConceptGetter<ContextAlbum> {
// Set up the new context albums
for (final AxArtifactKey contextAlbumKey : contextDifference.getRightOnly().keySet()) {
+ // In case if a context album is part of previous and current model, but needs to be cleared
+ // for example, due to a major version change
+ if (contextAlbums.containsKey(contextAlbumKey)) {
+ contextDistributor.removeContextAlbum(contextAlbumKey);
+ }
contextAlbums.put(contextAlbumKey, contextDistributor.createContextAlbum(contextAlbumKey));
}
diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/ApexEngine.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/ApexEngine.java
index 2c5167d1b..4c4166380 100644
--- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/ApexEngine.java
+++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/ApexEngine.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +22,6 @@
package org.onap.policy.apex.core.engine.engine;
import java.util.Map;
-
import org.onap.policy.apex.core.engine.event.EnEvent;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
@@ -49,9 +49,10 @@ public interface ApexEngine {
* transferred if there is common context in the old and new models.
*
* @param apexModel the apex model
+ * @param isSubsequentInstance if the current worker instance being updated is not the first one
* @throws ApexException on model update errors
*/
- void updateModel(AxPolicyModel apexModel) throws ApexException;
+ void updateModel(AxPolicyModel apexModel, boolean isSubsequentInstance) throws ApexException;
/**
* Starts an Apex engine so that it can receive events.
diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java
index 87ce1230e..9cbd2050f 100644
--- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java
+++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java
@@ -26,7 +26,6 @@ import static org.onap.policy.common.utils.validation.Assertions.argumentNotNull
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
-
import org.onap.policy.apex.context.ContextAlbum;
import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.core.engine.context.ApexInternalContext;
@@ -105,7 +104,7 @@ public class ApexEngineImpl implements ApexEngine {
* {@inheritDoc}.
*/
@Override
- public void updateModel(final AxPolicyModel apexModel) throws ApexException {
+ public void updateModel(final AxPolicyModel apexModel, final boolean isSubsequentInstance) throws ApexException {
if (apexModel != null) {
LOGGER.entry("updateModel()->" + key.getId() + ", apexPolicyModel=" + apexModel.getKey().getId());
} else {
@@ -125,8 +124,8 @@ public class ApexEngineImpl implements ApexEngine {
/// New internal context
internalContext = new ApexInternalContext(apexModel);
} else {
- // Exiting internal context which must be updated
- internalContext.update(apexModel);
+ // Existing internal context which must be updated
+ internalContext.update(apexModel, isSubsequentInstance);
}
} catch (final ContextException e) {
LOGGER.warn(UPDATE_MODEL + key.getId() + ", error setting the context for engine \"" + key.getId() + "\"",
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/context/ApexInternalContextTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/context/ApexInternalContextTest.java
index a75ad37f6..3d0d377bf 100644
--- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/context/ApexInternalContextTest.java
+++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/context/ApexInternalContextTest.java
@@ -1,25 +1,27 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.apex.core.engine.context;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -156,33 +158,23 @@ public class ApexInternalContextTest {
@Test
public void testAlbumUpdate() throws ContextException {
ApexInternalContext context = new ApexInternalContext(policyModel);
-
- try {
- context.update(null);
- fail("test should throw an exception");
- } catch (ContextException ce) {
- assertEquals("internal context update failed, supplied model is null", ce.getMessage());
- }
+ assertThatThrownBy(() -> context.update(null, false))
+ .hasMessage("internal context update failed, supplied model is null");
assertEquals(policyModel.getKey().getId(), context.getKey().getId());
assertEquals(1, context.getContextAlbums().size());
- try {
- context.update(incompatiblePolicyModel);
- fail("test should throw an exception here");
- } catch (ContextException ce) {
- assertEquals("internal context update failed on context album \"Album:0.0.1\" "
- + "in model \"PolicyModel:0.0.1\", "
- + "schema \"Schema:0.0.1\" on existing context model does not equal "
- + "schema \"IncompatibleSchema:0.0.1\" on incoming model", ce.getMessage());
- }
+ assertThatThrownBy(() -> context.update(incompatiblePolicyModel, false)).hasMessage(
+ "internal context update failed on context album \"Album:0.0.1\" " + "in model \"PolicyModel:0.0.1\", "
+ + "schema \"Schema:0.0.1\" on existing context model does not equal "
+ + "schema \"IncompatibleSchema:0.0.1\" on incoming model");
assertEquals(policyModel.getKey().getId(), context.getKey().getId());
- context.update(newVersionPolicyModel);
+ context.update(newVersionPolicyModel, false);
assertEquals(newVersionPolicyModel.getKey().getId(), context.getKey().getId());
- context.update(newPolicyModel);
+ context.update(newPolicyModel, true);
assertEquals(newPolicyModel.getKey().getId(), context.getKey().getId());
}
}
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java
index 6d35adc54..2663dfc0d 100644
--- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java
+++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java
@@ -1,25 +1,27 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.apex.core.engine.engine.impl;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -30,7 +32,6 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.HashMap;
-
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -50,7 +51,6 @@ import org.onap.policy.apex.core.engine.event.EnEvent;
import org.onap.policy.apex.core.engine.executor.StateMachineExecutor;
import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
-import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
import org.onap.policy.apex.model.basicmodel.service.ModelService;
@@ -167,161 +167,79 @@ public class ApexEngineImplTest {
}
@Test
- public void testSanity() {
+ public void testSanity() throws ApexException {
AxArtifactKey engineKey = new AxArtifactKey("Engine:0.0.1");
ApexEngineImpl engine = (ApexEngineImpl) new ApexEngineFactory().createApexEngine(engineKey);
assertNotNull(engine);
assertEquals(engineKey, engine.getKey());
- try {
- engine.start();
- fail("test should throw an exception");
- } catch (ApexException ae) {
- assertEquals("start()<-Engine:0.0.1,STOPPED, cannot start engine, "
- + "engine has not been initialized, its model is not loaded", ae.getMessage());
- }
+ assertThatThrownBy(() -> engine.start()).hasMessage("start()<-Engine:0.0.1,STOPPED, cannot start engine, "
+ + "engine has not been initialized, its model is not loaded");
- try {
- engine.stop();
- fail("test should throw an exception");
- } catch (ApexException ae) {
- assertEquals("stop()<-Engine:0.0.1,STOPPED, cannot stop engine, " + "engine is already stopped",
- ae.getMessage());
- }
+ assertThatThrownBy(() -> engine.stop())
+ .hasMessage("stop()<-Engine:0.0.1,STOPPED, cannot stop engine, " + "engine is already stopped");
assertEquals(AxEngineState.STOPPED, engine.getState());
assertEquals(0, engine.getEngineContext().size());
assertEquals(engineKey, engine.getEngineStatus().getKey());
assertNull(engine.getInternalContext());
- try {
- engine.clear();
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.clear();
- try {
- engine.addEventListener(null, null);
- fail("test should throw an exception");
- } catch (ApexRuntimeException ae) {
- assertEquals("addEventListener()<-Engine:0.0.1,STOPPED, listenerName is null", ae.getMessage());
- }
+ assertThatThrownBy(() -> engine.addEventListener(null, null))
+ .hasMessage("addEventListener()<-Engine:0.0.1,STOPPED, listenerName is null");
- try {
- engine.addEventListener("myListener", null);
- fail("test should throw an exception");
- } catch (ApexRuntimeException ae) {
- assertEquals("addEventListener()<-Engine:0.0.1,STOPPED, listener is null", ae.getMessage());
- }
+ assertThatThrownBy(() -> engine.addEventListener("myListener", null))
+ .hasMessage("addEventListener()<-Engine:0.0.1,STOPPED, listener is null");
- try {
- engine.removeEventListener(null);
- fail("test should throw an exception");
- } catch (ApexRuntimeException ae) {
- assertEquals("removeEventListener()<-Engine:0.0.1,STOPPED, listenerName is null", ae.getMessage());
- }
+ assertThatThrownBy(() -> engine.removeEventListener(null))
+ .hasMessage("removeEventListener()<-Engine:0.0.1,STOPPED, listenerName is null");
- try {
- engine.addEventListener("myListener", new DummyListener());
- engine.removeEventListener("myListener");
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ engine.addEventListener("myListener", new DummyListener());
+ engine.removeEventListener("myListener");
assertNull(engine.createEvent(null));
assertFalse(engine.handleEvent(null));
- try {
- engine.updateModel(null);
- fail("test should throw an exception");
- } catch (ApexException ae) {
- assertEquals("updateModel()<-Engine:0.0.1, Apex model is not defined, it has a null value",
- ae.getMessage());
- }
+ assertThatThrownBy(() -> engine.updateModel(null, false))
+ .hasMessage("updateModel()<-Engine:0.0.1, Apex model is not defined, it has a null value");
- try {
- engine.updateModel(policyModel);
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.updateModel(policyModel, false);
// Force a context exception
ModelService.registerModel(AxPolicyModel.class, new AxPolicyModel());
- try {
- engine.updateModel(incompatiblePolicyModel);
- fail("test should throw an exception");
- } catch (ApexException ae) {
- assertEquals("updateModel()<-Engine:0.0.1, error setting the context for engine \"Engine:0.0.1\"",
- ae.getMessage());
- }
+ assertThatThrownBy(() -> engine.updateModel(incompatiblePolicyModel, false))
+ .hasMessage("updateModel()<-Engine:0.0.1, error setting the context for engine \"Engine:0.0.1\"");
- try {
- engine.updateModel(policyModel);
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.updateModel(policyModel, false);
assertNotNull(engine.getInternalContext());
assertEquals(1, engine.getEngineContext().size());
- try {
- engine.start();
- assertEquals(AxEngineState.READY, engine.getState());
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.start();
+ assertEquals(AxEngineState.READY, engine.getState());
- try {
- engine.start();
- fail("test should throw an exception");
- } catch (ApexException ae) {
- assertEquals("start()<-Engine:0.0.1,READY, cannot start engine, engine not in state STOPPED",
- ae.getMessage());
- }
+ assertThatThrownBy(() -> engine.start())
+ .hasMessage("start()<-Engine:0.0.1,READY, cannot start engine, engine not in state STOPPED");
- try {
- engine.clear();
- fail("test should throw an exception");
- } catch (ApexException ae) {
- assertEquals("clear()<-Engine:0.0.1,READY, cannot clear engine, engine is not stopped", ae.getMessage());
- }
+ assertThatThrownBy(() -> engine.clear())
+ .hasMessage("clear()<-Engine:0.0.1,READY, cannot clear engine, engine is not stopped");
- try {
- engine.stop();
- assertEquals(AxEngineState.STOPPED, engine.getState());
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.stop();
+ assertEquals(AxEngineState.STOPPED, engine.getState());
- try {
- engine.clear();
- assertEquals(AxEngineState.STOPPED, engine.getState());
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.clear();
+ assertEquals(AxEngineState.STOPPED, engine.getState());
- try {
- engine.start();
- fail("test should throw an exception");
- } catch (ApexException ae) {
- assertEquals("start()<-Engine:0.0.1,STOPPED, cannot start engine, "
- + "engine has not been initialized, its model is not loaded", ae.getMessage());
- }
+ assertThatThrownBy(() -> engine.start()).hasMessage("start()<-Engine:0.0.1,STOPPED, cannot start engine, "
+ + "engine has not been initialized, its model is not loaded");
- try {
- engine.updateModel(policyModel);
- assertEquals(AxEngineState.STOPPED, engine.getState());
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.updateModel(policyModel, false);
+ assertEquals(AxEngineState.STOPPED, engine.getState());
- try {
- engine.start();
- assertEquals(AxEngineState.READY, engine.getState());
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.start();
+ assertEquals(AxEngineState.READY, engine.getState());
assertNull(engine.createEvent(null));
@@ -332,101 +250,52 @@ public class ApexEngineImplTest {
assertTrue(engine.handleEvent(event));
assertEquals(AxEngineState.READY, engine.getState());
- try {
- engine.stop();
- assertEquals(AxEngineState.STOPPED, engine.getState());
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.stop();
+ assertEquals(AxEngineState.STOPPED, engine.getState());
- try {
- engine.addEventListener("myListener", new DummyListener());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ engine.addEventListener("myListener", new DummyListener());
- try {
- engine.start();
- assertEquals(AxEngineState.READY, engine.getState());
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.start();
+ assertEquals(AxEngineState.READY, engine.getState());
- try {
- engine.updateModel(policyModel);
- fail("test should throw an exception");
- } catch (ApexException ae) {
- assertEquals("updateModel()<-Engine:0.0.1, cannot update model, "
- + "engine should be stopped but is in state READY", ae.getMessage());
- }
+ assertThatThrownBy(() -> engine.updateModel(policyModel, false)).hasMessage(
+ "updateModel()<-Engine:0.0.1, cannot update model, engine should be stopped but is in state READY");
assertTrue(engine.handleEvent(event));
assertEquals(AxEngineState.READY, engine.getState());
- try {
- engine.stop();
- assertEquals(AxEngineState.STOPPED, engine.getState());
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.stop();
+ assertEquals(AxEngineState.STOPPED, engine.getState());
- try {
- engine.addEventListener("badListener", new DummyEnEventListener());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ engine.addEventListener("badListener", new DummyEnEventListener());
- try {
- engine.start();
- assertEquals(AxEngineState.READY, engine.getState());
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.start();
+ assertEquals(AxEngineState.READY, engine.getState());
assertFalse(engine.handleEvent(event));
assertEquals(AxEngineState.READY, engine.getState());
- try {
- engine.stop();
- assertEquals(AxEngineState.STOPPED, engine.getState());
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.stop();
+ assertEquals(AxEngineState.STOPPED, engine.getState());
- try {
- engine.removeEventListener("badListener");
- engine.addEventListener("slowListener", new DummySlowEnEventListener());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ engine.removeEventListener("badListener");
+ engine.addEventListener("slowListener", new DummySlowEnEventListener());
}
@Test
- public void testState() throws InterruptedException {
+ public void testState() throws InterruptedException, ApexException {
AxArtifactKey engineKey = new AxArtifactKey("Engine:0.0.1");
ApexEngineImpl engine = (ApexEngineImpl) new ApexEngineFactory().createApexEngine(engineKey);
assertNotNull(engine);
assertEquals(engineKey, engine.getKey());
- try {
- engine.updateModel(policyModel);
- assertEquals(AxEngineState.STOPPED, engine.getState());
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.updateModel(policyModel, false);
+ assertEquals(AxEngineState.STOPPED, engine.getState());
DummySlowEnEventListener slowListener = new DummySlowEnEventListener();
- try {
- engine.addEventListener("slowListener", slowListener);
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ engine.addEventListener("slowListener", slowListener);
- try {
- engine.start();
- assertEquals(AxEngineState.READY, engine.getState());
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.start();
+ assertEquals(AxEngineState.READY, engine.getState());
assertEquals(AxEngineState.READY, engine.getState());
@@ -437,6 +306,7 @@ public class ApexEngineImplTest {
// 1 second is less than the 3 second wait on engine stopping
slowListener.setWaitTime(1000);
(new Thread() {
+ @Override
public void run() {
assertTrue(engine.handleEvent(event));
assertEquals(AxEngineState.STOPPED, engine.getState());
@@ -466,6 +336,7 @@ public class ApexEngineImplTest {
// 4 seconds is more than the 3 second wait on engine stopping
slowListener.setWaitTime(4000);
(new Thread() {
+ @Override
public void run() {
assertTrue(engine.handleEvent(event));
assertEquals(AxEngineState.STOPPED, engine.getState());
@@ -492,30 +363,22 @@ public class ApexEngineImplTest {
@Test
public void testStateMachineError() throws InterruptedException, IllegalArgumentException, IllegalAccessException,
- NoSuchFieldException, SecurityException {
+ NoSuchFieldException, SecurityException, ApexException {
AxArtifactKey engineKey = new AxArtifactKey("Engine:0.0.1");
ApexEngineImpl engine = (ApexEngineImpl) new ApexEngineFactory().createApexEngine(engineKey);
assertNotNull(engine);
assertEquals(engineKey, engine.getKey());
- try {
- engine.updateModel(policyModel);
- assertEquals(AxEngineState.STOPPED, engine.getState());
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.updateModel(policyModel, false);
+ assertEquals(AxEngineState.STOPPED, engine.getState());
final Field smHandlerField = engine.getClass().getDeclaredField("stateMachineHandler");
smHandlerField.setAccessible(true);
smHandlerField.set(engine, smHandlerMock);
- try {
- engine.start();
- assertEquals(AxEngineState.READY, engine.getState());
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.start();
+ assertEquals(AxEngineState.READY, engine.getState());
assertEquals(AxEngineState.READY, engine.getState());
@@ -556,45 +419,29 @@ public class ApexEngineImplTest {
@Test
public void testStateMachineHandler() throws InterruptedException, IllegalArgumentException, IllegalAccessException,
- NoSuchFieldException, SecurityException {
+ NoSuchFieldException, SecurityException, ApexException {
AxArtifactKey engineKey = new AxArtifactKey("Engine:0.0.1");
ApexEngineImpl engine = (ApexEngineImpl) new ApexEngineFactory().createApexEngine(engineKey);
assertNotNull(engine);
assertEquals(engineKey, engine.getKey());
- try {
- engine.updateModel(policyModelWithStates);
- assertEquals(AxEngineState.STOPPED, engine.getState());
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.updateModel(policyModelWithStates, false);
+ assertEquals(AxEngineState.STOPPED, engine.getState());
- try {
- engine.start();
- assertEquals(AxEngineState.READY, engine.getState());
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ engine.start();
+ assertEquals(AxEngineState.READY, engine.getState());
AxArtifactKey eventKey = new AxArtifactKey("Event:0.0.1");
EnEvent event = engine.createEvent(eventKey);
assertEquals(eventKey, event.getKey());
- try {
- engine.stop();
- assertEquals(AxEngineState.STOPPED, engine.getState());
- } catch (ApexException ae) {
- fail("test should not throw an exception");
- }
-
+ engine.stop();
assertEquals(AxEngineState.STOPPED, engine.getState());
- try {
- engine.start();
- assertEquals(AxEngineState.READY, engine.getState());
- } catch (ApexException e) {
- fail("test should not throw an exception");
- }
+ assertEquals(AxEngineState.STOPPED, engine.getState());
+
+ engine.start();
+ assertEquals(AxEngineState.READY, engine.getState());
assertEquals(AxEngineState.READY, engine.getState());