[jboss-cvs] JBoss Messaging SVN: r5372 - in trunk: src/main/org/jboss/messaging/jms/server/management/impl and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 17 12:07:34 EST 2008


Author: jmesnil
Date: 2008-11-17 12:07:33 -0500 (Mon, 17 Nov 2008)
New Revision: 5372

Added:
   trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/JMSQueueControlTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/JMSUtil.java
Modified:
   trunk/src/main/org/jboss/messaging/jms/server/management/JMSQueueControlMBean.java
   trunk/src/main/org/jboss/messaging/jms/server/management/impl/JMSQueueControl.java
   trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/TopicControlTest.java
Log:
added integration tests for [JMSQueue|Topic]Control

Modified: trunk/src/main/org/jboss/messaging/jms/server/management/JMSQueueControlMBean.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/server/management/JMSQueueControlMBean.java	2008-11-17 15:07:29 UTC (rev 5371)
+++ trunk/src/main/org/jboss/messaging/jms/server/management/JMSQueueControlMBean.java	2008-11-17 17:07:33 UTC (rev 5372)
@@ -45,6 +45,8 @@
    
    String getExpiryQueue();
    
+   void setExpiryQueue(@Parameter(name = "expiryQueue", desc = "Name of the expiry queueur") String expiryQueue);
+
    String getDLQ();
    
    int getMessagesAdded();

Modified: trunk/src/main/org/jboss/messaging/jms/server/management/impl/JMSQueueControl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/server/management/impl/JMSQueueControl.java	2008-11-17 15:07:29 UTC (rev 5371)
+++ trunk/src/main/org/jboss/messaging/jms/server/management/impl/JMSQueueControl.java	2008-11-17 17:07:33 UTC (rev 5372)
@@ -200,6 +200,16 @@
       }
    }
 
+   public void setExpiryQueue(String expiryQueueName)
+   {
+      QueueSettings queueSettings = queueSettingsRepository.getMatch(getName());
+      
+      if (expiryQueueName != null)
+      {
+         queueSettings.setExpiryQueue(new SimpleString(expiryQueueName));
+      }
+   }
+
    public boolean removeMessage(final String messageID) throws Exception
    {
       Filter filter = createFilterForJMSMessageID(messageID);

Added: trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/JMSQueueControlTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/JMSQueueControlTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/JMSQueueControlTest.java	2008-11-17 17:07:33 UTC (rev 5372)
@@ -0,0 +1,295 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * 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.messaging.tests.integration.jms.management;
+
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+
+import java.lang.management.ManagementFactory;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.jms.JBossQueue;
+import org.jboss.messaging.jms.client.JBossConnectionFactory;
+import org.jboss.messaging.jms.server.impl.JMSServerManagerImpl;
+import org.jboss.messaging.jms.server.management.JMSQueueControlMBean;
+import org.jboss.messaging.jms.server.management.impl.JMSManagementServiceImpl;
+
+/**
+ * A QueueControlTest
+ *
+ * @author <a href="jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * Created 14 nov. 2008 13:35:10
+ *
+ *
+ */
+public class JMSQueueControlTest extends TestCase
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   private MessagingService service;
+
+   private JMSServerManagerImpl serverManager;
+
+   private Queue queue;
+
+   // Static --------------------------------------------------------
+
+   private static JMSQueueControlMBean createQueueControl(Queue queue) throws Exception
+   {
+      JMSQueueControlMBean queueControl = (JMSQueueControlMBean)MBeanServerInvocationHandler.newProxyInstance(ManagementFactory.getPlatformMBeanServer(),
+                                                                                                              JMSManagementServiceImpl.getJMSQueueObjectName(queue.getQueueName()),
+                                                                                                              JMSQueueControlMBean.class,
+                                                                                                              false);
+      return queueControl;
+   }
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   public void testGetXXXCount() throws Exception
+   {
+      JMSQueueControlMBean queueControl = createQueueControl(queue);
+
+      assertEquals(0, queueControl.getMessageCount());
+      assertEquals(0, queueControl.getConsumerCount());
+
+      MessageConsumer consumer = JMSUtil.createConsumer(queue, true);
+
+      assertEquals(1, queueControl.getConsumerCount());
+
+      JMSUtil.sendMessages(queue, 2);
+
+      assertEquals(2, queueControl.getMessageCount());
+      assertEquals(2, queueControl.getMessagesAdded());
+
+      assertNotNull(consumer.receive(500));
+      assertNotNull(consumer.receive(500));
+
+      assertEquals(0, queueControl.getMessageCount());
+      assertEquals(2, queueControl.getMessagesAdded());
+
+      consumer.close();
+
+      assertEquals(0, queueControl.getConsumerCount());
+   }
+
+   public void testRemoveMessage() throws Exception
+   {
+      JMSQueueControlMBean queueControl = createQueueControl(queue);
+      assertEquals(0, queueControl.getMessageCount());
+
+      JMSUtil.sendMessages(queue, 2);
+
+      assertEquals(2, queueControl.getMessageCount());
+
+      TabularData data = queueControl.listAllMessages();
+      assertEquals(2, data.size());
+
+      // retrieve the first message info
+      CompositeData compositeData = (CompositeData)data.values().iterator().next();
+      String messageID = (String)compositeData.get("JMSMessageID");
+
+      queueControl.removeMessage(messageID);
+
+      assertEquals(1, queueControl.getMessageCount());
+   }
+
+   public void testRemoveAllMessages() throws Exception
+   {
+      JMSQueueControlMBean queueControl = createQueueControl(queue);
+      assertEquals(0, queueControl.getMessageCount());
+
+      JMSUtil.sendMessages(queue, 2);
+
+      assertEquals(2, queueControl.getMessageCount());
+
+      queueControl.removeAllMessages();
+
+      assertEquals(0, queueControl.getMessageCount());
+
+      MessageConsumer consumer = JMSUtil.createConsumer(queue, true);
+      assertNull(consumer.receive(500));
+   }
+
+   public void testRemoveMatchingMessages() throws Exception
+   {
+      JMSQueueControlMBean queueControl = createQueueControl(queue);
+      assertEquals(0, queueControl.getMessageCount());
+
+      JBossConnectionFactory cf = new JBossConnectionFactory(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+                                                             null,
+                                                             ClientSessionFactoryImpl.DEFAULT_PING_PERIOD,
+                                                             ClientSessionFactoryImpl.DEFAULT_CALL_TIMEOUT,
+                                                             null,
+                                                             ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE,
+                                                             ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE,
+                                                             ClientSessionFactoryImpl.DEFAULT_CONSUMER_WINDOW_SIZE,
+                                                             ClientSessionFactoryImpl.DEFAULT_CONSUMER_MAX_RATE,
+                                                             ClientSessionFactoryImpl.DEFAULT_SEND_WINDOW_SIZE,
+                                                             ClientSessionFactoryImpl.DEFAULT_PRODUCER_MAX_RATE,
+                                                             ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_ACKNOWLEDGE,
+                                                             ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_NON_PERSISTENT_SEND,
+                                                             true,
+                                                             ClientSessionFactoryImpl.DEFAULT_AUTO_GROUP,
+                                                             ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS);
+
+      Connection conn = cf.createConnection();
+
+      Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      MessageProducer producer = s.createProducer(queue);
+
+      Message message = s.createMessage();
+      message.setStringProperty("foo", "bar");
+      producer.send(message);
+
+      message = s.createMessage();
+      message.setStringProperty("foo", "baz");
+      producer.send(message);
+
+      assertEquals(2, queueControl.getMessageCount());
+
+      int removedMatchingMessagesCount = queueControl.removeMatchingMessages("foo = 'bar'");
+      assertEquals(1, removedMatchingMessagesCount);
+
+      assertEquals(1, queueControl.getMessageCount());
+
+      MessageConsumer consumer = JMSUtil.createConsumer(queue, true);
+      Message msg = consumer.receive(500);
+      assertNotNull(msg);
+      assertEquals("baz", msg.getStringProperty("foo"));
+   }
+
+   public void testChangeMessagePriority() throws Exception
+   {
+      JMSQueueControlMBean queueControl = createQueueControl(queue);
+
+      JMSUtil.sendMessages(queue, 1);
+
+      assertEquals(1, queueControl.getMessageCount());
+
+      TabularData data = queueControl.listAllMessages();
+      // retrieve the first message info
+      CompositeData compositeData = (CompositeData)data.values().iterator().next();
+      String messageID = (String)compositeData.get("JMSMessageID");
+      int currentPriority = (Integer)compositeData.get("JMSPriority");
+      int newPriority = 9;
+
+      assertTrue(newPriority != currentPriority);
+
+      queueControl.changeMessagePriority(messageID, newPriority);
+
+      MessageConsumer consumer = JMSUtil.createConsumer(queue, true);
+      Message message = consumer.receive(500);
+      assertNotNull(message);
+      assertEquals(newPriority, message.getJMSPriority());
+   }
+
+   public void testExpireMessage() throws Exception
+   {
+      JMSQueueControlMBean queueControl = createQueueControl(queue);
+      String expiryQueueName = randomString();
+      JBossQueue expiryQueue = new JBossQueue(expiryQueueName);
+      serverManager.createQueue(expiryQueueName, expiryQueueName);
+      // FIXME we must be able to pass the queue name, not its address
+      queueControl.setExpiryQueue(expiryQueue.getAddress());
+      JMSQueueControlMBean expiryQueueControl = createQueueControl(expiryQueue);
+
+      JMSUtil.sendMessages(queue, 1);
+
+      assertEquals(1, queueControl.getMessageCount());
+      assertEquals(0, expiryQueueControl.getMessageCount());
+
+      TabularData data = queueControl.listAllMessages();
+      // retrieve the first message info
+      CompositeData compositeData = (CompositeData)data.values().iterator().next();
+      String messageID = (String)compositeData.get("JMSMessageID");
+
+      assertTrue(queueControl.expireMessage(messageID));
+
+      assertEquals(0, queueControl.getMessageCount());
+      assertEquals(1, expiryQueueControl.getMessageCount());
+
+      MessageConsumer consumer = JMSUtil.createConsumer(expiryQueue, true);
+      Message message = consumer.receive(500);
+      assertNotNull(message);
+      assertEquals(messageID, message.getJMSMessageID());
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   @Override
+   protected void setUp() throws Exception
+   {
+
+      Configuration conf = new ConfigurationImpl();
+      conf.setSecurityEnabled(false);
+      conf.setJMXManagementEnabled(true);
+      conf.getAcceptorConfigurations()
+          .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
+      service = MessagingServiceImpl.newNullStorageMessagingServer(conf);
+      service.start();
+
+      serverManager = JMSServerManagerImpl.newJMSServerManagerImpl(service.getServer());
+      serverManager.start();
+      serverManager.setInitialContext(new NullInitialContext());
+
+      String queueName = randomString();
+      serverManager.createQueue(queueName, queueName);
+      queue = new JBossQueue(queueName);
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      service.stop();
+
+      super.tearDown();
+   }
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}
\ No newline at end of file

Added: trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/JMSUtil.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/JMSUtil.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/JMSUtil.java	2008-11-17 17:07:33 UTC (rev 5372)
@@ -0,0 +1,158 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * 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.messaging.tests.integration.jms.management;
+
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicSubscriber;
+
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.jms.client.JBossConnectionFactory;
+
+/**
+ * A JMSUtil
+ *
+ * @author <a href="jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * Created 14 nov. 2008 13:48:08
+ *
+ *
+ */
+public class JMSUtil
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   static MessageConsumer createConsumer(Destination destination, boolean startConnection) throws JMSException
+   {
+      JBossConnectionFactory cf = new JBossConnectionFactory(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+                                                             null,
+                                                             ClientSessionFactoryImpl.DEFAULT_PING_PERIOD,
+                                                             ClientSessionFactoryImpl.DEFAULT_CALL_TIMEOUT,
+                                                             null,
+                                                             ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE,
+                                                             ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE,
+                                                             ClientSessionFactoryImpl.DEFAULT_CONSUMER_WINDOW_SIZE,
+                                                             ClientSessionFactoryImpl.DEFAULT_CONSUMER_MAX_RATE,
+                                                             ClientSessionFactoryImpl.DEFAULT_SEND_WINDOW_SIZE,
+                                                             ClientSessionFactoryImpl.DEFAULT_PRODUCER_MAX_RATE,
+                                                             ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_ACKNOWLEDGE,
+                                                             ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_NON_PERSISTENT_SEND,
+                                                             true,
+                                                             ClientSessionFactoryImpl.DEFAULT_AUTO_GROUP,
+                                                             ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS);
+
+      Connection conn = cf.createConnection();
+
+      Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+      if (startConnection)
+      {
+         conn.start();
+      }
+
+      return s.createConsumer(destination);
+   }
+
+   static TopicSubscriber createDurableSubscriber(Topic topic, String clientID, String subscriptionName) throws JMSException
+   {
+      JBossConnectionFactory cf = new JBossConnectionFactory(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+                                                             null,
+                                                             ClientSessionFactoryImpl.DEFAULT_PING_PERIOD,
+                                                             ClientSessionFactoryImpl.DEFAULT_CALL_TIMEOUT,
+                                                             null,
+                                                             ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE,
+                                                             ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE,
+                                                             ClientSessionFactoryImpl.DEFAULT_CONSUMER_WINDOW_SIZE,
+                                                             ClientSessionFactoryImpl.DEFAULT_CONSUMER_MAX_RATE,
+                                                             ClientSessionFactoryImpl.DEFAULT_SEND_WINDOW_SIZE,
+                                                             ClientSessionFactoryImpl.DEFAULT_PRODUCER_MAX_RATE,
+                                                             ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_ACKNOWLEDGE,
+                                                             ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_NON_PERSISTENT_SEND,
+                                                             true,
+                                                             ClientSessionFactoryImpl.DEFAULT_AUTO_GROUP,
+                                                             ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS);
+
+      Connection conn = cf.createConnection();
+
+      conn.setClientID(clientID);
+      Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+      return s.createDurableSubscriber(topic, subscriptionName);
+   }
+
+   static void sendMessages(Destination destination, int messagesToSend) throws Exception
+   {
+      JBossConnectionFactory cf = new JBossConnectionFactory(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+                                                             null,
+                                                             ClientSessionFactoryImpl.DEFAULT_PING_PERIOD,
+                                                             ClientSessionFactoryImpl.DEFAULT_CALL_TIMEOUT,
+                                                             null,
+                                                             ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE,
+                                                             ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE,
+                                                             ClientSessionFactoryImpl.DEFAULT_CONSUMER_WINDOW_SIZE,
+                                                             ClientSessionFactoryImpl.DEFAULT_CONSUMER_MAX_RATE,
+                                                             ClientSessionFactoryImpl.DEFAULT_SEND_WINDOW_SIZE,
+                                                             ClientSessionFactoryImpl.DEFAULT_PRODUCER_MAX_RATE,
+                                                             ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_ACKNOWLEDGE,
+                                                             ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_NON_PERSISTENT_SEND,
+                                                             true,
+                                                             ClientSessionFactoryImpl.DEFAULT_AUTO_GROUP,
+                                                             ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS);
+
+      Connection conn = cf.createConnection();
+
+      Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      MessageProducer producer = s.createProducer(destination);
+
+      for (int i = 0; i < messagesToSend; i++)
+      {
+         producer.send(s.createTextMessage(randomString()));
+      }
+   }
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/TopicControlTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/TopicControlTest.java	2008-11-17 15:07:29 UTC (rev 5371)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/TopicControlTest.java	2008-11-17 17:07:33 UTC (rev 5372)
@@ -26,26 +26,17 @@
 
 import java.lang.management.ManagementFactory;
 
-import javax.jms.Connection;
-import javax.jms.JMSException;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
 import javax.jms.Topic;
-import javax.jms.TopicConnection;
-import javax.jms.TopicSession;
-import javax.jms.TopicSubscriber;
 import javax.management.MBeanServerInvocationHandler;
 
 import junit.framework.TestCase;
 
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
 import org.jboss.messaging.core.config.Configuration;
 import org.jboss.messaging.core.config.TransportConfiguration;
 import org.jboss.messaging.core.config.impl.ConfigurationImpl;
 import org.jboss.messaging.core.server.MessagingService;
 import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
 import org.jboss.messaging.jms.JBossTopic;
-import org.jboss.messaging.jms.client.JBossConnectionFactory;
 import org.jboss.messaging.jms.server.impl.JMSServerManagerImpl;
 import org.jboss.messaging.jms.server.management.TopicControlMBean;
 import org.jboss.messaging.jms.server.management.impl.JMSManagementServiceImpl;
@@ -86,89 +77,6 @@
                                                                                                         false);
       return topicControl;
    }
-
-   private static TopicSubscriber createDurableSubscriber(Topic topic, String clientID, String subscriptionName) throws JMSException
-   {
-      JBossConnectionFactory cf = new JBossConnectionFactory(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
-                                                             null,
-                                                             ClientSessionFactoryImpl.DEFAULT_PING_PERIOD,
-                                                             ClientSessionFactoryImpl.DEFAULT_CALL_TIMEOUT,
-                                                             null,
-                                                             ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE,
-                                                             ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE,
-                                                             ClientSessionFactoryImpl.DEFAULT_CONSUMER_WINDOW_SIZE,
-                                                             ClientSessionFactoryImpl.DEFAULT_CONSUMER_MAX_RATE,
-                                                             ClientSessionFactoryImpl.DEFAULT_SEND_WINDOW_SIZE,
-                                                             ClientSessionFactoryImpl.DEFAULT_PRODUCER_MAX_RATE,
-                                                             ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_ACKNOWLEDGE,
-                                                             ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_NON_PERSISTENT_SEND,
-                                                             true,
-                                                             ClientSessionFactoryImpl.DEFAULT_AUTO_GROUP,
-                                                             ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS);
-
-      Connection conn = cf.createConnection();
-
-      conn.setClientID(clientID);
-      Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-      return s.createDurableSubscriber(topic, subscriptionName);
-   }
-
-   private static TopicSubscriber createSubscriber(Topic topic) throws JMSException
-   {
-      JBossConnectionFactory cf = new JBossConnectionFactory(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
-                                                             null,
-                                                             ClientSessionFactoryImpl.DEFAULT_PING_PERIOD,
-                                                             ClientSessionFactoryImpl.DEFAULT_CALL_TIMEOUT,
-                                                             null,
-                                                             ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE,
-                                                             ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE,
-                                                             ClientSessionFactoryImpl.DEFAULT_CONSUMER_WINDOW_SIZE,
-                                                             ClientSessionFactoryImpl.DEFAULT_CONSUMER_MAX_RATE,
-                                                             ClientSessionFactoryImpl.DEFAULT_SEND_WINDOW_SIZE,
-                                                             ClientSessionFactoryImpl.DEFAULT_PRODUCER_MAX_RATE,
-                                                             ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_ACKNOWLEDGE,
-                                                             ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_NON_PERSISTENT_SEND,
-                                                             true,
-                                                             ClientSessionFactoryImpl.DEFAULT_AUTO_GROUP,
-                                                             ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS);
-
-      TopicConnection conn = cf.createTopicConnection();
-
-      TopicSession s = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
-
-      return s.createSubscriber(topic);
-   }
-
-   private static void sendMessages(Topic topic, int messagesToSend) throws Exception
-   {
-      JBossConnectionFactory cf = new JBossConnectionFactory(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
-                                                             null,
-                                                             ClientSessionFactoryImpl.DEFAULT_PING_PERIOD,
-                                                             ClientSessionFactoryImpl.DEFAULT_CALL_TIMEOUT,
-                                                             null,
-                                                             ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE,
-                                                             ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE,
-                                                             ClientSessionFactoryImpl.DEFAULT_CONSUMER_WINDOW_SIZE,
-                                                             ClientSessionFactoryImpl.DEFAULT_CONSUMER_MAX_RATE,
-                                                             ClientSessionFactoryImpl.DEFAULT_SEND_WINDOW_SIZE,
-                                                             ClientSessionFactoryImpl.DEFAULT_PRODUCER_MAX_RATE,
-                                                             ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_ACKNOWLEDGE,
-                                                             ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_NON_PERSISTENT_SEND,
-                                                             true,
-                                                             ClientSessionFactoryImpl.DEFAULT_AUTO_GROUP,
-                                                             ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS);
-
-      Connection conn = cf.createConnection();
-
-      Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-      MessageProducer producer = s.createProducer(topic);
-
-      for (int i = 0; i < messagesToSend; i++)
-      {
-         producer.send(s.createTextMessage(randomString()));
-      }
-   }
    
    // Constructors --------------------------------------------------
 
@@ -182,9 +90,9 @@
    public void testGetXXXSubscriptionsCount() throws Exception
    {
       // 1 non-durable subscriber, 2 durable subscribers
-      createSubscriber(topic);
-      createDurableSubscriber(topic, clientID, subscriptionName);
-      createDurableSubscriber(topic, clientID, subscriptionName + "2");
+      JMSUtil.createConsumer(topic, false);
+      JMSUtil.createDurableSubscriber(topic, clientID, subscriptionName);
+      JMSUtil.createDurableSubscriber(topic, clientID, subscriptionName + "2");
 
       TopicControlMBean topicControl = createTopicControl(topic);
       assertEquals(3, topicControl.getSubcriptionsCount());
@@ -195,9 +103,9 @@
    public void testGetXXXMessagesCount() throws Exception
    {
       // 1 non-durable subscriber, 2 durable subscribers
-      createSubscriber(topic);
-      createDurableSubscriber(topic, clientID, subscriptionName);
-      createDurableSubscriber(topic, clientID, subscriptionName + "2");
+      JMSUtil.createConsumer(topic, true);
+      JMSUtil.createDurableSubscriber(topic, clientID, subscriptionName);
+      JMSUtil.createDurableSubscriber(topic, clientID, subscriptionName + "2");
 
       TopicControlMBean topicControl = createTopicControl(topic);
 
@@ -205,16 +113,29 @@
       assertEquals(0, topicControl.getNonDurableMessagesCount());
       assertEquals(0, topicControl.getDurableMessagesCount());
 
-      sendMessages(topic, 2);
+      JMSUtil.sendMessages(topic, 2);
 
       assertEquals(3 * 2, topicControl.getMessageCount());
       assertEquals(1 * 2, topicControl.getNonDurableMessagesCount());
       assertEquals(2 * 2, topicControl.getDurableMessagesCount());
    }
 
+   public void testListXXXSubscriptionsCount() throws Exception
+   {
+      // 1 non-durable subscriber, 2 durable subscribers
+      JMSUtil.createConsumer(topic, false);
+      JMSUtil.createDurableSubscriber(topic, clientID, subscriptionName);
+      JMSUtil.createDurableSubscriber(topic, clientID, subscriptionName + "2");
+
+      TopicControlMBean topicControl = createTopicControl(topic);
+      assertEquals(3, topicControl.listAllSubscriptionInfos().length);
+      assertEquals(1, topicControl.listNonDurableSubscriptionInfos().length);
+      assertEquals(2, topicControl.listDurableSubscriptionInfos().length);
+   }
+   
    public void testDropDurableSubscriptionWithExistingSubscription() throws Exception
    {
-      createDurableSubscriber(topic, clientID, subscriptionName);
+      JMSUtil.createDurableSubscriber(topic, clientID, subscriptionName);
 
       TopicControlMBean topicControl = createTopicControl(topic);
       assertEquals(1, topicControl.getDurableSubcriptionsCount());
@@ -226,7 +147,7 @@
 
    public void testDropDurableSubscriptionWithUnknownSubscription() throws Exception
    {
-      createDurableSubscriber(topic, clientID, subscriptionName);
+      JMSUtil.createDurableSubscriber(topic, clientID, subscriptionName);
 
       TopicControlMBean topicControl = createTopicControl(topic);
       assertEquals(1, topicControl.getDurableSubcriptionsCount());
@@ -246,9 +167,9 @@
 
    public void testDropAllSubscriptions() throws Exception
    {
-      createSubscriber(topic);
-      createDurableSubscriber(topic, clientID, subscriptionName);
-      createDurableSubscriber(topic, clientID, subscriptionName + "2");
+      JMSUtil.createConsumer(topic, true);
+      JMSUtil.createDurableSubscriber(topic, clientID, subscriptionName);
+      JMSUtil.createDurableSubscriber(topic, clientID, subscriptionName + "2");
 
       TopicControlMBean topicControl = createTopicControl(topic);
       assertEquals(3, topicControl.getSubcriptionsCount());




More information about the jboss-cvs-commits mailing list