With the following commit, we can start a number of Carbon server instances from an integration TestSuite. Now it makes it very simple to write an integration test case which involves multiple Carbon products. Please take a look at the Javadocs of org.wso2.carbon.integration.framework.MultipleServersManager to see how this can be used. The automation team can use this API for automation purposes too.
---------- Forwarded message ---------- From: <[email protected]> Date: Mon, Dec 19, 2011 at 3:18 PM Subject: [Carbon-commits] [Carbon] svn commit r118036 - in trunk/carbon/core/integration: framework/src/main/java/org/wso2/carbon/integration/framework framework/src/main/java/org/wso2/carbon/integration/framework/utils tests/src/test/java/org/wso2/carbon/integration/tests To: [email protected] Author: azeez Date: Mon Dec 19 01:48:32 2011 New Revision: 118036 URL: http://wso2.org/svn/browse/wso2?view=rev&revision=118036 Log: Ability to start multiple Carbon servers inside an integration TestSuite Added: trunk/carbon/core/integration/tests/src/test/java/org/wso2/carbon/integration/tests/MultipleCarbonInstancesTestCase.java Modified: trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/ClientConnectionUtil.java trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/LoginLogoutUtil.java trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/MultipleServersManager.java trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/TestServerManager.java trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/utils/ServerUtils.java trunk/carbon/core/integration/tests/src/test/java/org/wso2/carbon/integration/tests/CarbonTestServerManager.java Modified: trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/ClientConnectionUtil.java URL: http://wso2.org/svn/browse/wso2/trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/ClientConnectionUtil.java?rev=118036&r1=118035&r2=118036&view=diff ============================================================================== --- trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/ClientConnectionUtil.java (original) +++ trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/ClientConnectionUtil.java Mon Dec 19 01:48:32 2011 @@ -72,6 +72,11 @@ throw new RuntimeException("Port " + port + " is not open"); } + /** + * Check whether the provided <code>port</code> is open + * @param port The port that needs to be checked + * @return true if the <code>port</code> is open & false otherwise + */ public static boolean isPortOpen(int port) { Socket socket = null; boolean isPortOpen = false; Modified: trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/LoginLogoutUtil.java URL: http://wso2.org/svn/browse/wso2/trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/LoginLogoutUtil.java?rev=118036&r1=118035&r2=118036&view=diff ============================================================================== --- trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/LoginLogoutUtil.java (original) +++ trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/LoginLogoutUtil.java Mon Dec 19 01:48:32 2011 @@ -30,18 +30,17 @@ import org.wso2.carbon.utils.NetworkUtils; /** - * All tests which require logging in & logging out should extend this class + * A utility for logging into & logging out of Carbon servers */ public final class LoginLogoutUtil { private static final Log log = LogFactory.getLog(LoginLogoutUtil.class); private String sessionCookie; /** - * This login method needs to be overridden in your TestNG test. Simply calling super.login() - * would be sufficient + * Log in to a Carbon server * * @return The session cookie on successful login - * @throws Exception If an error occurs while loggin in + * @throws Exception If an error occurs while logging in */ public String login() throws Exception { ClientConnectionUtil.waitForPort(Integer.parseInt(FrameworkSettings.HTTPS_PORT)); @@ -52,8 +51,8 @@ log.debug("UserName : " + FrameworkSettings.USER_NAME + " Password : " + FrameworkSettings.PASSWORD + " HostName : " + hostName); } - boolean isLoggedIn = authAdminStub.login(FrameworkSettings.USER_NAME, - FrameworkSettings.PASSWORD, hostName); + boolean isLoggedIn = authAdminStub.login(FrameworkSettings.USER_NAME, + FrameworkSettings.PASSWORD, hostName); assert isLoggedIn : "Login failed!"; log.debug("getting sessionCookie"); ServiceContext serviceContext = authAdminStub. @@ -68,6 +67,11 @@ } + /** + * Log out from a Carbon server you logged in to by calling the {@link #login} method + * + * @throws Exception If an error occurs while logging out + */ public void logout() throws Exception { AuthenticationAdminStub authenticationAdminStub = getAuthAdminStub(); try { @@ -82,7 +86,7 @@ } } - private static AuthenticationAdminStub getAuthAdminStub() throws AxisFault { + private AuthenticationAdminStub getAuthAdminStub() throws AxisFault { String authenticationServiceURL = FrameworkSettings.SERVICE_URL + "AuthenticationAdmin"; if (log.isDebugEnabled()) { log.debug("AuthenticationAdminService URL = " + authenticationServiceURL); Modified: trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/MultipleServersManager.java URL: http://wso2.org/svn/browse/wso2/trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/MultipleServersManager.java?rev=118036&r1=118035&r2=118036&view=diff ============================================================================== --- trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/MultipleServersManager.java (original) +++ trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/MultipleServersManager.java Mon Dec 19 01:48:32 2011 @@ -17,29 +17,49 @@ */ package org.wso2.carbon.integration.framework; -import org.wso2.carbon.integration.framework.utils.ServerUtils; - +import java.io.IOException; import java.util.HashMap; import java.util.Map; /** - * TODO: class description + * A container for multiple Carbon server instances. + * + * How to use this class: + * 1. Implement a TestServerManager instance for different types of servers. e.g. AS, ESB etc + * 2. Create a Class with @BeforeSuite & @AfterSuite annotations. + * In @BeforeSuite, you can call {@link MultipleServersManager#startServers(TestServerManager...)} + * In @AfterSuite, you can call {@link MultipleServersManager#stopAllServers()} */ public class MultipleServersManager { - private Map<String, ServerUtils> servers = new HashMap<String, ServerUtils>(); - - public void startServers(String... carbonZip){ + private Map<String, TestServerManager> servers = new HashMap<String, TestServerManager>(); + /** + * Start a set of Carbon servers + * @param serverManagers vararg which specifies a TestServerManager instance per Carbon server + * @throws IOException If an error occurs while copying deployment artifacts into Carbon servers + */ + public void startServers(TestServerManager... serverManagers) throws IOException { + for (TestServerManager zip : serverManagers) { + zip.startServer(); + servers.put(zip.getCarbonZip(), zip); + } } - public void stopServer(String carbonHome){ - + public void stopServer(String carbonZip) throws Exception { + TestServerManager serverManager = servers.get(carbonZip); + if(serverManager != null){ + serverManager.stopServer(); + } } - + + /** + * Stop all servers started by this MultipleServersManager + * @throws Exception If an error occurs while stopping servers + */ public void stopAllServers() throws Exception { - for (ServerUtils serverUtils : servers.values()) { - serverUtils.shutdown(); + for (TestServerManager serverUtils : servers.values()) { + serverUtils.stopServer(); } } } Modified: trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/TestServerManager.java URL: http://wso2.org/svn/browse/wso2/trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/TestServerManager.java?rev=118036&r1=118035&r2=118036&view=diff ============================================================================== --- trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/TestServerManager.java (original) +++ trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/TestServerManager.java Mon Dec 19 01:48:32 2011 @@ -32,6 +32,24 @@ public abstract class TestServerManager { private ServerUtils serverUtils = new ServerUtils(); + private String carbonZip; + private int portOffset; + + protected TestServerManager() { + } + + protected TestServerManager(String carbonZip) { + this.carbonZip = carbonZip; + } + + protected TestServerManager(String carbonZip, int portOffset) { + this.carbonZip = carbonZip; + this.portOffset = portOffset; + } + + public String getCarbonZip() { + return carbonZip; + } /** * This method is called for starting a Carbon server in preparation for execution of a @@ -44,14 +62,16 @@ * Carbon server */ protected String startServer() throws IOException { - String carbonZip = System.getProperty("carbon.zip"); + if (carbonZip == null) { + carbonZip = System.getProperty("carbon.zip"); + } if (carbonZip == null) { throw new IllegalArgumentException("carbon zip file is null"); } String carbonHome = serverUtils.setUpCarbonHome(carbonZip); TestUtil.copySecurityVerificationService(carbonHome); copyArtifacts(carbonHome); - serverUtils.startServerUsingCarbonHome(carbonHome); + serverUtils.startServerUsingCarbonHome(carbonHome, portOffset); FrameworkSettings.init(); return carbonHome; } Modified: trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/utils/ServerUtils.java URL: http://wso2.org/svn/browse/wso2/trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/utils/ServerUtils.java?rev=118036&r1=118035&r2=118036&view=diff ============================================================================== --- trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/utils/ServerUtils.java (original) +++ trunk/carbon/core/integration/framework/src/main/java/org/wso2/carbon/integration/framework/utils/ServerUtils.java Mon Dec 19 01:48:32 2011 @@ -19,7 +19,6 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.base.ServerConfigurationException; import org.wso2.carbon.utils.ArchiveManipulator; import org.wso2.carbon.utils.FileManipulator; import org.wso2.carbon.utils.ServerConstants; @@ -44,7 +43,7 @@ private final static String SERVER_SHUTDOWN_MESSAGE = "Halting JVM"; private final static long DEFAULT_START_STOP_WAIT_MS = 1000 * 60 * 4; - public synchronized void startServerUsingCarbonHome(String carbonHome) { + public synchronized void startServerUsingCarbonHome(String carbonHome, int portOffset) { if (process != null) { // An instance of the server is running return; } @@ -62,14 +61,17 @@ } log.info("Imported Code Coverage Details."); String temp; + File commandDir = new File(carbonHome); if (System.getProperty("os.name").toLowerCase().contains("windows")) { tempProcess = - Runtime.getRuntime().exec(new String[]{"bat", "bin/wso2server.bat"}, - null, new File(carbonHome)); + Runtime.getRuntime().exec(new String[]{"bat", "bin/wso2server.bat", "test", + "-DportOffset=" + String.valueOf(portOffset)}, + null, commandDir); } else { tempProcess = - Runtime.getRuntime().exec(new String[]{"sh", "bin/wso2server.sh", "test"}, - null, new File(carbonHome)); + Runtime.getRuntime().exec(new String[]{"sh", "bin/wso2server.sh", "test", + "-DportOffset="+ String.valueOf(portOffset)}, + null, commandDir); } Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { @@ -114,16 +116,6 @@ log.info("Successfully started Carbon server. Returning ..."); } - public synchronized void startServerUsingCarbonZip(String carbonServerZipFile) - throws ServerConfigurationException, IOException { - if (process != null) { // An instance of the server is running - return; - } - String carbonHome = setUpCarbonHome(carbonServerZipFile); - instrumentJarsForEmma(carbonHome); - startServerUsingCarbonHome(carbonHome); - } - public synchronized String setUpCarbonHome(String carbonServerZipFile) throws IOException { if (process != null) { // An instance of the server is running @@ -138,9 +130,11 @@ carbonServerZipFile.substring(carbonServerZipFile.lastIndexOf(fileSeparator) + 1, indexOfZip); FileManipulator.deleteDir(extractedCarbonDir); - new ArchiveManipulator().extract(carbonServerZipFile, "carbontmp"); + String extractDir = "carbontmp" + System.currentTimeMillis(); + new ArchiveManipulator().extract(carbonServerZipFile, extractDir); + String baseDir = (System.getProperty("basedir", ".")) + File.separator + "target"; return carbonHome = - new File(".").getAbsolutePath() + File.separator + "carbontmp" + File.separator + + new File(baseDir).getAbsolutePath() + File.separator + extractDir + File.separator + extractedCarbonDir; } Modified: trunk/carbon/core/integration/tests/src/test/java/org/wso2/carbon/integration/tests/CarbonTestServerManager.java URL: http://wso2.org/svn/browse/wso2/trunk/carbon/core/integration/tests/src/test/java/org/wso2/carbon/integration/tests/CarbonTestServerManager.java?rev=118036&r1=118035&r2=118036&view=diff ============================================================================== --- trunk/carbon/core/integration/tests/src/test/java/org/wso2/carbon/integration/tests/CarbonTestServerManager.java (original) +++ trunk/carbon/core/integration/tests/src/test/java/org/wso2/carbon/integration/tests/CarbonTestServerManager.java Mon Dec 19 01:48:32 2011 @@ -34,6 +34,13 @@ public class CarbonTestServerManager extends TestServerManager { private static final Log log = LogFactory.getLog(CarbonTestServerManager.class); + public CarbonTestServerManager() { + } + + public CarbonTestServerManager(String carbonZip, int portOffset) { + super(carbonZip, portOffset); + } + @Override @BeforeSuite(timeOut = 60000, description = "Starts up a Carbon core server") Added: trunk/carbon/core/integration/tests/src/test/java/org/wso2/carbon/integration/tests/MultipleCarbonInstancesTestCase.java URL: http://wso2.org/svn/browse/wso2/trunk/carbon/core/integration/tests/src/test/java/org/wso2/carbon/integration/tests/MultipleCarbonInstancesTestCase.java?pathrev=118036 ============================================================================== --- (empty file) +++ trunk/carbon/core/integration/tests/src/test/java/org/wso2/carbon/integration/tests/MultipleCarbonInstancesTestCase.java Mon Dec 19 01:48:32 2011 @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. 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.wso2.carbon.integration.tests; + +import org.testng.annotations.AfterGroups; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; +import org.wso2.carbon.integration.framework.MultipleServersManager; + +import java.io.IOException; + +/** + * TODO: class description + */ +public class MultipleCarbonInstancesTestCase { + + public MultipleServersManager manager = new MultipleServersManager(); + + @BeforeGroups(groups = {"carbon.multi.server"}) + public void testStartServers() throws IOException { + CarbonTestServerManager server1 = new CarbonTestServerManager(System.getProperty("carbon.zip"), + 10); + CarbonTestServerManager server2 = new CarbonTestServerManager(System.getProperty("carbon.zip"), + 12); + + manager.startServers(server1, server2); + } + + @Test(groups = {"carbon.multi.server"}) + public void test(){ + + } + + @AfterGroups(groups = {"carbon.multi.server"}) + public void testStopServers() throws Exception { + manager.stopAllServers(); + } +} _______________________________________________ Carbon-commits mailing list [email protected] https://wso2.org/cgi-bin/mailman/listinfo/carbon-commits -- *Afkham Azeez* Director of Architecture; WSO2, Inc.; http://wso2.com Member; Apache Software Foundation; http://www.apache.org/ * <http://www.apache.org/>** email: **[email protected]* <[email protected]>* cell: +94 77 3320919 blog: **http://blog.afkham.org* <http://blog.afkham.org>* twitter: **http://twitter.com/afkham_azeez*<http://twitter.com/afkham_azeez> * linked-in: **http://lk.linkedin.com/in/afkhamazeez* * * *Lean . Enterprise . Middleware*
_______________________________________________ Carbon-dev mailing list [email protected] http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev
