diff --git a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/monitor/utils/WireMonitor.java b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/monitor/utils/WireMonitor.java index c857f93362..2dfc8dcb8c 100644 --- a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/monitor/utils/WireMonitor.java +++ b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/monitor/utils/WireMonitor.java @@ -37,18 +37,13 @@ class WireMonitor extends Thread { public void run() { - OutputStream out = null; - InputStream in = null; - - try { + try (ServerSocket providerSocket = new ServerSocket(port, 10); + Socket connection = providerSocket.accept(); + InputStream in = connection.getInputStream(); + OutputStream out = connection.getOutputStream()) { // creating a server socket - providerSocket = new ServerSocket(port, 10); - log.info("Waiting for connection"); - connection = providerSocket.accept(); - log.info("Connection received from " + - connection.getInetAddress().getHostName()); - in = connection.getInputStream(); + log.info("Connection received from " + connection.getInetAddress().getHostName()); int ch; StringBuilder buffer = new StringBuilder(); StringBuffer headerBuffer = new StringBuffer(); @@ -75,7 +70,8 @@ public void run() { break; } // In this case no need of reading more than timeout value - if ((System.currentTimeMillis() > (time + trigger.READ_TIME_OUT)) || buffer.toString().contains("")) { + if ((System.currentTimeMillis() > (time + trigger.READ_TIME_OUT)) || buffer.toString() + .contains("")) { break; } } @@ -84,37 +80,13 @@ public void run() { trigger.response = headerBuffer.toString() + buffer.toString(); trigger.setFinished(true); - out = connection.getOutputStream(); + out.write(("HTTP/1.1 202 Accepted" + "\r\n\r\n").getBytes(Charset.defaultCharset())); out.flush(); - - - } catch (IOException ioException) { //Throw run exception - IllegalStateException - throw new IllegalStateException("wire monitor error occurred", ioException); - - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - log.warn("Stream close exception", e); - } - } - - if (in != null) { - try { - in.close(); - } catch (IOException e) { - log.warn("Stream close exception", e); - } - } - try { - connection.close(); - providerSocket.close(); - } catch (IOException e) { - log.warn("Error closing provide socket or connection"); - } - } + } catch (IOException ioException) { + throw new IllegalStateException("Wire monitor error occurred", ioException); + } catch (Exception e) { + log.warn("Error occurred", e); } public WireMonitor(int listenPort, WireMonitorServer trigger) { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/crossSubscription/CrossTenantSubscriptionTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/crossSubscription/CrossTenantSubscriptionTestCase.java index 9501d506ee..6aa2b03f87 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/crossSubscription/CrossTenantSubscriptionTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/crossSubscription/CrossTenantSubscriptionTestCase.java @@ -358,18 +358,26 @@ public void testVisibilityOfAPIFromOtherDomain() throws ApiException { } @Test(groups = {"wso2.am"}, description = "Check Visibility of API from cross Tenant") - public void testVisibilityOfAPIFromOtherDomain2() throws ApiException { + public void testVisibilityOfAPIFromOtherDomain2() throws ApiException, InterruptedException { - APIListDTO allAPIs = apiStoreRestClientTenant2.getAllAPIs(tenant1Name); - Assert.assertNotNull(allAPIs); - assert allAPIs.getCount() != null; - Assert.assertEquals(allAPIs.getCount().intValue(), 1); boolean found = false; - assert allAPIs.getList() != null; - for (APIInfoDTO apiInfoDTO : allAPIs.getList()) { - if (apiId1.equals(apiInfoDTO.getId())) { - found = true; - break; + int tries = 0; + while (!found && tries < 15) { + APIListDTO allAPIs = apiStoreRestClientTenant2.getAllAPIs(tenant1Name); + Assert.assertNotNull(allAPIs); + assert allAPIs.getCount() != null; + if (allAPIs.getCount() == 1) { + assert allAPIs.getList() != null; + for (APIInfoDTO apiInfoDTO : allAPIs.getList()) { + if (apiId1.equals(apiInfoDTO.getId())) { + found = true; + break; + } + } + } + tries++; + if (!found) { + Thread.sleep(5000); } } Assert.assertTrue(found, "API with ID" + apiId1 + "not found"); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/header/ESBJAVA5121CheckAuthHeaderOrderTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/header/ESBJAVA5121CheckAuthHeaderOrderTestCase.java index fc57335e1c..000799ca5e 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/header/ESBJAVA5121CheckAuthHeaderOrderTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/header/ESBJAVA5121CheckAuthHeaderOrderTestCase.java @@ -47,7 +47,7 @@ public class ESBJAVA5121CheckAuthHeaderOrderTestCase extends APIMIntegrationBase @BeforeClass(alwaysRun = true) public void setEnvironment() throws Exception { super.init(); - wireServer = new WireMonitorServer(8991); + wireServer = new WireMonitorServer(8993); AuthenticatorClient login = new AuthenticatorClient(gatewayContextMgt.getContextUrls().getBackEndUrl()); String session = login.login("admin", "admin", "localhost"); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/streamingapis/websub/WebSubAPITestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/streamingapis/websub/WebSubAPITestCase.java index 5dd4c436b4..0d8125ef35 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/streamingapis/websub/WebSubAPITestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/streamingapis/websub/WebSubAPITestCase.java @@ -336,6 +336,7 @@ public void testSubscriberVerification() throws Exception { apiDto.setEnableSubscriberVerification(true); restAPIPublisher.updateAPI(apiDto, apiId); createAPIRevisionAndDeployUsingRest(apiId, restAPIPublisher); + waitForAPIDeployment(); waitForAPIDeploymentSync(user.getUserName(), apiName, apiVersion, APIMIntegrationConstants.IS_API_EXISTS); callbackServerServlet.setCallbacksReceived(0); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/throttling/JWTRequestCountThrottlingTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/throttling/JWTRequestCountThrottlingTestCase.java index 701d075a62..cdeb9061b0 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/throttling/JWTRequestCountThrottlingTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/throttling/JWTRequestCountThrottlingTestCase.java @@ -158,10 +158,10 @@ public void setEnvironment() throws Exception { Assert.assertNotNull(apiPolicyId1, "The policy ID cannot be null or empty"); //Create the advanced throttling policy with conditions - RequestCountLimitDTO requestCountLimit10000PerMin = + RequestCountLimitDTO requestCountLimit10PerMin = DtoFactory.createRequestCountLimitDTO("min", 1, 10L); ThrottleLimitDTO defaultLimit2 = - DtoFactory.createThrottleLimitDTO(ThrottleLimitDTO.TypeEnum.REQUESTCOUNTLIMIT, requestCountLimit10000PerMin, null); + DtoFactory.createThrottleLimitDTO(ThrottleLimitDTO.TypeEnum.REQUESTCOUNTLIMIT, requestCountLimit10PerMin, null); AdvancedThrottlePolicyDTO requestCountAdvancedPolicyDTO2 = DtoFactory .createAdvancedThrottlePolicyDTO(apiPolicyName2, "", "", false, defaultLimit2, createConditionalGroups(defaultLimit)); @@ -367,14 +367,14 @@ public void testAPILevelThrottlingWithIpCondition() throws Exception { requestHeaders.put("content-type", "application/json"); requestHeaders.put("X-Forwarded-For", "10.100.1.22"); - Assert.assertFalse(isThrottled(requestHeaders, null,-1), + Assert.assertFalse(isThrottled(requestHeaders, null, 12), "Request was throttled unexpectedly in Unlimited API tier"); apidto.setApiThrottlingPolicy(apiPolicyName2); updatedAPI = restAPIPublisher.updateAPI(apidto, apiId); Assert.assertEquals(updatedAPI.getApiThrottlingPolicy(), apiPolicyName2, "API tier not updated."); - Assert.assertFalse(isThrottled(requestHeaders, null,-1), "Request not need to throttle since policy was " + + Assert.assertFalse(isThrottled(requestHeaders, null, 12), "Request not need to throttle since policy was " + "Unlimited"); // Create Revision and Deploy to Gateway createAPIRevisionAndDeployUsingRest(apiId, restAPIPublisher); diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/synapseconfigs/property/auth_headers.xml b/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/synapseconfigs/property/auth_headers.xml index a56a1fc94b..67195c66f8 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/synapseconfigs/property/auth_headers.xml +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/synapseconfigs/property/auth_headers.xml @@ -27,9 +27,9 @@ - + + value="http://localhost:8993/am/sample/calculator/v1/api/multiply"/> diff --git a/modules/integration/tests-integration/tests-restart/src/test/resources/artifacts/AM/synapseconfigs/property/auth_headers.xml b/modules/integration/tests-integration/tests-restart/src/test/resources/artifacts/AM/synapseconfigs/property/auth_headers.xml index a56a1fc94b..67195c66f8 100644 --- a/modules/integration/tests-integration/tests-restart/src/test/resources/artifacts/AM/synapseconfigs/property/auth_headers.xml +++ b/modules/integration/tests-integration/tests-restart/src/test/resources/artifacts/AM/synapseconfigs/property/auth_headers.xml @@ -27,9 +27,9 @@ - + + value="http://localhost:8993/am/sample/calculator/v1/api/multiply"/>