aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-intermediary/src/test/java
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-09-08 09:51:52 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2023-09-29 09:35:26 +0000
commit573057bf622d0a671d9327f32ad096f58bc31cc1 (patch)
tree238a9cd52edabe491a0f744370d87494721da15f /participant/participant-intermediary/src/test/java
parentde2047d46e61113e870b2ebb3573e87e40165a3a (diff)
Add migration support in ACM intermediary
Issue-ID: POLICY-4824 Change-Id: I4e9ef54be63a86b01c6e6fad4c78baa72e161eed Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-intermediary/src/test/java')
-rwxr-xr-xparticipant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java3
-rwxr-xr-xparticipant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java41
-rwxr-xr-xparticipant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionOutHandlerTest.java29
-rwxr-xr-xparticipant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java57
-rwxr-xr-xparticipant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandlerTest.java5
5 files changed, 102 insertions, 33 deletions
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java
index e959d136a..de948209f 100755
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java
@@ -81,6 +81,9 @@ class ParticipantCommTest {
var participantRestartListener = new ParticipantRestartListener(participantHandler);
assertEquals(ParticipantMessageType.PARTICIPANT_RESTART.name(),
participantRestartListener.getType());
+
+ var acMigrationListener = new AutomationCompositionMigrationListener(participantHandler);
+ assertEquals(ParticipantMessageType.AUTOMATION_COMPOSITION_MIGRATION.name(), acMigrationListener.getType());
}
@Test
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
index cb7e560ba..5f7d71e6f 100755
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
@@ -23,6 +23,7 @@ package org.onap.policy.clamp.acm.participant.intermediary.handler;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -43,6 +44,7 @@ import org.onap.policy.clamp.models.acm.concepts.LockState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionMigration;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.PropertiesUpdate;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
@@ -90,7 +92,7 @@ class AutomationCompositionHandlerTest {
var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener);
ach.handleAutomationCompositionStateChange(automationCompositionStateChange);
verify(listener, times(automationComposition.getElements().size())).undeploy(any(), any(), any());
- for (var element: automationComposition.getElements().values()) {
+ for (var element : automationComposition.getElements().values()) {
assertEquals(DeployState.UNDEPLOYING, element.getDeployState());
}
}
@@ -110,7 +112,7 @@ class AutomationCompositionHandlerTest {
var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener);
ach.handleAutomationCompositionStateChange(automationCompositionStateChange);
verify(listener, times(automationComposition.getElements().size())).lock(any(), any(), any());
- for (var element: automationComposition.getElements().values()) {
+ for (var element : automationComposition.getElements().values()) {
assertEquals(LockState.LOCKING, element.getLockState());
}
}
@@ -130,7 +132,7 @@ class AutomationCompositionHandlerTest {
var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener);
ach.handleAutomationCompositionStateChange(automationCompositionStateChange);
verify(listener, times(automationComposition.getElements().size())).unlock(any(), any(), any());
- for (var element: automationComposition.getElements().values()) {
+ for (var element : automationComposition.getElements().values()) {
assertEquals(LockState.UNLOCKING, element.getLockState());
}
}
@@ -150,7 +152,7 @@ class AutomationCompositionHandlerTest {
var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener);
ach.handleAutomationCompositionStateChange(automationCompositionStateChange);
verify(listener, times(automationComposition.getElements().size())).delete(any(), any(), any());
- for (var element: automationComposition.getElements().values()) {
+ for (var element : automationComposition.getElements().values()) {
assertEquals(DeployState.DELETING, element.getDeployState());
}
}
@@ -241,8 +243,7 @@ class AutomationCompositionHandlerTest {
void restartedTest() {
var listener = mock(ThreadHandler.class);
var cacheProvider = mock(CacheProvider.class);
- var ach = new AutomationCompositionHandler(cacheProvider, mock(ParticipantMessagePublisher.class),
- listener);
+ var ach = new AutomationCompositionHandler(cacheProvider, mock(ParticipantMessagePublisher.class), listener);
var compositionId = UUID.randomUUID();
var messageId = UUID.randomUUID();
@@ -254,4 +255,32 @@ class AutomationCompositionHandlerTest {
verify(cacheProvider).initializeAutomationComposition(compositionId, participantRestartAc);
verify(listener).restarted(messageId, compositionId, list, state, automationCompositionList);
}
+
+ @Test
+ void handleAutomationCompositionMigrationTest() {
+ var listener = mock(ThreadHandler.class);
+ var cacheProvider = mock(CacheProvider.class);
+ var ach = new AutomationCompositionHandler(cacheProvider, mock(ParticipantMessagePublisher.class), listener);
+ var migrationMsg = new AutomationCompositionMigration();
+ assertDoesNotThrow(() -> ach.handleAutomationCompositionMigration(migrationMsg));
+ var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next();
+ migrationMsg.setCompositionTargetId(UUID.randomUUID());
+ migrationMsg.setAutomationCompositionId(automationComposition.getInstanceId());
+ assertDoesNotThrow(() -> ach.handleAutomationCompositionMigration(migrationMsg));
+ when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ var participantDeploy = new ParticipantDeploy();
+ participantDeploy.setParticipantId(CommonTestData.getParticipantId());
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ migrationMsg.getParticipantUpdatesList().add(participantDeploy);
+ for (var element : automationComposition.getElements().values()) {
+ var acElementDeploy = new AcElementDeploy();
+ acElementDeploy.setProperties(Map.of());
+ acElementDeploy.setId(element.getId());
+ participantDeploy.getAcElementList().add(acElementDeploy);
+ }
+
+ ach.handleAutomationCompositionMigration(migrationMsg);
+ verify(listener, times(automationComposition.getElements().size())).migrate(any(), any(), any(), any(), any());
+ }
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionOutHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionOutHandlerTest.java
index c45be4e8b..cbd236efe 100755
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionOutHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionOutHandlerTest.java
@@ -22,6 +22,7 @@ package org.onap.policy.clamp.acm.participant.intermediary.handler;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -174,8 +175,7 @@ class AutomationCompositionOutHandlerTest {
var publisher = mock(ParticipantMessagePublisher.class);
var acOutHandler = new AutomationCompositionOutHandler(publisher, cacheProvider);
var compositionId = UUID.randomUUID();
- acOutHandler.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR,
- "Primed");
+ acOutHandler.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed");
verify(publisher).sendParticipantPrimeAck(any(ParticipantPrimeAck.class));
verify(cacheProvider, times(0)).removeElementDefinition(compositionId);
}
@@ -217,4 +217,29 @@ class AutomationCompositionOutHandlerTest {
acOutHandler.sendAcDefinitionInfo(compositionId, elementId, Map.of());
verify(publisher).sendHeartbeat(any(ParticipantStatus.class));
}
+
+ @Test
+ void updateMigrationStatusTest() {
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getParticipantId()).thenReturn(UUID.randomUUID());
+ var publisher = mock(ParticipantMessagePublisher.class);
+ var acOutHandler = new AutomationCompositionOutHandler(publisher, cacheProvider);
+
+ var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next();
+ when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+
+ var compositionTarget = UUID.randomUUID();
+ automationComposition.setCompositionTargetId(compositionTarget);
+ automationComposition.setDeployState(DeployState.MIGRATING);
+ when(cacheProvider.getAcElementsDefinitions()).thenReturn(Map.of(compositionTarget, Map.of()));
+
+ for (var element : automationComposition.getElements().values()) {
+ acOutHandler.updateAutomationCompositionElementState(automationComposition.getInstanceId(), element.getId(),
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "");
+ }
+ verify(publisher, times(automationComposition.getElements().size()))
+ .sendAutomationCompositionAck(any(AutomationCompositionDeployAck.class));
+ assertEquals(compositionTarget, automationComposition.getCompositionId());
+ }
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java
index c558e6668..7a0b048ff 100755
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java
@@ -37,6 +37,7 @@ import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionMigration;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantAckMessage;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
@@ -57,8 +58,8 @@ class ParticipantHandlerTest {
void handleParticipantStatusReqTest() {
var publisher = mock(ParticipantMessagePublisher.class);
var cacheProvider = mock(CacheProvider.class);
- var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
- mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
+ var participantHandler =
+ new ParticipantHandler(mock(AutomationCompositionHandler.class), publisher, cacheProvider);
participantHandler.handleParticipantStatusReq(new ParticipantStatusReq());
verify(publisher).sendParticipantStatus(any(ParticipantStatus.class));
}
@@ -66,8 +67,8 @@ class ParticipantHandlerTest {
@Test
void handleAutomationCompositionDeployTest() {
var acHandler = mock(AutomationCompositionHandler.class);
- var participantHandler = new ParticipantHandler(acHandler, mock(AutomationCompositionOutHandler.class),
- mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
+ var participantHandler =
+ new ParticipantHandler(acHandler, mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
var automationCompositionDeploy = new AutomationCompositionDeploy();
participantHandler.handleAutomationCompositionDeploy(automationCompositionDeploy);
verify(acHandler).handleAutomationCompositionDeploy(automationCompositionDeploy);
@@ -76,18 +77,28 @@ class ParticipantHandlerTest {
@Test
void handleAutomationCompositionStateChangeTest() {
var acHandler = mock(AutomationCompositionHandler.class);
- var participantHandler = new ParticipantHandler(acHandler, mock(AutomationCompositionOutHandler.class),
- mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
+ var participantHandler =
+ new ParticipantHandler(acHandler, mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
var acStateChange = new AutomationCompositionStateChange();
participantHandler.handleAutomationCompositionStateChange(acStateChange);
verify(acHandler).handleAutomationCompositionStateChange(acStateChange);
}
@Test
+ void handleAutomationCompositionMigrationTest() {
+ var acHandler = mock(AutomationCompositionHandler.class);
+ var participantHandler =
+ new ParticipantHandler(acHandler, mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
+ var migrationMsg = new AutomationCompositionMigration();
+ participantHandler.handleAutomationCompositionMigration(migrationMsg);
+ verify(acHandler).handleAutomationCompositionMigration(migrationMsg);
+ }
+
+ @Test
void handleAcPropertyUpdateTest() {
var acHandler = mock(AutomationCompositionHandler.class);
- var participantHandler = new ParticipantHandler(acHandler, mock(AutomationCompositionOutHandler.class),
- mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
+ var participantHandler =
+ new ParticipantHandler(acHandler, mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
var propertyUpdateMsg = new PropertiesUpdate();
participantHandler.handleAcPropertyUpdate(propertyUpdateMsg);
verify(acHandler).handleAcPropertyUpdate(propertyUpdateMsg);
@@ -98,7 +109,7 @@ class ParticipantHandlerTest {
var cacheProvider = mock(CacheProvider.class);
when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
- mock(AutomationCompositionOutHandler.class), mock(ParticipantMessagePublisher.class), cacheProvider);
+ mock(ParticipantMessagePublisher.class), cacheProvider);
var participantAckMsg = new ParticipantAckMessage(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY);
assertTrue(participantHandler.appliesTo(participantAckMsg));
@@ -116,8 +127,8 @@ class ParticipantHandlerTest {
var cacheProvider = mock(CacheProvider.class);
when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
when(cacheProvider.getSupportedAcElementTypes()).thenReturn(List.of(new ParticipantSupportedElementType()));
- var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
- mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
+ var participantHandler =
+ new ParticipantHandler(mock(AutomationCompositionHandler.class), publisher, cacheProvider);
participantHandler.sendParticipantRegister();
verify(publisher).sendParticipantRegister(any(ParticipantRegister.class));
@@ -128,8 +139,8 @@ class ParticipantHandlerTest {
var publisher = mock(ParticipantMessagePublisher.class);
var cacheProvider = mock(CacheProvider.class);
when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
- var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
- mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
+ var participantHandler =
+ new ParticipantHandler(mock(AutomationCompositionHandler.class), publisher, cacheProvider);
participantHandler.handleParticipantRegisterAck(new ParticipantRegisterAck());
verify(publisher).sendParticipantStatus(any(ParticipantStatus.class));
@@ -140,8 +151,8 @@ class ParticipantHandlerTest {
var publisher = mock(ParticipantMessagePublisher.class);
var cacheProvider = mock(CacheProvider.class);
when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
- var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
- mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
+ var participantHandler =
+ new ParticipantHandler(mock(AutomationCompositionHandler.class), publisher, cacheProvider);
participantHandler.sendParticipantDeregister();
verify(publisher).sendParticipantDeregister(any(ParticipantDeregister.class));
@@ -150,8 +161,7 @@ class ParticipantHandlerTest {
@Test
void handleParticipantDeregisterAckTest() {
var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
- mock(AutomationCompositionOutHandler.class), mock(ParticipantMessagePublisher.class),
- mock(CacheProvider.class));
+ mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
var participantDeregisterAck = new ParticipantDeregisterAck();
assertDoesNotThrow(() -> participantHandler.handleParticipantDeregisterAck(participantDeregisterAck));
}
@@ -168,8 +178,7 @@ class ParticipantHandlerTest {
var publisher = mock(ParticipantMessagePublisher.class);
var acHandler = mock(AutomationCompositionHandler.class);
- var participantHandler = new ParticipantHandler(acHandler, mock(AutomationCompositionOutHandler.class),
- publisher, cacheProvider);
+ var participantHandler = new ParticipantHandler(acHandler, publisher, cacheProvider);
participantHandler.handleParticipantPrime(participantPrime);
verify(cacheProvider).addElementDefinition(any(), any());
@@ -186,8 +195,7 @@ class ParticipantHandlerTest {
var cacheProvider = mock(CacheProvider.class);
var publisher = mock(ParticipantMessagePublisher.class);
var acHandler = mock(AutomationCompositionHandler.class);
- var participantHandler = new ParticipantHandler(acHandler, mock(AutomationCompositionOutHandler.class),
- publisher, cacheProvider);
+ var participantHandler = new ParticipantHandler(acHandler, publisher, cacheProvider);
participantHandler.handleParticipantRestart(participantRestartMsg);
verify(cacheProvider).addElementDefinition(any(), any());
@@ -200,8 +208,7 @@ class ParticipantHandlerTest {
when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
var publisher = mock(ParticipantMessagePublisher.class);
var acHandler = mock(AutomationCompositionHandler.class);
- var participantHandler = new ParticipantHandler(acHandler, mock(AutomationCompositionOutHandler.class),
- publisher, cacheProvider);
+ var participantHandler = new ParticipantHandler(acHandler, publisher, cacheProvider);
var participantPrime = new ParticipantPrime();
var compositionId = UUID.randomUUID();
participantPrime.setCompositionId(compositionId);
@@ -218,8 +225,8 @@ class ParticipantHandlerTest {
when(cacheProvider.getAutomationCompositions()).thenReturn(CommonTestData.getTestAutomationCompositionMap());
var publisher = mock(ParticipantMessagePublisher.class);
when(publisher.isActive()).thenReturn(true);
- var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
- mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
+ var participantHandler =
+ new ParticipantHandler(mock(AutomationCompositionHandler.class), publisher, cacheProvider);
participantHandler.sendHeartbeat();
verify(publisher).sendHeartbeat(any(ParticipantStatus.class));
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandlerTest.java
index 16334f545..2ac3c8df2 100755
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandlerTest.java
@@ -75,6 +75,11 @@ class ThreadHandlerTest {
verify(listener, timeout(TIMEOUT)).update(instanceId, element, properties);
clearInvocations(listener);
+ var compositionTargetId = UUID.randomUUID();
+ threadHandler.migrate(messageId, instanceId, element, compositionTargetId, properties);
+ verify(listener, timeout(TIMEOUT)).migrate(instanceId, element, compositionTargetId, properties);
+
+ clearInvocations(listener);
threadHandler.lock(messageId, instanceId, elementId);
verify(listener, timeout(TIMEOUT)).lock(instanceId, elementId);