Author: clebert.suconic(a)jboss.com
Date: 2011-09-27 18:24:35 -0400 (Tue, 27 Sep 2011)
New Revision: 11435
Modified:
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/topology/IsolatedTopologyTest.java
Log:
improving test
Modified:
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/topology/IsolatedTopologyTest.java
===================================================================
---
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/topology/IsolatedTopologyTest.java 2011-09-27
20:42:05 UTC (rev 11434)
+++
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/cluster/topology/IsolatedTopologyTest.java 2011-09-27
22:24:35 UTC (rev 11435)
@@ -18,12 +18,17 @@
import java.util.List;
import java.util.Map;
+import junit.framework.Assert;
+
import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.core.client.impl.Topology;
+import org.hornetq.core.client.impl.TopologyMember;
import org.hornetq.core.config.ClusterConnectionConfiguration;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.remoting.impl.netty.TransportConstants;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.tests.util.ServiceTestBase;
+import org.hornetq.tests.util.UnitTestCase;
/**
* A IsolatedTopologyTest
@@ -34,52 +39,73 @@
*/
public class IsolatedTopologyTest extends ServiceTestBase
{
-
+
+ @Override
public void setUp() throws Exception
{
super.setUp();
}
-
+ @Override
public void tearDown() throws Exception
{
super.tearDown();
}
-
-
+
public void testIsolatedClusters() throws Exception
{
-
+
HornetQServer server1 = createServer1();
HornetQServer server2 = createServer2();
-
+
try
{
server1.start();
- Thread.sleep(500);
server2.start();
-
- Thread.sleep(2000);
-
-
System.out.println(server1.getClusterManager().getClusterConnection("cc1").getTopology().describe());
-
-
System.out.println(server1.getClusterManager().getClusterConnection("cc2").getTopology().describe());
-
-
System.out.println(server2.getClusterManager().getClusterConnection("cc1").getTopology().describe());
-
-
System.out.println(server2.getClusterManager().getClusterConnection("cc2").getTopology().describe());
-
+
waitForTopology(server1, "cc1", 2, 5000);
-
+
waitForTopology(server1, "cc2", 2, 5000);
-
+
waitForTopology(server2, "cc1", 2, 5000);
-
+
waitForTopology(server2, "cc2", 2, 5000);
+
+ String node1 = server1.getNodeID().toString();
+ String node2 = server2.getNodeID().toString();
+
+ checkTopology(server1,
+ "cc1",
+ node1,
+ node2,
+ createInVMTransportConnectorConfig(1, "srv1"),
+ createInVMTransportConnectorConfig(3, "srv1"));
+
+ checkTopology(server2,
+ "cc1",
+ node1,
+ node2,
+ createInVMTransportConnectorConfig(1, "srv1"),
+ createInVMTransportConnectorConfig(3, "srv1"));
+
+ checkTopology(server1,
+ "cc2",
+ node1,
+ node2,
+ createInVMTransportConnectorConfig(2, "srv1"),
+ createInVMTransportConnectorConfig(4, "srv1"));
+
+ checkTopology(server2,
+ "cc2",
+ node1,
+ node2,
+ createInVMTransportConnectorConfig(2, "srv1"),
+ createInVMTransportConnectorConfig(4, "srv1"));
}
finally
{
+ Thread.sleep(500);
try
{
server1.stop();
@@ -87,7 +113,7 @@
catch (Throwable ignored)
{
}
-
+
try
{
server2.stop();
@@ -98,135 +124,154 @@
}
}
+ private void checkTopology(final HornetQServer serverParameter,
+ final String clusterName,
+ final String nodeId1,
+ final String nodeId2,
+ final TransportConfiguration cfg1,
+ final TransportConfiguration cfg2)
+ {
+ Topology topology =
serverParameter.getClusterManager().getClusterConnection(clusterName).getTopology();
+ TopologyMember member1 = topology.getMember(nodeId1);
+ TopologyMember member2 = topology.getMember(nodeId2);
+ Assert.assertEquals(member1.getA().toString(), cfg1.toString());
+ Assert.assertEquals(member2.getA().toString(), cfg2.toString());
+ }
+
private HornetQServer createServer1()
{
// Server1 with two acceptors, each acceptor on a different cluster connection
// talking to a different connector.
// i.e. two cluster connections isolated on the same node
- Configuration config1 = createBasicConfig(0);
-
+ Configuration config1 = UnitTestCase.createBasicConfig(0);
+
config1.setClustered(true);
-
+
Map<String, Object> params = new HashMap<String, Object>();
params.put(TransportConstants.CLUSTER_CONNECTION, "cc1");
params.put(org.hornetq.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME,
"1");
-
- TransportConfiguration acceptor1VM1 = new
TransportConfiguration(INVM_ACCEPTOR_FACTORY, params, "acceptor-cc1");
+
+ TransportConfiguration acceptor1VM1 = new
TransportConfiguration(ServiceTestBase.INVM_ACCEPTOR_FACTORY,
+ params,
+
"acceptor-cc1");
config1.getAcceptorConfigurations().add(acceptor1VM1);
-
+
config1.getConnectorConfigurations().put("local-cc1",
createInVMTransportConnectorConfig(1, "local-cc1"));
config1.getConnectorConfigurations().put("local-cc2",
createInVMTransportConnectorConfig(2, "local-cc2"));
config1.getConnectorConfigurations().put("other-cc1",
createInVMTransportConnectorConfig(3, "other-cc1"));
config1.getConnectorConfigurations().put("other-cc2",
createInVMTransportConnectorConfig(4, "other-cc2"));
-
params = new HashMap<String, Object>();
params.put(TransportConstants.CLUSTER_CONNECTION, "cc2");
params.put(org.hornetq.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME,
"2");
-
- TransportConfiguration acceptor2VM1 = new
TransportConfiguration(INVM_ACCEPTOR_FACTORY, params, "acceptor-cc2");
+
+ TransportConfiguration acceptor2VM1 = new
TransportConfiguration(ServiceTestBase.INVM_ACCEPTOR_FACTORY,
+ params,
+
"acceptor-cc2");
config1.getAcceptorConfigurations().add(acceptor2VM1);
-
+
List<String> connectTo = new ArrayList<String>();
connectTo.add("other-cc1");
-
+
ClusterConnectionConfiguration server1CC1 = new
ClusterConnectionConfiguration("cc1",
- "jms",
- "local-cc1",
- 250,
- true,
- false,
- 1,
- 1024,
- connectTo,
- false);
-
+
"jms",
+
"local-cc1",
+
250,
+
true,
+
false,
+ 1,
+
1024,
+
connectTo,
+
false);
+
config1.getClusterConfigurations().add(server1CC1);
-
+
connectTo = new ArrayList<String>();
connectTo.add("other-cc2");
-
+
ClusterConnectionConfiguration server1CC2 = new
ClusterConnectionConfiguration("cc2",
- "jms",
- "local-cc2",
- 250,
- true,
- false,
- 1,
- 1024,
- connectTo,
- false);
-
+
"jms",
+
"local-cc2",
+
250,
+
true,
+
false,
+ 1,
+
1024,
+
connectTo,
+
false);
+
config1.getClusterConfigurations().add(server1CC2);
-
+
return createServer(false, config1);
}
-
private HornetQServer createServer2()
{
// Server1 with two acceptors, each acceptor on a different cluster connection
// talking to a different connector.
// i.e. two cluster connections isolated on the same node
- Configuration config1 = createBasicConfig(3);
-
+ Configuration config1 = UnitTestCase.createBasicConfig(3);
+
config1.setClustered(true);
-
+
Map<String, Object> params = new HashMap<String, Object>();
params.put(TransportConstants.CLUSTER_CONNECTION, "cc1");
params.put(org.hornetq.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME,
"3");
-
- TransportConfiguration acceptor1VM1 = new
TransportConfiguration(INVM_ACCEPTOR_FACTORY, params, "acceptor-cc1");
+
+ TransportConfiguration acceptor1VM1 = new
TransportConfiguration(ServiceTestBase.INVM_ACCEPTOR_FACTORY,
+ params,
+
"acceptor-cc1");
config1.getAcceptorConfigurations().add(acceptor1VM1);
-
+
config1.getConnectorConfigurations().put("local-cc1",
createInVMTransportConnectorConfig(3, "local-cc1"));
config1.getConnectorConfigurations().put("local-cc2",
createInVMTransportConnectorConfig(4, "local-cc2"));
config1.getConnectorConfigurations().put("other-cc1",
createInVMTransportConnectorConfig(1, "other-cc1"));
config1.getConnectorConfigurations().put("other-cc2",
createInVMTransportConnectorConfig(2, "other-cc2"));
-
params = new HashMap<String, Object>();
params.put(TransportConstants.CLUSTER_CONNECTION, "cc2");
params.put(org.hornetq.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME,
"4");
-
- TransportConfiguration acceptor2VM1 = new
TransportConfiguration(INVM_ACCEPTOR_FACTORY, params, "acceptor-cc2");
+
+ TransportConfiguration acceptor2VM1 = new
TransportConfiguration(ServiceTestBase.INVM_ACCEPTOR_FACTORY,
+ params,
+
"acceptor-cc2");
config1.getAcceptorConfigurations().add(acceptor2VM1);
-
+
List<String> connectTo = new ArrayList<String>();
connectTo.add("other-cc1");
-
+
ClusterConnectionConfiguration server1CC1 = new
ClusterConnectionConfiguration("cc1",
- "jms",
- "local-cc1",
- 250,
- true,
- false,
- 1,
- 1024,
- connectTo,
- false);
-
+
"jms",
+
"local-cc1",
+
250,
+
true,
+
false,
+ 1,
+
1024,
+
connectTo,
+
false);
+
config1.getClusterConfigurations().add(server1CC1);
-
+
connectTo = new ArrayList<String>();
connectTo.add("other-cc2");
-
+
ClusterConnectionConfiguration server1CC2 = new
ClusterConnectionConfiguration("cc2",
- "jms",
- "local-cc2",
- 250,
- true,
- false,
- 1,
- 1024,
- connectTo,
- false);
-
+
"jms",
+
"local-cc2",
+
250,
+
true,
+
false,
+ 1,
+
1024,
+
connectTo,
+
false);
+
config1.getClusterConfigurations().add(server1CC2);
-
+
return createServer(false, config1);
}