From 552af85d4daa66dff8d4b920db61fe6010eee388 Mon Sep 17 00:00:00 2001 From: Ram Krishna Verma Date: Fri, 19 Jun 2020 17:49:21 -0400 Subject: Parallel execution of Client Health check Issue-ID: POLICY-2390 Signed-off-by: puthuparambil.aditya Change-Id: I42f443c64bcf6652adb9795ee8e71e37d8fa8c71 --- .../TestPolicyComponentsHealthCheckProvider.java | 32 +++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'main/src/test') diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java index 9d2fa63f..bdf4700c 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java @@ -65,6 +65,7 @@ public class TestPolicyComponentsHealthCheckProvider { private static final String CLIENT_1 = "client1"; private static final String PDP_GROUP_DATA_FILE = "rest/pdpGroup.json"; private static final String PAP_GROUP_PARAMS_NAME = "PapGroup"; + private static final String HEALTHY = "healthy"; @Mock private PolicyModelsProvider dao; @@ -135,6 +136,9 @@ public class TestPolicyComponentsHealthCheckProvider { List params = papParameterGroup.getHealthCheckRestClientParameters(); when(clientFactory.build(params.get(0))).thenReturn(client1); when(clientFactory.build(params.get(1))).thenReturn(client2); + + PolicyComponentsHealthCheckProvider.initializeClientHealthCheckExecutorService(papParameterGroup, + clientFactory); } /** @@ -147,56 +151,58 @@ public class TestPolicyComponentsHealthCheckProvider { } else { ParameterService.deregister(PAP_GROUP_PARAMS_NAME); } + PolicyComponentsHealthCheckProvider.cleanup(); } + @Test - public void testFetchPolicyComponentsHealthStatus_allHealthy() throws Exception { - PolicyComponentsHealthCheckProvider provider = new PolicyComponentsHealthCheckProvider(clientFactory); + public void testFetchPolicyComponentsHealthStatus_allHealthy() { + PolicyComponentsHealthCheckProvider provider = new PolicyComponentsHealthCheckProvider(); Pair> ret = provider.fetchPolicyComponentsHealthStatus(); assertEquals(Response.Status.OK, ret.getLeft()); - assertTrue((Boolean) ret.getRight().get("healthy")); + assertTrue((Boolean) ret.getRight().get(HEALTHY)); } @Test - public void testFetchPolicyComponentsHealthStatus_unhealthyClient() throws Exception { + public void testFetchPolicyComponentsHealthStatus_unhealthyClient() { when(response1.getStatus()).thenReturn(HttpURLConnection.HTTP_INTERNAL_ERROR); when(response1.readEntity(HealthCheckReport.class)) - .thenReturn(createReport(HttpURLConnection.HTTP_INTERNAL_ERROR, false)); + .thenReturn(createReport(HttpURLConnection.HTTP_INTERNAL_ERROR, false)); Map result = callFetchPolicyComponentsHealthStatus(); - assertFalse((Boolean) result.get("healthy")); + assertFalse((Boolean) result.get(HEALTHY)); HealthCheckReport report = (HealthCheckReport) result.get(CLIENT_1); assertFalse(report.isHealthy()); when(response1.getStatus()).thenReturn(HttpURLConnection.HTTP_OK); when(response1.readEntity(HealthCheckReport.class)).thenReturn(createReport(HttpURLConnection.HTTP_OK, false)); Map result2 = callFetchPolicyComponentsHealthStatus(); - assertFalse((Boolean) result2.get("healthy")); + assertFalse((Boolean) result2.get(HEALTHY)); HealthCheckReport report2 = (HealthCheckReport) result.get(CLIENT_1); assertFalse(report2.isHealthy()); } @SuppressWarnings("unchecked") @Test - public void testFetchPolicyComponentsHealthStatus_unhealthyPdps() throws Exception { + public void testFetchPolicyComponentsHealthStatus_unhealthyPdps() { // Get a PDP and set it unhealthy groups.get(0).getPdpSubgroups().get(0).getPdpInstances().get(0).setHealthy(PdpHealthStatus.NOT_HEALTHY); Map result = callFetchPolicyComponentsHealthStatus(); Map> pdpListWithType = (Map>) result.get(PapConstants.POLICY_PDPS); assertEquals(2, pdpListWithType.size()); - assertFalse((Boolean) result.get("healthy")); + assertFalse((Boolean) result.get(HEALTHY)); } @Test - public void testFetchPolicyComponentsHealthStatus_unhealthyPap() throws Exception { + public void testFetchPolicyComponentsHealthStatus_unhealthyPap() { when(papActivator.isAlive()).thenReturn(false); Map result = callFetchPolicyComponentsHealthStatus(); - assertFalse((Boolean) result.get("healthy")); + assertFalse((Boolean) result.get(HEALTHY)); HealthCheckReport report = (HealthCheckReport) result.get(PapConstants.POLICY_PAP); assertFalse(report.isHealthy()); } - private Map callFetchPolicyComponentsHealthStatus() throws Exception { - PolicyComponentsHealthCheckProvider provider = new PolicyComponentsHealthCheckProvider(clientFactory); + private Map callFetchPolicyComponentsHealthStatus() { + PolicyComponentsHealthCheckProvider provider = new PolicyComponentsHealthCheckProvider(); return provider.fetchPolicyComponentsHealthStatus().getRight(); } -- cgit 1.2.3-korg