Author: ataylor
Date: 2010-10-06 09:49:22 -0400 (Wed, 06 Oct 2010)
New Revision: 9759
Modified:
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/jms/cluster/JMSFailoverTest.java
Log:
fixed jms failover tests
Modified:
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/jms/cluster/JMSFailoverTest.java
===================================================================
---
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/jms/cluster/JMSFailoverTest.java 2010-10-06
11:24:44 UTC (rev 9758)
+++
branches/2_2_0_HA_Improvements/tests/src/org/hornetq/tests/integration/jms/cluster/JMSFailoverTest.java 2010-10-06
13:49:22 UTC (rev 9759)
@@ -13,7 +13,9 @@
package org.hornetq.tests.integration.jms.cluster;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import javax.jms.BytesMessage;
@@ -36,6 +38,8 @@
import org.hornetq.api.core.client.ClientSession;
import org.hornetq.api.jms.HornetQJMSClient;
import org.hornetq.core.client.impl.ClientSessionInternal;
+import org.hornetq.core.config.BackupConnectorConfiguration;
+import org.hornetq.core.config.ClusterConnectionConfiguration;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.config.impl.ConfigurationImpl;
import org.hornetq.core.logging.Logger;
@@ -43,13 +47,16 @@
import org.hornetq.core.remoting.impl.invm.TransportConstants;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.core.server.HornetQServers;
+import org.hornetq.core.server.cluster.impl.FakeLockFile;
import org.hornetq.jms.client.HornetQConnectionFactory;
import org.hornetq.jms.client.HornetQDestination;
import org.hornetq.jms.client.HornetQSession;
import org.hornetq.jms.server.JMSServerManager;
import org.hornetq.jms.server.impl.JMSServerManagerImpl;
import org.hornetq.spi.core.protocol.RemotingConnection;
+import org.hornetq.tests.integration.jms.server.management.JMSUtil;
import org.hornetq.tests.unit.util.InVMContext;
+import org.hornetq.tests.util.FakeLockHornetQServer;
import org.hornetq.tests.util.RandomUtil;
import org.hornetq.tests.util.UnitTestCase;
@@ -91,7 +98,12 @@
protected HornetQServer backupService;
protected Map<String, Object> backupParams = new HashMap<String,
Object>();
+ private TransportConfiguration backuptc;
+ private TransportConfiguration livetc;
+ private TransportConfiguration liveAcceptortc;
+ private TransportConfiguration backupAcceptortc;
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -102,26 +114,19 @@
{
liveJMSService.createQueue(true, "queue1", null, true,
"/queue/queue1");
assertNotNull(ctx1.lookup("/queue/queue1"));
- liveJMSService.stop();
- Object obj = null;
+ HornetQConnectionFactory jbcf =
HornetQJMSClient.createConnectionFactoryWithHA(livetc);
- try
- {
- obj = ctx1.lookup("/queue/queue1");
- }
- catch (NamingException expected)
- {
+ jbcf.setReconnectAttempts(-1);
- }
+ Connection conn = jbcf.createConnection();
- assertNull(obj);
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- backupJMSService.stop();
+ ClientSession coreSession = ((HornetQSession)sess).getCoreSession();
- backupConf.setBackup(false);
+ JMSUtil.crash(liveService, coreSession);
- backupJMSService.start();
assertNotNull(ctx2.lookup("/queue/queue1"));
}
@@ -131,36 +136,26 @@
{
liveJMSService.createTopic(true, "topic", "/topic/t1");
assertNotNull(ctx1.lookup("//topic/t1"));
- liveJMSService.stop();
- Object obj = null;
+ HornetQConnectionFactory jbcf =
HornetQJMSClient.createConnectionFactoryWithHA(livetc);
- try
- {
- obj = ctx1.lookup("//topic/t1");
- }
- catch (NamingException expected)
- {
+ jbcf.setReconnectAttempts(-1);
- }
+ Connection conn = jbcf.createConnection();
- assertNull(obj);
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- backupJMSService.stop();
+ ClientSession coreSession = ((HornetQSession)sess).getCoreSession();
- backupConf.setBackup(false);
+ JMSUtil.crash(liveService, coreSession);
- backupJMSService.start();
-
assertNotNull(ctx2.lookup("/topic/t1"));
}
public void testAutomaticFailover() throws Exception
{
- HornetQConnectionFactory jbcf = (HornetQConnectionFactory)
HornetQJMSClient.createConnectionFactoryWithoutHA(new
TransportConfiguration("org.hornetq.core.remoting.impl.invm.InVMConnectorFactory"),
- new
TransportConfiguration("org.hornetq.core.remoting.impl.invm.InVMConnectorFactory",
-
backupParams));
-
+ HornetQConnectionFactory jbcf =
HornetQJMSClient.createConnectionFactoryWithHA(livetc);
+ jbcf.setReconnectAttempts(-1);
jbcf.setBlockOnDurableSend(true);
jbcf.setBlockOnNonDurableSend(true);
@@ -184,8 +179,6 @@
ClientSession coreSession = ((HornetQSession)sess).getCoreSession();
- RemotingConnection coreConn =
((ClientSessionInternal)coreSession).getConnection();
-
SimpleString jmsQueueName = new
SimpleString(HornetQDestination.JMS_QUEUE_ADDRESS_PREFIX + "myqueue");
coreSession.createQueue(jmsQueueName, jmsQueueName, null, true);
@@ -215,10 +208,8 @@
Thread.sleep(2000);
- HornetQException me = new HornetQException(HornetQException.NOT_CONNECTED);
+ JMSUtil.crash(liveService, ((HornetQSession) sess).getCoreSession());
- coreConn.fail(me);
-
for (int i = 0; i < numMessages; i++)
{
JMSFailoverTest.log.info("got message " + i);
@@ -236,22 +227,20 @@
conn.close();
- Assert.assertNotNull(listener.e);
-
- Assert.assertTrue(me == listener.e.getCause());
}
public void testManualFailover() throws Exception
{
- HornetQConnectionFactory jbcfLive = (HornetQConnectionFactory)
HornetQJMSClient.createConnectionFactoryWithoutHA(new
TransportConfiguration("org.hornetq.core.remoting.impl.invm.InVMConnectorFactory"));
+ HornetQConnectionFactory jbcfLive =
HornetQJMSClient.createConnectionFactoryWithoutHA(new
TransportConfiguration("org.hornetq.core.remoting.impl.invm.InVMConnectorFactory"));
jbcfLive.setBlockOnNonDurableSend(true);
jbcfLive.setBlockOnDurableSend(true);
- HornetQConnectionFactory jbcfBackup = (HornetQConnectionFactory)
HornetQJMSClient.createConnectionFactoryWithoutHA(new
TransportConfiguration("org.hornetq.core.remoting.impl.invm.InVMConnectorFactory",
+ HornetQConnectionFactory jbcfBackup =
HornetQJMSClient.createConnectionFactoryWithoutHA(new
TransportConfiguration("org.hornetq.core.remoting.impl.invm.InVMConnectorFactory",
backupParams));
jbcfBackup.setBlockOnNonDurableSend(true);
jbcfBackup.setBlockOnDurableSend(true);
+ jbcfBackup.setReconnectAttempts(-1);
Connection connLive = jbcfLive.createConnection();
@@ -284,16 +273,8 @@
// Note we block on P send to make sure all messages get to server before failover
- HornetQException me = new HornetQException(HornetQException.NOT_CONNECTED);
+ JMSUtil.crash(liveService, coreSessionLive);
- coreConnLive.fail(me);
-
- Assert.assertNotNull(listener.e);
-
- JMSException je = listener.e;
-
- Assert.assertEquals(me, je.getCause());
-
connLive.close();
// Now recreate on backup
@@ -330,7 +311,7 @@
protected void setUp() throws Exception
{
super.setUp();
-
+ FakeLockFile.clearLocks();
startServers();
}
@@ -339,7 +320,25 @@
*/
protected void startServers() throws Exception
{
+ backuptc = new
TransportConfiguration("org.hornetq.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams);
+ livetc = new
TransportConfiguration("org.hornetq.core.remoting.impl.invm.InVMConnectorFactory");
+
+ liveAcceptortc = new
TransportConfiguration("org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory");
+
+
+ backupAcceptortc = new
TransportConfiguration("org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory",
+ backupParams);
+
backupConf = new ConfigurationImpl();
+
+ backupConf.getAcceptorConfigurations().add(backupAcceptortc);
+ backupConf.getConnectorConfigurations().put(livetc.getName(), livetc);
+ backupConf.getConnectorConfigurations().put(backuptc.getName(), backuptc);
+ ArrayList<String> staticConnectors = new ArrayList<String>();
+ staticConnectors.add(livetc.getName());
+ backupConf.setBackupConnectorConfiguration(new
BackupConnectorConfiguration(staticConnectors, backuptc.getName()) );
+
backupConf.setSecurityEnabled(false);
backupConf.setJournalType(getDefaultJournalType());
backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
@@ -352,7 +351,9 @@
backupConf.setJournalDirectory(getJournalDir());
backupConf.setPagingDirectory(getPageDir());
backupConf.setLargeMessagesDirectory(getLargeMessagesDir());
- backupService = HornetQServers.newHornetQServer(backupConf, true);
+ backupConf.setPersistenceEnabled(true);
+ backupConf.setClustered(true);
+ backupService = new FakeLockHornetQServer(backupConf);
backupJMSService = new JMSServerManagerImpl(backupService);
@@ -365,7 +366,11 @@
liveConf = new ConfigurationImpl();
liveConf.setSecurityEnabled(false);
liveConf.getAcceptorConfigurations()
- .add(new
TransportConfiguration("org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory"));
+ .add(liveAcceptortc);
+ List<String> pairs = null;
+ ClusterConnectionConfiguration ccc0 = new
ClusterConnectionConfiguration("cluster1", "jms", livetc.getName(),
-1, false, false, 1, 1,
+ pairs);
+ liveConf.getClusterConfigurations().add(ccc0);
liveConf.setSharedStore(true);
liveConf.setJournalType(getDefaultJournalType());
liveConf.setBindingsDirectory(getBindingsDir());
@@ -373,8 +378,10 @@
liveConf.setJournalDirectory(getJournalDir());
liveConf.setPagingDirectory(getPageDir());
liveConf.setLargeMessagesDirectory(getLargeMessagesDir());
-
- liveService = HornetQServers.newHornetQServer(liveConf, true);
+ liveConf.getConnectorConfigurations().put(livetc.getName(), livetc);
+ liveConf.setPersistenceEnabled(true);
+ liveConf.setClustered(true);
+ liveService = new FakeLockHornetQServer(liveConf);
liveJMSService = new JMSServerManagerImpl(liveService);
@@ -382,6 +389,7 @@
liveJMSService.start();
+ JMSUtil.waitForServer(backupService);
}
@Override