summaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/test
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2022-06-10 12:43:06 +0200
committerPatrikBuhr <patrik.buhr@est.tech>2022-06-10 13:11:04 +0200
commit87b1ff527a8110f592b4b5e2fcf13b8cd43b6d1f (patch)
treef375243d253097b84250550b13ee7558936087e9 /a1-policy-management/src/test
parent779509036cdadb5735d336ed93a3bfac5a0be72a (diff)
NONRTRIC PMS, Sporadic instability
Some further simplifications and added test. Issue-ID: CCSDK-3683 Signed-off-by: PatrikBuhr <patrik.buhr@est.tech> Change-Id: I1ec98017d63047a0036db5ea12f770db00b1152b
Diffstat (limited to 'a1-policy-management/src/test')
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java10
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java1
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java28
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1Client.java24
4 files changed, 39 insertions, 24 deletions
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java
index dcb03a5a..c689097d 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java
@@ -920,11 +920,16 @@ class ApplicationTest {
final Instant startTime = Instant.now();
List<Thread> threads = new ArrayList<>();
List<ConcurrencyTestRunnable> tests = new ArrayList<>();
- a1ClientFactory.setResponseDelay(Duration.ofMillis(1));
+ a1ClientFactory.setResponseDelay(Duration.ofMillis(2));
addRic("ric");
addPolicyType("type1", "ric");
addPolicyType("type2", "ric");
+ final String NON_RESPONDING_RIC = "NonRespondingRic";
+ Ric nonRespondingRic = addRic(NON_RESPONDING_RIC);
+ MockA1Client a1Client = a1ClientFactory.getOrCreateA1Client(NON_RESPONDING_RIC);
+ a1Client.setErrorInject("errorInject");
+
for (int i = 0; i < 10; ++i) {
AsyncRestClient restClient = restClient();
ConcurrencyTestRunnable test =
@@ -942,6 +947,9 @@ class ApplicationTest {
}
assertThat(policies.size()).isZero();
logger.info("Concurrency test took " + Duration.between(startTime, Instant.now()));
+
+ assertThat(nonRespondingRic.getState()).isEqualTo(RicState.UNAVAILABLE);
+ nonRespondingRic.setState(RicState.AVAILABLE);
}
private AsyncRestClient restClient(String baseUrl, boolean useTrustValidation) {
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java
index 203cc3e5..2ecb9c28 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java
@@ -87,6 +87,7 @@ class RefreshConfigTaskTest {
private RefreshConfigTask createTestObject(boolean configFileExists, Rics rics, Policies policies,
boolean stubConfigFileExists) {
SecurityContext secContext = new SecurityContext("");
+
RefreshConfigTask obj =
spy(new RefreshConfigTask(configurationFileMock, appConfig, rics, policies, new Services(appConfig),
new PolicyTypes(appConfig), new A1ClientFactory(appConfig, secContext), secContext));
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java
index 396a4063..b2bf58e4 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java
@@ -24,8 +24,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import java.time.Instant;
@@ -148,7 +148,7 @@ class RicSupervisionTest {
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
- verifyNoMoreInteractions(supervisorUnderTest);
+ verify(synchronizationTaskMock, times(0)).synchronizeRic(RIC_1);
assertThat(RIC_1.getState()).isEqualTo(RicState.AVAILABLE);
}
@@ -161,10 +161,8 @@ class RicSupervisionTest {
doReturn(synchronizationTaskMock).when(supervisorUnderTest).createSynchronizationTask();
doReturn(Mono.just(RIC_1)).when(synchronizationTaskMock).synchronizeRic(any());
supervisorUnderTest.checkAllRics();
- verify(supervisorUnderTest).checkAllRics();
- verify(supervisorUnderTest).createSynchronizationTask();
verify(synchronizationTaskMock).synchronizeRic(RIC_1);
- verifyNoMoreInteractions(supervisorUnderTest);
+
assertThat(RIC_1.getState()).isEqualTo(RicState.UNAVAILABLE);
}
@@ -179,7 +177,7 @@ class RicSupervisionTest {
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
- verifyNoMoreInteractions(supervisorUnderTest);
+ verify(synchronizationTaskMock, times(0)).synchronizeRic(RIC_1);
assertThat(RIC_1.getState()).isEqualTo(RicState.SYNCHRONIZING);
}
@@ -196,7 +194,8 @@ class RicSupervisionTest {
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
- verifyNoMoreInteractions(supervisorUnderTest);
+ verify(synchronizationTaskMock, times(0)).synchronizeRic(RIC_1);
+
assertThat(RIC_1.getState()).isEqualTo(RicState.UNAVAILABLE);
}
@@ -218,9 +217,8 @@ class RicSupervisionTest {
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
- verify(supervisorUnderTest).createSynchronizationTask();
verify(synchronizationTaskMock).synchronizeRic(RIC_1);
- verifyNoMoreInteractions(supervisorUnderTest);
+
assertThat(RIC_1.getState()).isEqualTo(RicState.UNAVAILABLE);
}
@@ -242,11 +240,9 @@ class RicSupervisionTest {
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
- verify(supervisorUnderTest).createSynchronizationTask();
verify(synchronizationTaskMock).synchronizeRic(RIC_1);
- verifyNoMoreInteractions(supervisorUnderTest);
- assertThat(RIC_1.getState()).isEqualTo(RicState.UNAVAILABLE);
+ assertThat(RIC_1.getState()).isEqualTo(RicState.UNAVAILABLE);
}
@Test
@@ -263,7 +259,8 @@ class RicSupervisionTest {
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
- verifyNoMoreInteractions(supervisorUnderTest);
+ verify(synchronizationTaskMock, times(0)).synchronizeRic(RIC_1);
+
assertThat(RIC_1.getState()).isEqualTo(RicState.UNAVAILABLE);
}
@@ -286,9 +283,8 @@ class RicSupervisionTest {
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
- verify(supervisorUnderTest).createSynchronizationTask();
verify(synchronizationTaskMock).synchronizeRic(RIC_1);
- verifyNoMoreInteractions(supervisorUnderTest);
+
assertThat(RIC_1.getState()).isEqualTo(RicState.UNAVAILABLE);
}
@@ -315,9 +311,7 @@ class RicSupervisionTest {
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
- verify(supervisorUnderTest).createSynchronizationTask();
verify(synchronizationTaskMock).synchronizeRic(RIC_1);
- verifyNoMoreInteractions(supervisorUnderTest);
assertThat(RIC_1.getState()).isEqualTo(RicState.UNAVAILABLE);
}
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1Client.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1Client.java
index 2a3b28ef..b76f1e72 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1Client.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1Client.java
@@ -28,6 +28,8 @@ import java.time.Duration;
import java.util.List;
import java.util.Vector;
+import lombok.Setter;
+
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
@@ -44,7 +46,12 @@ import reactor.core.publisher.MonoSink;
public class MockA1Client implements A1Client {
Policies policies;
private final PolicyTypes policyTypes;
- private final Duration asynchDelay;
+
+ @Setter
+ private Duration asynchDelay;
+
+ @Setter
+ private String errorInject;
public MockA1Client(String ricId, ApplicationConfig appConfig, PolicyTypes policyTypes, Duration asynchDelay) {
this.policyTypes = policyTypes;
@@ -117,14 +124,19 @@ public class MockA1Client implements A1Client {
}
private <T> Mono<T> mono(T value) {
- if (this.asynchDelay.isZero()) {
- return Mono.just(value);
- } else {
- return Mono.create(monoSink -> asynchResponse(monoSink, value));
+ Mono<T> res = Mono.just(value);
+ if (!this.asynchDelay.isZero()) {
+ res = Mono.create(monoSink -> asynchResponse(monoSink, value));
}
+
+ if (this.errorInject != null) {
+ res = res.flatMap(x -> monoError(this.errorInject, HttpStatus.BAD_GATEWAY));
+ }
+
+ return res;
}
- public static Mono<String> monoError(String responseBody, HttpStatus status) {
+ public static <T> Mono<T> monoError(String responseBody, HttpStatus status) {
byte[] responseBodyBytes = responseBody.getBytes(StandardCharsets.UTF_8);
WebClientResponseException a1Exception = new WebClientResponseException(status.value(),
status.getReasonPhrase(), null, responseBodyBytes, StandardCharsets.UTF_8, null);