[hornetq-commits] JBoss hornetq SVN: r8918 - in trunk: tests/jms-tests/src/org/hornetq/jms/tests and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Mar 8 10:34:58 EST 2010


Author: jmesnil
Date: 2010-03-08 10:34:57 -0500 (Mon, 08 Mar 2010)
New Revision: 8918

Added:
   trunk/tests/jms-tests/src/org/hornetq/jms/tests/NoLocalSubscriberTest.java
Modified:
   trunk/src/main/org/hornetq/jms/client/HornetQMessageProducer.java
Log:
fix nolocal bug

* remove the CONNECTION_ID property when sending a message from
  a connection without nolocal. The property may have been set
  when the message was previously sent on a connection with nolocal

Modified: trunk/src/main/org/hornetq/jms/client/HornetQMessageProducer.java
===================================================================
--- trunk/src/main/org/hornetq/jms/client/HornetQMessageProducer.java	2010-03-08 10:02:39 UTC (rev 8917)
+++ trunk/src/main/org/hornetq/jms/client/HornetQMessageProducer.java	2010-03-08 15:34:57 UTC (rev 8918)
@@ -449,6 +449,11 @@
       {
          coreMessage.putStringProperty(HornetQConnection.CONNECTION_ID_PROPERTY_NAME, connID);
       }
+      else
+      {
+         // make sure the message does not get a connID from a previous producer on another connection
+         coreMessage.removeProperty(HornetQConnection.CONNECTION_ID_PROPERTY_NAME);
+      }
 
       try
       {

Added: trunk/tests/jms-tests/src/org/hornetq/jms/tests/NoLocalSubscriberTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/hornetq/jms/tests/NoLocalSubscriberTest.java	                        (rev 0)
+++ trunk/tests/jms-tests/src/org/hornetq/jms/tests/NoLocalSubscriberTest.java	2010-03-08 15:34:57 UTC (rev 8918)
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.  See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package org.hornetq.jms.tests;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.hornetq.tests.util.RandomUtil;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ */
+public class NoLocalSubscriberTest extends JMSTestCase
+{
+   // Constants -----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   /**
+    * Test that a message created from the same connection than a nolocal consumer
+    * can be sent by *another* connection and will be received by the nolocal consumer
+    */
+   public void testNoLocal() throws Exception
+   {
+      if (log.isTraceEnabled())
+      {
+         log.trace("testNoLocal");
+      }
+
+      Connection defaultConn = null;
+      Connection newConn = null;
+
+      try
+      {
+         defaultConn = JMSTestCase.cf.createConnection();
+         Session defaultSess = defaultConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer defaultConsumer = defaultSess.createConsumer(HornetQServerTestCase.topic1);
+         MessageConsumer noLocalConsumer = defaultSess.createConsumer(HornetQServerTestCase.topic1, null, true);
+         MessageProducer defaultProd = defaultSess.createProducer(HornetQServerTestCase.topic1);
+         
+         defaultConn.start();
+
+         String text = RandomUtil.randomString();
+         // message is created only once from the same connection than the noLocalConsumer
+         TextMessage messageSent = defaultSess.createTextMessage(text);
+         for (int i = 0; i < 10; i++)
+         {
+            defaultProd.send(messageSent);            
+         }
+
+         Message received = null;
+         for (int i = 0; i < 10; i++)
+         {
+            received = defaultConsumer.receive(5000);
+            assertNotNull(received);
+            assertEquals(text, ((TextMessage)received).getText());
+         }
+
+         newConn = JMSTestCase.cf.createConnection();
+         Session newSession = newConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer newProd = newSession.createProducer(HornetQServerTestCase.topic1);
+         MessageConsumer newConsumer = newSession.createConsumer(HornetQServerTestCase.topic1);
+
+         newConn.start();
+         
+         text = RandomUtil.randomString();
+         messageSent.setText(text);
+         defaultProd.send(messageSent);
+
+         received = newConsumer.receive(5000);
+         assertNotNull(received);
+         assertEquals(text, ((TextMessage)received).getText());
+
+         text = RandomUtil.randomString();
+         messageSent.setText(text);
+         // we send the message created at the start of the test but on the *newConn* this time
+         newProd.send(messageSent);
+         newConn.close();
+         
+         received = noLocalConsumer.receive(5000);
+         assertNotNull("nolocal consumer did not get message", received);
+         assertEquals(text, ((TextMessage)received).getText());
+      }
+      finally
+      {
+         if (defaultConn != null)
+         {
+            defaultConn.close();
+         }
+         if (newConn != null)
+         {
+            newConn.close();
+         }
+      }
+   }
+}



More information about the hornetq-commits mailing list