[jboss-cvs] JBoss Messaging SVN: r2831 - in trunk: tests/src/org/jboss/test/messaging/core/postoffice and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jul 3 15:11:24 EDT 2007


Author: timfox
Date: 2007-07-03 15:11:24 -0400 (Tue, 03 Jul 2007)
New Revision: 2831

Modified:
   trunk/src/main/org/jboss/messaging/core/impl/postoffice/MessagingPostOffice.java
   trunk/tests/src/org/jboss/test/messaging/core/postoffice/ClusteredPostOfficeTest.java
   trunk/tests/src/org/jboss/test/messaging/core/postoffice/PostOfficeTest.java
Log:
Fix failing post office test


Modified: trunk/src/main/org/jboss/messaging/core/impl/postoffice/MessagingPostOffice.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/postoffice/MessagingPostOffice.java	2007-07-03 17:35:17 UTC (rev 2830)
+++ trunk/src/main/org/jboss/messaging/core/impl/postoffice/MessagingPostOffice.java	2007-07-03 19:11:24 UTC (rev 2831)
@@ -294,7 +294,8 @@
    {
    	if (started)
    	{
-   		throw new IllegalStateException(this + " is already started");
+   		log.warn(this + " is already started");
+   		return;
    	}
    	
       if (trace) { log.trace(this + " starting"); }
@@ -340,7 +341,9 @@
    {
       if (!started)
    	{
-   		throw new IllegalStateException(this + " is not started");
+   		log.warn(this + " is not started");
+   		
+   		return;
    	}
    	
       if (trace) { log.trace(this + " stopping"); }
@@ -1499,11 +1502,6 @@
          		
          			//Local queue
 
-         			//TODO - There is a slight kludge here -
-         			//When routing to a clustered temp queue, the queue is unreliable - but we always want to route to the local
-         			//one so we need to add the check that we only route remotely if it's a topic
-         			//We could do this better by making sure that only one queue with the same name is routed to on the cluster
-         			
          			boolean routeLocal = false;
          			
          			if (!fromCluster)
@@ -1514,10 +1512,11 @@
          			else
          			{
          				//From the cluster
-         				if (!queue.isRecoverable())
+         				if (!queue.isRecoverable() && queue.isClustered())
          				{
          					//When routing from the cluster we only route to non recoverable queues
          					//who haven't already been routed to on the sending node (same name)
+         					//Also we don't route to non clustered queues
          					if (names == null || !names.contains(queue.getName()))
          					{
          						routeLocal = true;

Modified: trunk/tests/src/org/jboss/test/messaging/core/postoffice/ClusteredPostOfficeTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/postoffice/ClusteredPostOfficeTest.java	2007-07-03 17:35:17 UTC (rev 2830)
+++ trunk/tests/src/org/jboss/test/messaging/core/postoffice/ClusteredPostOfficeTest.java	2007-07-03 19:11:24 UTC (rev 2831)
@@ -1285,8 +1285,7 @@
          assertGotAll(2, bindings, queue1.getName());
          
          bindings = office3.getAllBindings();         
-         assertGotAll(3, bindings, queue1.getName());
-         
+         assertGotAll(3, bindings, queue1.getName());         
                   
          if (checkNoBindingData())
          {
@@ -1381,6 +1380,16 @@
    	this.clusteredRouteFourNodes(false);
    }
    
+   public void testRouteWithNonClusteredQueuesNonPersistent() throws Throwable
+   {
+   	this.routeWithNonClusteredQueues(false);
+   }
+   
+   public void testRouteWithNonClusteredQueuesPersistent() throws Throwable
+   {
+   	this.routeWithNonClusteredQueues(true);
+   }
+   
    public void testStartTxInternally() throws Throwable
    {
    	PostOffice office1 = null;
@@ -2437,9 +2446,208 @@
 
    	}
    }
+   
+   
+   private void routeWithNonClusteredQueues(boolean persistentMessage) throws Throwable
+   {
+   	PostOffice office1 = null;
 
+   	PostOffice office2 = null;
 
+   	try
+   	{   
+   		office1 = createClusteredPostOffice(1, "testgroup");
+   		office2 = createClusteredPostOffice(2, "testgroup");
 
+   		Queue[] queues = new Queue[16];
+
+   		//condition1
+
+   		queues[0] = new MessagingQueue(1, "sub1", channelIDManager.getID(), ms, pm, false, -1, null, false);
+   		queues[0].activate();
+   		boolean added = office1.addBinding(new Binding(new SimpleCondition("condition1"), queues[0], false), false);
+   		assertTrue(added);
+
+   		queues[1] = new MessagingQueue(1, "sub2", channelIDManager.getID(), ms, pm, false, -1, null, true);
+   		queues[1].activate();
+   		added = office1.addBinding(new Binding(new SimpleCondition("condition1"), queues[1], false), false);
+   		assertTrue(added);
+
+   		queues[2] = new MessagingQueue(2, "sub3", channelIDManager.getID(), ms, pm, false, -1, null, false);
+   		queues[2].activate();
+   		added = office2.addBinding(new Binding(new SimpleCondition("condition1"), queues[2], false), false);
+   		assertTrue(added);
+
+   		queues[3] = new MessagingQueue(2, "sub4", channelIDManager.getID(), ms, pm, false, -1, null, true);
+   		queues[3].activate();
+   		added = office2.addBinding(new Binding(new SimpleCondition("condition1"), queues[3], false), false);
+   		assertTrue(added);
+
+   		queues[4] = new MessagingQueue(2, "sub5", channelIDManager.getID(), ms, pm, true, -1, null, false);
+   		queues[4].activate();
+   		added = office2.addBinding(new Binding(new SimpleCondition("condition1"), queues[4], false), false);
+   		assertTrue(added);
+
+   		queues[5] = new MessagingQueue(1, "sub6", channelIDManager.getID(), ms, pm, false, -1, null, true);
+   		queues[5].activate();
+   		added = office1.addBinding(new Binding(new SimpleCondition("condition1"), queues[5], false), false);
+   		assertTrue(added);
+
+   		queues[6] = new MessagingQueue(1, "sub7", channelIDManager.getID(), ms, pm, true, -1, null, false);
+   		queues[6].activate();
+   		added = office1.addBinding(new Binding(new SimpleCondition("condition1"), queues[6], false), false);
+   		assertTrue(added);
+
+   		queues[7] = new MessagingQueue(1, "sub8", channelIDManager.getID(), ms, pm, true, -1, null, true);
+   		queues[7].activate();
+   		added = office1.addBinding(new Binding(new SimpleCondition("condition1"), queues[7], false), false);
+   		assertTrue(added);
+
+   		//condition2
+
+
+   		queues[8] = new MessagingQueue(1, "sub9", channelIDManager.getID(), ms, pm, false, -1, null, false);
+   		queues[8].activate();
+   		added = office1.addBinding(new Binding(new SimpleCondition("condition2"), queues[8], false), false);
+   		assertTrue(added);
+
+   		queues[9] = new MessagingQueue(1, "sub10", channelIDManager.getID(), ms, pm, false, -1, null, true);
+   		queues[9].activate();
+   		added = office1.addBinding(new Binding(new SimpleCondition("condition2"), queues[9], false), false);
+   		assertTrue(added);
+
+   		queues[10] = new MessagingQueue(2, "sub11", channelIDManager.getID(), ms, pm, false, -1, null, false);
+   		queues[10].activate();
+   		added = office2.addBinding(new Binding(new SimpleCondition("condition2"), queues[10], false), false);
+   		assertTrue(added);
+
+   		queues[11] = new MessagingQueue(2, "sub12", channelIDManager.getID(), ms, pm, false, -1, null, true);
+   		queues[11].activate();
+   		added = office2.addBinding(new Binding(new SimpleCondition("condition2"), queues[11], false), false);
+   		assertTrue(added);
+
+   		queues[12] = new MessagingQueue(2, "sub13", channelIDManager.getID(), ms, pm, true, -1, null, false);
+   		queues[12].activate();
+   		added = office2.addBinding(new Binding(new SimpleCondition("condition2"), queues[12], false), false);
+   		assertTrue(added);
+
+   		queues[13] = new MessagingQueue(1, "sub14", channelIDManager.getID(), ms, pm, false, -1, null, true);
+   		queues[13].activate();
+   		added = office1.addBinding(new Binding(new SimpleCondition("condition2"), queues[13], false), false);
+   		assertTrue(added);
+
+   		queues[14] = new MessagingQueue(1, "sub15", channelIDManager.getID(), ms, pm, true, -1, null, false);
+   		queues[14].activate();
+   		added = office1.addBinding(new Binding(new SimpleCondition("condition2"), queues[14], false), false);
+   		assertTrue(added);
+
+   		queues[15] = new MessagingQueue(1, "sub16", channelIDManager.getID(), ms, pm, true, -1, null, true);
+   		queues[15].activate();
+   		added = office1.addBinding(new Binding(new SimpleCondition("condition2"), queues[15], false), false);
+   		assertTrue(added);
+
+   		SimpleReceiver[] receivers = new SimpleReceiver[16];
+
+   		for (int i = 0; i < 16; i++)
+   		{
+   			receivers[i] = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
+   			queues[i].getLocalDistributor().add(receivers[i]);
+   		}
+
+   		Message msg = CoreMessageFactory.createCoreMessage(1, persistentMessage, null);      
+   		MessageReference ref = ms.reference(msg);         
+
+   		boolean routed = office1.route(ref, new SimpleCondition("condition1"), null);         
+   		assertTrue(routed);
+
+   		//Messages are sent asych so may take some finite time to arrive
+   		Thread.sleep(1000);
+
+   		//Durable queues on remote node should never get the message - neither should non clustered ones
+
+   		for (int i = 0; i < 16; i++)
+   		{
+   			if (i >= 8 || (queues[i].getNodeID() == 2 && queues[i].isRecoverable())
+   					|| (queues[i].getNodeID() == 2 && !queues[i].isClustered()))
+   			{
+   				this.checkNotGetsMessage(queues[i], receivers[i]);
+   			}
+   			else
+   			{
+   				//Should get the message
+   				this.checkGetsMessage(queues[i], receivers[i], msg);
+   			}
+   		}
+
+   		//Now route to condition2
+
+   		msg = CoreMessageFactory.createCoreMessage(2, persistentMessage, null);;      
+   		ref = ms.reference(msg);         
+
+   		routed = office2.route(ref, new SimpleCondition("condition2"), null);         
+   		assertTrue(routed);
+   		//Messages are sent asych so may take some finite time to arrive
+   		Thread.sleep(1000);
+
+   		for (int i = 0; i < 16; i++)
+   		{
+   			if (i < 8 || (queues[i].getNodeID() == 1 && queues[i].isRecoverable())
+   					|| (queues[i].getNodeID() == 1 && !queues[i].isClustered()))
+   			{
+   				//Shouldn't get the message
+   				this.checkNotGetsMessage(queues[i], receivers[i]);
+   			}
+   			else
+   			{
+   				//Should get the message
+   				this.checkGetsMessage(queues[i], receivers[i], msg);
+   			}
+
+   		}
+
+   		if (checkNoMessageData())
+   		{
+   			fail("Message data still in database");
+   		}
+   	}
+   	finally
+   	{
+   		if (office1 != null)
+   		{
+   			try
+   			{              
+   				office1.removeBinding("sub7", false);
+   				office1.removeBinding("sub8", false);               
+   				office1.removeBinding("sub15", false);
+   				office1.removeBinding("sub16", false);
+   			}
+   			catch (Exception ignore)
+   			{
+   				ignore.printStackTrace();
+   			}
+
+   			office1.stop();
+   		}
+
+   		if (office2 != null)
+   		{
+   			try
+   			{
+   				office2.removeBinding("sub5", false);
+   				office2.removeBinding("sub13", false);
+   			}
+   			catch (Exception ignore)
+   			{     
+   				ignore.printStackTrace();
+   			}
+   			office2.stop();
+   		}
+
+   	}
+   }
+
+
+
    /*
     * Queues with same name on different nodes of the cluster.
     * If queue is routed to locally it shouldn't be routed to on other nodes

Modified: trunk/tests/src/org/jboss/test/messaging/core/postoffice/PostOfficeTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/postoffice/PostOfficeTest.java	2007-07-03 17:35:17 UTC (rev 2830)
+++ trunk/tests/src/org/jboss/test/messaging/core/postoffice/PostOfficeTest.java	2007-07-03 19:11:24 UTC (rev 2831)
@@ -85,18 +85,12 @@
          
          Condition condition1 = new SimpleCondition("condition1");
                   
-         office1.addBinding(new Binding(condition1, queue1, false), false);
+         boolean added = office1.addBinding(new Binding(condition1, queue1, false), false);
+         assertTrue(added);
          
          //Binding twice with the same name should fail      
-         try
-         {
-            office1.addBinding(new Binding(condition1, queue1, false), false);
-            fail();
-         }
-         catch (IllegalArgumentException e)
-         {
-            //Ok
-         }
+         added = office1.addBinding(new Binding(condition1, queue1, false), false);
+         assertFalse(added);
          
          //Can't bind a queue from another node
          
@@ -122,7 +116,8 @@
          
          Condition condition2 = new SimpleCondition("condition2");         
          
-         office1.addBinding(new Binding(condition2, queue2, false), false);
+         added = office1.addBinding(new Binding(condition2, queue2, false), false);
+         assertTrue(added);
          
          //Check they're there
          
@@ -137,9 +132,7 @@
          assertEquals(1, queues.size());
          Queue rqueue2 = (Queue)queues.iterator().next();
          assertEquals(queue2, rqueue2);
-         
-         
-         
+                          
          office1.stop();
          
          //Throw away the office and create another
@@ -157,9 +150,8 @@
          assertTrue(queues.isEmpty());
          
          //Unbind the binding
-         office2.removeBinding(queue1.getName(), false);
+         office2.removeBinding(queue1.getName(), false);         
          
-         
          //Make sure no longer there
          queues = office2.getQueuesForCondition(condition1, true);
          assertNotNull(queues);
@@ -182,6 +174,11 @@
          queues = office3.getQueuesForCondition(condition2, true);
          assertNotNull(queues);
          assertTrue(queues.isEmpty());
+         
+         if (checkNoBindingData())
+         {
+            fail("Binding data still in database");
+         }
                   
       }
       finally
@@ -199,12 +196,7 @@
          if (office3 != null)
          {
             office2.stop();
-         }
-         
-         if (checkNoBindingData())
-         {
-            fail("Binding data still in database");
-         }
+         }         
       }
             
    }
@@ -315,6 +307,11 @@
          assertTrue(queues.contains(queue7));
          assertTrue(queues.contains(queue8));
          
+         if (checkNoBindingData())
+         {
+            fail("Binding data still in database");
+         }
+         
       }
       finally
       {
@@ -322,11 +319,7 @@
          {
             office.stop();
          }
-         
-         if (checkNoBindingData())
-         {
-            fail("Binding data still in database");
-         }
+        
       }
          
    }
@@ -393,6 +386,11 @@
  
          b3 = office.getBindingForQueueName("queue3");
          assertNull(b3);                     
+                  
+         if (checkNoBindingData())
+         {
+            fail("Binding data still in database");
+         }
       }
       finally
       {
@@ -400,13 +398,7 @@
          {
             office.stop();
          }
-         
-         if (checkNoBindingData())
-         {
-            fail("Binding data still in database");
-         }
-      }
-         
+      }         
    }
    
    public void testGetBindingForChannelID() throws Throwable
@@ -471,6 +463,11 @@
  
          b3 = office.getBindingForChannelID(queue3.getChannelID());
          assertNull(b3);                     
+         
+         if (checkNoBindingData())
+         {
+            fail("Binding data still in database");
+         }
       }
       finally
       {
@@ -478,11 +475,7 @@
          {
             office.stop();
          }
-         
-         if (checkNoBindingData())
-         {
-            fail("Binding data still in database");
-         }
+        
       }
          
    }




More information about the jboss-cvs-commits mailing list