X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fpolicyagent%2FConcurrencyTestRunnable.java;h=2d57e52af9c1530f3a6ff091f4e41132edca794f;hb=ba50f8809edc7d49a74021e25b4094f4c3174b26;hp=7f80a8e8a3f8c9a12b05b6b9e5992b6d2d4318de;hpb=80dbdcb047bc11ed20f4ff2fad44639ea4d67bc5;p=nonrtric.git 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 7f80a8e8..2d57e52a 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/ConcurrencyTestRunnable.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/ConcurrencyTestRunnable.java @@ -22,6 +22,7 @@ package org.oransc.policyagent; import java.util.concurrent.atomic.AtomicInteger; +import org.oransc.policyagent.clients.AsyncRestClient; import org.oransc.policyagent.repository.ImmutablePolicy; import org.oransc.policyagent.repository.Policy; import org.oransc.policyagent.repository.PolicyType; @@ -33,10 +34,7 @@ import org.oransc.policyagent.utils.MockA1Client; import org.oransc.policyagent.utils.MockA1ClientFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.web.client.RestTemplate; +import org.springframework.http.ResponseEntity; /** * Invoke operations over the NBI and start synchronizations in a separate @@ -44,8 +42,7 @@ import org.springframework.web.client.RestTemplate; */ class ConcurrencyTestRunnable implements Runnable { private static final Logger logger = LoggerFactory.getLogger(ConcurrencyTestRunnable.class); - private final RestTemplate restTemplate = new RestTemplate(); - private final String baseUrl; + private final AsyncRestClient webClient; static AtomicInteger nextCount = new AtomicInteger(0); private final int count; private final RicSupervision supervision; @@ -55,19 +52,34 @@ class ConcurrencyTestRunnable implements Runnable { ConcurrencyTestRunnable(String baseUrl, RicSupervision supervision, MockA1ClientFactory a1ClientFactory, Rics rics, PolicyTypes types) { - this.baseUrl = baseUrl; this.count = nextCount.incrementAndGet(); this.supervision = supervision; this.a1ClientFactory = a1ClientFactory; this.rics = rics; this.types = types; + this.webClient = new AsyncRestClient(baseUrl); + } + + private void printStatusInfo() { + try { + String url = "/actuator/metrics/jvm.threads.live"; + ResponseEntity result = webClient.getForEntity(url).block(); + System.out.println(Thread.currentThread() + result.getBody()); + + url = "/rics"; + result = webClient.getForEntity(url).block(); + System.out.println(Thread.currentThread() + result.getBody()); + + } catch (Exception e) { + logger.error(Thread.currentThread() + "Concurrency test printStatusInfo exception " + e.toString()); + } } @Override public void run() { try { - for (int i = 0; i < 100; ++i) { - if (i % 10 == 0) { + for (int i = 0; i < 500; ++i) { + if (i % 100 == 0) { createInconsistency(); this.supervision.checkAllRics(); } @@ -81,6 +93,7 @@ class ConcurrencyTestRunnable implements Runnable { } } catch (Exception e) { logger.error("Concurrency test exception " + e.toString()); + printStatusInfo(); } } @@ -94,6 +107,7 @@ class ConcurrencyTestRunnable implements Runnable { .ric(ric) // .ownerServiceName("") // .lastModified("") // + .isTransient(false) // .build(); } @@ -105,29 +119,22 @@ class ConcurrencyTestRunnable implements Runnable { } private void listPolicies() { - String uri = baseUrl + "/policies"; - restTemplate.getForObject(uri, String.class); + String uri = "/policies"; + webClient.getForEntity(uri).block(); } private void listTypes() { - String uri = baseUrl + "/policy_types"; - restTemplate.getForObject(uri, String.class); + String uri = "/policy_types"; + webClient.getForEntity(uri).block(); } private void putPolicy(String name) { - String putUrl = baseUrl + "/policy?type=type1&id=" + name + "&ric=ric&service=service1"; - restTemplate.put(putUrl, createJsonHttpEntity("{}")); + String putUrl = "/policy?type=type1&id=" + name + "&ric=ric&service=service1"; + webClient.putForEntity(putUrl, "{}").block(); } private void deletePolicy(String name) { - String deleteUrl = baseUrl + "/policy?id=" + name; - restTemplate.delete(deleteUrl); + String deleteUrl = "/policy?id=" + name; + webClient.delete(deleteUrl).block(); } - - private static HttpEntity createJsonHttpEntity(String content) { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - return new HttpEntity(content, headers); - } - }