http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/mariadb/MariaDbLiveRackspaceTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/mariadb/MariaDbLiveRackspaceTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/mariadb/MariaDbLiveRackspaceTest.java new file mode 100644 index 0000000..d5fcb25 --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/mariadb/MariaDbLiveRackspaceTest.java @@ -0,0 +1,104 @@ +/* + * 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.brooklyn.entity.database.mariadb; + +import java.util.Arrays; + +import org.apache.brooklyn.api.entity.proxying.EntitySpec; +import org.testng.annotations.Test; + +import org.apache.brooklyn.entity.database.DatastoreMixins.DatastoreCommon; +import org.apache.brooklyn.entity.database.VogellaExampleAccess; +import org.apache.brooklyn.location.basic.SshMachineLocation; +import org.apache.brooklyn.location.jclouds.JcloudsLocation; +import brooklyn.util.net.Protocol; +import brooklyn.util.ssh.IptablesCommands; +import brooklyn.util.ssh.IptablesCommands.Chain; +import brooklyn.util.ssh.IptablesCommands.Policy; + +import com.google.common.collect.ImmutableList; + +/** + * The MariaDbLiveTest installs MariaDb on various operating systems like Ubuntu, CentOS, Red Hat etc. To make sure that + * MariaDb works like expected on these Operating Systems. + */ +public class MariaDbLiveRackspaceTest extends MariaDbIntegrationTest { + @Test(groups = {"Live"}) + public void test_Debian_6() throws Exception { + test("Debian 6"); + } + + @Test(groups = {"Live"}) + public void test_Ubuntu_10_0() throws Exception { + test("Ubuntu 10.0"); + } + + @Test(groups = {"Live", "Live-sanity"}) + public void test_Ubuntu_12_0() throws Exception { + test("Ubuntu 12.0"); + } + + @Test(groups = {"Live"}) + public void test_Ubuntu_13() throws Exception { + test("Ubuntu 13"); + } + + @Test(groups = {"Live"}) + public void test_CentOS_6() throws Exception { + test("CentOS 6"); + } + + @Test(groups = {"Live"}) + public void test_CentOS_5() throws Exception { + test("CentOS 5"); + } + + @Test(groups = {"Live"}) + public void test_Fedora() throws Exception { + test("Fedora "); + } + + @Test(groups = {"Live"}) + public void test_Red_Hat_Enterprise_Linux_6() throws Exception { + test("Red Hat Enterprise Linux 6"); + } + + @Test(groups = {"Live"}) + public void test_localhost() throws Exception { + super.test_localhost(); + } + + public void test(String osRegex) throws Exception { + MariaDbNode mariadb = tapp.createAndManageChild(EntitySpec.create(MariaDbNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, CREATION_SCRIPT)); + + brooklynProperties.put("brooklyn.location.jclouds.rackspace-cloudservers-uk.imageNameRegex", osRegex); + brooklynProperties.remove("brooklyn.location.jclouds.rackspace-cloudservers-uk.image-id"); + brooklynProperties.remove("brooklyn.location.jclouds.rackspace-cloudservers-uk.imageId"); + brooklynProperties.put("brooklyn.location.jclouds.rackspace-cloudservers-uk.inboundPorts", Arrays.asList(22, 3306)); + JcloudsLocation jcloudsLocation = (JcloudsLocation) managementContext.getLocationRegistry().resolve("jclouds:rackspace-cloudservers-uk"); + + tapp.start(ImmutableList.of(jcloudsLocation)); + + SshMachineLocation l = (SshMachineLocation) mariadb.getLocations().iterator().next(); + l.execCommands("add iptables rule", ImmutableList.of(IptablesCommands.insertIptablesRule(Chain.INPUT, Protocol.TCP, 3306, Policy.ACCEPT))); + + new VogellaExampleAccess("com.mysql.jdbc.Driver", mariadb.getAttribute(DatastoreCommon.DATASTORE_URL)).readModifyAndRevertDataBase(); + } +}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterIntegrationTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterIntegrationTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterIntegrationTest.java new file mode 100644 index 0000000..86764cf --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterIntegrationTest.java @@ -0,0 +1,44 @@ +/* + * 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.brooklyn.entity.database.mysql; + +import org.apache.brooklyn.api.entity.Entity; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; + +import brooklyn.entity.BrooklynAppLiveTestSupport; +import brooklyn.util.os.Os; + +public class MySqlClusterIntegrationTest extends BrooklynAppLiveTestSupport { + + @Test(groups = {"Integration"}) + public void test_localhost() throws Exception { + try { + MySqlClusterTestHelper.test(app, mgmt.getLocationRegistry().resolve("localhost")); + } finally { + for (Entity member : Iterables.getOnlyElement(app.getChildren()).getChildren()) { + String runDir = member.getAttribute(MySqlNode.RUN_DIR); + if (runDir != null) { + Os.deleteRecursively(runDir); + } + } + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterLiveEc2Test.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterLiveEc2Test.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterLiveEc2Test.java new file mode 100644 index 0000000..1849ab0 --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterLiveEc2Test.java @@ -0,0 +1,43 @@ +/* + * 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.brooklyn.entity.database.mysql; + +import org.testng.annotations.Test; + +import brooklyn.entity.AbstractEc2LiveTest; + +import org.apache.brooklyn.api.location.Location; + +@Test(groups = { "Live" }) +public class MySqlClusterLiveEc2Test extends AbstractEc2LiveTest { + + @Override + protected void doTest(Location loc) throws Exception { + MySqlClusterTestHelper.test(app, loc); + } + + @Override + @Test(enabled=false, groups = "Live") + public void test_Debian_7_2() throws Exception { } // Disabled because MySQl not available + + @Test(enabled=false) + public void testDummy() {} // Convince testng IDE integration that this really does have test methods + +} + http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterLiveSoftlayerTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterLiveSoftlayerTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterLiveSoftlayerTest.java new file mode 100644 index 0000000..a911200 --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterLiveSoftlayerTest.java @@ -0,0 +1,39 @@ +/* + * 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.brooklyn.entity.database.mysql; + +import org.testng.annotations.Test; + +import brooklyn.entity.AbstractSoftlayerLiveTest; + +import org.apache.brooklyn.api.location.Location; + +@Test(groups = { "Live" }) +public class MySqlClusterLiveSoftlayerTest extends AbstractSoftlayerLiveTest { + + @Override + protected void doTest(Location loc) throws Exception { + MySqlClusterTestHelper.test(app, loc); + } + + @Test(enabled=false) + public void testDummy() {} // Convince testng IDE integration that this really does have test methods + +} + http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterTestHelper.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterTestHelper.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterTestHelper.java new file mode 100644 index 0000000..4080173 --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterTestHelper.java @@ -0,0 +1,115 @@ +/* + * 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.brooklyn.entity.database.mysql; + +import static org.testng.Assert.assertEquals; + +import java.util.List; + +import org.apache.brooklyn.api.entity.proxying.EntitySpec; +import org.apache.brooklyn.api.location.Location; +import org.apache.brooklyn.test.entity.TestApplication; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; + +import org.apache.brooklyn.entity.database.VogellaExampleAccess; +import brooklyn.test.Asserts; +import brooklyn.util.collections.MutableMap; +import brooklyn.util.exceptions.Exceptions; + +/** + * Runs a slightly modified version of the popular Vogella MySQL tutorial, + * from + * http://www.vogella.de/articles/MySQLJava/article.html + */ +public class MySqlClusterTestHelper { + public static final Logger log = LoggerFactory.getLogger(MySqlClusterTestHelper.class); + + // From http://www.vogella.de/articles/MySQLJava/article.html + public static final String CREATION_SCRIPT = Joiner.on("\n").join(ImmutableList.of( + "CREATE DATABASE feedback;", + "CREATE USER 'sqluser'@'localhost' IDENTIFIED BY 'sqluserpw';", + "GRANT USAGE ON *.* TO 'sqluser'@'localhost';", + "GRANT ALL PRIVILEGES ON feedback.* TO 'sqluser'@'localhost';", + "CREATE USER 'sqluser'@'%' IDENTIFIED BY 'sqluserpw';", + "GRANT USAGE ON *.* TO 'sqluser'@'%';", + "GRANT ALL PRIVILEGES ON feedback.* TO 'sqluser'@'%';", + "FLUSH PRIVILEGES;", + "USE feedback;", + "CREATE TABLE COMMENTS (", + " id INT NOT NULL AUTO_INCREMENT,", + " MYUSER VARCHAR(30) NOT NULL,", + " EMAIL VARCHAR(30), ", + " WEBPAGE VARCHAR(100) NOT NULL,", + " DATUM DATE NOT NULL, ", + " SUMMARY VARCHAR(40) NOT NULL,", + " COMMENTS VARCHAR(400) NOT NULL,", + " PRIMARY KEY (ID)", + " );", + "", + "INSERT INTO COMMENTS values (default, 'lars', '[email protected]','http://www.vogella.de', '2009-09-14 10:33:11', 'Summary','My first comment' );" + )); + + public static void test(TestApplication app, Location location) throws Exception { + MySqlCluster mysql = app.createAndManageChild(EntitySpec.create(MySqlCluster.class) + .configure(MySqlCluster.INITIAL_SIZE, 2) + .configure(MySqlNode.MYSQL_SERVER_CONF, MutableMap.<String, Object>of("skip-name-resolve",""))); + + app.start(ImmutableList.of(location)); + log.info("MySQL started"); + MySqlNode masterEntity = (MySqlNode) mysql.getAttribute(MySqlCluster.FIRST); + masterEntity.invoke(MySqlNode.EXECUTE_SCRIPT, ImmutableMap.of("commands", CREATION_SCRIPT)).asTask().getUnchecked(); + + VogellaExampleAccess masterDb = new VogellaExampleAccess("com.mysql.jdbc.Driver", mysql.getAttribute(MySqlNode.DATASTORE_URL)); + VogellaExampleAccess slaveDb = new VogellaExampleAccess("com.mysql.jdbc.Driver", Iterables.getOnlyElement(mysql.getAttribute(MySqlCluster.SLAVE_DATASTORE_URL_LIST))); + masterDb.connect(); + slaveDb.connect(); + + assertSlave(masterDb, slaveDb, 1); + masterDb.modifyDataBase(); + assertSlave(masterDb, slaveDb, 2); + masterDb.revertDatabase(); + assertSlave(masterDb, slaveDb, 1); + + masterDb.close(); + slaveDb.close(); + + log.info("Ran vogella MySQL example -- SUCCESS"); + } + + private static void assertSlave(final VogellaExampleAccess masterDb, final VogellaExampleAccess slaveDb, final int recordCnt) throws Exception { + Asserts.succeedsEventually(new Runnable() { + @Override + public void run() { + try { + List<List<String>> masterResult = masterDb.readDataBase(); + assertEquals(masterResult.size(), recordCnt); + assertEquals(masterResult, slaveDb.readDataBase()); + } catch (Exception e) { + throw Exceptions.propagate(e); + } + } + }); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlIntegrationTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlIntegrationTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlIntegrationTest.java new file mode 100644 index 0000000..d22a979 --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlIntegrationTest.java @@ -0,0 +1,106 @@ +/* + * 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.brooklyn.entity.database.mysql; + +import java.io.File; + +import org.apache.brooklyn.api.entity.proxying.EntitySpec; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.Test; + +import brooklyn.entity.BrooklynAppLiveTestSupport; +import org.apache.brooklyn.entity.database.VogellaExampleAccess; +import org.apache.brooklyn.location.basic.LocalhostMachineProvisioningLocation; +import brooklyn.util.collections.MutableMap; +import brooklyn.util.net.Networking; +import brooklyn.util.os.Os; + +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableList; +import com.google.common.io.Files; + +/** + * Runs a slightly modified version of the popular Vogella MySQL tutorial, + * from + * http://www.vogella.de/articles/MySQLJava/article.html + */ +public class MySqlIntegrationTest extends BrooklynAppLiveTestSupport { + + public static final Logger log = LoggerFactory.getLogger(MySqlIntegrationTest.class); + + // can start in AWS by running this -- or use brooklyn CLI/REST for most clouds, or programmatic/config for set of fixed IP machines + static String hostname = Networking.getLocalHost().getHostName(); + + // From http://www.vogella.de/articles/MySQLJava/article.html + // Expects COMMENTS to be injected as the test.table.name config value, for VogellaExampleAccess to work. + public static final String CREATION_SCRIPT = Joiner.on("\n").join(ImmutableList.of( + "CREATE DATABASE feedback;", + "CREATE USER 'sqluser'@'localhost' IDENTIFIED BY 'sqluserpw';", + "GRANT USAGE ON *.* TO 'sqluser'@'localhost';", + "GRANT ALL PRIVILEGES ON feedback.* TO 'sqluser'@'localhost';", + "CREATE USER 'sqluser'@'%' IDENTIFIED BY 'sqluserpw';", + "GRANT USAGE ON *.* TO 'sqluser'@'%';", + "GRANT ALL PRIVILEGES ON feedback.* TO 'sqluser'@'%';", + "CREATE USER 'sqluser'@'$hostname' IDENTIFIED BY 'sqluserpw';", + "GRANT USAGE ON *.* TO 'sqluser'@'$hostname';", + "GRANT ALL PRIVILEGES ON feedback.* TO 'sqluser'@'$hostname';", + "FLUSH PRIVILEGES;", + "USE feedback;", + "CREATE TABLE ${config['test.table.name']} (", + " id INT NOT NULL AUTO_INCREMENT,", + " MYUSER VARCHAR(30) NOT NULL,", + " EMAIL VARCHAR(30), ", + " WEBPAGE VARCHAR(100) NOT NULL,", + " DATUM DATE NOT NULL, ", + " SUMMARY VARCHAR(40) NOT NULL,", + " COMMENTS VARCHAR(400) NOT NULL,", + " PRIMARY KEY (ID)", + " );", + "", + "INSERT INTO ${config['test.table.name']} values (default, 'lars', '[email protected]','http://www.vogella.de', '2009-09-14 10:33:11', 'Summary','My first comment' );" + )); + + @Test(groups = {"Integration"}) + public void test_localhost() throws Exception { + File dataDir = Files.createTempDir(); + try { + MySqlNode mysql = app.createAndManageChild(EntitySpec.create(MySqlNode.class) + .configure("mysql.server.conf", MutableMap.of("skip-name-resolve","")) + .configure("creationScriptContents", CREATION_SCRIPT) + .configure("dataDir", dataDir.getAbsolutePath()) + .configure("test.table.name", "COMMENTS")); // to ensure creation script is templated + LocalhostMachineProvisioningLocation location = new LocalhostMachineProvisioningLocation(); + + app.start(ImmutableList.of(location));; + log.info("MySQL started"); + + new VogellaExampleAccess("com.mysql.jdbc.Driver", mysql.getAttribute(MySqlNode.DATASTORE_URL)).readModifyAndRevertDataBase(); + + log.info("Ran vogella MySQL example -- SUCCESS"); + + // Ensure the data directory was successfully overridden. + File mysqlSubdirFile = new File(dataDir, "mysql"); + Assert.assertTrue(mysqlSubdirFile.exists()); + } finally { + Os.deleteRecursively(dataDir); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlLiveEc2Test.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlLiveEc2Test.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlLiveEc2Test.java new file mode 100644 index 0000000..69afffc --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlLiveEc2Test.java @@ -0,0 +1,53 @@ +/* + * 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.brooklyn.entity.database.mysql; + +import org.apache.brooklyn.api.entity.proxying.EntitySpec; +import org.apache.brooklyn.api.location.Location; +import org.testng.annotations.Test; + +import brooklyn.entity.AbstractEc2LiveTest; +import org.apache.brooklyn.entity.database.DatastoreMixins.DatastoreCommon; +import org.apache.brooklyn.entity.database.VogellaExampleAccess; + +import com.google.common.collect.ImmutableList; + +@Test(groups = { "Live" }) +public class MySqlLiveEc2Test extends AbstractEc2LiveTest { + + @Override + protected void doTest(Location loc) throws Exception { + MySqlNode mysql = app.createAndManageChild(EntitySpec.create(MySqlNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, MySqlIntegrationTest.CREATION_SCRIPT) + .configure("test.table.name", "COMMENTS")); + + app.start(ImmutableList.of(loc)); + + new VogellaExampleAccess("com.mysql.jdbc.Driver", mysql.getAttribute(DatastoreCommon.DATASTORE_URL)).readModifyAndRevertDataBase(); + } + + @Override + @Test(enabled=false, groups = "Live") + public void test_Debian_7_2() throws Exception { } // Disabled because MySQl not available + + @Test(enabled=false) + public void testDummy() {} // Convince testng IDE integration that this really does have test methods + +} + http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlLiveGceTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlLiveGceTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlLiveGceTest.java new file mode 100644 index 0000000..3af4daa --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlLiveGceTest.java @@ -0,0 +1,49 @@ +/* + * 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.brooklyn.entity.database.mysql; + +import org.apache.brooklyn.api.entity.proxying.EntitySpec; +import org.apache.brooklyn.api.location.Location; +import org.testng.annotations.Test; + +import brooklyn.entity.AbstractGoogleComputeLiveTest; +import org.apache.brooklyn.entity.database.DatastoreMixins.DatastoreCommon; +import org.apache.brooklyn.entity.database.VogellaExampleAccess; + +import com.google.common.collect.ImmutableList; + +@Test(groups = { "Live" }) +public class MySqlLiveGceTest extends AbstractGoogleComputeLiveTest { + + @Override + protected void doTest(Location loc) throws Exception { + MySqlNode mysql = app.createAndManageChild(EntitySpec.create(MySqlNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, MySqlIntegrationTest.CREATION_SCRIPT) + .configure("test.table.name", "COMMENTS")); + + app.start(ImmutableList.of(loc)); + + new VogellaExampleAccess("com.mysql.jdbc.Driver", mysql.getAttribute(DatastoreCommon.DATASTORE_URL)).readModifyAndRevertDataBase(); + } + + @Test(enabled=false) + public void testDummy() {} // Convince testng IDE integration that this really does have test methods + +} + http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlLiveRackspaceTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlLiveRackspaceTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlLiveRackspaceTest.java new file mode 100644 index 0000000..26f9fb9 --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlLiveRackspaceTest.java @@ -0,0 +1,107 @@ +/* + * 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.brooklyn.entity.database.mysql; + +import java.util.Arrays; + +import org.apache.brooklyn.api.entity.proxying.EntitySpec; +import org.testng.annotations.Test; + +import brooklyn.config.BrooklynProperties; +import org.apache.brooklyn.entity.database.DatastoreMixins.DatastoreCommon; +import org.apache.brooklyn.entity.database.VogellaExampleAccess; +import org.apache.brooklyn.location.basic.SshMachineLocation; +import org.apache.brooklyn.location.jclouds.JcloudsLocation; +import brooklyn.util.net.Protocol; +import brooklyn.util.ssh.IptablesCommands; +import brooklyn.util.ssh.IptablesCommands.Chain; +import brooklyn.util.ssh.IptablesCommands.Policy; + +import com.google.common.collect.ImmutableList; + +/** + * The MySqlLiveTest installs MySQL on various operating systems like Ubuntu, CentOS, Red Hat etc. To make sure that + * MySQL works like expected on these Operating Systems. + */ +public class MySqlLiveRackspaceTest extends MySqlIntegrationTest { + @Test(groups = {"Live"}) + public void test_Debian_6() throws Exception { + test("Debian 6"); + } + + @Test(groups = {"Live"}) + public void test_Ubuntu_10_0() throws Exception { + test("Ubuntu 10.0"); + } + + @Test(groups = {"Live", "Live-sanity"}) + public void test_Ubuntu_12_0() throws Exception { + test("Ubuntu 12.0"); + } + + @Test(groups = {"Live"}) + public void test_Ubuntu_13() throws Exception { + test("Ubuntu 13"); + } + + @Test(groups = {"Live"}) + public void test_CentOS_6() throws Exception { + test("CentOS 6"); + } + + @Test(groups = {"Live"}) + public void test_CentOS_5() throws Exception { + test("CentOS 5"); + } + + @Test(groups = {"Live"}) + public void test_Fedora() throws Exception { + test("Fedora "); + } + + @Test(groups = {"Live"}) + public void test_Red_Hat_Enterprise_Linux_6() throws Exception { + test("Red Hat Enterprise Linux 6"); + } + + @Test(enabled=false, groups = {"Live"}) // only run this in MySqlIntegrationTest + public void test_localhost() throws Exception { + super.test_localhost(); + } + + public void test(String osRegex) throws Exception { + MySqlNode mysql = app.createAndManageChild(EntitySpec.create(MySqlNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, CREATION_SCRIPT) + .configure("test.table.name", "COMMENTS")); + + BrooklynProperties brooklynProperties = mgmt.getBrooklynProperties(); + brooklynProperties.put("brooklyn.location.jclouds.rackspace-cloudservers-uk.imageNameRegex", osRegex); + brooklynProperties.remove("brooklyn.location.jclouds.rackspace-cloudservers-uk.image-id"); + brooklynProperties.remove("brooklyn.location.jclouds.rackspace-cloudservers-uk.imageId"); + brooklynProperties.put("brooklyn.location.jclouds.rackspace-cloudservers-uk.inboundPorts", Arrays.asList(22, 3306)); + JcloudsLocation jcloudsLocation = (JcloudsLocation) mgmt.getLocationRegistry().resolve("jclouds:rackspace-cloudservers-uk"); + + app.start(ImmutableList.of(jcloudsLocation)); + + SshMachineLocation l = (SshMachineLocation) mysql.getLocations().iterator().next(); + l.execCommands("add iptables rule", ImmutableList.of(IptablesCommands.insertIptablesRule(Chain.INPUT, Protocol.TCP, 3306, Policy.ACCEPT))); + + new VogellaExampleAccess("com.mysql.jdbc.Driver", mysql.getAttribute(DatastoreCommon.DATASTORE_URL)).readModifyAndRevertDataBase(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlRestartIntegrationTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlRestartIntegrationTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlRestartIntegrationTest.java new file mode 100644 index 0000000..b0f0f72 --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlRestartIntegrationTest.java @@ -0,0 +1,42 @@ +/* + * 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.brooklyn.entity.database.mysql; + +import org.apache.brooklyn.api.entity.proxying.EntitySpec; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.Test; + +import brooklyn.entity.basic.AbstractSoftwareProcessRestartIntegrationTest; +import brooklyn.entity.basic.SoftwareProcess; + +/** + * Tests restart of the software *process* (as opposed to the VM). + */ +@Test(groups="Integration") +public class MySqlRestartIntegrationTest extends AbstractSoftwareProcessRestartIntegrationTest { + + @SuppressWarnings("unused") + private static final Logger LOG = LoggerFactory.getLogger(MySqlRestartIntegrationTest.class); + + @Override + protected EntitySpec<? extends SoftwareProcess> newEntitySpec() { + return EntitySpec.create(MySqlNode.class); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MysqlDockerLiveTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MysqlDockerLiveTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MysqlDockerLiveTest.java new file mode 100644 index 0000000..4bffa18 --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MysqlDockerLiveTest.java @@ -0,0 +1,48 @@ +/* + * 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.brooklyn.entity.database.mysql; + +import org.apache.brooklyn.entity.database.DatastoreMixins.DatastoreCommon; +import org.apache.brooklyn.entity.database.VogellaExampleAccess; +import brooklyn.entity.software.AbstractDockerLiveTest; + +import com.google.common.collect.ImmutableList; + +import org.apache.brooklyn.api.entity.proxying.EntitySpec; +import org.apache.brooklyn.api.location.Location; +import org.testng.annotations.Test; + +public class MysqlDockerLiveTest extends AbstractDockerLiveTest { + + @Override + protected void doTest(Location loc) throws Exception { + MySqlNode mysql = app.createAndManageChild(EntitySpec.create(MySqlNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, MySqlIntegrationTest.CREATION_SCRIPT) + .configure("test.table.name", "COMMENTS")); + + app.start(ImmutableList.of(loc)); + + new VogellaExampleAccess("com.mysql.jdbc.Driver", mysql.getAttribute(DatastoreCommon.DATASTORE_URL)) + .readModifyAndRevertDataBase(); + } + + @Test(enabled=false) + public void testDummy() { } // Convince testng IDE integration that this really does have test methods +} + http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqDockerLiveTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqDockerLiveTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqDockerLiveTest.java new file mode 100644 index 0000000..9789d18 --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqDockerLiveTest.java @@ -0,0 +1,46 @@ +/* + * 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.brooklyn.entity.database.postgresql; + +import org.apache.brooklyn.entity.database.DatastoreMixins.DatastoreCommon; +import org.apache.brooklyn.entity.database.VogellaExampleAccess; +import brooklyn.entity.software.AbstractDockerLiveTest; + +import com.google.common.collect.ImmutableList; + +import org.apache.brooklyn.api.entity.proxying.EntitySpec; +import org.apache.brooklyn.api.location.Location; +import org.testng.annotations.Test; + +public class PostgreSqDockerLiveTest extends AbstractDockerLiveTest { + + @Override + protected void doTest(Location loc) throws Exception { + PostgreSqlNode psql = app.createAndManageChild(EntitySpec.create(PostgreSqlNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, PostgreSqlIntegrationTest.CREATION_SCRIPT)); + + app.start(ImmutableList.of(loc)); + + new VogellaExampleAccess("org.postgresql.Driver", psql.getAttribute(DatastoreCommon.DATASTORE_URL)).readModifyAndRevertDataBase(); + } + + @Test(enabled=false) + public void testDummy() { } // Convince testng IDE integration that this really does have test methods +} + http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlChefTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlChefTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlChefTest.java new file mode 100644 index 0000000..1a75d88 --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlChefTest.java @@ -0,0 +1,105 @@ +/* + * 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.brooklyn.entity.database.postgresql; + +import java.util.Random; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.Test; + +import brooklyn.entity.basic.Entities; +import brooklyn.entity.chef.ChefLiveTestSupport; +import org.apache.brooklyn.entity.database.DatastoreMixins.DatastoreCommon; +import org.apache.brooklyn.entity.database.VogellaExampleAccess; +import brooklyn.entity.effector.EffectorTasks; +import brooklyn.entity.software.SshEffectorTasks; + +import org.apache.brooklyn.api.location.PortRange; +import org.apache.brooklyn.core.util.task.system.ProcessTaskWrapper; +import org.apache.brooklyn.location.basic.PortRanges; +import org.apache.brooklyn.location.basic.SshMachineLocation; + +import brooklyn.util.time.Duration; + +import com.google.common.collect.ImmutableList; + +/** + * Tests Chef installation of PostgreSql. Requires chef-server (knife). + * <p> + * To be able to run repeatedly on the same box, you will need the patched version of the postgresql library, + * at https://github.com/opscode-cookbooks/postgresql/pull/73 . + * + * @author alex + * + */ +public class PostgreSqlChefTest extends ChefLiveTestSupport { + + private static final Logger log = LoggerFactory.getLogger(PostgreSqlChefTest.class); + + PostgreSqlNode psql; + + @Test(groups="Live") + public void testPostgresStartsAndStops() throws Exception { + ChefLiveTestSupport.installBrooklynChefHostedConfig(app); + psql = app.createAndManageChild(PostgreSqlSpecs.specChef()); + + app.start(ImmutableList.of(targetLocation)); + + Entities.submit(psql, SshEffectorTasks.ssh("ps aux | grep [p]ostgres").requiringExitCodeZero()); + SshMachineLocation targetMachine = EffectorTasks.getSshMachine(psql); + + psql.stop(); + + try { + // if host is still contactable ensure postgres is not running + ProcessTaskWrapper<Integer> t = Entities.submit(app, SshEffectorTasks.ssh("ps aux | grep [p]ostgres").machine(targetMachine).allowingNonZeroExitCode()); + t.getTask().blockUntilEnded(Duration.TEN_SECONDS); + if (!t.isDone()) + Assert.fail("Task not finished yet: "+t.getTask()); + Assert.assertNotEquals(t.get(), (Integer)0, "Task ended with code "+t.get()+"; output: "+t.getStdout() ); + } catch (Exception e) { + // host has been killed, that is fine + log.info("Machine "+targetMachine+" destroyed on stop (expected - "+e+")"); + } + } + + @Test(groups="Live") + public void testPostgresScriptAndAccess() throws Exception { + ChefLiveTestSupport.installBrooklynChefHostedConfig(app); + PortRange randomPort = PortRanges.fromString(String.format("%d+", 5420 + new Random().nextInt(10))); + psql = app.createAndManageChild(PostgreSqlSpecs.specChef() + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, PostgreSqlIntegrationTest.CREATION_SCRIPT) + .configure(PostgreSqlNode.POSTGRESQL_PORT, randomPort) + .configure(PostgreSqlNode.SHARED_MEMORY, "8MB") + ); + + app.start(ImmutableList.of(targetLocation)); + + String url = psql.getAttribute(DatastoreCommon.DATASTORE_URL); + log.info("Trying to connect to "+psql+" at "+url); + Assert.assertNotNull(url); + Assert.assertTrue(url.contains("542")); + + new VogellaExampleAccess("org.postgresql.Driver", url).readModifyAndRevertDataBase(); + } + +} + http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlEc2LiveTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlEc2LiveTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlEc2LiveTest.java new file mode 100644 index 0000000..b65716b --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlEc2LiveTest.java @@ -0,0 +1,54 @@ +/* + * 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.brooklyn.entity.database.postgresql; + +import org.apache.brooklyn.api.entity.proxying.EntitySpec; +import org.apache.brooklyn.api.location.Location; +import org.testng.annotations.Test; + +import brooklyn.entity.AbstractEc2LiveTest; +import org.apache.brooklyn.entity.database.DatastoreMixins.DatastoreCommon; +import org.apache.brooklyn.entity.database.VogellaExampleAccess; + +import com.google.common.collect.ImmutableList; + +public class PostgreSqlEc2LiveTest extends AbstractEc2LiveTest { + + @Override + protected void doTest(Location loc) throws Exception { + PostgreSqlNode psql = app.createAndManageChild(EntitySpec.create(PostgreSqlNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, PostgreSqlIntegrationTest.CREATION_SCRIPT)); + + app.start(ImmutableList.of(loc)); + + new VogellaExampleAccess("org.postgresql.Driver", psql.getAttribute(DatastoreCommon.DATASTORE_URL)).readModifyAndRevertDataBase(); + } + + @Override + @Test(enabled=false, groups = "Live") + public void test_Debian_6() throws Exception { } // Disabled because PostgreSql 9.1 not available + + @Override + @Test(enabled=false, groups = "Live") + public void test_Ubuntu_10_0() throws Exception { } // Disabled because PostgreSql 9.1 not available + + @Test(enabled=false) + public void testDummy() { } // Convince testng IDE integration that this really does have test methods +} + http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlGceLiveTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlGceLiveTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlGceLiveTest.java new file mode 100644 index 0000000..bec33c1 --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlGceLiveTest.java @@ -0,0 +1,46 @@ +/* + * 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.brooklyn.entity.database.postgresql; + +import org.apache.brooklyn.api.entity.proxying.EntitySpec; +import org.apache.brooklyn.api.location.Location; +import org.testng.annotations.Test; + +import brooklyn.entity.AbstractGoogleComputeLiveTest; +import org.apache.brooklyn.entity.database.DatastoreMixins.DatastoreCommon; +import org.apache.brooklyn.entity.database.VogellaExampleAccess; + +import com.google.common.collect.ImmutableList; + +public class PostgreSqlGceLiveTest extends AbstractGoogleComputeLiveTest { + + @Override + protected void doTest(Location loc) throws Exception { + PostgreSqlNode psql = app.createAndManageChild(EntitySpec.create(PostgreSqlNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, PostgreSqlIntegrationTest.CREATION_SCRIPT)); + + app.start(ImmutableList.of(loc)); + + new VogellaExampleAccess("org.postgresql.Driver", psql.getAttribute(DatastoreCommon.DATASTORE_URL)).readModifyAndRevertDataBase(); + } + + @Test(enabled=false) + public void testDummy() { } // Convince testng IDE integration that this really does have test methods +} + http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlIntegrationTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlIntegrationTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlIntegrationTest.java new file mode 100644 index 0000000..ede5fec --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlIntegrationTest.java @@ -0,0 +1,96 @@ +/* + * 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.brooklyn.entity.database.postgresql; + +import org.apache.brooklyn.api.entity.proxying.EntitySpec; +import org.apache.brooklyn.api.management.ManagementContext; +import org.apache.brooklyn.core.management.internal.LocalManagementContext; +import org.apache.brooklyn.test.entity.TestApplication; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import brooklyn.config.BrooklynProperties; +import brooklyn.entity.basic.ApplicationBuilder; +import brooklyn.entity.basic.Entities; +import org.apache.brooklyn.entity.database.DatastoreMixins.DatastoreCommon; +import org.apache.brooklyn.entity.database.VogellaExampleAccess; +import org.apache.brooklyn.location.basic.LocalhostMachineProvisioningLocation; + +import com.google.common.collect.ImmutableList; + +/** + * Runs the popular Vogella MySQL tutorial against PostgreSQL + * from + * http://www.vogella.de/articles/MySQLJava/article.html + */ +public class PostgreSqlIntegrationTest { + + public static final Logger log = LoggerFactory.getLogger(PostgreSqlIntegrationTest.class); + + protected BrooklynProperties brooklynProperties; + protected ManagementContext managementContext; + protected TestApplication tapp; + + @BeforeMethod(alwaysRun = true) + public void setUp() { + brooklynProperties = BrooklynProperties.Factory.newDefault(); + managementContext = new LocalManagementContext(brooklynProperties); + tapp = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext); + } + + @AfterMethod(alwaysRun = true) + public void ensureShutDown() { + Entities.destroyAllCatching(managementContext); + } + + //from http://www.vogella.de/articles/MySQLJava/article.html + public static final String CREATION_SCRIPT = + "CREATE USER sqluser WITH PASSWORD 'sqluserpw';\n" + + "CREATE DATABASE feedback OWNER sqluser;\n" + + "\\c feedback;\n" + + "CREATE TABLE COMMENTS ( " + + "id INT8 NOT NULL, " + + "MYUSER VARCHAR(30) NOT NULL, " + + "EMAIL VARCHAR(30), " + + "WEBPAGE VARCHAR(100) NOT NULL, " + + "DATUM DATE NOT NULL, " + + "SUMMARY VARCHAR(40) NOT NULL, " + + "COMMENTS VARCHAR(400) NOT NULL, " + + "PRIMARY KEY (ID) " + + ");\n" + + "GRANT ALL ON comments TO sqluser;\n" + + "INSERT INTO COMMENTS values (1, 'lars', '[email protected]','http://www.vogella.de', '2009-09-14 10:33:11', 'Summary','My first comment' );"; + + @Test(groups = "Integration") + public void test_localhost() throws Exception { + PostgreSqlNode pgsql = tapp.createAndManageChild(EntitySpec.create(PostgreSqlNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, CREATION_SCRIPT) + .configure(PostgreSqlNode.MAX_CONNECTIONS, 10) + .configure(PostgreSqlNode.SHARED_MEMORY, "512kB")); // Very low so kernel configuration not needed + + tapp.start(ImmutableList.of(new LocalhostMachineProvisioningLocation())); + String url = pgsql.getAttribute(DatastoreCommon.DATASTORE_URL); + log.info("PostgreSql started on "+url); + new VogellaExampleAccess("org.postgresql.Driver", url).readModifyAndRevertDataBase(); + log.info("Ran vogella PostgreSql example -- SUCCESS"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlRackspaceLiveTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlRackspaceLiveTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlRackspaceLiveTest.java new file mode 100644 index 0000000..796c740 --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlRackspaceLiveTest.java @@ -0,0 +1,108 @@ +/* + * 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.brooklyn.entity.database.postgresql; + +import java.util.Arrays; + +import org.apache.brooklyn.api.entity.proxying.EntitySpec; +import org.testng.annotations.Test; + +import org.apache.brooklyn.entity.database.DatastoreMixins.DatastoreCommon; +import org.apache.brooklyn.entity.database.VogellaExampleAccess; +import org.apache.brooklyn.location.basic.PortRanges; +import org.apache.brooklyn.location.basic.SshMachineLocation; +import org.apache.brooklyn.location.jclouds.JcloudsLocation; +import brooklyn.util.net.Protocol; +import brooklyn.util.ssh.IptablesCommands; +import brooklyn.util.ssh.IptablesCommands.Chain; +import brooklyn.util.ssh.IptablesCommands.Policy; + +import com.google.common.collect.ImmutableList; + +/** + * The PostgreSqlRackspaceLiveTest installs Postgresql on various operating systems like Ubuntu, CentOS, Red Hat etc. To + * make sure that PostgreSql works like expected on these Operating Systems. + */ +public class PostgreSqlRackspaceLiveTest extends PostgreSqlIntegrationTest { + @Test(groups = "Live") + public void test_Debian_6() throws Exception { + test("Debian 6"); + } + + @Test(groups = "Live") + public void test_Ubuntu_10_0() throws Exception { + test("Ubuntu 10.0"); + } + + @Test(groups = "Live") + public void test_Ubuntu_11_0() throws Exception { + test("Ubuntu 11.0"); + } + + @Test(groups = "Live") + public void test_Ubuntu_12_0() throws Exception { + test("Ubuntu 12.0"); + } + + @Test(groups = "Live") + public void test_CentOS_6_0() throws Exception { + test("CentOS 6.0"); + } + + @Test(groups = "Live") + public void test_CentOS_5_6() throws Exception { + test("CentOS 5.6"); + } + + @Test(groups = "Live") + public void test_Fedora_17() throws Exception { + test("Fedora 17"); + } + + @Test(groups = "Live") + public void test_Red_Hat_Enterprise_Linux_6() throws Exception { + test("Red Hat Enterprise Linux 6"); + } + + @Test(groups = "Live") + public void test_localhost() throws Exception { + super.test_localhost(); + } + + public void test(String osRegex) throws Exception { + PostgreSqlNode psql = tapp.createAndManageChild(EntitySpec.create(PostgreSqlNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, CREATION_SCRIPT) + .configure(PostgreSqlNode.POSTGRESQL_PORT, PortRanges.fromInteger(5432)) + .configure(PostgreSqlNode.SHARED_MEMORY, "32MB")); + + brooklynProperties.put("brooklyn.location.jclouds.rackspace-cloudservers-uk.imageNameRegex", osRegex); + brooklynProperties.remove("brooklyn.location.jclouds.rackspace-cloudservers-uk.image-id"); + brooklynProperties.remove("brooklyn.location.jclouds.rackspace-cloudservers-uk.imageId"); + brooklynProperties.put("brooklyn.location.jclouds.rackspace-cloudservers-uk.inboundPorts", Arrays.asList(22, 5432)); + JcloudsLocation jcloudsLocation = (JcloudsLocation) managementContext.getLocationRegistry().resolve("jclouds:rackspace-cloudservers-uk"); + + tapp.start(ImmutableList.of(jcloudsLocation)); + + SshMachineLocation l = (SshMachineLocation) psql.getLocations().iterator().next(); + l.execCommands("add iptables rule", ImmutableList.of(IptablesCommands.insertIptablesRule(Chain.INPUT, Protocol.TCP, 5432, Policy.ACCEPT))); + + String url = psql.getAttribute(DatastoreCommon.DATASTORE_URL); + new VogellaExampleAccess("org.postgresql.Driver", url).readModifyAndRevertDataBase(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlRebindIntegrationTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlRebindIntegrationTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlRebindIntegrationTest.java new file mode 100644 index 0000000..8c3ee48 --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlRebindIntegrationTest.java @@ -0,0 +1,58 @@ +/* + * 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.brooklyn.entity.database.postgresql; + +import org.apache.brooklyn.api.entity.proxying.EntitySpec; +import org.apache.brooklyn.test.EntityTestUtils; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import brooklyn.entity.rebind.RebindTestFixtureWithApp; +import org.apache.brooklyn.location.basic.LocalhostMachineProvisioningLocation; + +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; + +public class PostgreSqlRebindIntegrationTest extends RebindTestFixtureWithApp { + + private LocalhostMachineProvisioningLocation loc; + + @BeforeMethod(alwaysRun=true) + @Override + public void setUp() throws Exception { + super.setUp(); + loc = origApp.newLocalhostProvisioningLocation(); + } + + @Test(groups = {"Integration"}) + public void testRebind() throws Exception { + origApp.createAndManageChild(EntitySpec.create(PostgreSqlNode.class)); + origApp.start(ImmutableList.of(loc)); + + // rebind + rebind(); + final PostgreSqlNode newEntity = (PostgreSqlNode) Iterables.find(newApp.getChildren(), Predicates.instanceOf(PostgreSqlNode.class)); + + // confirm effectors still work on entity + EntityTestUtils.assertAttributeEqualsEventually(newEntity, PostgreSqlNode.SERVICE_UP, true); + newEntity.stop(); + EntityTestUtils.assertAttributeEqualsEventually(newEntity, PostgreSqlNode.SERVICE_UP, false); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlRestartIntegrationTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlRestartIntegrationTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlRestartIntegrationTest.java new file mode 100644 index 0000000..4597d18 --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/postgresql/PostgreSqlRestartIntegrationTest.java @@ -0,0 +1,50 @@ +/* + * 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.brooklyn.entity.database.postgresql; + +import org.apache.brooklyn.api.entity.proxying.EntitySpec; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.Test; + +import brooklyn.entity.basic.AbstractSoftwareProcessRestartIntegrationTest; +import brooklyn.entity.basic.SoftwareProcess; + +/** + * Tests restart of the software *process* (as opposed to the VM). + */ +@Test(groups="Integration") +public class PostgreSqlRestartIntegrationTest extends AbstractSoftwareProcessRestartIntegrationTest { + + @SuppressWarnings("unused") + private static final Logger LOG = LoggerFactory.getLogger(PostgreSqlRestartIntegrationTest.class); + + @Override + protected EntitySpec<? extends SoftwareProcess> newEntitySpec() { + return EntitySpec.create(PostgreSqlNode.class); + } + + // TODO The second start() will fail because customize operations forbidden while there is existing data: + // "If you want to create a new database system, either remove or empty". + // I haven't checked whether it damaged the data in the database though! + @Test(enabled=false, groups={"Integration", "WIP"}) + public void testStopProcessAndStart() throws Exception { + super.testStopProcessAndStart(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepEc2LiveTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepEc2LiveTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepEc2LiveTest.java new file mode 100644 index 0000000..8686c5e --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepEc2LiveTest.java @@ -0,0 +1,75 @@ +/* + * 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.brooklyn.entity.database.rubyrep; + +import org.apache.brooklyn.api.entity.proxying.EntitySpec; +import org.apache.brooklyn.api.location.Location; +import org.testng.annotations.Test; + +import brooklyn.entity.AbstractEc2LiveTest; +import org.apache.brooklyn.entity.database.DatastoreMixins.DatastoreCommon; +import org.apache.brooklyn.entity.database.postgresql.PostgreSqlIntegrationTest; +import org.apache.brooklyn.entity.database.postgresql.PostgreSqlNode; + +import org.apache.brooklyn.location.basic.PortRanges; + +public class RubyRepEc2LiveTest extends AbstractEc2LiveTest { + + @Override + protected void doTest(Location loc) throws Exception { + PostgreSqlNode db1 = app.createAndManageChild(EntitySpec.create(PostgreSqlNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, PostgreSqlIntegrationTest.CREATION_SCRIPT) + .configure(PostgreSqlNode.POSTGRESQL_PORT, PortRanges.fromInteger(9111))); + + PostgreSqlNode db2 = app.createAndManageChild(EntitySpec.create(PostgreSqlNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, PostgreSqlIntegrationTest.CREATION_SCRIPT) + .configure(PostgreSqlNode.POSTGRESQL_PORT, PortRanges.fromInteger(9111))); + + RubyRepIntegrationTest.startInLocation(app, db1, db2, loc); + RubyRepIntegrationTest.testReplication(db1, db2); + } + + @Override + @Test(enabled=false, groups = "Live") + public void test_Debian_6() throws Exception { } // Disabled because PostgreSql 9.1 not available + + @Override + @Test(enabled=false, groups = "Live") + public void test_Ubuntu_10_0() throws Exception { } // Disabled because PostgreSql 9.1 not available + + @Override + @Test(enabled=false, groups = "Live") + public void test_Debian_7_2() throws Exception { } // Diabling all except Ubuntu 12.0 temporarily + + @Override + @Test(enabled=false, groups = "Live") + public void test_CentOS_6_3() throws Exception { } // Diabling all except Ubuntu 12.0 temporarily + + @Override + @Test(enabled=false, groups = "Live") + public void test_CentOS_5() throws Exception { } // Diabling all except Ubuntu 12.0 temporarily + + @Override + @Test(enabled=false, groups = "Live") + public void test_Red_Hat_Enterprise_Linux_6() throws Exception { } // Diabling all except Ubuntu 12.0 temporarily + + @Test(enabled=false) + public void testDummy() {} // Convince testng IDE integration that this really does have test methods +} + http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepIntegrationTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepIntegrationTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepIntegrationTest.java new file mode 100644 index 0000000..e58b250 --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepIntegrationTest.java @@ -0,0 +1,191 @@ +/* + * 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.brooklyn.entity.database.rubyrep; + +import static org.testng.Assert.assertEquals; + +import java.util.Arrays; +import java.util.List; + +import org.apache.brooklyn.api.entity.proxying.EntitySpec; +import org.apache.brooklyn.api.location.Location; +import org.apache.brooklyn.api.management.ManagementContext; +import org.apache.brooklyn.core.management.internal.LocalManagementContext; +import org.apache.brooklyn.test.entity.TestApplication; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import brooklyn.config.BrooklynProperties; +import brooklyn.entity.basic.ApplicationBuilder; +import brooklyn.entity.basic.Entities; +import org.apache.brooklyn.entity.database.DatastoreMixins.DatastoreCommon; +import org.apache.brooklyn.entity.database.VogellaExampleAccess; +import org.apache.brooklyn.entity.database.mysql.MySqlIntegrationTest; +import org.apache.brooklyn.entity.database.mysql.MySqlNode; +import org.apache.brooklyn.entity.database.postgresql.PostgreSqlIntegrationTest; +import org.apache.brooklyn.entity.database.postgresql.PostgreSqlNode; + +import org.apache.brooklyn.location.basic.LocalhostMachineProvisioningLocation; +import org.apache.brooklyn.location.basic.PortRanges; + +public class RubyRepIntegrationTest { + + public static final Logger log = LoggerFactory.getLogger(RubyRepIntegrationTest.class); + protected BrooklynProperties brooklynProperties; + protected ManagementContext managementContext; + protected TestApplication tapp; + + @BeforeMethod(alwaysRun = true) + public void setUp() { + brooklynProperties = BrooklynProperties.Factory.newDefault(); + managementContext = new LocalManagementContext(brooklynProperties); + tapp = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext); + } + + @AfterMethod(alwaysRun = true) + public void tearDown() { + Entities.destroyAllCatching(managementContext); + } + + @Test(groups = "Integration") + public void test_localhost_mysql() throws Exception { + MySqlNode db1 = tapp.createAndManageChild(EntitySpec.create(MySqlNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, MySqlIntegrationTest.CREATION_SCRIPT) + .configure("test.table.name", "COMMENTS") + .configure(MySqlNode.MYSQL_PORT, PortRanges.fromInteger(9111))); + + MySqlNode db2 = tapp.createAndManageChild(EntitySpec.create(MySqlNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, MySqlIntegrationTest.CREATION_SCRIPT) + .configure("test.table.name", "COMMENTS") + .configure(MySqlNode.MYSQL_PORT, PortRanges.fromInteger(9112))); + + + startInLocation(tapp, db1, db2, new LocalhostMachineProvisioningLocation()); + testReplication(db1, db2); + } + + /** + * Altered to use a single postgresql server to avoid issues with shared memory limits + */ + @Test(groups = {"Integration"}) + public void test_localhost_postgres() throws Exception { + String createTwoDbsScript = PostgreSqlIntegrationTest.CREATION_SCRIPT + + PostgreSqlIntegrationTest.CREATION_SCRIPT.replaceAll("CREATE USER.*", "").replaceAll(" feedback", " feedback1"); + + PostgreSqlNode db1 = tapp.createAndManageChild(EntitySpec.create(PostgreSqlNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, createTwoDbsScript) + .configure(PostgreSqlNode.POSTGRESQL_PORT, PortRanges.fromInteger(9113)) + .configure(PostgreSqlNode.MAX_CONNECTIONS, 10) + .configure(PostgreSqlNode.SHARED_MEMORY, "512kB")); // Very low so kernel configuration not needed + + startInLocation(tapp, db1, "feedback", db1, "feedback1", new LocalhostMachineProvisioningLocation()); + testReplication(db1, "feedback", db1, "feedback1"); + } + + @Test(enabled = false, groups = "Integration") // TODO this doesn't appear to be supported by RubyRep + public void test_localhost_postgres_mysql() throws Exception { + PostgreSqlNode db1 = tapp.createAndManageChild(EntitySpec.create(PostgreSqlNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, PostgreSqlIntegrationTest.CREATION_SCRIPT) + .configure(PostgreSqlNode.POSTGRESQL_PORT, PortRanges.fromInteger(9115)) + .configure(PostgreSqlNode.MAX_CONNECTIONS, 10) + .configure(PostgreSqlNode.SHARED_MEMORY, "512kB")); // Very low so kernel configuration not needed + + MySqlNode db2 = tapp.createAndManageChild(EntitySpec.create(MySqlNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, MySqlIntegrationTest.CREATION_SCRIPT) + .configure(MySqlNode.MYSQL_PORT, PortRanges.fromInteger(9116))); + + startInLocation(tapp, db1, db2, new LocalhostMachineProvisioningLocation()); + testReplication(db1, db2); + } + + public static void startInLocation(TestApplication tapp, DatastoreCommon db1, DatastoreCommon db2, Location... locations) throws Exception { + startInLocation(tapp, db1, "feedback", db2, "feedback", locations); + } + + /** + * Configures rubyrep to connect to the two databases and starts the app + */ + public static void startInLocation(TestApplication tapp, DatastoreCommon db1, String dbName1, DatastoreCommon db2, String dbName2, Location... locations) throws Exception { + tapp.createAndManageChild(EntitySpec.create(RubyRepNode.class) + .configure("startupTimeout", 300) + .configure("leftDatabase", db1) + .configure("rightDatabase", db2) + .configure("leftUsername", "sqluser") + .configure("rightUsername", "sqluser") + .configure("rightPassword", "sqluserpw") + .configure("leftPassword", "sqluserpw") + .configure("leftDatabaseName", dbName1) + .configure("rightDatabaseName", dbName2) + .configure("replicationInterval", 1) + ); + + tapp.start(Arrays.asList(locations)); + } + + public static void testReplication(DatastoreCommon db1, DatastoreCommon db2) throws Exception { + testReplication(db1, "feedback", db2, "feedback"); + } + + /** + * Tests replication between the two databases by altering the first and checking the change is applied to the second + */ + public static void testReplication(DatastoreCommon db1, String dbName1, DatastoreCommon db2, String dbName2) throws Exception { + String db1Url = db1.getAttribute(DatastoreCommon.DATASTORE_URL); + String db2Url = db2.getAttribute(DatastoreCommon.DATASTORE_URL); + + log.info("Testing replication between " + db1Url + " and " + db2Url); + + VogellaExampleAccess vea1 = new VogellaExampleAccess(db1 instanceof MySqlNode ? "com.mysql.jdbc.Driver" : "org.postgresql.Driver", db1Url, dbName1); + VogellaExampleAccess vea2 = new VogellaExampleAccess(db2 instanceof MySqlNode ? "com.mysql.jdbc.Driver" : "org.postgresql.Driver", db2Url, dbName2); + + try { + vea1.connect(); + List<List<String>> rs = vea1.readDataBase(); + assertEquals(rs.size(), 1); + + vea2.connect(); + rs = vea2.readDataBase(); + assertEquals(rs.size(), 1); + + log.info("Modifying left database"); + vea1.modifyDataBase(); + + log.info("Reading left database"); + rs = vea1.readDataBase(); + assertEquals(rs.size(), 2); + + log.info("Reading right database"); + rs = vea2.readDataBase(); + + for (int i = 0; i < 60 && rs.size() != 2; i++) { + log.info("Sleeping for a second"); + Thread.sleep(1000); + rs = vea2.readDataBase(); + } + + assertEquals(rs.size(), 2); + } finally { + vea1.close(); + vea2.close(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepRackspaceLiveTest.java ---------------------------------------------------------------------- diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepRackspaceLiveTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepRackspaceLiveTest.java new file mode 100644 index 0000000..f72b13c --- /dev/null +++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepRackspaceLiveTest.java @@ -0,0 +1,130 @@ +/* + * 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.brooklyn.entity.database.rubyrep; + +import java.util.Arrays; + +import org.apache.brooklyn.api.entity.proxying.EntitySpec; +import org.apache.brooklyn.api.location.Location; +import org.testng.annotations.Test; + +import org.apache.brooklyn.entity.database.DatastoreMixins.DatastoreCommon; +import org.apache.brooklyn.entity.database.postgresql.PostgreSqlIntegrationTest; +import org.apache.brooklyn.entity.database.postgresql.PostgreSqlNode; + +import org.apache.brooklyn.location.basic.PortRanges; +import org.apache.brooklyn.location.basic.SshMachineLocation; + +import brooklyn.util.net.Protocol; +import brooklyn.util.ssh.IptablesCommands; +import brooklyn.util.ssh.IptablesCommands.Chain; +import brooklyn.util.ssh.IptablesCommands.Policy; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; + +/** + * The RubyRepRackspaceLiveTest installs RubyRep on various operating systems like Ubuntu, CentOS, Red Hat etc. To make sure that + * RubyRep and PostgreSql works like expected on these Operating Systems. + */ +public class RubyRepRackspaceLiveTest extends RubyRepIntegrationTest { + + @Test(groups = "Live") + public void test_Debian_6() throws Exception { + test("Debian 6"); + } + + @Test(groups = "Live") + public void test_Ubuntu_10_0() throws Exception { + test("Ubuntu 10.0"); + } + + @Test(groups = "Live") + public void test_Ubuntu_12_0() throws Exception { + test("Ubuntu 12.0"); + } + + @Test(groups = "Live") + public void test_Ubuntu_13() throws Exception { + test("Ubuntu 13"); + } + + @Test(groups = "Live") + public void test_CentOS_6() throws Exception { + test("CentOS 6"); + } + + @Test(groups = "Live") + public void test_CentOS_5() throws Exception { + test("CentOS 5"); + } + + @Test(groups = "Live") + public void test_Fedora() throws Exception { + test("Fedora "); + } + + @Test(groups = "Live") + public void test_Red_Hat_Enterprise_Linux_6() throws Exception { + test("Red Hat Enterprise Linux 6"); + } + + public void test(String osRegex) throws Exception { + PostgreSqlNode db1 = tapp.createAndManageChild(EntitySpec.create(PostgreSqlNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, PostgreSqlIntegrationTest.CREATION_SCRIPT) + .configure(PostgreSqlNode.POSTGRESQL_PORT, PortRanges.fromInteger(9111))); + PostgreSqlNode db2 = tapp.createAndManageChild(EntitySpec.create(PostgreSqlNode.class) + .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, PostgreSqlIntegrationTest.CREATION_SCRIPT) + .configure(PostgreSqlNode.POSTGRESQL_PORT, PortRanges.fromInteger(9111))); + + brooklynProperties.put("brooklyn.location.jclouds.rackspace-cloudservers-uk.imageNameRegex", osRegex); + brooklynProperties.remove("brooklyn.location.jclouds.rackspace-cloudservers-uk.image-id"); + brooklynProperties.remove("brooklyn.location.jclouds.rackspace-cloudservers-uk.imageId"); + brooklynProperties.put("brooklyn.location.jclouds.rackspace-cloudservers-uk.inboundPorts", Arrays.asList(22, 9111)); + Location loc = managementContext.getLocationRegistry().resolve("jclouds:rackspace-cloudservers-uk"); + + startInLocation(tapp, db1, db2, loc); + + //hack to get the port for mysql open; is the inbounds property not respected on rackspace?? + for (DatastoreCommon node : ImmutableSet.of(db1, db2)) { + SshMachineLocation l = (SshMachineLocation) node.getLocations().iterator().next(); + l.execCommands("add iptables rule", ImmutableList.of(IptablesCommands.insertIptablesRule(Chain.INPUT, Protocol.TCP, 9111, Policy.ACCEPT))); + } + + testReplication(db1, db2); + } + + // disable inherited non-live tests + @Test(enabled = false, groups = "Integration") + public void test_localhost_mysql() throws Exception { + super.test_localhost_mysql(); + } + + // disable inherited non-live tests + @Test(enabled = false, groups = "Integration") + public void test_localhost_postgres() throws Exception { + super.test_localhost_postgres(); + } + + // disable inherited non-live tests + @Test(enabled = false, groups = "Integration") + public void test_localhost_postgres_mysql() throws Exception { + super.test_localhost_postgres_mysql(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac1a7c09/software/monitoring/src/test/java/org/apache/brooklyn/entity/monitoring/monit/MonitIntegrationTest.java ---------------------------------------------------------------------- diff --git a/software/monitoring/src/test/java/org/apache/brooklyn/entity/monitoring/monit/MonitIntegrationTest.java b/software/monitoring/src/test/java/org/apache/brooklyn/entity/monitoring/monit/MonitIntegrationTest.java index 5b58c72..48bfafa 100644 --- a/software/monitoring/src/test/java/org/apache/brooklyn/entity/monitoring/monit/MonitIntegrationTest.java +++ b/software/monitoring/src/test/java/org/apache/brooklyn/entity/monitoring/monit/MonitIntegrationTest.java @@ -41,7 +41,7 @@ import brooklyn.entity.BrooklynAppLiveTestSupport; import brooklyn.entity.basic.Entities; import brooklyn.entity.basic.SameServerEntity; import brooklyn.entity.basic.SoftwareProcess; -import brooklyn.entity.database.mysql.MySqlNode; +import org.apache.brooklyn.entity.database.mysql.MySqlNode; import brooklyn.event.basic.DependentConfiguration; import org.apache.brooklyn.location.basic.LocalhostMachineProvisioningLocation;
