summaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/test
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2024-06-05 14:32:37 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2024-06-06 13:29:49 +0000
commitf010d3432b500258121a190ecf94d757c881390e (patch)
treed66a043185e31ee2897fd52ec2b8c76893220e98 /runtime-acm/src/test
parenta48f784beca5e7aa189217c52cfa83452cf8fc47 (diff)
Remove Map in ACM-R for timeout Deploy/Undeploy
Issue-ID: POLICY-5040 Change-Id: I6aa5e93fc63cc865648096512487994fb2f48a54 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm/src/test')
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java12
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java30
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/TimeoutHandlerTest.java67
3 files changed, 38 insertions, 71 deletions
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
index cd1a3856a..bcfdea1dd 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -155,6 +155,7 @@ class InstantiationControllerTest extends CommonRestController {
var automationCompositionFromDb =
instantiationProvider.getAutomationComposition(compositionId, instResponse.getInstanceId());
+ automationCompositionFromRsc.setLastMsg(automationCompositionFromDb.getLastMsg());
assertNotNull(automationCompositionFromDb);
assertEquals(automationCompositionFromRsc, automationCompositionFromDb);
@@ -223,7 +224,9 @@ class InstantiationControllerTest extends CommonRestController {
var automationCompositionsQuery = rawresp.readEntity(AutomationCompositions.class);
assertNotNull(automationCompositionsQuery);
assertThat(automationCompositionsQuery.getAutomationCompositionList()).hasSize(1);
- assertEquals(automationComposition, automationCompositionsQuery.getAutomationCompositionList().get(0));
+ var automationCompositionRc = automationCompositionsQuery.getAutomationCompositionList().get(0);
+ automationComposition.setLastMsg(automationCompositionRc.getLastMsg());
+ assertEquals(automationComposition, automationCompositionRc);
}
@Test
@@ -241,6 +244,7 @@ class InstantiationControllerTest extends CommonRestController {
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
var automationCompositionGet = rawresp.readEntity(AutomationComposition.class);
assertNotNull(automationCompositionGet);
+ automationComposition.setLastMsg(automationCompositionGet.getLastMsg());
assertEquals(automationComposition, automationCompositionGet);
}
@@ -272,7 +276,9 @@ class InstantiationControllerTest extends CommonRestController {
assertNotNull(automationCompositionsFromDb);
assertThat(automationCompositionsFromDb.getAutomationCompositionList()).hasSize(1);
- assertEquals(automationComposition, automationCompositionsFromDb.getAutomationCompositionList().get(0));
+ var acFromDb = automationCompositionsFromDb.getAutomationCompositionList().get(0);
+ automationComposition.setLastMsg(acFromDb.getLastMsg());
+ assertEquals(automationComposition, acFromDb);
}
@Test
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
index 8ed250fba..d5163be14 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
@@ -243,10 +243,15 @@ class SupervisionScannerTest {
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
automationComposition.setDeployState(DeployState.DEPLOYING);
automationComposition.setLockState(LockState.NONE);
+ automationComposition.setPhase(0);
automationComposition.setCompositionId(compositionId);
- for (Map.Entry<UUID, AutomationCompositionElement> entry : automationComposition.getElements().entrySet()) {
+ for (var entry : automationComposition.getElements().entrySet()) {
entry.getValue().setDeployState(DeployState.DEPLOYING);
}
+ // the first element is already completed
+ automationComposition.getElements().entrySet().iterator().next().getValue()
+ .setDeployState(DeployState.DEPLOYED);
+
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.getAcInstancesInTransition()).thenReturn(List.of(automationComposition));
@@ -261,14 +266,22 @@ class SupervisionScannerTest {
acRuntimeParameterGroup);
automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
+ automationComposition.setLastMsg(TimestampHelper.now());
scannerObj2.run();
verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class));
assertEquals(StateChangeResult.TIMEOUT, automationComposition.getStateChangeResult());
+ //already in TIMEOUT
+ clearInvocations(automationCompositionProvider);
+ scannerObj2.run();
+ verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
+
+ clearInvocations(automationCompositionProvider);
for (Map.Entry<UUID, AutomationCompositionElement> entry : automationComposition.getElements().entrySet()) {
entry.getValue().setDeployState(DeployState.DEPLOYED);
}
scannerObj2.run();
+ verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class));
assertEquals(StateChangeResult.NO_ERROR, automationComposition.getStateChangeResult());
}
@@ -277,6 +290,7 @@ class SupervisionScannerTest {
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
automationComposition.setDeployState(DeployState.DEPLOYING);
automationComposition.setLockState(LockState.NONE);
+ automationComposition.setPhase(0);
automationComposition.setCompositionId(compositionId);
for (var element : automationComposition.getElements().values()) {
if ("org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement"
@@ -314,10 +328,15 @@ class SupervisionScannerTest {
var compositionTargetId = UUID.randomUUID();
automationComposition.setCompositionTargetId(compositionTargetId);
automationComposition.setLockState(LockState.LOCKED);
+ automationComposition.setLastMsg(TimestampHelper.now());
+ automationComposition.setPhase(0);
for (var element : automationComposition.getElements().values()) {
element.setDeployState(DeployState.DEPLOYED);
element.setLockState(LockState.LOCKED);
}
+ // first element is not migrated yet
+ automationComposition.getElements().entrySet().iterator().next().getValue()
+ .setDeployState(DeployState.MIGRATING);
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.getAcInstancesInTransition()).thenReturn(List.of(automationComposition));
@@ -331,7 +350,15 @@ class SupervisionScannerTest {
acRuntimeParameterGroup);
supervisionScanner.run();
+ verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
+ assertEquals(DeployState.MIGRATING, automationComposition.getDeployState());
+
+ // first element is migrated
+ automationComposition.getElements().entrySet().iterator().next().getValue()
+ .setDeployState(DeployState.DEPLOYED);
+ supervisionScanner.run();
verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class));
+
assertEquals(DeployState.DEPLOYED, automationComposition.getDeployState());
assertEquals(compositionTargetId, automationComposition.getCompositionId());
}
@@ -342,6 +369,7 @@ class SupervisionScannerTest {
automationComposition.setDeployState(DeployState.DEPLOYED);
automationComposition.setLockState(LockState.UNLOCKING);
automationComposition.setCompositionId(compositionId);
+ automationComposition.setPhase(0);
for (var element : automationComposition.getElements().values()) {
if ("org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement"
.equals(element.getDefinition().getName())) {
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/TimeoutHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/TimeoutHandlerTest.java
deleted file mode 100644
index 21c5b3d2c..000000000
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/TimeoutHandlerTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2023 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.clamp.acm.runtime.supervision;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.jupiter.api.Test;
-
-class TimeoutHandlerTest {
-
- private static final int ID = 1;
-
- @Test
- void testFault() {
- var timeoutHandler = new TimeoutHandler<Integer>();
- timeoutHandler.setTimeout(ID);
- assertThat(timeoutHandler.isTimeout(ID)).isTrue();
- timeoutHandler.clear(ID);
- assertThat(timeoutHandler.isTimeout(ID)).isFalse();
- }
-
- @Test
- void testDuration() {
- var timeoutHandler = new TimeoutHandler<Integer>() {
- long epochMilli = 0;
-
- @Override
- protected long getEpochMilli() {
- return epochMilli;
- }
- };
- timeoutHandler.epochMilli = 100;
- var result = timeoutHandler.getDuration(ID);
- assertThat(result).isZero();
-
- timeoutHandler.epochMilli += 100;
- result = timeoutHandler.getDuration(ID);
- assertThat(result).isEqualTo(100);
-
- timeoutHandler.epochMilli += 100;
- result = timeoutHandler.getDuration(ID);
- assertThat(result).isEqualTo(200);
-
- timeoutHandler.epochMilli += 100;
- timeoutHandler.clear(ID);
- result = timeoutHandler.getDuration(ID);
- assertThat(result).isZero();
- }
-}