aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-03-23 15:49:28 -0400
committerJim Hahn <jrh3@att.com>2020-03-23 17:48:52 -0400
commit6084c6dcf5bf061f33204e01116573160bf39fa6 (patch)
tree80f8e286ab3e26dbca322aa9f640001c95cc2ec2 /controlloop/common/eventmanager/src/main
parentdc24e69b789603dd7c8df72a945eaa82e05dd21c (diff)
Enable guards in junit tests
Flipped the flag(s) to enable guard checks in the various junit tests for the Usecases and Frankfurt controllers. Note: the guard checks use the guard simulator. Modified new actor code to not include operation history on first "guard denied" report (i.e., make it work like usecases does). Issue-ID: POLICY-2434 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: I2897da4a0c8fb76fa00cb0f6cf8562c0703005d3
Diffstat (limited to 'controlloop/common/eventmanager/src/main')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java23
1 files changed, 21 insertions, 2 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java
index b880fd190..156dad7e6 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java
@@ -107,6 +107,13 @@ public class ControlLoopOperationManager2 implements Serializable {
private final Deque<Operation> operationHistory = new ConcurrentLinkedDeque<>();
/**
+ * Set to {@code true} to prevent the last item in {@link #operationHistory} from
+ * being included in the outcome of {@link #getHistory()}. Used when the operation
+ * aborts prematurely due to lock-denied, guard-denied, etc.
+ */
+ private boolean holdLast = false;
+
+ /**
* Queue of outcomes yet to be processed. Outcomes are added to this each time the
* "start" or "complete" callback is invoked.
*/
@@ -417,6 +424,7 @@ public class ControlLoopOperationManager2 implements Serializable {
case LOCK_LOST:
case GUARD_DENIED:
case CONTROL_LOOP_TIMEOUT:
+ holdLast = false;
return false;
default:
break;
@@ -541,8 +549,16 @@ public class ControlLoopOperationManager2 implements Serializable {
* @return the list of control loop operations
*/
public List<ControlLoopOperation> getHistory() {
- return operationHistory.stream().map(Operation::getClOperation).map(ControlLoopOperation::new)
- .collect(Collectors.toList());
+ Operation last = (holdLast ? operationHistory.removeLast() : null);
+
+ List<ControlLoopOperation> result = operationHistory.stream().map(Operation::getClOperation)
+ .map(ControlLoopOperation::new).collect(Collectors.toList());
+
+ if (last != null) {
+ operationHistory.add(last);
+ }
+
+ return result;
}
/**
@@ -553,6 +569,9 @@ public class ControlLoopOperationManager2 implements Serializable {
* @param message message to put into the DB
*/
private void storeFailureInDataBase(OperationOutcome outcome, PolicyResult result, String message) {
+ // don't include this in history yet
+ holdLast = true;
+
outcome.setActor(actor);
outcome.setOperation(operation);
outcome.setMessage(message);