You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by re...@apache.org on 2015/08/14 12:59:22 UTC
[4/4] stratos git commit: adding termination behavior test and list
test case for all the artifacts
adding termination behavior test and list test case for all the artifacts
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/512280af
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/512280af
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/512280af
Branch: refs/heads/master
Commit: 512280afcf554ae8dd855b0772f065753238f088
Parents: 0f2b953
Author: reka <rt...@gmail.com>
Authored: Fri Aug 14 13:53:06 2015 +0530
Committer: reka <rt...@gmail.com>
Committed: Fri Aug 14 15:38:08 2015 +0530
----------------------------------------------------------------------
.../tests/StratosTestServerManager.java | 2 +-
.../integration/tests/TopologyHandler.java | 157 +++++++--
.../application/ApplicationBurstingTest.java | 75 ++--
.../application/ApplicationUpdateTest.java | 16 +-
.../application/GroupStartupOrderTest.java | 12 +-
.../GroupTerminationBehaviorTest.java | 350 +++++++++++++++++++
.../PartitionOneAfterAnotherClusterTest.java | 10 +-
.../PartitionRoundRobinClusterTest.java | 16 +-
.../application/SingleClusterScalingTest.java | 10 +-
.../tests/group/CartridgeGroupTest.java | 183 ++++++++--
.../integration/tests/group/CartridgeTest.java | 73 +++-
.../tests/policies/NetworkPartitionTest.java | 85 ++++-
.../integration/tests/rest/RestClient.java | 30 ++
.../group-1-cartridge-group-test.json | 50 +++
.../group-2-cartridge-group-test.json | 50 +++
.../cartridges/mock/c1-cartridge-test.json | 124 +++++++
.../cartridges/mock/c2-cartridge-test.json | 124 +++++++
...cation-policy-application-bursting-test.json | 17 -
...-policy-group-termination-behavior-test.json | 17 +
.../group-termination-behavior-test.json | 4 +-
...caling-policy-application-bursting-test.json | 14 -
...-policy-group-termination-behavior-test.json | 14 +
...-groups-group-termination-behavior-test.json | 4 +-
...-policy-group-termination-behavior-test.json | 18 +
...oyment-policy-termination-behavior-test.json | 22 --
...k-partition-application-bursting-test-1.json | 15 -
...ition-group-termination-behavior-test-1.json | 15 +
.../src/test/resources/mock-iaas.xml | 20 ++
...work-partition-network-partition-test-1.json | 15 +
...work-partition-network-partition-test-2.json | 15 +
.../src/test/resources/stratos-testing.xml | 15 +-
31 files changed, 1359 insertions(+), 213 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/512280af/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosTestServerManager.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosTestServerManager.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosTestServerManager.java
index 342df28..6a69b75 100755
--- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosTestServerManager.java
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosTestServerManager.java
@@ -58,7 +58,7 @@ public class StratosTestServerManager extends TestServerManager {
private static final String JNDI_PROPERTIES_FILE = "jndi.properties";
private static final String JMS_OUTPUT_ADAPTER_FILE = "JMSOutputAdaptor.xml";
protected RestClient restClient;
- private String endpoint = "https://localhost:9443";
+ private String endpoint = "http://localhost:9763";
private BrokerService broker = new BrokerService();
private TestLogAppender testLogAppender = new TestLogAppender();
http://git-wip-us.apache.org/repos/asf/stratos/blob/512280af/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/TopologyHandler.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/TopologyHandler.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/TopologyHandler.java
index 85e370b..85987f5 100644
--- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/TopologyHandler.java
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/TopologyHandler.java
@@ -33,10 +33,8 @@ import org.apache.stratos.messaging.domain.topology.Member;
import org.apache.stratos.messaging.domain.topology.MemberStatus;
import org.apache.stratos.messaging.domain.topology.Service;
import org.apache.stratos.messaging.event.Event;
-import org.apache.stratos.messaging.event.application.GroupInstanceCreatedEvent;
-import org.apache.stratos.messaging.event.topology.ClusterInstanceCreatedEvent;
-import org.apache.stratos.messaging.event.topology.MemberCreatedEvent;
-import org.apache.stratos.messaging.event.topology.MemberTerminatedEvent;
+import org.apache.stratos.messaging.event.application.*;
+import org.apache.stratos.messaging.event.topology.*;
import org.apache.stratos.messaging.listener.application.*;
import org.apache.stratos.messaging.listener.topology.*;
import org.apache.stratos.messaging.message.receiver.application.ApplicationManager;
@@ -68,10 +66,11 @@ public class TopologyHandler {
private ApplicationsEventReceiver applicationsEventReceiver;
private TopologyEventReceiver topologyEventReceiver;
public static TopologyHandler topologyHandler;
- private Map<String, Map<String, Long>> terminatedNodes = new ConcurrentHashMap<String, Map<String, Long>>();
private Map<String, Long> terminatedMembers = new ConcurrentHashMap<String, Long>();
- private Map<String, Map<String, Long>> createdNodes = new ConcurrentHashMap<String, Map<String, Long>>();
- private Map<String, Map<String, Long>> activeNodes = new ConcurrentHashMap<String, Map<String, Long>>();
+ private Map<String, Long> terminatingMembers = new ConcurrentHashMap<String, Long>();
+ private Map<String, Long> createdMembers = new ConcurrentHashMap<String, Long>();
+ private Map<String, Long> inActiveMembers = new ConcurrentHashMap<String, Long>();
+ private Map<String, Long> activateddMembers = new ConcurrentHashMap<String, Long>();
private TopologyHandler() {
// Set jndi.properties.dir system property for initializing event receivers
@@ -82,6 +81,7 @@ public class TopologyHandler {
assertApplicationTopologyInitialized();
assertTopologyInitialized();
addTopologyEventListeners();
+ addApplicationEventListeners();
}
public static TopologyHandler getInstance() {
@@ -457,30 +457,27 @@ public class TopologyHandler {
@Override
protected void onEvent(Event event) {
MemberTerminatedEvent memberTerminatedEvent = (MemberTerminatedEvent) event;
- terminatedMembers.put(memberTerminatedEvent.getMemberId(), System.currentTimeMillis());
+ getTerminatedMembers().put(memberTerminatedEvent.getMemberId(), System.currentTimeMillis());
}
});
- topologyEventReceiver.addEventListener(new MemberCreatedEventListener() {
- @Override
- protected void onEvent(Event event) {
-
-
- }
- });
topologyEventReceiver.addEventListener(new ClusterInstanceCreatedEventListener() {
@Override
protected void onEvent(Event event) {
ClusterInstanceCreatedEvent event1 = (ClusterInstanceCreatedEvent) event;
-
+ String clusterId = event1.getClusterId();
+ getCreatedMembers().put(clusterId, System.currentTimeMillis());
}
});
topologyEventReceiver.addEventListener(new ClusterInstanceActivatedEventListener() {
@Override
protected void onEvent(Event event) {
+ ClusterInstanceActivatedEvent event1 = (ClusterInstanceActivatedEvent) event;
+ String clusterId = event1.getClusterId();
+ getActivateddMembers().put(clusterId, System.currentTimeMillis());
}
});
@@ -488,14 +485,27 @@ public class TopologyHandler {
topologyEventReceiver.addEventListener(new ClusterInstanceInactivateEventListener() {
@Override
protected void onEvent(Event event) {
-
+ ClusterInstanceInactivateEvent event1 = (ClusterInstanceInactivateEvent) event;
+ String clusterId = event1.getClusterId();
+ getInActiveMembers().put(clusterId, System.currentTimeMillis());
}
});
topologyEventReceiver.addEventListener(new ClusterInstanceTerminatedEventListener() {
@Override
protected void onEvent(Event event) {
+ ClusterInstanceTerminatedEvent event1 = (ClusterInstanceTerminatedEvent) event;
+ String clusterId = event1.getClusterId();
+ getTerminatedMembers().put(clusterId, System.currentTimeMillis());
+ }
+ });
+ topologyEventReceiver.addEventListener(new ClusterInstanceTerminatingEventListener() {
+ @Override
+ protected void onEvent(Event event) {
+ ClusterInstanceTerminatingEvent event1 = (ClusterInstanceTerminatingEvent) event;
+ String clusterId = event1.getClusterId();
+ getTerminatingMembers().put(clusterId, System.currentTimeMillis());
}
});
@@ -503,46 +513,135 @@ public class TopologyHandler {
}
private void addApplicationEventListeners() {
- applicationsEventReceiver.addEventListener(new ApplicationInstanceCreatedEventListener() {
- @Override
- protected void onEvent(Event event) {
-
-
- }
- });
applicationsEventReceiver.addEventListener(new GroupInstanceCreatedEventListener() {
@Override
protected void onEvent(Event event) {
GroupInstanceCreatedEvent event1 = (GroupInstanceCreatedEvent) event;
String appId = event1.getAppId();
- String id = event1.getGroupId();
+ String groupId = event1.getGroupId();
String instanceId = event1.getGroupInstance().getInstanceId();
+ String id = generateId(appId, groupId, instanceId);
+ getCreatedMembers().put(id, System.currentTimeMillis());
}
});
-
-
applicationsEventReceiver.addEventListener(new GroupInstanceActivatedEventListener() {
@Override
protected void onEvent(Event event) {
-
+ GroupInstanceActivatedEvent event1 = (GroupInstanceActivatedEvent) event;
+ String appId = event1.getAppId();
+ String groupId = event1.getGroupId();
+ String instanceId = event1.getInstanceId();
+ String id = generateId(appId, groupId, instanceId);
+ getActivateddMembers().put(id, System.currentTimeMillis());
}
});
applicationsEventReceiver.addEventListener(new GroupInstanceInactivateEventListener() {
@Override
protected void onEvent(Event event) {
-
+ GroupInstanceInactivatedEvent event1 = (GroupInstanceInactivatedEvent) event;
+ String appId = event1.getAppId();
+ String groupId = event1.getGroupId();
+ String instanceId = event1.getInstanceId();
+ String id = generateId(appId, groupId, instanceId);
+ getInActiveMembers().put(id, System.currentTimeMillis());
}
});
applicationsEventReceiver.addEventListener(new GroupInstanceTerminatedEventListener() {
@Override
protected void onEvent(Event event) {
+ GroupInstanceTerminatedEvent event1 = (GroupInstanceTerminatedEvent) event;
+ String appId = event1.getAppId();
+ String groupId = event1.getGroupId();
+ String instanceId = event1.getInstanceId();
+ String id = generateId(appId, groupId, instanceId);
+ getTerminatedMembers().put(id, System.currentTimeMillis());
+ }
+ });
+ applicationsEventReceiver.addEventListener(new GroupInstanceTerminatingEventListener() {
+ @Override
+ protected void onEvent(Event event) {
+ GroupInstanceTerminatingEvent event1 = (GroupInstanceTerminatingEvent) event;
+ String appId = event1.getAppId();
+ String groupId = event1.getGroupId();
+ String instanceId = event1.getInstanceId();
+ String id = generateId(appId, groupId, instanceId);
+ getTerminatingMembers().put(id, System.currentTimeMillis());
}
});
}
+
+ public String generateId(String appId, String groupId, String instanceId) {
+ return appId + "-" + groupId + "-" + instanceId;
+ }
+
+ public String getClusterIdFromAlias(String applicationId, String alias) {
+ Application application = ApplicationManager.getApplications().getApplication(applicationId);
+ assertNotNull(application);
+
+ ClusterDataHolder dataHolder = application.getClusterDataHolderRecursivelyByAlias(alias);
+ assertNotNull(dataHolder);
+
+ return dataHolder.getClusterId();
+ }
+
+
+ public void removeMembersFromMaps(String applicationId) {
+ for(Map.Entry<String, Long> entry: getActivateddMembers().entrySet()) {
+ if(entry.getKey().contains(applicationId)) {
+ getActivateddMembers().remove(entry.getKey());
+ }
+ }
+
+ for(Map.Entry<String, Long> entry: getTerminatedMembers().entrySet()) {
+ if(entry.getKey().contains(applicationId)) {
+ getTerminatedMembers().remove(entry.getKey());
+ }
+ }
+ }
+
+ public Map<String, Long> getTerminatedMembers() {
+ return terminatedMembers;
+ }
+
+ public void setTerminatedMembers(Map<String, Long> terminatedMembers) {
+ this.terminatedMembers = terminatedMembers;
+ }
+
+ public Map<String, Long> getTerminatingMembers() {
+ return terminatingMembers;
+ }
+
+ public void setTerminatingMembers(Map<String, Long> terminatingMembers) {
+ this.terminatingMembers = terminatingMembers;
+ }
+
+ public Map<String, Long> getCreatedMembers() {
+ return createdMembers;
+ }
+
+ public void setCreatedMembers(Map<String, Long> createdMembers) {
+ this.createdMembers = createdMembers;
+ }
+
+ public Map<String, Long> getInActiveMembers() {
+ return inActiveMembers;
+ }
+
+ public void setInActiveMembers(Map<String, Long> inActiveMembers) {
+ this.inActiveMembers = inActiveMembers;
+ }
+
+ public Map<String, Long> getActivateddMembers() {
+ return activateddMembers;
+ }
+
+ public void setActivateddMembers(Map<String, Long> activateddMembers) {
+ this.activateddMembers = activateddMembers;
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/512280af/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTest.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTest.java
index 6c62056..70f79f2 100644
--- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTest.java
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTest.java
@@ -29,8 +29,7 @@ import org.apache.stratos.integration.tests.TopologyHandler;
import org.apache.stratos.messaging.domain.application.ApplicationStatus;
import org.testng.annotations.Test;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.*;
/**
* This will handle the application bursting test cases
@@ -44,30 +43,30 @@ public class ApplicationBurstingTest extends StratosTestServerManager {
public void testApplicationBusting() {
try {
log.info("-------------------------------Started application Bursting test case-------------------------------");
-
+ TopologyHandler topologyHandler = TopologyHandler.getInstance();
String autoscalingPolicyId = "autoscaling-policy-application-bursting-test";
boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH
+ "/" + autoscalingPolicyId + ".json",
RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME);
- assertEquals(addedScalingPolicy, true);
+ assertTrue(addedScalingPolicy);
boolean addedC1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "esb-application-bursting-test.json",
RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
- assertEquals(addedC1, true);
+ assertTrue(addedC1);
boolean addedC2 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "php-application-bursting-test.json",
RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
- assertEquals(addedC2, true);
+ assertTrue(addedC2);
boolean addedC3 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "tomcat-application-bursting-test.json",
RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
- assertEquals(addedC3, true);
+ assertTrue(addedC3);
boolean addedG1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
"/" + "esb-php-group-application-bursting-test.json", RestConstants.CARTRIDGE_GROUPS,
RestConstants.CARTRIDGE_GROUPS_NAME);
- assertEquals(addedG1, true);
+ assertTrue(addedG1);
CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient.
getEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group-application-bursting-test",
@@ -77,22 +76,22 @@ public class ApplicationBurstingTest extends StratosTestServerManager {
boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
"network-partition-application-bursting-test-1.json",
RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
- assertEquals(addedN1, true);
+ assertTrue(addedN1);
boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
"network-partition-application-bursting-test-2.json",
RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
- assertEquals(addedN2, true);
+ assertTrue(addedN2);
boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
"deployment-policy-application-bursting-test.json",
RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME);
- assertEquals(addedDep, true);
+ assertTrue(addedDep);
boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
"app-bursting-single-cartriddge-group.json", RestConstants.APPLICATIONS,
RestConstants.APPLICATIONS_NAME);
- assertEquals(added, true);
+ assertTrue(added);
ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
"application-bursting-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
@@ -101,7 +100,7 @@ public class ApplicationBurstingTest extends StratosTestServerManager {
boolean addAppPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" +
"application-policy-application-bursting-test.json", RestConstants.APPLICATION_POLICIES,
RestConstants.APPLICATION_POLICIES_NAME);
- assertEquals(addAppPolicy, true);
+ assertTrue(addAppPolicy);
ApplicationPolicyBean policyBean = (ApplicationPolicyBean) restClient.getEntity(
RestConstants.APPLICATION_POLICIES,
@@ -113,35 +112,35 @@ public class ApplicationBurstingTest extends StratosTestServerManager {
RestConstants.APPLICATIONS_DEPLOY + "/" + "application-policy-application-bursting-test";
boolean deployed = restClient.deployEntity(resourcePath,
RestConstants.APPLICATIONS_NAME);
- assertEquals(deployed, true);
+ assertTrue(deployed);
//Application active handling
- TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId(),
+ topologyHandler.assertApplicationStatus(bean.getApplicationId(),
ApplicationStatus.Active);
//Group active handling
- TopologyHandler.getInstance().assertGroupActivation(bean.getApplicationId());
+ topologyHandler.assertGroupActivation(bean.getApplicationId());
//Cluster active handling
- TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId());
+ topologyHandler.assertClusterActivation(bean.getApplicationId());
boolean removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group-application-bursting-test",
RestConstants.CARTRIDGE_GROUPS_NAME);
- assertEquals(removedGroup, false);
+ assertFalse(removedGroup);
boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
- assertEquals(removedAuto, false);
+ assertFalse(removedAuto);
boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
"network-partition-application-bursting-test-1",
RestConstants.NETWORK_PARTITIONS_NAME);
//Trying to remove the used network partition
- assertEquals(removedNet, false);
+ assertFalse(removedNet);
boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
"deployment-policy-application-bursting-test", RestConstants.DEPLOYMENT_POLICIES_NAME);
- assertEquals(removedDep, false);
+ assertFalse(removedDep);
//Un-deploying the application
String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + "application-bursting-test" +
@@ -149,9 +148,9 @@ public class ApplicationBurstingTest extends StratosTestServerManager {
boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy,
RestConstants.APPLICATIONS_NAME);
- assertEquals(unDeployed, true);
+ assertTrue(unDeployed);
- boolean undeploy = TopologyHandler.getInstance().assertApplicationUndeploy("application-bursting-test");
+ boolean undeploy = topologyHandler.assertApplicationUndeploy("application-bursting-test");
if (!undeploy) {
//Need to forcefully undeploy the application
log.info("Force undeployment is going to start for the [application] " + "application-bursting-test");
@@ -159,63 +158,63 @@ public class ApplicationBurstingTest extends StratosTestServerManager {
restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + "application-bursting-test" +
RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS);
- boolean forceUndeployed = TopologyHandler.getInstance().assertApplicationUndeploy("application-bursting-test");
+ boolean forceUndeployed = topologyHandler.assertApplicationUndeploy("application-bursting-test");
assertEquals(String.format("Forceful undeployment failed for the application %s",
- "application-bursting-test"), forceUndeployed, true);
+ "application-bursting-test"), forceUndeployed);
}
boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, "application-bursting-test",
RestConstants.APPLICATIONS_NAME);
- assertEquals(removed, true);
+ assertTrue(removed);
ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
"application-bursting-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
- assertEquals(beanRemoved, null);
+ assertNull(beanRemoved);
removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group-application-bursting-test",
RestConstants.CARTRIDGE_GROUPS_NAME);
- assertEquals(removedGroup, true);
+ assertTrue(removedGroup);
boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "esb-application-bursting-test",
RestConstants.CARTRIDGES_NAME);
- assertEquals(removedC1, true);
+ assertTrue(removedC1);
boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "php-application-bursting-test",
RestConstants.CARTRIDGES_NAME);
- assertEquals(removedC2, true);
+ assertTrue(removedC2);
boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "tomcat-application-bursting-test",
RestConstants.CARTRIDGES_NAME);
- assertEquals(removedC3, true);
+ assertTrue(removedC3);
removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
- assertEquals(removedAuto, true);
+ assertTrue(removedAuto);
removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
"deployment-policy-application-bursting-test", RestConstants.DEPLOYMENT_POLICIES_NAME);
- assertEquals(removedDep, true);
+ assertTrue(removedDep);
removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
"network-partition-application-bursting-test-1", RestConstants.NETWORK_PARTITIONS_NAME);
- assertEquals(removedNet, false);
+ assertFalse(removedNet);
boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
"network-partition-application-bursting-test-2", RestConstants.NETWORK_PARTITIONS_NAME);
- assertEquals(removedN2, false);
+ assertFalse(removedN2);
boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES,
"application-policy-application-bursting-test", RestConstants.APPLICATION_POLICIES_NAME);
- assertEquals(removeAppPolicy, true);
+ assertTrue(removeAppPolicy);
removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
"network-partition-application-bursting-test-1", RestConstants.NETWORK_PARTITIONS_NAME);
- assertEquals(removedNet, true);
+ assertTrue(removedNet);
removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
"network-partition-application-bursting-test-2", RestConstants.NETWORK_PARTITIONS_NAME);
- assertEquals(removedN2, true);
+ assertTrue(removedN2);
log.info("-------------------------------Ended application bursting test case-------------------------------");
http://git-wip-us.apache.org/repos/asf/stratos/blob/512280af/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTest.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTest.java
index c9e64b2..f3f1b91 100644
--- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTest.java
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTest.java
@@ -44,7 +44,7 @@ public class ApplicationUpdateTest extends StratosTestServerManager {
public void testDeployApplication() {
try {
log.info("-------------------------Started application runtime update test case-------------------------");
-
+ TopologyHandler topologyHandler = TopologyHandler.getInstance();
String autoscalingPolicyId = "autoscaling-policy-application-update-test";
boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH
@@ -116,14 +116,14 @@ public class ApplicationUpdateTest extends StratosTestServerManager {
assertEquals(deployed, true);
//Application active handling
- TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId(),
+ topologyHandler.assertApplicationStatus(bean.getApplicationId(),
ApplicationStatus.Active);
//Group active handling
- TopologyHandler.getInstance().assertGroupActivation(bean.getApplicationId());
+ topologyHandler.assertGroupActivation(bean.getApplicationId());
//Cluster active handling
- TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId());
+ topologyHandler.assertClusterActivation(bean.getApplicationId());
//Updating application
boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
@@ -131,9 +131,9 @@ public class ApplicationUpdateTest extends StratosTestServerManager {
RestConstants.APPLICATIONS_NAME);
assertEquals(updated, true);
- TopologyHandler.getInstance().assertGroupInstanceCount(bean.getApplicationId(), "group3-application-update-test", 2);
+ topologyHandler.assertGroupInstanceCount(bean.getApplicationId(), "group3-application-update-test", 2);
- TopologyHandler.getInstance().assertClusterMinMemberCount(bean.getApplicationId(), 2);
+ topologyHandler.assertClusterMinMemberCount(bean.getApplicationId(), 2);
ApplicationBean updatedBean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
"g-sc-G123-1-application-update-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
@@ -165,7 +165,7 @@ public class ApplicationUpdateTest extends StratosTestServerManager {
RestConstants.APPLICATIONS_NAME);
assertEquals(unDeployed, true);
- boolean undeploy = TopologyHandler.getInstance().assertApplicationUndeploy("g-sc-G123-1-application-update-test");
+ boolean undeploy = topologyHandler.assertApplicationUndeploy("g-sc-G123-1-application-update-test");
if (!undeploy) {
//Need to forcefully undeploy the application
log.info("Force undeployment is going to start for the [application] " + "g-sc-G123-1-application-update-test");
@@ -173,7 +173,7 @@ public class ApplicationUpdateTest extends StratosTestServerManager {
restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + "g-sc-G123-1-application-update-test" +
RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS);
- boolean forceUndeployed = TopologyHandler.getInstance().assertApplicationUndeploy("g-sc-G123-1-application-update-test");
+ boolean forceUndeployed = topologyHandler.assertApplicationUndeploy("g-sc-G123-1-application-update-test");
assertEquals(String.format("Forceful undeployment failed for the application %s",
"g-sc-G123-1-application-update-test"), forceUndeployed, true);
http://git-wip-us.apache.org/repos/asf/stratos/blob/512280af/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/GroupStartupOrderTest.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/GroupStartupOrderTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/GroupStartupOrderTest.java
index 1f3aa56..7cd8e9f 100644
--- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/GroupStartupOrderTest.java
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/GroupStartupOrderTest.java
@@ -43,7 +43,7 @@ public class GroupStartupOrderTest extends StratosTestServerManager {
public void testApplicationBusting() {
try {
log.info("-------------------------------Started application Bursting test case-------------------------------");
-
+ TopologyHandler topologyHandler = TopologyHandler.getInstance();
String autoscalingPolicyId = "autoscaling-policy-application-bursting-test";
boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH
@@ -115,14 +115,14 @@ public class GroupStartupOrderTest extends StratosTestServerManager {
assertEquals(deployed, true);
//Application active handling
- TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId(),
+ topologyHandler.assertApplicationStatus(bean.getApplicationId(),
ApplicationStatus.Active);
//Group active handling
- TopologyHandler.getInstance().assertGroupActivation(bean.getApplicationId());
+ topologyHandler.assertGroupActivation(bean.getApplicationId());
//Cluster active handling
- TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId());
+ topologyHandler.assertClusterActivation(bean.getApplicationId());
boolean removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group-application-bursting-test",
RestConstants.CARTRIDGE_GROUPS_NAME);
@@ -150,7 +150,7 @@ public class GroupStartupOrderTest extends StratosTestServerManager {
RestConstants.APPLICATIONS_NAME);
assertEquals(unDeployed, true);
- boolean undeploy = TopologyHandler.getInstance().assertApplicationUndeploy("application-bursting-test");
+ boolean undeploy = topologyHandler.assertApplicationUndeploy("application-bursting-test");
if (!undeploy) {
//Need to forcefully undeploy the application
log.info("Force undeployment is going to start for the [application] " + "application-bursting-test");
@@ -158,7 +158,7 @@ public class GroupStartupOrderTest extends StratosTestServerManager {
restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + "application-bursting-test" +
RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS);
- boolean forceUndeployed = TopologyHandler.getInstance().assertApplicationUndeploy("application-bursting-test");
+ boolean forceUndeployed = topologyHandler.assertApplicationUndeploy("application-bursting-test");
assertEquals(String.format("Forceful undeployment failed for the application %s",
"application-bursting-test"), forceUndeployed, true);
http://git-wip-us.apache.org/repos/asf/stratos/blob/512280af/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/GroupTerminationBehaviorTest.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/GroupTerminationBehaviorTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/GroupTerminationBehaviorTest.java
index b86d674..415f67a 100644
--- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/GroupTerminationBehaviorTest.java
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/GroupTerminationBehaviorTest.java
@@ -18,10 +18,360 @@
*/
package org.apache.stratos.integration.tests.application;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.beans.application.ApplicationBean;
+import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean;
+import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean;
+import org.apache.stratos.integration.tests.RestConstants;
import org.apache.stratos.integration.tests.StratosTestServerManager;
+import org.apache.stratos.integration.tests.TopologyHandler;
+import org.apache.stratos.messaging.domain.application.Application;
+import org.apache.stratos.messaging.domain.application.ApplicationStatus;
+import org.apache.stratos.messaging.domain.application.Group;
+import org.apache.stratos.messaging.message.receiver.application.ApplicationManager;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import static junit.framework.Assert.*;
/**
* Handling the termination behavior of the group
*/
public class GroupTerminationBehaviorTest extends StratosTestServerManager {
+ private static final Log log = LogFactory.getLog(GroupTerminationBehaviorTest.class);
+ private static final String RESOURCES_PATH = "/group-termination-behavior-test";
+ private static final int GROUP_INACTIVE_TIMEOUT = 300000;
+
+ @Test
+ public void testTerminationBehavior() {
+ try {
+ log.info("-------------------------------Started application termination behavior test case-------------------------------");
+
+ String autoscalingPolicyId = "autoscaling-policy-group-termination-behavior-test";
+ TopologyHandler topologyHandler = TopologyHandler.getInstance();
+
+ boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH
+ + "/" + autoscalingPolicyId + ".json",
+ RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME);
+ assertTrue(addedScalingPolicy);
+
+ boolean addedC1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c1-group-termination-behavior-test.json",
+ RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+ assertTrue(addedC1);
+
+ boolean addedC2 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c2-group-termination-behavior-test.json",
+ RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+ assertTrue(addedC2);
+
+ boolean addedC3 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c3-group-termination-behavior-test.json",
+ RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+ assertTrue(addedC3);
+
+ boolean addedC4 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c4-group-termination-behavior-test.json",
+ RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+ assertTrue(addedC4);
+
+ boolean addedG1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
+ "/" + "cartridge-groups-group-termination-behavior-test.json", RestConstants.CARTRIDGE_GROUPS,
+ RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertTrue(addedG1);
+
+ CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient.
+ getEntity(RestConstants.CARTRIDGE_GROUPS, "g-sc-G4-group-termination-behavior-test",
+ CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertEquals(beanG1.getName(), "g-sc-G4-group-termination-behavior-test");
+
+ boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+ "network-partition-group-termination-behavior-test-1.json",
+ RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+ assertTrue(addedN1);
+
+ boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
+ "deployment-policy-group-termination-behavior-test.json",
+ RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME);
+ assertTrue(addedDep);
+
+ boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
+ "group-termination-behavior-test.json", RestConstants.APPLICATIONS,
+ RestConstants.APPLICATIONS_NAME);
+ assertTrue(added);
+
+ ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
+ "group-termination-behavior-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+ assertEquals(bean.getApplicationId(), "group-termination-behavior-test");
+
+ boolean addAppPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" +
+ "application-policy-group-termination-behavior-test.json", RestConstants.APPLICATION_POLICIES,
+ RestConstants.APPLICATION_POLICIES_NAME);
+ assertTrue(addAppPolicy);
+
+ ApplicationPolicyBean policyBean = (ApplicationPolicyBean) restClient.getEntity(
+ RestConstants.APPLICATION_POLICIES,
+ "application-policy-group-termination-behavior-test", ApplicationPolicyBean.class,
+ RestConstants.APPLICATION_POLICIES_NAME);
+
+ //deploy the application
+ String resourcePath = RestConstants.APPLICATIONS + "/" + "group-termination-behavior-test" +
+ RestConstants.APPLICATIONS_DEPLOY + "/" + "application-policy-group-termination-behavior-test";
+ boolean deployed = restClient.deployEntity(resourcePath,
+ RestConstants.APPLICATIONS_NAME);
+ assertTrue(deployed);
+
+ //Application active handling
+ topologyHandler.assertApplicationStatus(bean.getApplicationId(),
+ ApplicationStatus.Active);
+ String groupId = topologyHandler.generateId(bean.getApplicationId(),
+ "g-G1-1x0-group-termination-behavior-test", bean.getApplicationId() + "-1");
+
+ String clusterIdC3 = topologyHandler.
+ getClusterIdFromAlias(bean.getApplicationId(),
+ "c3-1x0-group-termination-behavior-test");
+
+ String clusterIdC4 = topologyHandler.
+ getClusterIdFromAlias(bean.getApplicationId(),
+ "c4-1x0-group-termination-behavior-test");
+
+ String clusterIdC2 = topologyHandler.
+ getClusterIdFromAlias(bean.getApplicationId(),
+ "c2-1x0-group-termination-behavior-test");
+
+ assertCreationOfNodes(groupId, clusterIdC2);
+ assertCreationOfNodes(clusterIdC3, clusterIdC4);
+
+ //Group active handling
+ topologyHandler.assertGroupActivation(bean.getApplicationId());
+
+ //Cluster active handling
+ topologyHandler.assertClusterActivation(bean.getApplicationId());
+
+ List<String> clusterIds = new ArrayList<String>();
+ clusterIds.add(clusterIdC3);
+ clusterIds.add(clusterIdC4);
+ clusterIds.add(clusterIdC2);
+
+ assertGroupInactive(groupId, clusterIdC3);
+
+ assertTerminatingOfNodes(groupId, clusterIds);
+
+ assertTerminationOfNodes(groupId, clusterIds);
+
+ //Application active handling
+ topologyHandler.assertApplicationStatus(bean.getApplicationId(),
+ ApplicationStatus.Active);
+
+ assertCreationOfNodes(groupId, clusterIdC2);
+ assertCreationOfNodes(clusterIdC3, clusterIdC4);
+
+ //Group active handling
+ topologyHandler.assertGroupActivation(bean.getApplicationId());
+
+ //Cluster active handling
+ topologyHandler.assertClusterActivation(bean.getApplicationId());
+
+ boolean removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS,
+ "g-sc-G4-group-termination-behavior-test",
+ RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertFalse(removedGroup);
+
+ boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+ autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
+ assertFalse(removedAuto);
+
+ boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
+ "network-partition-group-termination-behavior-test-1",
+ RestConstants.NETWORK_PARTITIONS_NAME);
+ //Trying to remove the used network partition
+ assertFalse(removedNet);
+
+ boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+ "deployment-policy-group-termination-behavior-test", RestConstants.DEPLOYMENT_POLICIES_NAME);
+ assertFalse(removedDep);
+
+ //Un-deploying the application
+ String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + "group-termination-behavior-test" +
+ RestConstants.APPLICATIONS_UNDEPLOY;
+
+ boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy,
+ RestConstants.APPLICATIONS_NAME);
+ assertTrue(unDeployed);
+
+ boolean undeploy = topologyHandler.assertApplicationUndeploy("group-termination-behavior-test");
+ if (!undeploy) {
+ //Need to forcefully undeploy the application
+ log.info("Force undeployment is going to start for the [application] " + "group-termination-behavior-test");
+
+ restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + "group-termination-behavior-test" +
+ RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS);
+
+ boolean forceUndeployed = topologyHandler.assertApplicationUndeploy("group-termination-behavior-test");
+ assertTrue(String.format("Forceful undeployment failed for the application %s",
+ "group-termination-behavior-test"), forceUndeployed);
+
+ }
+
+ boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, "group-termination-behavior-test",
+ RestConstants.APPLICATIONS_NAME);
+ assertTrue(removed);
+
+ ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
+ "group-termination-behavior-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+ assertNull(beanRemoved);
+
+ removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS,
+ "g-sc-G4-group-termination-behavior-test",
+ RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertTrue(removedGroup);
+
+ boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c1-group-termination-behavior-test",
+ RestConstants.CARTRIDGES_NAME);
+ assertTrue(removedC1);
+
+ boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c2-group-termination-behavior-test",
+ RestConstants.CARTRIDGES_NAME);
+ assertTrue(removedC2);
+
+ boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c3-group-termination-behavior-test",
+ RestConstants.CARTRIDGES_NAME);
+ assertTrue(removedC3);
+
+ boolean removedC4 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4-group-termination-behavior-test",
+ RestConstants.CARTRIDGES_NAME);
+ assertTrue(removedC4);
+
+ removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+ autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
+ assertTrue(removedAuto);
+
+ removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+ "deployment-policy-group-termination-behavior-test", RestConstants.DEPLOYMENT_POLICIES_NAME);
+ assertTrue(removedDep);
+
+ removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
+ "network-partition-group-termination-behavior-test-1", RestConstants.NETWORK_PARTITIONS_NAME);
+ assertFalse(removedNet);
+
+ boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES,
+ "application-policy-group-termination-behavior-test", RestConstants.APPLICATION_POLICIES_NAME);
+ assertTrue(removeAppPolicy);
+
+ removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
+ "network-partition-group-termination-behavior-test-1", RestConstants.NETWORK_PARTITIONS_NAME);
+ assertTrue(removedNet);
+
+ log.info("-------------------------------Ended application termination behavior test case-------------------------------");
+
+ } catch (Exception e) {
+ log.error("An error occurred while handling application termination behavior", e);
+ assertTrue("An error occurred while handling application termination behavior", false);
+ }
+ }
+
+ private void assertGroupInactive(String groupId, String clusterId) {
+ long startTime = System.currentTimeMillis();
+ Map<String, Long> inActiveMap = TopologyHandler.getInstance().getInActiveMembers();
+
+ while(!inActiveMap.containsKey(clusterId)) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ignore) {
+ }
+ inActiveMap = TopologyHandler.getInstance().getInActiveMembers();
+ if ((System.currentTimeMillis() - startTime) > GROUP_INACTIVE_TIMEOUT) {
+ break;
+ }
+ }
+ assertTrue(inActiveMap.containsKey(clusterId));
+
+ while(!inActiveMap.containsKey(groupId)) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ignore) {
+ }
+ inActiveMap = TopologyHandler.getInstance().getInActiveMembers();
+ if ((System.currentTimeMillis() - startTime) > GROUP_INACTIVE_TIMEOUT) {
+ break;
+ }
+ }
+ assertTrue(inActiveMap.containsKey(groupId));
+
+ }
+
+ private void assertTerminatingOfNodes(String groupId, List<String> clusterIds) {
+ Map<String, Long> terminatingMembers = TopologyHandler.getInstance().getTerminatingMembers();
+ for(String clusterId : clusterIds) {
+ long startTime = System.currentTimeMillis();
+ while(!terminatingMembers.containsKey(clusterId)) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ignore) {
+ }
+ terminatingMembers = TopologyHandler.getInstance().getTerminatingMembers();
+ if ((System.currentTimeMillis() - startTime) > GROUP_INACTIVE_TIMEOUT) {
+ break;
+ }
+ }
+ assertTrue(terminatingMembers.containsKey(groupId));
+ }
+ long startTime = System.currentTimeMillis();
+ while(!terminatingMembers.containsKey(groupId)) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ignore) {
+ }
+ terminatingMembers = TopologyHandler.getInstance().getTerminatingMembers();
+ if ((System.currentTimeMillis() - startTime) > GROUP_INACTIVE_TIMEOUT) {
+ break;
+ }
+ }
+ assertTrue(terminatingMembers.containsKey(groupId));
+
+ }
+
+ private void assertTerminationOfNodes(String groupId, List<String> clusterIds) {
+ long startTime = System.currentTimeMillis();
+ Map<String, Long> terminatedMembers = TopologyHandler.getInstance().getTerminatedMembers();
+
+ for(String clusterId : clusterIds) {
+ while(!terminatedMembers.containsKey(clusterId)) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ignore) {
+ }
+ terminatedMembers = TopologyHandler.getInstance().getTerminatedMembers();
+ if ((System.currentTimeMillis() - startTime) > GROUP_INACTIVE_TIMEOUT) {
+ break;
+ }
+ }
+ assertTrue(terminatedMembers.containsKey(clusterId));
+ }
+
+ while(!terminatedMembers.containsKey(groupId)) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ignore) {
+ }
+ terminatedMembers = TopologyHandler.getInstance().getTerminatedMembers();
+ if ((System.currentTimeMillis() - startTime) > GROUP_INACTIVE_TIMEOUT) {
+ break;
+ }
+ }
+
+ assertTrue(terminatedMembers.containsKey(groupId));
+ }
+
+ private void assertCreationOfNodes(String firstNodeId, String secondNodeId) {
+ //group1 started first, then cluster started later
+
+ Map<String, Long> activeMembers = TopologyHandler.getInstance().getActivateddMembers();
+ Map<String, Long> createdMembers = TopologyHandler.getInstance().getCreatedMembers();
+ //Active member should be available at the time cluster is started to create.
+ assertTrue(activeMembers.containsKey(firstNodeId));
+ assertTrue(createdMembers.containsKey(secondNodeId));
+
+ assertTrue(createdMembers.get(secondNodeId) > activeMembers.get(firstNodeId));
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/512280af/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionOneAfterAnotherClusterTest.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionOneAfterAnotherClusterTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionOneAfterAnotherClusterTest.java
index d8f6965..1e8324e 100644
--- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionOneAfterAnotherClusterTest.java
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionOneAfterAnotherClusterTest.java
@@ -52,7 +52,7 @@ public class PartitionOneAfterAnotherClusterTest extends StratosTestServerManage
public void testDeployApplication() {
try {
log.info("-------------------------------Started Partition One after another test case-------------------------------");
-
+ TopologyHandler topologyHandler = TopologyHandler.getInstance();
String autoscalingPolicyId = "autoscaling-policy-3";
boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH
@@ -101,11 +101,11 @@ public class PartitionOneAfterAnotherClusterTest extends StratosTestServerManage
assertEquals(deployed, true);
//Application active handling
- TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId(),
+ topologyHandler.assertApplicationStatus(bean.getApplicationId(),
ApplicationStatus.Active);
//Cluster active handling
- TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId());
+ topologyHandler.assertClusterActivation(bean.getApplicationId());
//Verifying whether members got created using round robin algorithm
assertClusterWithRoundRobinAlgorithm(bean.getApplicationId());
@@ -135,7 +135,7 @@ public class PartitionOneAfterAnotherClusterTest extends StratosTestServerManage
RestConstants.APPLICATIONS_NAME);
assertEquals(unDeployed, true);
- boolean undeploy = TopologyHandler.getInstance().assertApplicationUndeploy("single-cluster-scaling-test");
+ boolean undeploy = topologyHandler.assertApplicationUndeploy("single-cluster-scaling-test");
if (!undeploy) {
//Need to forcefully undeploy the application
log.info("Force undeployment is going to start for the [application] " + "single-cluster-scaling-test");
@@ -143,7 +143,7 @@ public class PartitionOneAfterAnotherClusterTest extends StratosTestServerManage
restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + "single-cluster-scaling-test" +
RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS);
- boolean forceUndeployed = TopologyHandler.getInstance().assertApplicationUndeploy("single-cluster-scaling-test");
+ boolean forceUndeployed = topologyHandler.assertApplicationUndeploy("single-cluster-scaling-test");
assertEquals(String.format("Forceful undeployment failed for the application %s",
"single-cluster-scaling-test"), forceUndeployed, true);
http://git-wip-us.apache.org/repos/asf/stratos/blob/512280af/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTest.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTest.java
index ab7d592..3c0cee1 100644
--- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTest.java
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTest.java
@@ -52,7 +52,7 @@ public class PartitionRoundRobinClusterTest extends StratosTestServerManager {
public void testDeployApplication() {
try {
log.info("-------------------------------Started application Bursting test case-------------------------------");
-
+ TopologyHandler topologyHandler = TopologyHandler.getInstance();
String autoscalingPolicyId = "autoscaling-policy-partition-round-robin-test";
boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH
@@ -97,11 +97,11 @@ public class PartitionRoundRobinClusterTest extends StratosTestServerManager {
//Application active handling
- TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId(),
+ topologyHandler.assertApplicationStatus(bean.getApplicationId(),
ApplicationStatus.Active);
//Cluster active handling
- TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId());
+ topologyHandler.assertClusterActivation(bean.getApplicationId());
//Verifying whether members got created using round robin algorithm
assertClusterWithRoundRobinAlgorithm(bean.getApplicationId());
@@ -109,15 +109,15 @@ public class PartitionRoundRobinClusterTest extends StratosTestServerManager {
//Application in-active handling
log.info("Waiting for the faulty member detection from " +
"CEP as the statistics are stopped...");
- TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId(),
+ topologyHandler.assertApplicationStatus(bean.getApplicationId(),
ApplicationStatus.Inactive);
//Application active handling after application becomes active again
- TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId(),
+ topologyHandler.assertApplicationStatus(bean.getApplicationId(),
ApplicationStatus.Active);
//Cluster active handling
- TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId());
+ topologyHandler.assertClusterActivation(bean.getApplicationId());
boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
@@ -141,7 +141,7 @@ public class PartitionRoundRobinClusterTest extends StratosTestServerManager {
RestConstants.APPLICATIONS_NAME);
assertEquals(unDeployed, true);
- boolean undeploy = TopologyHandler.getInstance().assertApplicationUndeploy("partition-round-robin-test");
+ boolean undeploy = topologyHandler.assertApplicationUndeploy("partition-round-robin-test");
if (!undeploy) {
//Need to forcefully undeploy the application
log.info("Force undeployment is going to start for the [application] " + "partition-round-robin-test");
@@ -149,7 +149,7 @@ public class PartitionRoundRobinClusterTest extends StratosTestServerManager {
restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + "partition-round-robin-test" +
RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS);
- boolean forceUndeployed = TopologyHandler.getInstance().assertApplicationUndeploy("partition-round-robin-test");
+ boolean forceUndeployed = topologyHandler.assertApplicationUndeploy("partition-round-robin-test");
assertEquals(String.format("Forceful undeployment failed for the application %s",
"partition-round-robin-test"), forceUndeployed, true);
http://git-wip-us.apache.org/repos/asf/stratos/blob/512280af/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java
index f5fba7c..5a89d67 100644
--- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java
@@ -54,7 +54,7 @@ public class SingleClusterScalingTest extends StratosTestServerManager {
public void testDeployApplication() {
try {
log.info("-------------------------------Started application Bursting test case-------------------------------");
-
+ TopologyHandler topologyHandler = TopologyHandler.getInstance();
String autoscalingPolicyId = "autoscaling-policy-single-cluster-scaling-test";
boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH
@@ -103,11 +103,11 @@ public class SingleClusterScalingTest extends StratosTestServerManager {
assertEquals(deployed, true);
//Application active handling
- TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId()
+ topologyHandler.assertApplicationStatus(bean.getApplicationId()
, ApplicationStatus.Active);
//Cluster active handling
- TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId());
+ topologyHandler.assertClusterActivation(bean.getApplicationId());
//Verifying whether members got created using round robin algorithm
assertClusterWithScalingup(bean.getApplicationId());
@@ -134,7 +134,7 @@ public class SingleClusterScalingTest extends StratosTestServerManager {
RestConstants.APPLICATIONS_NAME);
assertEquals(unDeployed, true);
- boolean undeploy = TopologyHandler.getInstance().assertApplicationUndeploy("single-cluster-scaling-test");
+ boolean undeploy = topologyHandler.assertApplicationUndeploy("single-cluster-scaling-test");
if (!undeploy) {
//Need to forcefully undeploy the application
log.info("Force undeployment is going to start for the [application] " + "single-cluster-scaling-test");
@@ -142,7 +142,7 @@ public class SingleClusterScalingTest extends StratosTestServerManager {
restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + "single-cluster-scaling-test" +
RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS);
- boolean forceUndeployed = TopologyHandler.getInstance().assertApplicationUndeploy("single-cluster-scaling-test");
+ boolean forceUndeployed = topologyHandler.assertApplicationUndeploy("single-cluster-scaling-test");
assertEquals(String.format("Forceful undeployment failed for the application %s",
"single-cluster-scaling-test"), forceUndeployed, true);
http://git-wip-us.apache.org/repos/asf/stratos/blob/512280af/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java
index ccaeaf6..60db78f 100644
--- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java
@@ -19,6 +19,7 @@
package org.apache.stratos.integration.tests.group;
+import com.google.gson.reflect.TypeToken;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean;
@@ -26,8 +27,11 @@ import org.apache.stratos.integration.tests.RestConstants;
import org.apache.stratos.integration.tests.StratosTestServerManager;
import org.testng.annotations.Test;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertTrue;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import static junit.framework.Assert.*;
/**
* Test to handle Cartridge group CRUD operations
@@ -44,26 +48,26 @@ public class CartridgeGroupTest extends StratosTestServerManager {
boolean addedC1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH +
"/" + "c4-cartridge-group-test.json",
RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
- assertEquals(String.format("Cartridge did not added: [cartridge-name] %s",
- "c4-cartridge-group-test"), addedC1, true);
+ assertTrue(String.format("Cartridge did not added: [cartridge-name] %s",
+ "c4-cartridge-group-test"), addedC1);
boolean addedC2 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH +
"/" + "c5-cartridge-group-test.json",
RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
- assertEquals(String.format("Cartridge did not added: [cartridge-name] %s",
- "c5-cartridge-group-test"), addedC2, true);
+ assertTrue(String.format("Cartridge did not added: [cartridge-name] %s",
+ "c5-cartridge-group-test"), addedC2);
boolean addedC3 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH +
"/" + "c6-cartridge-group-test.json",
RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
- assertEquals(String.format("Cartridge did not added: [cartridge-name] %s",
- "c6-cartridge-group-test"), addedC3, true);
+ assertTrue(String.format("Cartridge did not added: [cartridge-name] %s",
+ "c6-cartridge-group-test"), addedC3);
boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
"/" + "g4-g5-g6-cartridge-group-test.json", RestConstants.CARTRIDGE_GROUPS,
RestConstants.CARTRIDGE_GROUPS_NAME);
- assertEquals(String.format("Cartridge Group did not added: [cartridge-group-name] %s",
- "g4-g5-g6-cartridge-group-test"), added, true);
+ assertTrue(String.format("Cartridge Group did not added: [cartridge-group-name] %s",
+ "g4-g5-g6-cartridge-group-test"), added);
CartridgeGroupBean bean = (CartridgeGroupBean) restClient.
getEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test",
@@ -74,8 +78,8 @@ public class CartridgeGroupTest extends StratosTestServerManager {
boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
"/" + "g4-g5-g6-cartridge-group-test-v1.json",
RestConstants.CARTRIDGE_GROUPS, RestConstants.CARTRIDGE_GROUPS_NAME);
- assertEquals(String.format("Cartridge Group did not updated: [cartridge-group-name] %s",
- "g4-g5-g6-cartridge-group-test"), updated, true);
+ assertTrue(String.format("Cartridge Group did not updated: [cartridge-group-name] %s",
+ "g4-g5-g6-cartridge-group-test"), updated);
CartridgeGroupBean updatedBean = (CartridgeGroupBean) restClient.
getEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test",
@@ -85,25 +89,25 @@ public class CartridgeGroupTest extends StratosTestServerManager {
boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test",
RestConstants.CARTRIDGE_GROUPS_NAME);
- assertEquals(String.format("Cartridge can be removed while it is used in " +
- "cartridge group: [cartridge-name] %s", "c4-cartridge-group-test"), removedC1, false);
+ assertFalse(String.format("Cartridge can be removed while it is used in " +
+ "cartridge group: [cartridge-name] %s", "c4-cartridge-group-test"), removedC1);
boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test",
RestConstants.CARTRIDGE_GROUPS_NAME);
- assertEquals(String.format("Cartridge can be removed while it is used in " +
+ assertFalse(String.format("Cartridge can be removed while it is used in " +
"cartridge group: [cartridge-name] %s",
- "c5-cartridge-group-test"), removedC2, false);
+ "c5-cartridge-group-test"), removedC2);
boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test",
RestConstants.CARTRIDGE_GROUPS_NAME);
- assertEquals(String.format("Cartridge can be removed while it is used in " +
+ assertFalse(String.format("Cartridge can be removed while it is used in " +
"cartridge group: [cartridge-name] %s",
- "c6-cartridge-group-test"), removedC3, false);
+ "c6-cartridge-group-test"), removedC3);
boolean removed = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test",
RestConstants.CARTRIDGE_GROUPS_NAME);
- assertEquals(String.format("Cartridge Group did not removed: [cartridge-group-name] %s",
- "g4-g5-g6-cartridge-group-test"), removed, true);
+ assertTrue(String.format("Cartridge Group did not removed: [cartridge-group-name] %s",
+ "g4-g5-g6-cartridge-group-test"), removed);
CartridgeGroupBean beanRemoved = (CartridgeGroupBean) restClient.
getEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test",
@@ -114,24 +118,149 @@ public class CartridgeGroupTest extends StratosTestServerManager {
removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test",
RestConstants.CARTRIDGE_GROUPS_NAME);
- assertEquals(String.format("Cartridge can not be removed : [cartridge-name] %s",
- "c4-cartridge-group-test"), removedC1, true);
+ assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s",
+ "c4-cartridge-group-test"), removedC1);
removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test",
RestConstants.CARTRIDGE_GROUPS_NAME);
- assertEquals(String.format("Cartridge can not be removed : [cartridge-name] %s",
- "c5-cartridge-group-test"), removedC2, true);
+ assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s",
+ "c5-cartridge-group-test"), removedC2);
removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test",
RestConstants.CARTRIDGE_GROUPS_NAME);
- assertEquals(String.format("Cartridge can not be removed : [cartridge-name] %s",
- "c6-cartridge-group-test"), removedC3, true);
+ assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s",
+ "c6-cartridge-group-test"), removedC3);
log.info("-------------------------Ended Cartridge group test case-------------------------");
} catch (Exception e) {
log.error("An error occurred while handling Cartridge group test case", e);
- assertTrue("An error occurred while handling Cartridge group test case", false);
+ assertFalse("An error occurred while handling Cartridge group test case", false);
+ }
+ }
+
+ @Test
+ public void testCartridgeGroupList() {
+ try {
+ log.info("-------------------------Started Cartridge group list test case-------------------------");
+
+ boolean addedC1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH +
+ "/" + "c4-cartridge-group-test.json",
+ RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+ assertTrue(String.format("Cartridge did not added: [cartridge-name] %s",
+ "c4-cartridge-group-test"), addedC1);
+
+ boolean addedC2 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH +
+ "/" + "c5-cartridge-group-test.json",
+ RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+ assertTrue(String.format("Cartridge did not added: [cartridge-name] %s",
+ "c5-cartridge-group-test"), addedC2);
+
+ boolean addedC3 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH +
+ "/" + "c6-cartridge-group-test.json",
+ RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+ assertTrue(String.format("Cartridge did not added: [cartridge-name] %s",
+ "c6-cartridge-group-test"), addedC3);
+
+ String group1 = "group-1-cartridge-group-test";
+ String group2 = "group-2-cartridge-group-test";
+
+ boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
+ "/" + group1 + ".json", RestConstants.CARTRIDGE_GROUPS,
+ RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertTrue(String.format("Cartridge Group did not added: [cartridge-group-name] %s",
+ group1), added);
+
+ added = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
+ "/" + group2 + ".json", RestConstants.CARTRIDGE_GROUPS,
+ RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertTrue(String.format("Cartridge Group did not added: [cartridge-group-name] %s",
+ group1), added);
+
+ Type listType = new TypeToken<ArrayList<CartridgeGroupBean>>() {
+ }.getType();
+
+ List<CartridgeGroupBean> cartridgeGroupList = (List<CartridgeGroupBean>) restClient.
+ listEntity(RestConstants.CARTRIDGE_GROUPS,
+ listType, RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertEquals(cartridgeGroupList.size(), 2);
+
+ CartridgeGroupBean bean1 = null;
+ for (CartridgeGroupBean cartridgeGroupBean : cartridgeGroupList) {
+ if (cartridgeGroupBean.getName().equals(group1)) {
+ bean1 = cartridgeGroupBean;
+ }
+ }
+ assertNotNull(bean1);
+
+ CartridgeGroupBean bean2 = null;
+ for (CartridgeGroupBean cartridgeGroupBean : cartridgeGroupList) {
+ if (cartridgeGroupBean.getName().equals(group2)) {
+ bean2 = cartridgeGroupBean;
+ }
+ }
+ assertNotNull(bean2);
+
+ boolean removed = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, group1,
+ RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertTrue(String.format("Cartridge Group did not removed: [cartridge-group-name] %s",
+ group1), removed);
+
+ CartridgeGroupBean beanRemoved = (CartridgeGroupBean) restClient.
+ getEntity(RestConstants.CARTRIDGE_GROUPS, group1,
+ CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertNull(String.format("Cartridge Group did not removed completely: " +
+ "[cartridge-group-name] %s",
+ group1), beanRemoved);
+
+ boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test",
+ RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertFalse(String.format("Cartridge can be removed while it is used in " +
+ "cartridge group: [cartridge-name] %s", "c4-cartridge-group-test"), removedC1);
+
+ boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test",
+ RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertFalse(String.format("Cartridge can be removed while it is used in " +
+ "cartridge group: [cartridge-name] %s",
+ "c5-cartridge-group-test"), removedC2);
+
+ boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test",
+ RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertFalse(String.format("Cartridge can be removed while it is used in " +
+ "cartridge group: [cartridge-name] %s",
+ "c6-cartridge-group-test"), removedC3);
+
+ removed = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, group2,
+ RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertTrue(String.format("Cartridge Group did not removed: [cartridge-group-name] %s",
+ group2), removed);
+
+ beanRemoved = (CartridgeGroupBean) restClient.
+ getEntity(RestConstants.CARTRIDGE_GROUPS, group2,
+ CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertNull(String.format("Cartridge Group did not removed completely: " +
+ "[cartridge-group-name] %s",
+ group2), beanRemoved);
+
+ removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test",
+ RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s",
+ "c4-cartridge-group-test"), removedC1);
+
+ removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test",
+ RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s",
+ "c5-cartridge-group-test"), removedC2);
+
+ removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test",
+ RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s",
+ "c6-cartridge-group-test"), removedC3);
+
+ log.info("-------------------------Ended Cartridge group list test case-------------------------");
+ } catch (Exception e) {
+ log.error("An error occurred while handling Cartridge list group test case", e);
+ assertFalse("An error occurred while handling Cartridge list group test case", false);
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/512280af/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java
index ac39161..7b413c1 100644
--- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java
@@ -19,6 +19,7 @@
package org.apache.stratos.integration.tests.group;
+import com.google.gson.reflect.TypeToken;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.common.beans.PropertyBean;
@@ -27,8 +28,11 @@ import org.apache.stratos.integration.tests.RestConstants;
import org.apache.stratos.integration.tests.StratosTestServerManager;
import org.testng.annotations.Test;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertTrue;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import static junit.framework.Assert.*;
/**
* Test to handle Cartridge CRUD operations
@@ -127,4 +131,69 @@ public class CartridgeTest extends StratosTestServerManager {
assertTrue("An error occurred while handling RESTConstants.CARTRIDGES_PATH", false);
}
}
+
+ @Test
+ public void testCartridgeList() {
+ log.info("--------------------Started Cartridge list test case-----------------------------");
+
+ try {
+ String cartridgeType1 = "c1-cartridge-test";
+ String cartridgeType2 = "c2-cartridge-test";
+ boolean added1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" +
+ cartridgeType1 + ".json",
+ RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+ assertEquals(added1, true);
+
+ boolean added2 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" +
+ cartridgeType2 + ".json",
+ RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+ assertEquals(added2, true);
+
+ Type listType = new TypeToken<ArrayList<CartridgeBean>>() {
+ }.getType();
+
+ List<CartridgeBean> cartridgeList = (List<CartridgeBean>) restClient.listEntity(RestConstants.CARTRIDGES,
+ listType, RestConstants.CARTRIDGES_NAME);
+ assertEquals(cartridgeList.size(), 2);
+
+ CartridgeBean bean1 = null;
+ for (CartridgeBean cartridgeBean : cartridgeList) {
+ if (cartridgeBean.getType().equals(cartridgeType1)) {
+ bean1 = cartridgeBean;
+ }
+ }
+ assertNotNull(bean1);
+
+ CartridgeBean bean2 = null;
+ for (CartridgeBean cartridgeBean : cartridgeList) {
+ if (cartridgeBean.getType().equals(cartridgeType1)) {
+ bean2 = cartridgeBean;
+ }
+ }
+ assertNotNull(bean2);
+
+ boolean removed = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeType1,
+ RestConstants.CARTRIDGES_NAME);
+ assertEquals(removed, true);
+
+ CartridgeBean beanRemoved = (CartridgeBean) restClient.
+ getEntity(RestConstants.CARTRIDGES, cartridgeType1,
+ CartridgeBean.class, RestConstants.CARTRIDGES_NAME);
+ assertEquals(beanRemoved, null);
+
+ removed = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeType2,
+ RestConstants.CARTRIDGES_NAME);
+ assertEquals(removed, true);
+
+ beanRemoved = (CartridgeBean) restClient.
+ getEntity(RestConstants.CARTRIDGES, cartridgeType2,
+ CartridgeBean.class, RestConstants.CARTRIDGES_NAME);
+ assertEquals(beanRemoved, null);
+
+ log.info("---------------------------Ended Cartridge list test case-------------------------");
+ } catch (Exception e) {
+ log.error("An error occurred while handling Cartridges list", e);
+ assertTrue("An error occurred while handling Cartridges list", false);
+ }
+ }
}