You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2015/03/05 15:57:13 UTC

[2/4] incubator-brooklyn git commit: Covert MySqlIntegrationTest from groovy to java

Covert MySqlIntegrationTest from groovy to java


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/a3f82578
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/a3f82578
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/a3f82578

Branch: refs/heads/master
Commit: a3f82578619858d9f7b98e8a4af3045e6f6cdca1
Parents: 817b820
Author: Aled Sage <al...@gmail.com>
Authored: Tue Mar 3 16:16:49 2015 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Mar 3 16:17:06 2015 +0000

----------------------------------------------------------------------
 .../entity/BrooklynAppLiveTestSupport.java      |   4 +-
 .../database/mysql/MySqlIntegrationTest.groovy  | 124 -------------------
 .../database/mysql/MySqlIntegrationTest.java    | 104 ++++++++++++++++
 .../database/mysql/MySqlLiveRackspaceTest.java  |   8 +-
 4 files changed, 111 insertions(+), 129 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a3f82578/core/src/test/java/brooklyn/entity/BrooklynAppLiveTestSupport.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/BrooklynAppLiveTestSupport.java b/core/src/test/java/brooklyn/entity/BrooklynAppLiveTestSupport.java
index ce57757..e64101a 100644
--- a/core/src/test/java/brooklyn/entity/BrooklynAppLiveTestSupport.java
+++ b/core/src/test/java/brooklyn/entity/BrooklynAppLiveTestSupport.java
@@ -26,7 +26,7 @@ import org.testng.annotations.BeforeMethod;
 import brooklyn.config.BrooklynProperties;
 import brooklyn.entity.basic.ApplicationBuilder;
 import brooklyn.entity.basic.Entities;
-import brooklyn.management.ManagementContext;
+import brooklyn.management.internal.ManagementContextInternal;
 import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.test.entity.TestApplication;
 
@@ -41,7 +41,7 @@ public class BrooklynAppLiveTestSupport {
     private static final Logger LOG = LoggerFactory.getLogger(BrooklynAppLiveTestSupport.class);
 
     protected TestApplication app;
-    protected ManagementContext mgmt;
+    protected ManagementContextInternal mgmt;
 
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a3f82578/software/database/src/test/java/brooklyn/entity/database/mysql/MySqlIntegrationTest.groovy
----------------------------------------------------------------------
diff --git a/software/database/src/test/java/brooklyn/entity/database/mysql/MySqlIntegrationTest.groovy b/software/database/src/test/java/brooklyn/entity/database/mysql/MySqlIntegrationTest.groovy
deleted file mode 100644
index acf8736..0000000
--- a/software/database/src/test/java/brooklyn/entity/database/mysql/MySqlIntegrationTest.groovy
+++ /dev/null
@@ -1,124 +0,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.
- */
-package brooklyn.entity.database.mysql
-
-import org.slf4j.Logger
-import org.slf4j.LoggerFactory
-import org.testng.Assert
-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 brooklyn.entity.database.VogellaExampleAccess
-import brooklyn.entity.proxying.EntitySpec
-import brooklyn.location.basic.LocalhostMachineProvisioningLocation
-import brooklyn.management.ManagementContext
-import brooklyn.management.internal.LocalManagementContext
-import brooklyn.test.entity.TestApplication
-import brooklyn.util.collections.MutableMap
-import brooklyn.util.net.Networking;
-import brooklyn.util.text.Strings
-
-/**
- * Runs a slightly modified version of the popular Vogella MySQL tutorial,
- * from
- * http://www.vogella.de/articles/MySQLJava/article.html
- */
-public class MySqlIntegrationTest {
-
-    public static final Logger log = LoggerFactory.getLogger(MySqlIntegrationTest.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() {
-        if (tapp != null) {
-            Entities.destroyAll(tapp.getManagementContext());
-            tapp = null;
-        }
-    }
-
-    // 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
-    public static final String CREATION_SCRIPT = """
-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 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', 'myemail@gmail.com','http://www.vogella.de', '2009-09-14 10:33:11', 'Summary','My first comment' );
-""";
-
-    @Test(groups = ["Integration"])
-    public void test_localhost() throws Exception {
-        String dataDir = "/tmp/mysql-data-" + Strings.makeRandomId(8);
-        MySqlNode mysql = tapp.createAndManageChild(EntitySpec.create(MySqlNode.class)
-                .configure(MySqlNode.MYSQL_SERVER_CONF, MutableMap.of("skip-name-resolve",""))
-                .configure("creationScriptContents", CREATION_SCRIPT)
-                .configure("dataDir", dataDir));
-        LocalhostMachineProvisioningLocation location = new LocalhostMachineProvisioningLocation();
-        
-        tapp.start([location]);
-        log.info("MySQL started");
-
-        new VogellaExampleAccess("com.mysql.jdbc.Driver", mysql.getAttribute(MySqlNode.DB_URL)).readModifyAndRevertDataBase();
-
-        log.info("Ran vogella MySQL example -- SUCCESS");
-
-        // Ensure the data directory was successfully overridden.
-        File dataDirFile = new File(dataDir);
-        File mysqlSubdirFile = new File(dataDirFile, "mysql");
-        Assert.assertTrue(mysqlSubdirFile.exists());
-
-        // Clean up.
-        dataDirFile.deleteDir();
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a3f82578/software/database/src/test/java/brooklyn/entity/database/mysql/MySqlIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/database/src/test/java/brooklyn/entity/database/mysql/MySqlIntegrationTest.java b/software/database/src/test/java/brooklyn/entity/database/mysql/MySqlIntegrationTest.java
new file mode 100644
index 0000000..d5d0fed
--- /dev/null
+++ b/software/database/src/test/java/brooklyn/entity/database/mysql/MySqlIntegrationTest.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 brooklyn.entity.database.mysql;
+
+import java.io.File;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.BrooklynAppLiveTestSupport;
+import brooklyn.entity.database.VogellaExampleAccess;
+import brooklyn.entity.proxying.EntitySpec;
+import 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
+    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 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', 'myemail@gmail.com','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()));
+            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/a3f82578/software/database/src/test/java/brooklyn/entity/database/mysql/MySqlLiveRackspaceTest.java
----------------------------------------------------------------------
diff --git a/software/database/src/test/java/brooklyn/entity/database/mysql/MySqlLiveRackspaceTest.java b/software/database/src/test/java/brooklyn/entity/database/mysql/MySqlLiveRackspaceTest.java
index 0ab5aff..6ec40bb 100644
--- a/software/database/src/test/java/brooklyn/entity/database/mysql/MySqlLiveRackspaceTest.java
+++ b/software/database/src/test/java/brooklyn/entity/database/mysql/MySqlLiveRackspaceTest.java
@@ -22,6 +22,7 @@ import java.util.Arrays;
 
 import org.testng.annotations.Test;
 
+import brooklyn.config.BrooklynProperties;
 import brooklyn.entity.database.DatastoreMixins.DatastoreCommon;
 import brooklyn.entity.database.VogellaExampleAccess;
 import brooklyn.entity.proxying.EntitySpec;
@@ -85,16 +86,17 @@ public class MySqlLiveRackspaceTest extends MySqlIntegrationTest {
     }
 
     public void test(String osRegex) throws Exception {
-        MySqlNode mysql = tapp.createAndManageChild(EntitySpec.create(MySqlNode.class)
+        MySqlNode mysql = app.createAndManageChild(EntitySpec.create(MySqlNode.class)
                 .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, CREATION_SCRIPT));
 
+        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) managementContext.getLocationRegistry().resolve("jclouds:rackspace-cloudservers-uk");
+        JcloudsLocation jcloudsLocation = (JcloudsLocation) mgmt.getLocationRegistry().resolve("jclouds:rackspace-cloudservers-uk");
 
-        tapp.start(ImmutableList.of(jcloudsLocation));
+        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)));