Author: jmesnil
Date: 2010-09-15 09:00:32 -0400 (Wed, 15 Sep 2010)
New Revision: 9689
Modified:
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/MultipleBackupsFailoverTestBase.java
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/MultipleLivesMultipleBackupsFailoverTest.java
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/RemoteMultipleLivesMultipleBackupsFailoverTest.java
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/RemoteSingleLiveMultipleBackupsFailoverTest.java
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/SingleLiveMultipleBackupsFailoverTest.java
Log:
added test for failback to primary live server
Modified:
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/MultipleBackupsFailoverTestBase.java
===================================================================
---
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/MultipleBackupsFailoverTestBase.java 2010-09-15
00:39:30 UTC (rev 9688)
+++
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/MultipleBackupsFailoverTestBase.java 2010-09-15
13:00:32 UTC (rev 9689)
@@ -15,6 +15,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -70,7 +71,7 @@
protected abstract boolean isNetty();
- protected int waitForBackup(long seconds, List<TestableServer> servers, int...
nodes)
+ protected int waitForBackup(long seconds, Map<Integer, TestableServer> servers,
int... nodes)
{
long time = System.currentTimeMillis();
long toWait = seconds * 1000;
Modified:
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/MultipleLivesMultipleBackupsFailoverTest.java
===================================================================
---
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/MultipleLivesMultipleBackupsFailoverTest.java 2010-09-15
00:39:30 UTC (rev 9688)
+++
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/MultipleLivesMultipleBackupsFailoverTest.java 2010-09-15
13:00:32 UTC (rev 9689)
@@ -14,7 +14,9 @@
package org.hornetq.tests.integration.cluster.failover;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientSession;
@@ -30,7 +32,7 @@
*/
public class MultipleLivesMultipleBackupsFailoverTest extends
MultipleBackupsFailoverTestBase
{
- protected ArrayList<TestableServer> servers = new
ArrayList<TestableServer>(5);
+ protected Map<Integer, TestableServer> servers = new HashMap<Integer,
TestableServer>();
public void testMultipleFailovers2LiveServers() throws Exception
{
@@ -124,7 +126,7 @@
config1.setPagingDirectory(config1.getPagingDirectory() + "_" +
liveNode);
config1.setLargeMessagesDirectory(config1.getLargeMessagesDirectory() +
"_" + liveNode);
- servers.add(new SameProcessHornetQServer(createFakeLockServer(true, config1)));
+ servers.put(nodeid, new SameProcessHornetQServer(createFakeLockServer(true,
config1)));
}
protected void createLiveConfig(int liveNode, int ... otherLiveNodes)
@@ -154,7 +156,7 @@
config0.setPagingDirectory(config0.getPagingDirectory() + "_" +
liveNode);
config0.setLargeMessagesDirectory(config0.getLargeMessagesDirectory() +
"_" + liveNode);
- servers.add(new SameProcessHornetQServer(createFakeLockServer(true, config0)));
+ servers.put(liveNode, new SameProcessHornetQServer(createFakeLockServer(true,
config0)));
}
protected boolean isNetty()
Modified:
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/RemoteMultipleLivesMultipleBackupsFailoverTest.java
===================================================================
---
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/RemoteMultipleLivesMultipleBackupsFailoverTest.java 2010-09-15
00:39:30 UTC (rev 9688)
+++
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/RemoteMultipleLivesMultipleBackupsFailoverTest.java 2010-09-15
13:00:32 UTC (rev 9689)
@@ -76,13 +76,13 @@
@Override
protected void createLiveConfig(int liveNode, int... otherLiveNodes)
{
- servers.add(new RemoteProcessHornetQServer(lives.get(liveNode)));
+ servers.put(liveNode, new RemoteProcessHornetQServer(lives.get(liveNode)));
}
@Override
protected void createBackupConfig(int liveNode, int nodeid, boolean
createClusterConnections, int... nodes)
{
- servers.add(new RemoteProcessHornetQServer(backups.get(nodeid)));
+ servers.put(nodeid, new RemoteProcessHornetQServer(backups.get(nodeid)));
}
// Private -------------------------------------------------------
Modified:
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/RemoteSingleLiveMultipleBackupsFailoverTest.java
===================================================================
---
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/RemoteSingleLiveMultipleBackupsFailoverTest.java 2010-09-15
00:39:30 UTC (rev 9688)
+++
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/RemoteSingleLiveMultipleBackupsFailoverTest.java 2010-09-15
13:00:32 UTC (rev 9689)
@@ -19,6 +19,9 @@
import java.util.Map;
import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.api.core.client.ClientSession;
+import org.hornetq.api.core.client.ServerLocator;
+import org.hornetq.core.client.impl.ClientSessionFactoryInternal;
import org.hornetq.core.config.BackupConnectorConfiguration;
import org.hornetq.core.config.ClusterConnectionConfiguration;
import org.hornetq.core.config.Configuration;
@@ -42,6 +45,62 @@
// Public --------------------------------------------------------
+ /**
+ * Checks that if the live server is restarted, it will became live again after killin
the current activated server.
+ */
+ public void testMultipleFailoversAndRestartLiveServer() throws Exception
+ {
+ createLiveConfig(0);
+ createBackupConfig(0, 1, false, 0, 2, 3);
+ createBackupConfig(0, 2, false, 0, 1, 3);
+ createBackupConfig(0, 3, false, 0, 1, 2);
+ servers.get(0).start();
+ servers.get(1).start();
+ servers.get(2).start();
+ servers.get(3).start();
+
+ ServerLocator locator = getServerLocator(0);
+
+ locator.setBlockOnNonDurableSend(true);
+ locator.setBlockOnDurableSend(true);
+ locator.setBlockOnAcknowledge(true);
+ locator.setReconnectAttempts(-1);
+ ClientSessionFactoryInternal sf = createSessionFactoryAndWaitForTopology(locator,
2);
+ int backupNode;
+ ClientSession session = sendAndConsume(sf, true);
+ System.out.println("failing live node ");
+ servers.get(0).crash(session);
+
+ session.close();
+ backupNode = waitForBackup(5, servers, 1, 2, 3);
+ session = sendAndConsume(sf, false);
+
+ System.out.println("restarting live node as a backup");
+ createBackupConfig(0, 0, false, 1, 2, 3);
+ servers.get(0).start();
+
+ System.out.println("stopping waiting nodes");
+ for (int i = 1; i <= 3; i++)
+ {
+ if (i != backupNode)
+ {
+ System.out.println("stopping node " + i);
+ servers.get(i).stop();
+ }
+ }
+
+ System.out.println("failing node " + backupNode);
+ servers.get(backupNode).crash(session);
+ session.close();
+ backupNode = waitForBackup(5, servers, 0);
+ assertEquals(0, backupNode);
+ session = sendAndConsume(sf, false);
+
+ locator.close();
+
+ servers.get(0).stop();
+ }
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
@@ -51,6 +110,7 @@
{
super.setUp();
+ backups.put(0, SharedBackupServerConfiguration0.class.getName());
backups.put(1, SharedBackupServerConfiguration1.class.getName());
backups.put(2, SharedBackupServerConfiguration2.class.getName());
backups.put(3, SharedBackupServerConfiguration3.class.getName());
@@ -66,13 +126,13 @@
@Override
protected void createLiveConfig(int liveNode, int... otherLiveNodes)
{
- servers.add(new
RemoteProcessHornetQServer(SharedLiveServerConfiguration.class.getName()));
+ servers.put(liveNode, new
RemoteProcessHornetQServer(SharedLiveServerConfiguration.class.getName()));
}
@Override
protected void createBackupConfig(int liveNode, int nodeid, boolean
createClusterConnections, int... nodes)
{
- servers.add(new RemoteProcessHornetQServer(backups.get(nodeid)));
+ servers.put(nodeid, new RemoteProcessHornetQServer(backups.get(nodeid)));
}
// Private -------------------------------------------------------
@@ -117,6 +177,15 @@
}
}
+ public static class SharedBackupServerConfiguration0 extends
RemoteServerConfiguration
+ {
+ @Override
+ public Configuration getConfiguration()
+ {
+ return createBackupConfiguration(0, 0, false, 1, 2, 3, 4, 5);
+ }
+ }
+
public static class SharedBackupServerConfiguration1 extends
RemoteServerConfiguration
{
@Override
@@ -188,7 +257,7 @@
config1.setBackupConnectorConfiguration(connectorConfiguration);
config1.getConnectorConfigurations().put(backupConnector.getName(),
backupConnector);
-
+System.out.println(config1.getBindingsDirectory());
config1.setBindingsDirectory(config1.getBindingsDirectory() + "_" +
liveNode);
config1.setJournalDirectory(config1.getJournalDirectory() + "_" +
liveNode);
config1.setPagingDirectory(config1.getPagingDirectory() + "_" +
liveNode);
Modified:
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/SingleLiveMultipleBackupsFailoverTest.java
===================================================================
---
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/SingleLiveMultipleBackupsFailoverTest.java 2010-09-15
00:39:30 UTC (rev 9688)
+++
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/cluster/failover/SingleLiveMultipleBackupsFailoverTest.java 2010-09-15
13:00:32 UTC (rev 9689)
@@ -13,8 +13,14 @@
package org.hornetq.tests.integration.cluster.failover;
+import static java.util.concurrent.TimeUnit.SECONDS;
+
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executors;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientSession;
@@ -31,7 +37,7 @@
public class SingleLiveMultipleBackupsFailoverTest extends
MultipleBackupsFailoverTestBase
{
- protected ArrayList<TestableServer> servers = new
ArrayList<TestableServer>(5);
+ protected Map<Integer, TestableServer> servers = new HashMap<Integer,
TestableServer>();
public void testMultipleFailovers() throws Exception
{
@@ -90,7 +96,7 @@
session.close();
servers.get(backupNode).stop();
}
-
+
protected void createBackupConfig(int liveNode, int nodeid, boolean
createClusterConnections, int... nodes)
{
Configuration config1 = super.createDefaultConfig();
@@ -117,13 +123,12 @@
config1.setBackupConnectorConfiguration(connectorConfiguration);
config1.getConnectorConfigurations().put(backupConnector.getName(),
backupConnector);
-
config1.setBindingsDirectory(config1.getBindingsDirectory() + "_" +
liveNode);
config1.setJournalDirectory(config1.getJournalDirectory() + "_" +
liveNode);
config1.setPagingDirectory(config1.getPagingDirectory() + "_" +
liveNode);
config1.setLargeMessagesDirectory(config1.getLargeMessagesDirectory() +
"_" + liveNode);
- servers.add(new SameProcessHornetQServer(createFakeLockServer(true, config1)));
+ servers.put(nodeid, new SameProcessHornetQServer(createFakeLockServer(true,
config1)));
}
protected void createLiveConfig(int liveNode, int ... otherLiveNodes)
@@ -153,7 +158,7 @@
config0.setPagingDirectory(config0.getPagingDirectory() + "_" +
liveNode);
config0.setLargeMessagesDirectory(config0.getLargeMessagesDirectory() +
"_" + liveNode);
- servers.add(new SameProcessHornetQServer(createFakeLockServer(true, config0)));
+ servers.put(liveNode, new SameProcessHornetQServer(createFakeLockServer(true,
config0)));
}
protected boolean isNetty()