This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Starting Multiple Servers

WSO2 products servers can be started by providing different system properties.  In order to test certain product features, you might need to start the servers with specific server properties. Some of those system properties are mentioned below.

system-properties:  

  -DhttpPort= Overrides the HTTP port defined in the config files.  
  -DhttpsPort= Overrides the HTTPS port defined in the config files.  
  -DosgiConsole=[port] Starts Carbon with Equinox OSGi console.  
  -DportOffset=[port] Starts server with different port offsets.  
  -Dsetup Can be used to start server after dropping the database.

The test framework starts the default server instances on the default product ports before all test suites.Thus, starting another server on the default product ports on the same host will cause port binding errors. In order to start multiple server instances, you have to set the -DportOffset property. If you are going to run multiple product instances on the same host for integration tests, then setting the port offset property is a must.

MultipleServersManager (org.wso2.carbon.automation.extensions.MultipleServersManager)

The test framework provides MultipleServersManager.java which acts as a container for multiple carbon instances. To use this class, you have to Implement a TestServerManager instance for different types of servers. E.g. AS, ESB etc. Then create a class with appropriate testNG annotation to start the server before you suite or test class execution.

TestServerManager (org.wso2.carbon.automation.core.TestServerManager)

TestServerManager is responsible for preparing the Carbon server for test executions, and it shuts down the server after test executions. All test suites/classes which require starting of a new server instance should extend this class.

How to start multiple product instances in integration tests

The following code sample demonstrates the usage of the TestServerManager class. It implements CarbonTestServerManager as the container for TestServerManager instances.

public class CarbonTestServerManager extends TestServerManager {  
  
  public CarbonTestServerManager() {  
  }  
  
  public CarbonTestServerManager(String carbonZip, Map<String, String> startupParameterMap) {  
        super(carbonZip, startupParameterMap);  
  }  
  
  public CarbonTestServerManager(int portOffset) {  
        super(portOffset);  
  }  
  
  public String startServer() throws IOException {  
        String carbonHome = super.startServer();  
        System.setProperty("carbon.home", carbonHome);  
        return carbonHome;  
  }  
  
  public void stopServer() throws Exception {  
        super.stopServer();  
  }  
  
  protected void copyArtifacts(String carbonHome) throws IOException {  
  }  
}  

The following test class demonstrates the usage of CarbonServerManager to start two ESB instances with different port offsets. In order to start server instances with different system properties, you need to define a HashMap and put all system properties as key value pairs. Once the map is passed to the multiple server manager, the framework will start a new server instance with all the provided system properties.

public class NewInstanceTestCase extends CarbonTestServerManager {  
public MultipleServersManager manager = new MultipleServersManager();  
public Map<String, String> startupParameterMap1 = new HashMap<String, String>();  
public Map<String, String> startupParameterMap2 = new HashMap<String, String>();  
  
	@SetEnvironment(executionEnvironments = {ExecutionEnvironment.integration_all})  
	@BeforeClass(groups = {"esb.multi.server"})  
	public void testStartServers() throws IOException {  
  		startupParameterMap1.put("-DportOffset", "10");  
  	CarbonTestServerManager server1 = new CarbonTestServerManager(System.getProperty("carbon.zip"),  
                                startupParameterMap1);  
  	startupParameterMap2.put("-DportOffset", "20");  
  	CarbonTestServerManager server2 = new CarbonTestServerManager(System.getProperty("carbon.zip"),  
                                startupParameterMap2);  
  	manager.startServers(server1, server2);  
	}  
  
	@SetEnvironment(executionEnvironments = {ExecutionEnvironment.integration_all})  
	@Test(groups = {"esb.multi.server"})  
	public void test() {  
		System.out.println("Test server startup with system properties");  
	}  
  
	@SetEnvironment(executionEnvironments = {ExecutionEnvironment.integration_all})  
	@AfterClass  
	public void clean() throws Exception {  
   	manager.stopAllServers();  
 	}  
}


Also note that since the test case is depending on the carbon zip file to start server instances, you have to use custom annotation @SetEnvironment to skip the test from platform setup. In the above example, the test case will be executed only on an integration level.