Skip to content

Commit

Permalink
Merge pull request #13321 from npamudika/master
Browse files Browse the repository at this point in the history
Add improvements for tests
  • Loading branch information
npamudika authored Jan 16, 2024
2 parents 27c1a81 + a5652ec commit b4750ea
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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("</soapenv:Envelope>")) {
if ((System.currentTimeMillis() > (time + trigger.READ_TIME_OUT)) || buffer.toString()
.contains("</soapenv:Envelope>")) {
break;
}
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
<inSequence>
<send>
<endpoint name="admin--AuthHeaderTestAPI_APIproductionEndpoint_0">
<http uri-template="http://localhost:8991/am/sample/calculator/v1/api/multiply"/>
<http uri-template="http://localhost:8993/am/sample/calculator/v1/api/multiply"/>
<property name="ENDPOINT_ADDRESS"
value="http://localhost:8991/am/sample/calculator/v1/api/multiply"/>
value="http://localhost:8993/am/sample/calculator/v1/api/multiply"/>
</endpoint>
</send>
</inSequence>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
<inSequence>
<send>
<endpoint name="admin--AuthHeaderTestAPI_APIproductionEndpoint_0">
<http uri-template="http://localhost:8991/am/sample/calculator/v1/api/multiply"/>
<http uri-template="http://localhost:8993/am/sample/calculator/v1/api/multiply"/>
<property name="ENDPOINT_ADDRESS"
value="http://localhost:8991/am/sample/calculator/v1/api/multiply"/>
value="http://localhost:8993/am/sample/calculator/v1/api/multiply"/>
</endpoint>
</send>
</inSequence>
Expand Down

0 comments on commit b4750ea

Please sign in to comment.