Commit 8acc61df authored by Rucha Deshpande's avatar Rucha Deshpande
Browse files

Add parallel API tests for getgroups and create group

commit 58c7fdc4 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Mon Dec 14 2020 15:05:30 GMT-0600 (Central Standard Time) 

    Merge remote-tracking branch 'remotes/origin/dev' into deshruch


commit 1c5a5109 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Mon Dec 14 2020 15:04:14 GMT-0600 (Central Standard Time) 

    Minor- Fix the group description


commit 8d17fd88 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Mon Dec 14 2020 11:05:52 GMT-0600 (Central Standard Time) 

    Add parallel api tests


commit 3963a46e 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Mon Dec 07 2020 11:18:55 GMT-0600 (Central Standard Time) 

    Fix: Update Role enum to have only OWNER/MEMBER
parent 2c23c576
......@@ -23,6 +23,11 @@ import org.opengroup.osdu.core.common.model.entitlements.GroupInfo;
import org.opengroup.osdu.core.common.model.entitlements.Groups;
import org.opengroup.osdu.entitlements.utils.*;
import org.opengroup.osdu.core.aws.entitlements.MemberInfo;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.sql.Timestamp;
import java.util.*;
......@@ -79,6 +84,41 @@ public class EntitlementsApiTests {
}
@Test
public void should_beAbleToRunApiInParallel_getGroups() throws Exception {
String path = "groups";
ExecutorService executor = Executors.newFixedThreadPool(10);
List<Callable<ClientResponse>> tasks = new ArrayList<>();
for (int i = 0; i < 10; i++) {
Callable<ClientResponse> task = () -> {
try {
return HTTPUtil.send(path, "GET",HTTPUtil.getHeaders(), "", "");
} catch (Exception ex) {
return null;
}
};
tasks.add(task);
}
List<Future<ClientResponse>> responses = executor.invokeAll(tasks);
executor.shutdown();
executor.awaitTermination(120, TimeUnit.SECONDS);
int sucessResponseCount = 0;
int errorResponseCount = 0;
for (Future<ClientResponse> future : responses) {
if (future.get().getStatus() == 200)
sucessResponseCount++;
else
errorResponseCount++;
}
assertEquals(error("Expected all successful responses. Actual " + sucessResponseCount), 10, sucessResponseCount);
assertEquals(error("Unexpected error response returned"), 0, errorResponseCount);
}
@Test
public void getGroupsTest_noToken_thenForbidden() throws Exception {
String path = "groups";
......@@ -148,6 +188,50 @@ public class EntitlementsApiTests {
}
@Test
public void should_onlyCreateMax1Resource_and_return409ForTheRest_when_creatingTheSameResourceInParallel_createGroup() throws Exception {
String path = "groups";
String token = client.getToken(AwsConfig.getAWSCognitoTestUsername(),AwsConfig.getAWSCognitoTestUserPassword(),"bearer");
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
String ts= Long.toString(timestamp.getTime());
String groupName= "int-test-group-test-parallel"+ts;
String groupDescription = "int-test-group-test-parallel";
Map<String, String> group = new HashMap();
group.put("name",groupName);
group.put("description", groupDescription);
String newGroupRequestBody = new Gson().toJson(group);
ExecutorService executor = Executors.newFixedThreadPool(8);
List<Callable<ClientResponse>> tasks = new ArrayList<>();
for (int i = 0; i < 8; i++) {
Callable<ClientResponse> task = () -> {
try {
return HTTPUtil.send(path, "POST",HTTPUtil.getHeaders(AwsConfig.getTenant(), token), newGroupRequestBody, "");
} catch (Exception ex) {
return null;
}
};
tasks.add(task);
}
List<Future<ClientResponse>> responses = executor.invokeAll(tasks);
executor.shutdown();
executor.awaitTermination(20, TimeUnit.SECONDS);
int sucessResponseCount = 0;
int non409ErrorResponseCount = 0;
for (Future<ClientResponse> future : responses) {
if (future.get().getStatus() == HttpStatus.SC_OK)
sucessResponseCount++;
else if (future.get().getStatus() != 409)
non409ErrorResponseCount++;
}
assertTrue(error("Expected 1 successful response. Actual " + sucessResponseCount), sucessResponseCount <= 1);
assertEquals(error("Unexpected error response returned"), 0, non409ErrorResponseCount);
}
@Test
public void createGroup_noToken_Forbiddden() throws Exception {
......@@ -349,7 +433,9 @@ public class EntitlementsApiTests {
}
protected String error(String body) {
return String.format("%s", body);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment