[jboss-cvs] JBoss Messaging SVN: r8254 - branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/clustering.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 6 10:38:13 EDT 2011
Author: gaohoward
Date: 2011-04-06 10:38:13 -0400 (Wed, 06 Apr 2011)
New Revision: 8254
Modified:
branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/clustering/FailoverTest.java
Log:
JBMESSAGING-1855
Modified: branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/clustering/FailoverTest.java
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/clustering/FailoverTest.java 2011-04-04 09:39:31 UTC (rev 8253)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/clustering/FailoverTest.java 2011-04-06 14:38:13 UTC (rev 8254)
@@ -6,15 +6,15 @@
*/
package org.jboss.test.messaging.jms.clustering;
-import java.util.ArrayList;
import java.util.Enumeration;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
+import javax.jms.ExceptionListener;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
@@ -2394,6 +2394,118 @@
}
}
+
+ public void testExceptionListenerOnFailoverFailure() throws Exception
+ {
+ Connection conn = null;
+
+ try
+ {
+ conn = createConnectionOnServer(cf, 1);
+
+ SimpleExceptionListener listener = new SimpleExceptionListener();
+ conn.setExceptionListener(listener);
+
+ conn.start();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ //start a thread to receive
+ ReceiveThread thr = new ReceiveThread(session, queue[1]);
+ thr.start();
+
+ // register a failover listener
+ SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+ ((JBossConnection)conn).registerFailoverListener(failoverListener);
+
+ try
+ {
+ Thread.sleep(5000);
+ }
+ catch(InterruptedException e)
+ {
+ }
+
+ ServerManagement.stop(1);
+
+ // wait for the client-side failover to complete
+
+ while(true)
+ {
+ FailoverEvent event = failoverListener.getEvent(120000);
+ if (event != null && FailoverEvent.FAILOVER_FAILED == event.getType())
+ {
+ break;
+ }
+ if (event == null)
+ {
+ fail("Did not get expected FAILOVER_FAILED event");
+ }
+ }
+
+ thr.join();
+
+ try
+ {
+ //give time for notification
+ Thread.sleep(5000);
+ }
+ catch(InterruptedException e)
+ {
+ }
+
+ assertTrue(listener.getNotified());
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ JBossConnection c = (JBossConnection)conn;
+ System.out.println("Server id for connectio is : " + c.getServerID());
+ conn.close();
+ }
+ }
+ }
+
// Inner classes --------------------------------------------------------------------------------
+ public static class SimpleExceptionListener implements ExceptionListener
+ {
+ AtomicBoolean getNotified = new AtomicBoolean(false);
+
+ public void onException(JMSException arg0)
+ {
+ getNotified.set(true);
+ }
+
+ public boolean getNotified()
+ {
+ return getNotified.get();
+ }
+ }
+
+ public static class ReceiveThread extends Thread
+ {
+ Session session;
+ Queue queue;
+
+ public ReceiveThread(Session session, Queue queue)
+ {
+ this.session = session;
+ this.queue = queue;
+ }
+
+ public void run()
+ {
+ try
+ {
+ MessageConsumer consumer = session.createConsumer(queue);
+ consumer.receive(0);
+ }
+ catch (JMSException e)
+ {
+ fail("Failed to run receiver " + e);
+ }
+ }
+ }
}
More information about the jboss-cvs-commits
mailing list