[jboss-cvs] JBossAS SVN: r67028 - in branches/JBPAPP_4_2/testsuite: src/main/org/jboss/test/jbossmessaging/clustertest and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Nov 13 11:43:26 EST 2007
Author: clebert.suconic at jboss.com
Date: 2007-11-13 11:43:26 -0500 (Tue, 13 Nov 2007)
New Revision: 67028
Modified:
branches/JBPAPP_4_2/testsuite/build.xml
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/clustertest/ClusteredTestCase.java
branches/JBPAPP_4_2/testsuite/src/resources/jbossmessaging/test-clustered-destinations-full-service.xml
Log:
http://jira.jboss.com/jira/browse/JBMESSAGING-726, http://jira.jboss.com/jira/browse/JBQA-1129 - small tweaks & adding more tests
Modified: branches/JBPAPP_4_2/testsuite/build.xml
===================================================================
--- branches/JBPAPP_4_2/testsuite/build.xml 2007-11-13 16:08:38 UTC (rev 67027)
+++ branches/JBPAPP_4_2/testsuite/build.xml 2007-11-13 16:43:26 UTC (rev 67028)
@@ -1002,7 +1002,7 @@
</create-config>
</target>
- <target name="tests-jbmcluster"
+ <target name="tests-jbmcluster" if="jbosstest.test.soa"
description="Run JBM in cluster">
<antcall target="create-jbmcluster"/>
@@ -1011,8 +1011,8 @@
<server:start name="jbm-cluster2"/>
<antcall target="exec-jbmclustered"/>
-
- <server:stop name="jbm-cluster2"/>
+
+ <!-- I'm not stopping jbm-cluster2 as this server will be killed during the test -->
<server:stop name="jbm-cluster1"/>
</target>
Modified: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/clustertest/ClusteredTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/clustertest/ClusteredTestCase.java 2007-11-13 16:08:38 UTC (rev 67027)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/clustertest/ClusteredTestCase.java 2007-11-13 16:43:26 UTC (rev 67028)
@@ -22,10 +22,12 @@
package org.jboss.test.jbossmessaging.clustertest;
+import java.util.StringTokenizer;
import java.util.concurrent.CountDownLatch;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
@@ -34,13 +36,20 @@
import javax.management.ObjectName;
import javax.naming.Context;
import javax.naming.InitialContext;
+
import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
+import org.jboss.jms.client.FailoverEvent;
+import org.jboss.jms.client.FailoverListener;
import org.jboss.jms.client.JBossConnection;
import org.jboss.test.JBossClusteredTestCase;
import org.jboss.test.JBossTestClusteredServices;
+import org.jboss.test.JBossTestClusteredSetup;
+import org.jboss.test.JBossTestSetup;
import org.jboss.util.id.GUID;
+import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
+
import junit.framework.Test;
/**
@@ -55,18 +64,20 @@
{
CountDownLatch latchCluster = new CountDownLatch(1);
- CountDownLatch latchFailover = new CountDownLatch(3);
+ CountDownLatch latchFailover = new CountDownLatch(5);
CountDownLatch latchServerAlreadyKilled = new CountDownLatch(1);
public ParallelTest[] getTests()
{
return new ParallelTest[]
- { new ClusterTestSimple(latchCluster), new FailoverTestSimple(latchFailover, latchServerAlreadyKilled),
+ { new ClusterTestSimple(latchCluster),
+ new FailoverTestSimple(latchFailover, latchServerAlreadyKilled),
new FailoverTestSimpleTransacted("testFailoverTransactedKillOnCommit", true, latchFailover, latchServerAlreadyKilled, "testDistributedQueueC"),
- new FailoverTestSimpleTransacted("testFailoverTransactedKillOnMessageReceive", false, latchFailover, latchServerAlreadyKilled, "testDistributedQueueD")};
+ new FailoverTestSimpleTransacted("testFailoverTransactedKillOnMessageReceive", false, latchFailover, latchServerAlreadyKilled, "testDistributedQueueD"),
+ new FailoverTestSessionWithOneTransactedPersistentMessageFailover(latchFailover, latchServerAlreadyKilled),
+ new FailoverSessionWithOneTransactedNonPersistentMessageFailover(latchFailover, latchServerAlreadyKilled)};
}
-
public void doTest() throws Exception
{
@@ -128,28 +139,45 @@
}
}
- class FailoverTestSimple extends ParallelTest
+ abstract class FailoverTest extends ParallelTest
{
-
Context ctx;
ConnectionFactory cf;
CountDownLatch latch;
CountDownLatch latchAlreadyKilled;
- public FailoverTestSimple(CountDownLatch latch, CountDownLatch latchAlreadyKilled)
+ public FailoverTest(String name, CountDownLatch latch, CountDownLatch latchAlreadyKilled)
{
- super("testSimpleFailover");
-
+ super(name);
this.latch = latch;
- this.latchAlreadyKilled = latchAlreadyKilled;
+ this.latchAlreadyKilled = latchAlreadyKilled;
}
public void setUp() throws Exception
{
+ super.setUp();
ctx = new InitialContext();
cf = (ConnectionFactory) ctx.lookup("/ClusteredConnectionFactory");
}
+ public abstract void runTest() throws Throwable;
+
+ }
+
+ class FailoverTestSimple extends FailoverTest
+ {
+
+
+ public FailoverTestSimple(CountDownLatch latch, CountDownLatch latchAlreadyKilled)
+ {
+ super("testSimpleFailover", latch, latchAlreadyKilled);
+ }
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ }
+
public void tearDown() throws Exception
{
super.tearDown();
@@ -200,37 +228,32 @@
ignored.printStackTrace();
}
- latch.countDown();
+ if (!latchCalled)
+ {
+ latch.countDown();
+ }
+
}
}
}
-
- class FailoverTestSimpleTransacted extends ParallelTest
+
+ class FailoverTestSimpleTransacted extends FailoverTest
{
- Context ctx;
- ConnectionFactory cf;
- CountDownLatch latch;
- CountDownLatch latchAlreadyKilled;
String jndiQueue;
-
boolean killOnTransaction;
public FailoverTestSimpleTransacted(String name, boolean killOnTransaction, CountDownLatch latch, CountDownLatch latchAlreadyKilled, String jndiQueue)
{
- super(name);
-
- this.latch = latch;
- this.latchAlreadyKilled = latchAlreadyKilled;
+ super(name, latch, latchAlreadyKilled);
this.killOnTransaction = killOnTransaction;
this.jndiQueue = jndiQueue;
}
public void setUp() throws Exception
{
- ctx = new InitialContext();
- cf = (ConnectionFactory) ctx.lookup("/ClusteredConnectionFactory");
+ super.setUp();
}
public void tearDown() throws Exception
@@ -398,17 +421,292 @@
}
}
+
+ class FailoverTestSessionWithOneTransactedPersistentMessageFailover extends FailoverTest
+ {
+ public FailoverTestSessionWithOneTransactedPersistentMessageFailover(
+ CountDownLatch latch,
+ CountDownLatch latchAlreadyKilled)
+ {
+ super("testSessionWithOneTransactedPersistentMessageFailover", latch, latchAlreadyKilled);
+ }
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ }
+
+ public void runTest() throws Throwable
+ {
+ boolean latchAlreadyCalled = false;
+ Connection conn = null;
+
+ Queue queue = (Queue) ctx.lookup("/queue/testDistributedQueueE");
+
+ try
+ {
+ conn = createConnectionOnServer(cf, 1);
+
+ conn.start();
+
+ Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
+
+ // send 2 transacted messages (one persistent and one non-persistent) but don't commit
+ MessageProducer prod = session.createProducer(queue);
+
+ prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+ prod.send(session.createTextMessage("clik-persistent"));
+
+ // close the producer
+ prod.close();
+
+ System.out.println("producer closed");
+
+ // create a consumer on the same local queue (creating a consumer AFTER failover will end
+ // up getting messages from a local queue, not a failed over queue; at least until
+ // redistribution is implemented.
+
+ Session session2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer cons = session2.createConsumer(queue);
+
+ // register a failover listener
+ SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+ ((JBossConnection)conn).registerFailoverListener(failoverListener);
+
+ latchAlreadyCalled = true;
+ latch.countDown();
+ latchAlreadyKilled.await();
+
+ // wait for the client-side failover to complete
+
+ while(true)
+ {
+ FailoverEvent event = failoverListener.getEvent(30000);
+ if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+ {
+ break;
+ }
+ if (event == null)
+ {
+ fail("Did not get expected FAILOVER_COMPLETED event");
+ }
+ }
+
+ // failover complete
+ assertEquals(0, getServerId(conn));
+
+ // commit the failed-over session
+ session.commit();
+
+ // make sure messages made it to the queue
+
+ TextMessage tm = (TextMessage)cons.receive(2000);
+ assertNotNull(tm);
+ assertEquals("clik-persistent", tm.getText());
+ }
+ finally
+ {
+ if (!latchAlreadyCalled)
+ {
+ latch.countDown();
+ }
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ }
+
+ }
+
+ class FailoverSessionWithOneTransactedNonPersistentMessageFailover extends FailoverTest
+ {
+
+ public FailoverSessionWithOneTransactedNonPersistentMessageFailover(
+ CountDownLatch latch,
+ CountDownLatch latchAlreadyKilled)
+ {
+ super("testSessionWithOneTransactedNonPersistentMessageFailover", latch, latchAlreadyKilled);
+ }
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ }
+
+ public void runTest() throws Throwable
+ {
+ Connection conn = null;
+
+ boolean latchCalled = false;
+
+ Queue queue = (Queue) ctx.lookup("queue/testDistributedQueueF");
+
+ try
+ {
+ conn = createConnectionOnServer(cf, 1);
+
+ conn.start();
+
+ Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
+
+ MessageProducer prod = session.createProducer(queue);
+
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ prod.send(session.createTextMessage("clik-non-persistent"));
+
+ // close the producer
+ prod.close();
+
+ // create a consumer on the same local queue (creating a consumer AFTER failover will end
+ // up getting messages from a local queue, not a failed over queue; at least until
+ // redistribution is implemented.
+
+ Session session2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer cons = session2.createConsumer(queue);
+
+ // register a failover listener
+ SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+ ((JBossConnection)conn).registerFailoverListener(failoverListener);
+
+ latchCalled = true;
+ latch.countDown();
+ latchAlreadyKilled.await();
+
+ // wait for the client-side failover to complete
+
+ while(true)
+ {
+ FailoverEvent event = failoverListener.getEvent(30000);
+ if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+ {
+ break;
+ }
+ if (event == null)
+ {
+ fail("Did not get expected FAILOVER_COMPLETED event");
+ }
+ }
+
+ // failover complete
+
+ assertEquals(0, getServerId(conn));
+
+ // commit the failed-over session
+ session.commit();
+
+ // make sure messages made it to the queue
+
+ TextMessage tm = (TextMessage)cons.receive(2000);
+ assertNotNull(tm);
+ assertEquals("clik-non-persistent", tm.getText());
+ }
+ finally
+ {
+ if (!latchCalled)
+ {
+ latch.countDown();
+ }
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ }
+ }
+
+
public static Test suite() throws Exception
{
- Test test = new ClusteredTestCase();
-
ClassLoader loader = ClusteredTestCase.class.getClassLoader();
- String destinations = loader.getResource("jbossmessaging/test-clustered-destinations-full-service.xml").toString();
- //String killJar = loader.getResource("jbm-killservice.sar").toString();
- test = JBossClusteredTestCase.getDeploySetup(test, destinations + ",jbm-killservice.sar");
+ final String destinations = loader.getResource("jbossmessaging/test-clustered-destinations-full-service.xml").toString();
+ final String jarNames = destinations + ",jbm-killservice.sar";
+ final Test test = new ClusteredTestCase();
- return test;
+
+ JBossTestSetup wrapper = new JBossTestClusteredSetup(test)
+ {
+
+ protected void setUp() throws Exception
+ {
+ if (jarNames == null) return;
+
+ // deploy the comma seperated list of jars
+ StringTokenizer st = new StringTokenizer(jarNames, ", ");
+ while (st != null && st.hasMoreTokens())
+ {
+ String jarName = st.nextToken();
+ this.redeploy(jarName);
+ this.getLog().debug("deployed package: " + jarName);
+ }
+
+ // wait a few seconds so that the cluster stabilize
+ synchronized (this)
+ {
+ wait(2000);
+ }
+ }
+
+ protected void tearDown() throws Exception
+ {
+
+ if (jarNames != null)
+ {
+ JBossTestClusteredServices clusteredDelegate = (JBossTestClusteredServices) delegate;
+
+ // deploy the comma seperated list of jars
+ StringTokenizer st = new StringTokenizer(jarNames, ", ");
+ String[] depoyments = new String[st.countTokens()];
+ for (int i = depoyments.length - 1; i >= 0; i--)
+ depoyments[i] = st.nextToken();
+ for (int i = 0; i < depoyments.length; i++)
+ {
+ String jarName = depoyments[i];
+ this.getLog().debug("Attempt undeploy of " + jarName);
+ clusteredDelegate.undeploy(clusteredDelegate.getAdaptor(0), jarName);
+ this.getLog().debug("undeployed package: " + jarName);
+ }
+ }
+ }
+ };
+ return wrapper;
+
}
+
+
+ // Inner classes --------------------------------------------------------------------------------
+
+ protected class SimpleFailoverListener implements FailoverListener
+ {
+ private LinkedQueue buffer;
+
+ public SimpleFailoverListener()
+ {
+ buffer = new LinkedQueue();
+ }
+
+ public void failoverEventOccured(FailoverEvent event)
+ {
+ try
+ {
+ buffer.put(event);
+ }
+ catch(InterruptedException e)
+ {
+ throw new RuntimeException("Putting thread interrupted while trying to add event " +
+ "to buffer", e);
+ }
+ }
+
+ /**
+ * Blocks until a FailoverEvent is available or timeout occurs, in which case returns null.
+ */
+ public FailoverEvent getEvent(long timeout) throws InterruptedException
+ {
+ return (FailoverEvent)buffer.poll(timeout);
+ }
+ }
+
}
Modified: branches/JBPAPP_4_2/testsuite/src/resources/jbossmessaging/test-clustered-destinations-full-service.xml
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/resources/jbossmessaging/test-clustered-destinations-full-service.xml 2007-11-13 16:08:38 UTC (rev 67027)
+++ branches/JBPAPP_4_2/testsuite/src/resources/jbossmessaging/test-clustered-destinations-full-service.xml 2007-11-13 16:43:26 UTC (rev 67028)
@@ -54,5 +54,31 @@
<attribute name="Clustered">true</attribute>
</mbean>
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=testDistributedQueueE"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ <attribute name="SecurityConfig">
+ <security>
+ <role name="guest" read="true" write="true"/>
+ </security>
+ </attribute>
+ <attribute name="Clustered">true</attribute>
+ </mbean>
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=testDistributedQueueF"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ <attribute name="SecurityConfig">
+ <security>
+ <role name="guest" read="true" write="true"/>
+ </security>
+ </attribute>
+ <attribute name="Clustered">true</attribute>
+ </mbean>
+
+
</server>
More information about the jboss-cvs-commits
mailing list