Updated Branches: refs/heads/master 2231b6e40 -> b0c11fdda
Adding deployment test cases Signed-off-by: Lahiru Sandaruwan <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/01001cf9 Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/01001cf9 Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/01001cf9 Branch: refs/heads/master Commit: 01001cf9fe7ffc0036b434bc30a605fb797cfe60 Parents: a6610f1 Author: Melan Nimesh <[email protected]> Authored: Tue Jan 7 17:51:59 2014 +0530 Committer: Lahiru Sandaruwan <[email protected]> Committed: Tue Jan 7 18:16:47 2014 +0530 ---------------------------------------------------------------------- products/autoscaler/modules/integration/pom.xml | 17 +++- .../tests/AutoscalerTestServerManager.java | 20 +++-- .../AutoscalingPolicyDeploymentTestCase.java | 82 +++++++++++++++++++ .../DeploymentPolicyDeploymentTestCase.java | 60 ++++++++++++++ .../tests/PartitionDeploymentTestCase.java | 70 ++++++++++++++++ .../resources/CloudControllerService_1.0.0.aar | Bin 0 -> 313389 bytes .../src/test/resources/autoscaler.xml | 34 ++++++++ .../integration/src/test/resources/testng.xml | 58 ++++++------- products/autoscaler/pom.xml | 1 + 9 files changed, 306 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/01001cf9/products/autoscaler/modules/integration/pom.xml ---------------------------------------------------------------------- diff --git a/products/autoscaler/modules/integration/pom.xml b/products/autoscaler/modules/integration/pom.xml index bdef4a4..1e02456 100644 --- a/products/autoscaler/modules/integration/pom.xml +++ b/products/autoscaler/modules/integration/pom.xml @@ -198,14 +198,27 @@ <dependency> <groupId>org.apache.stratos</groupId> <artifactId>org.apache.stratos.messaging</artifactId> - <version>4.0.0-SNAPSHOT</version> + <version>${project.version}</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.stratos</groupId> + <artifactId>org.apache.stratos.cloud.controller.service.stub</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.stratos</groupId> + <artifactId>org.apache.stratos.autoscaler.service.stub</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + </dependencies> <properties> - <clarity.version>4.1.3</clarity.version> + <clarity.version>4.2.2</clarity.version> <carbon.kernel.version>4.2.0</carbon.kernel.version> </properties> http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/01001cf9/products/autoscaler/modules/integration/src/test/java/org/apache/stratos/autoscaler/integration/tests/AutoscalerTestServerManager.java ---------------------------------------------------------------------- diff --git a/products/autoscaler/modules/integration/src/test/java/org/apache/stratos/autoscaler/integration/tests/AutoscalerTestServerManager.java b/products/autoscaler/modules/integration/src/test/java/org/apache/stratos/autoscaler/integration/tests/AutoscalerTestServerManager.java index b69a84a..218b2b7 100644 --- a/products/autoscaler/modules/integration/src/test/java/org/apache/stratos/autoscaler/integration/tests/AutoscalerTestServerManager.java +++ b/products/autoscaler/modules/integration/src/test/java/org/apache/stratos/autoscaler/integration/tests/AutoscalerTestServerManager.java @@ -61,24 +61,22 @@ public class AutoscalerTestServerManager extends TestServerManager { String carbonHome = super.startServer(); System.setProperty("carbon.home", carbonHome); - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - throw new IOException(e); - } return carbonHome; } @Override - @AfterSuite(timeOut = 60000) + @AfterSuite(timeOut = 60000,dependsOnGroups= {"stratos.autoscaler"}) public void stopServer() throws Exception { + log.info("Stoping carbon server...."); super.stopServer(); if (builder.getFrameworkSettings().getEnvironmentSettings().is_builderEnabled()) { if (activeMqBroker != null) { + log.info("Stoping JMS Broker...."); Assert.assertTrue(activeMqBroker.stop(), "JMS Broker Stopping failed"); } } } + protected void copyArtifacts(String carbonHome) throws IOException { Assert.assertNotNull(carbonHome, "carbon home cannot be null"); @@ -86,10 +84,20 @@ public class AutoscalerTestServerManager extends TestServerManager { System.getProperty("basedir") + "src" + File.separator + "test" + File.separator + "resources" + File.separator ); String libDir = carbonHome + File.separator + "repository"+ File.separator + "components"+ File.separator + "lib"; String confDir = carbonHome + File.separator + "repository"+ File.separator + "conf"; + + //FIXME: provider a way to configure carbon startup script filename inside test framework rather than copying stratos.{sh,bat} to wso2server.{sh,bat} + FileUtils.copyFile(new File(carbonHome + File.separator + "bin","stratos.sh"),new File(carbonHome + File.separator + "bin","wso2server.sh")); + FileUtils.copyFile(new File(carbonHome + File.separator + "bin","stratos.bat"),new File(carbonHome + File.separator + "bin","wso2server.bat")); + + //copy dummy CC service + FileUtils.copyFile(new File(resourceLocation,"CloudControllerService_1.0.0.aar"),new File(carbonHome + File.separator + "repository"+ File.separator + "deployment"+ File.separator + "server"+ File.separator + "axis2services","CloudControllerService.aar")); + log.info("Copying jndi.properties file...."); FileUtils.copyFile(new File(resourceLocation,"jndi.properties"),new File(confDir,"jndi.properties")); log.info("Copying ActiveMQ dependencies...."); FileUtils.copyDirectory(new File(resourceLocation + File.separator + "artifacts"+ File.separator + "jar"), new File(libDir)); + log.info("Copying autoscaler.xml...."); + FileUtils.copyFile(new File(resourceLocation,"autoscaler.xml"),new File(confDir,"autoscaler.xml")); } private JMSBrokerConfiguration getJMSBrokerConfiguration() { http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/01001cf9/products/autoscaler/modules/integration/src/test/java/org/apache/stratos/autoscaler/integration/tests/AutoscalingPolicyDeploymentTestCase.java ---------------------------------------------------------------------- diff --git a/products/autoscaler/modules/integration/src/test/java/org/apache/stratos/autoscaler/integration/tests/AutoscalingPolicyDeploymentTestCase.java b/products/autoscaler/modules/integration/src/test/java/org/apache/stratos/autoscaler/integration/tests/AutoscalingPolicyDeploymentTestCase.java new file mode 100644 index 0000000..45a899e --- /dev/null +++ b/products/autoscaler/modules/integration/src/test/java/org/apache/stratos/autoscaler/integration/tests/AutoscalingPolicyDeploymentTestCase.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.autoscaler.integration.tests; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy; +import org.apache.stratos.autoscaler.policy.model.LoadAverage; +import org.apache.stratos.autoscaler.policy.model.LoadThresholds; +import org.apache.stratos.autoscaler.policy.model.MemoryConsumption; +import org.apache.stratos.autoscaler.policy.model.RequestsInFlight; +import org.apache.stratos.autoscaler.stub.AutoScalerServiceStub; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * A test case which tests Autoscaling policy deployment + */ +public class AutoscalingPolicyDeploymentTestCase { + + private static final Log log = LogFactory.getLog(AutoscalingPolicyDeploymentTestCase.class); + + @Test(groups = {"stratos.autoscaler"}) + public void deploy() throws Exception { + log.info("Deploying autoscaling policy..."); + AutoScalerServiceStub stub = new AutoScalerServiceStub("https://localhost:9443/services/AutoScalerService"); + + AutoscalePolicy autoscalePolicy = new AutoscalePolicy(); + autoscalePolicy.setId("economyPolicy"); + LoadThresholds loadThresholds = new LoadThresholds(); + + LoadAverage loadAverage = new LoadAverage(); + loadAverage.setAverage(6000); + loadAverage.setGradient(0); + loadAverage.setSecondDerivative(0); + loadAverage.setScaleDownMarginOfGradient(1); + loadAverage.setScaleDownMarginOfSecondDerivative(0.2f); + loadThresholds.setLoadAverage(loadAverage); + + MemoryConsumption memoryConsumption = new MemoryConsumption(); + memoryConsumption.setAverage(6000); + memoryConsumption.setGradient(0); + memoryConsumption.setSecondDerivative(0); + memoryConsumption.setScaleDownMarginOfGradient(1); + memoryConsumption.setScaleDownMarginOfSecondDerivative(0.2f); + loadThresholds.setMemoryConsumption(memoryConsumption); + + RequestsInFlight requestsInFlight = new RequestsInFlight(); + requestsInFlight.setAverage(6000); + requestsInFlight.setGradient(0); + requestsInFlight.setSecondDerivative(0); + requestsInFlight.setScaleDownMarginOfGradient(1); + requestsInFlight.setScaleDownMarginOfSecondDerivative(0.2f); + loadThresholds.setRequestsInFlight(requestsInFlight); + + autoscalePolicy.setLoadThresholds(loadThresholds); + boolean deployed = stub.addAutoScalingPolicy(autoscalePolicy); + Assert.assertTrue(deployed, "Cannot deploy autoscaling-policy"); + + AutoscalePolicy policy = stub.getAutoscalingPolicy(autoscalePolicy.getId()); + Assert.assertNotNull(policy, "Cannot get deployed autoscaling-policy"); + + } + +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/01001cf9/products/autoscaler/modules/integration/src/test/java/org/apache/stratos/autoscaler/integration/tests/DeploymentPolicyDeploymentTestCase.java ---------------------------------------------------------------------- diff --git a/products/autoscaler/modules/integration/src/test/java/org/apache/stratos/autoscaler/integration/tests/DeploymentPolicyDeploymentTestCase.java b/products/autoscaler/modules/integration/src/test/java/org/apache/stratos/autoscaler/integration/tests/DeploymentPolicyDeploymentTestCase.java new file mode 100644 index 0000000..89e1d87 --- /dev/null +++ b/products/autoscaler/modules/integration/src/test/java/org/apache/stratos/autoscaler/integration/tests/DeploymentPolicyDeploymentTestCase.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.autoscaler.integration.tests; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy; +import org.apache.stratos.autoscaler.partition.PartitionGroup; +import org.apache.stratos.autoscaler.stub.AutoScalerServiceStub; +import org.apache.stratos.cloud.controller.deployment.partition.Partition; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * A test case which tests Autoscaling policy deployment + */ +public class DeploymentPolicyDeploymentTestCase { + + private static final Log log = LogFactory.getLog(DeploymentPolicyDeploymentTestCase.class); + + @Test(groups = { "stratos.autoscaler" }) + public void deploy() throws Exception { + log.info("Deploying deployment policy..."); + AutoScalerServiceStub stub = new AutoScalerServiceStub("https://localhost:9443/services/AutoScalerService"); + DeploymentPolicy deploymentPolicy = new DeploymentPolicy(); + deploymentPolicy.setId("isuruh-ec2"); + PartitionGroup group = new PartitionGroup(); + group.setId("ec2"); + group.setPartitionAlgo("one-after-another"); + Partition partition =new Partition(); + partition.setId("P1"); + partition.setPartitionMin(1); + partition.setPartitionMax(3); + group.setPartitions(new Partition[]{partition}); + deploymentPolicy.setPartitionGroups(new PartitionGroup[]{group}); + + boolean deployed = stub.addDeploymentPolicy(deploymentPolicy); + Assert.assertTrue(deployed, "Cannot deploy deployment-policy"); + + DeploymentPolicy policy = stub.getDeploymentPolicy(deploymentPolicy.getId()); + Assert.assertNotNull(policy, "Cannot get deployed deployment-policy"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/01001cf9/products/autoscaler/modules/integration/src/test/java/org/apache/stratos/autoscaler/integration/tests/PartitionDeploymentTestCase.java ---------------------------------------------------------------------- diff --git a/products/autoscaler/modules/integration/src/test/java/org/apache/stratos/autoscaler/integration/tests/PartitionDeploymentTestCase.java b/products/autoscaler/modules/integration/src/test/java/org/apache/stratos/autoscaler/integration/tests/PartitionDeploymentTestCase.java new file mode 100644 index 0000000..1ba9387 --- /dev/null +++ b/products/autoscaler/modules/integration/src/test/java/org/apache/stratos/autoscaler/integration/tests/PartitionDeploymentTestCase.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.autoscaler.integration.tests; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.autoscaler.stub.AutoScalerServiceStub; +import org.apache.stratos.cloud.controller.deployment.partition.Partition; +import org.apache.stratos.cloud.controller.pojo.Properties; +import org.apache.stratos.cloud.controller.pojo.Property; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * A test case which tests partitions deployment + */ +public class PartitionDeploymentTestCase { + + private static final Log log = LogFactory.getLog(PartitionDeploymentTestCase.class); + + @Test(groups = {"stratos.autoscaler"}) + public void deploy() throws Exception { + log.info("Deploying partition..."); + AutoScalerServiceStub stub = new AutoScalerServiceStub("https://localhost:9443/services/AutoScalerService"); + Partition partition = new Partition(); + partition.setId("P1"); + partition.setPartitionMax(3); + partition.setPartitionMin(1); + Properties properties = new Properties(); + Property region = new Property(); + region.setName("region"); + region.setValue("ap-southeast-1"); + properties.setProperties(new Property[]{region}); + partition.setProperties(properties); + partition.setProvider("ec2"); + + boolean deployed = stub.addPartition(partition); + Assert.assertTrue(deployed, "Cannot deploy partition"); + Partition[] allAvailablePartitions = stub.getAllAvailablePartitions(); + + //FIXME: getting deployed partition using stub.getPartition rather than + // iterates the partitions + for (Partition part : allAvailablePartitions) { + if(partition.getId().equals(part.getId())) + return; + } + Assert.fail("Cannot get deployed partition"); + + //Partition deployedPartition = stub.getPartition(partition.getId()); + //Assert.assertNotNull(deployedPartition, "Cannot get deployed partition"); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/01001cf9/products/autoscaler/modules/integration/src/test/resources/CloudControllerService_1.0.0.aar ---------------------------------------------------------------------- diff --git a/products/autoscaler/modules/integration/src/test/resources/CloudControllerService_1.0.0.aar b/products/autoscaler/modules/integration/src/test/resources/CloudControllerService_1.0.0.aar new file mode 100644 index 0000000..9038cfe Binary files /dev/null and b/products/autoscaler/modules/integration/src/test/resources/CloudControllerService_1.0.0.aar differ http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/01001cf9/products/autoscaler/modules/integration/src/test/resources/autoscaler.xml ---------------------------------------------------------------------- diff --git a/products/autoscaler/modules/integration/src/test/resources/autoscaler.xml b/products/autoscaler/modules/integration/src/test/resources/autoscaler.xml new file mode 100644 index 0000000..13bf316 --- /dev/null +++ b/products/autoscaler/modules/integration/src/test/resources/autoscaler.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<configuration> + <autoscaler> + <rulesEvaluator> + <schedule> + <initialDelay>30</initialDelay> + <period>15</period> + </schedule> + </rulesEvaluator> + <cloudController> + <hostname>localhost</hostname> + <port>9443</port> + <clientTimeout>300000</clientTimeout> + </cloudController> + </autoscaler> +</configuration> http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/01001cf9/products/autoscaler/modules/integration/src/test/resources/testng.xml ---------------------------------------------------------------------- diff --git a/products/autoscaler/modules/integration/src/test/resources/testng.xml b/products/autoscaler/modules/integration/src/test/resources/testng.xml index 29d8751..973d5f5 100644 --- a/products/autoscaler/modules/integration/src/test/resources/testng.xml +++ b/products/autoscaler/modules/integration/src/test/resources/testng.xml @@ -1,33 +1,35 @@ <?xml version='1.0'?> <!-- - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - ---> + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> <!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" > -<suite name="Apache Stratos Autoscaler Test Suite"> - <test name="testing" preserve-order="true"> - <classes> - <class name="org.apache.stratos.autoscaler.integration.tests.AutoscalerTestServerManager"/> - <class name="org.apache.stratos.autoscaler.integration.tests.LoginLogoutTestCase"/> - <class name="org.apache.stratos.autoscaler.integration.tests.SecurityVerificationTestCase"/> - <class name="org.apache.stratos.autoscaler.integration.tests.TopologyEventsPublisherTestCase"></class> - </classes> - </test> +<suite name="Apache Stratos Autoscaler Test Suite" parallel="false"> + + <test name="autoscaler-test" preserve-order="true" parallel="false"> + <classes> + <class name="org.apache.stratos.autoscaler.integration.tests.AutoscalerTestServerManager"/> + <class name="org.apache.stratos.autoscaler.integration.tests.LoginLogoutTestCase" /> + <class name="org.apache.stratos.autoscaler.integration.tests.PartitionDeploymentTestCase" /> + <class name="org.apache.stratos.autoscaler.integration.tests.AutoscalingPolicyDeploymentTestCase"/> + <class name="org.apache.stratos.autoscaler.integration.tests.DeploymentPolicyDeploymentTestCase"/> + <class name="org.apache.stratos.autoscaler.integration.tests.SecurityVerificationTestCase" /> + <!--class name="org.apache.stratos.autoscaler.integration.tests.TopologyEventsPublisherTestCase" /--> + </classes> + </test> </suite> http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/01001cf9/products/autoscaler/pom.xml ---------------------------------------------------------------------- diff --git a/products/autoscaler/pom.xml b/products/autoscaler/pom.xml index b93932e..2df6086 100644 --- a/products/autoscaler/pom.xml +++ b/products/autoscaler/pom.xml @@ -38,6 +38,7 @@ <modules> <module>modules/p2-profile</module> <module>modules/distribution</module> + <module>modules/integration</module> </modules> <pluginRepositories>
