From c75f4b117df1c9dd9ff5fb0e370b5fc52130407f Mon Sep 17 00:00:00 2001 From: PatrikBuhr Date: Thu, 17 Sep 2020 09:36:04 +0200 Subject: [PATCH] Fixed broken unittest in policy agent 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 --- policy-agent/pom.xml | 2 +- .../org/oransc/policyagent/clients/A1ClientFactory.java | 4 +++- .../oransc/policyagent/dmaap/DmaapMessageConsumer.java | 3 ++- .../test/java/org/oransc/policyagent/ApplicationTest.java | 15 +++++++++++---- .../org/oransc/policyagent/ConcurrencyTestRunnable.java | 12 +++++++++--- .../java/org/oransc/policyagent/aspect/LogAspectTest.java | 1 - 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/policy-agent/pom.xml b/policy-agent/pom.xml index e1884fc0..56393fc7 100644 --- a/policy-agent/pom.xml +++ b/policy-agent/pom.xml @@ -54,7 +54,7 @@ 20190722 3.6 3.8.0 - 2.8.1 + 2.12.2 1.18.0 0.30.0 1.1.11 diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientFactory.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientFactory.java index 113abcb6..0860f778 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientFactory.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientFactory.java @@ -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. diff --git a/policy-agent/src/main/java/org/oransc/policyagent/dmaap/DmaapMessageConsumer.java b/policy-agent/src/main/java/org/oransc/policyagent/dmaap/DmaapMessageConsumer.java index 9d43001f..0ee62132 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/dmaap/DmaapMessageConsumer.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/dmaap/DmaapMessageConsumer.java @@ -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); diff --git a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java index 66c87421..4de5c71f 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java @@ -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 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())); } diff --git a/policy-agent/src/test/java/org/oransc/policyagent/ConcurrencyTestRunnable.java b/policy-agent/src/test/java/org/oransc/policyagent/ConcurrencyTestRunnable.java index 2d57e52a..0ca55340 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/ConcurrencyTestRunnable.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/ConcurrencyTestRunnable.java @@ -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"); diff --git a/policy-agent/src/test/java/org/oransc/policyagent/aspect/LogAspectTest.java b/policy-agent/src/test/java/org/oransc/policyagent/aspect/LogAspectTest.java index c4f3f997..ae8ed2cb 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/aspect/LogAspectTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/aspect/LogAspectTest.java @@ -18,7 +18,6 @@ * ========================LICENSE_END=================================== */ - package org.oransc.policyagent.aspect; import static ch.qos.logback.classic.Level.TRACE; -- 2.16.6