Fixed broken unittest in policy agent 10/4710/1
authorPatrikBuhr <patrik.buhr@est.tech>
Thu, 17 Sep 2020 07:36:04 +0000 (09:36 +0200)
committerPatrikBuhr <patrik.buhr@est.tech>
Thu, 17 Sep 2020 07:38:06 +0000 (09:38 +0200)
The concurrency testwas broken and tested nothing.
The code formatting plugin had stopped working.
Version is updated and works now.

Change-Id: I3b6d1d7ed66f863e2240906d7bb99da8f7b1324d
Issue-ID: NONRTRIC-195
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
policy-agent/pom.xml
policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientFactory.java
policy-agent/src/main/java/org/oransc/policyagent/dmaap/DmaapMessageConsumer.java
policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java
policy-agent/src/test/java/org/oransc/policyagent/ConcurrencyTestRunnable.java
policy-agent/src/test/java/org/oransc/policyagent/aspect/LogAspectTest.java

index e1884fc..56393fc 100644 (file)
@@ -54,7 +54,7 @@
         <json.version>20190722</json.version>
         <commons-net.version>3.6</commons-net.version>
         <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
-        <formatter-maven-plugin.version>2.8.1</formatter-maven-plugin.version>
+        <formatter-maven-plugin.version>2.12.2</formatter-maven-plugin.version>
         <spotless-maven-plugin.version>1.18.0</spotless-maven-plugin.version>
         <docker-maven-plugin>0.30.0</docker-maven-plugin>
         <version.dmaap>1.1.11</version.dmaap>
index 113abcb..0860f77 100644 (file)
@@ -20,6 +20,8 @@
 
 package org.oransc.policyagent.clients;
 
+import lombok.Getter;
+
 import org.oransc.policyagent.clients.A1Client.A1ProtocolType;
 import org.oransc.policyagent.configuration.ApplicationConfig;
 import org.oransc.policyagent.configuration.ControllerConfig;
@@ -29,7 +31,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import reactor.core.publisher.Mono;
-import lombok.Getter;
+
 /**
  * Factory for A1 clients that supports four different protocol versions of the
  * A1 api.
index 9d43001..0ee6213 100644 (file)
@@ -149,7 +149,8 @@ public class DmaapMessageConsumer {
     protected DmaapMessageHandler getDmaapMessageHandler() {
         if (this.dmaapMessageHandler == null) {
             String agentBaseUrl = "http://localhost:" + this.localServerHttpPort;
-            AsyncRestClient agentClient = new AsyncRestClient(agentBaseUrl, this.applicationConfig.getWebClientConfig());
+            AsyncRestClient agentClient =
+                new AsyncRestClient(agentBaseUrl, this.applicationConfig.getWebClientConfig());
             AsyncRestClient producer = new AsyncRestClient(this.applicationConfig.getDmaapProducerTopicUrl(),
                 this.applicationConfig.getWebClientConfig());
             this.dmaapMessageHandler = new DmaapMessageHandler(producer, agentClient);
index 66c8742..4de5c71 100644 (file)
@@ -359,7 +359,8 @@ class ApplicationTest {
 
     @Test
     /**
-     * Test that HttpStatus and body from failing REST call to A1 is passed on to the caller.
+     * Test that HttpStatus and body from failing REST call to A1 is passed on to
+     * the caller.
      *
      * @throws ServiceException
      */
@@ -720,17 +721,23 @@ class ApplicationTest {
         addRic("ric");
         addPolicyType("type1", "ric");
         addPolicyType("type2", "ric");
+        List<ConcurrencyTestRunnable> tests = new ArrayList<>();
 
         for (int i = 0; i < 10; ++i) {
-            Thread thread =
-                new Thread(new ConcurrencyTestRunnable(baseUrl(), supervision, a1ClientFactory, rics, policyTypes),
-                    "TestThread_" + i);
+            ConcurrencyTestRunnable test =
+                new ConcurrencyTestRunnable(restClient(), supervision, a1ClientFactory, rics, policyTypes);
+            Thread thread = new Thread(test, "TestThread_" + i);
             thread.start();
             threads.add(thread);
+            tests.add(test);
         }
         for (Thread t : threads) {
             t.join();
         }
+        for (ConcurrencyTestRunnable test : tests) {
+            assertThat(test.isFailed()).isFalse();
+        }
+
         assertThat(policies.size()).isZero();
         logger.info("Concurrency test took " + Duration.between(startTime, Instant.now()));
     }
index 2d57e52..0ca5534 100644 (file)
@@ -49,15 +49,16 @@ class ConcurrencyTestRunnable implements Runnable {
     private final MockA1ClientFactory a1ClientFactory;
     private final Rics rics;
     private final PolicyTypes types;
+    private boolean failed = false;
 
-    ConcurrencyTestRunnable(String baseUrl, RicSupervision supervision, MockA1ClientFactory a1ClientFactory, Rics rics,
-        PolicyTypes types) {
+    ConcurrencyTestRunnable(AsyncRestClient webClient, RicSupervision supervision, MockA1ClientFactory a1ClientFactory,
+        Rics rics, PolicyTypes types) {
         this.count = nextCount.incrementAndGet();
         this.supervision = supervision;
         this.a1ClientFactory = a1ClientFactory;
         this.rics = rics;
         this.types = types;
-        this.webClient = new AsyncRestClient(baseUrl);
+        this.webClient = webClient;
     }
 
     private void printStatusInfo() {
@@ -94,9 +95,14 @@ class ConcurrencyTestRunnable implements Runnable {
         } catch (Exception e) {
             logger.error("Concurrency test exception " + e.toString());
             printStatusInfo();
+            failed = true;
         }
     }
 
+    public boolean isFailed() {
+        return this.failed;
+    }
+
     private Policy createPolicyObject(String id) {
         Ric ric = this.rics.get("ric");
         PolicyType type = this.types.get("type1");
index c4f3f99..ae8ed2c 100644 (file)
@@ -18,7 +18,6 @@
  * ========================LICENSE_END===================================
  */
 
-
 package org.oransc.policyagent.aspect;
 
 import static ch.qos.logback.classic.Level.TRACE;