There are times when you need to involve multiple containers in the same test case, if you for instance want to test clustering. The first step you need to take is to add a group with multiple containers to your Arquillian configuration.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<group qualifier="tomcat-cluster">
<container qualifier="container-1" default="true">
<configuration>
<property name="tomcatHome">target/tomcat-embedded-6-standby</property>
<property name="workDir">work</property>
<property name="bindHttpPort">8880</property>
<property name="unpackArchive">true</property>
</configuration>
<dependencies>
<dependency>org.jboss.arquillian.container:arquillian-tomcat-embedded-6:1.0.0-SNAPSHOT</dependency>
<dependency>org.apache.tomcat:catalina:6.0.29</dependency>
<dependency>org.apache.tomcat:coyote:6.0.29</dependency>
<dependency>org.apache.tomcat:jasper:6.0.29</dependency>
</dependencies>
</container>
<container qualifier="container-2">
<configuration>
<property name="tomcatHome">target/tomcat-embedded-6-active-1</property>
<property name="workDir">work</property>
<property name="bindHttpPort">8881</property>
<property name="unpackArchive">true</property>
</configuration>
<dependencies>
<dependency>org.jboss.arquillian.container:arquillian-tomcat-embedded-6:1.0.0-SNAPSHOT</dependency>
<dependency>org.apache.tomcat:catalina:6.0.29</dependency>
<dependency>org.apache.tomcat:coyote:6.0.29</dependency>
<dependency>org.apache.tomcat:jasper:6.0.29</dependency>
</dependencies>
</container>
</group>
</arquillian>
So what we have done here is to say we have two containers that Arquillian will control, container-1 and container-2. Arquillian will now instead of starting up one container, which is normal, start up two. In your test class you can target different deployments against the different containers using the @TargetsContainer("containerName") annotation on your Deployment methods.
@Deployment(name = "dep1") @TargetsContainer("container-1")
public static WebArchive createDep1() {}
@Deployment(name = "dep2") @TargetsContainer("container-2")
public static WebArchive createDep2() {}
@Test @OperateOnDeployment("dep1")
public void testRunningInDep1() {}
@Test @OperateOnDeployment("dep2")
public void testRunningInDep2() {}
We now have a single test class that will be executed in two different containers. testRunningInDep1 will operate in the context of the dep1 deployment which is deployed on the container named container-1 and testRunningInDep2 will operate in the context of deployment dep2 which is deployed on container container-2. As the test moves along, each method is executed inside the individual containers.
We also define the containers dependencies as part of the Arquillian xml. In some cases, like when running against multiple containers of the same type and the container has no client side state, this might not be needed. But for the sake of the example we define them in the configuration. In this case you should not have any of these dependencies on your application classpath.
Defining dependencies in arquillian xml is at the moment considered a experimental feature.