[Jboss-cvs] JBoss Messaging SVN: r1265 - branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/crash

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Sep 6 18:51:50 EDT 2006


Author: clebert.suconic at jboss.com
Date: 2006-09-06 18:51:49 -0400 (Wed, 06 Sep 2006)
New Revision: 1265

Added:
   branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/crash/DurableCrash1.java
   branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/crash/DurableCrash2.java
Log:
JBMESSAGING-424 - Adding testcases

Added: branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/crash/DurableCrash1.java
===================================================================
--- branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/crash/DurableCrash1.java	2006-09-06 04:04:35 UTC (rev 1264)
+++ branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/crash/DurableCrash1.java	2006-09-06 22:51:49 UTC (rev 1265)
@@ -0,0 +1,121 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2006, RedHat Middle LLc, and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package org.jboss.test.messaging.jms.crash;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.naming.InitialContext;
+
+import org.jboss.test.messaging.MessagingTestCase;
+import org.jboss.test.messaging.tools.ServerManagement;
+
+public class DurableCrash1 extends MessagingTestCase
+{
+	   // Constants -----------------------------------------------------
+
+	   // Static --------------------------------------------------------
+
+	   // Attributes ----------------------------------------------------
+
+	   protected InitialContext ic;
+
+	   // Constructors --------------------------------------------------
+
+	   public DurableCrash1(String name)
+	   {
+	      super(name);
+	   }
+
+	   // Public --------------------------------------------------------
+
+	   public void setUp() throws Exception
+	   {
+	      super.setUp();
+
+	      ServerManagement.start("all");
+	            
+	      ServerManagement.undeployTopic("TopicCrash");
+	      ServerManagement.deployTopic("TopicCrash");
+
+	      ic = new InitialContext(ServerManagement.getJNDIEnvironment());
+
+	      log.debug("setup done");
+	   }
+
+	   public void testSimplestDurableSubscription() throws Exception
+	   {
+	      ConnectionFactory cf = (ConnectionFactory)ic.lookup("ConnectionFactory");
+	      Topic topic = (Topic)ic.lookup("/topic/TopicCrash");
+	      
+	      Connection conn = cf.createConnection();
+	      conn.setClientID("client1");
+	      conn.start();
+
+	      Connection conn2 = cf.createConnection();
+	      conn2.setClientID("client2");
+	      conn2.start();
+
+	      Session s = conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
+	      Session s2 = conn2.createSession(true, Session.AUTO_ACKNOWLEDGE);
+
+	      MessageProducer prod = s.createProducer(topic);
+	      prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+	      MessageConsumer durable = s.createDurableSubscriber(topic, "subs1");
+	      MessageConsumer durable2 = s2.createDurableSubscriber(topic, "subs2");
+
+	      conn2.close(); // If I close conn2 durable2 is able to receive its message.
+	      
+	      
+	      for (int i=0;i<10;i++)
+	      {
+	    	  prod.send(s.createTextMessage("k"+i));
+	      }
+	      s.commit();
+
+	      conn.close();
+	      conn = cf.createConnection();
+	      conn.setClientID("client1");
+	      conn.start();
+	      s = conn.createSession(true, Session.CLIENT_ACKNOWLEDGE);
+	      durable = s.createDurableSubscriber(topic, "subs1");
+
+	      for (int i=0;i<2;i++)
+	      {
+	    	  TextMessage tm = (TextMessage)durable.receive(1000);
+	    	  assertNotNull(tm);
+	    	  s.commit();
+	    	  System.out.println(tm.getText());
+	    	  assertEquals("k" + i, tm.getText());
+	      }
+
+	      //System.exit(0); -- this is not needed as there is not tearDown, the client VM will simply be finished the same way an exit would do, and this is better since it will keep proper JUNIT report outputs
+	   }
+
+	}

Added: branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/crash/DurableCrash2.java
===================================================================
--- branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/crash/DurableCrash2.java	2006-09-06 04:04:35 UTC (rev 1264)
+++ branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/crash/DurableCrash2.java	2006-09-06 22:51:49 UTC (rev 1265)
@@ -0,0 +1,107 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2006, RedHat Middle LLc, and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package org.jboss.test.messaging.jms.crash;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.naming.InitialContext;
+
+import org.jboss.test.messaging.MessagingTestCase;
+import org.jboss.test.messaging.tools.ServerManagement;
+
+public class DurableCrash2 extends MessagingTestCase
+{
+	   // Constants -----------------------------------------------------
+
+	   // Static --------------------------------------------------------
+
+	   // Attributes ----------------------------------------------------
+
+	   protected InitialContext ic;
+
+	   // Constructors --------------------------------------------------
+
+	   public DurableCrash2(String name)
+	   {
+	      super(name);
+	   }
+
+	   // Public --------------------------------------------------------
+
+	   public void setUp() throws Exception
+	   {
+	      super.setUp();
+	      ic = new InitialContext(ServerManagement.getJNDIEnvironment());
+
+	      log.debug("setup done");
+	   }
+
+	   public void testSimplestDurableSubscription() throws Exception
+	   {
+	      ConnectionFactory cf = (ConnectionFactory)ic.lookup("ConnectionFactory");
+	      Topic topic = (Topic)ic.lookup("/topic/TopicCrash");
+	      
+	      Connection conn = null;
+	      Session s = null;
+	      MessageConsumer durable = null;
+
+	      Connection conn2 = cf.createConnection();
+	      conn2.setClientID("client2");
+	      conn2.start();
+	      Session s2 = conn2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+	      MessageConsumer durable2 = s2.createDurableSubscriber(topic, "subs2");
+
+		  for (int i=0;i<10;i++)
+	      {
+	    	  TextMessage tm = (TextMessage)durable2.receive(1000);
+	    	  assertNotNull(tm);
+	    	  tm.acknowledge();
+	    	  System.out.println(tm.getText());
+	    	  assertEquals("k" + i, tm.getText());
+	      }
+		  
+	      conn.close();
+	      conn = cf.createConnection();
+	      conn.setClientID("client1");
+	      conn.start();
+	      s = conn.createSession(true, Session.CLIENT_ACKNOWLEDGE);
+	      durable = s.createDurableSubscriber(topic, "subs1");
+
+	      for (int i=2;i<10;i++)
+	      {
+	    	  TextMessage tm = (TextMessage)durable.receive(1000);
+	    	  assertNotNull(tm);
+	    	  s.commit();
+	    	  System.out.println(tm.getText());
+	    	  assertEquals("k" + i, tm.getText());
+	      }
+
+
+	   }
+
+	}




More information about the jboss-cvs-commits mailing list