[jboss-cvs] JBoss Messaging SVN: r4723 - in branches/Branch_JBMESSAGING-1303: src/main/org/jboss/messaging/core/management/impl and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jul 24 09:11:19 EDT 2008


Author: jmesnil
Date: 2008-07-24 09:11:19 -0400 (Thu, 24 Jul 2008)
New Revision: 4723

Modified:
   branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/MessagingServerControlMBean.java
   branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/MessagingServerManagement.java
   branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/QueueControlMBean.java
   branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java
   branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/MessagingServerManagementImpl.java
   branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/QueueControl.java
   branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/server/Queue.java
   branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java
   branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java
   branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/management/impl/QueueControlTest.java
   branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/PostOfficeImplTest.java
   branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueImplTest.java
Log:
JBMESSAGING-1303: Revisit management interfaces
* added attributes to QueueControlMBean
* renamed {add|remove}Destination() to {add|remove}Address() in MessagingServerControlMBean
* tests + clean up

Modified: branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/MessagingServerControlMBean.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/MessagingServerControlMBean.java	2008-07-24 12:39:56 UTC (rev 4722)
+++ branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/MessagingServerControlMBean.java	2008-07-24 13:11:19 UTC (rev 4723)
@@ -34,7 +34,7 @@
    // Attributes ----------------------------------------------------
 
    String getVersion();
-   
+
    int getServerID();
 
    int getConnectionCount();
@@ -95,19 +95,27 @@
          @Parameter(name = "name", desc = "Name of the queue") String name)
          throws Exception;
 
+   @Operation(desc = "Create a queue", impact = ACTION)
+   void createQueue(
+         @Parameter(name = "address", desc = "Address of the queue") String address,
+         @Parameter(name = "name", desc = "Name of the queue") String name,
+         @Parameter(name = "filter", desc = "Filter of the queue") String filter,
+         @Parameter(name = "durable", desc = "Is the queue durable?") boolean durable,
+         @Parameter(name = "temporary", desc = "Is the queue temporary?") boolean temporary)
+         throws Exception;
+
    @Operation(desc = "Destroy a queue", impact = ACTION)
    void destroyQueue(
          @Parameter(name = "name", desc = "Name of the queue to destroy") String name)
          throws Exception;
 
    @Operation(desc = "Add an address to the post office", impact = ACTION)
-   boolean addDestination(
-         @Parameter(name = "address", desc = "Address of the destination") String address)
+   boolean addAddress(
+         @Parameter(name = "address", desc = "The address to add") String address)
          throws Exception;
 
    @Operation(desc = "Remove an address from the post office", impact = ACTION)
-   boolean removeDestination(
-         @Parameter(name = "address", desc = "Address of the destination") String address)
+   boolean removeAddress(
+         @Parameter(name = "address", desc = "The address to remove") String address)
          throws Exception;
-
 }

Modified: branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/MessagingServerManagement.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/MessagingServerManagement.java	2008-07-24 12:39:56 UTC (rev 4722)
+++ branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/MessagingServerManagement.java	2008-07-24 13:11:19 UTC (rev 4723)
@@ -56,6 +56,17 @@
    void createQueue(SimpleString address, SimpleString name) throws Exception;
 
    /**
+    * @param address
+    * @param name
+    * @param filter
+    * @param durable
+    * @param temporary
+    * @throws Exception
+    */
+   void createQueue(SimpleString address, SimpleString name, SimpleString filter,
+         boolean durable, boolean temporary) throws Exception;
+
+   /**
     * destroy a particular queue
     * @param name the name of the queue
     * @throws Exception if a problem occurred
@@ -279,4 +290,5 @@
     */
    String getVersion();
 
+
 }

Modified: branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/QueueControlMBean.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/QueueControlMBean.java	2008-07-24 12:39:56 UTC (rev 4722)
+++ branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/QueueControlMBean.java	2008-07-24 13:11:19 UTC (rev 4723)
@@ -39,6 +39,8 @@
 
    String getName();
 
+   long getPersistenceID();
+
    boolean isClustered();
 
    boolean isTemporary();
@@ -47,10 +49,20 @@
 
    String getFilter();
 
-   int getMessageCount();
+   long getSizeBytes();
 
    int getMaxSizeBytes();
 
+   int getMessageCount();
+
+   long getScheduledCount();
+
+   int getConsumerCount();
+
+   int getDeliveringCount();
+
+   int getMessagesAdded();
+
    // Operations ----------------------------------------------------
 
    @Operation(desc = "List all the messages in the queue", impact = INFO)
@@ -65,7 +77,7 @@
    void removeAllMessages() throws Exception;
 
    @Operation(desc = "Remove the message corresponding to the given messageID", impact = ACTION)
-   public boolean removeMessage(
+   boolean removeMessage(
          @Parameter(name = "messageID", desc = "A message ID") long messageID)
          throws Exception;
 }

Modified: branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java	2008-07-24 12:39:56 UTC (rev 4722)
+++ branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java	2008-07-24 13:11:19 UTC (rev 4723)
@@ -102,7 +102,6 @@
       return server.isStarted();
    }
 
-
    public String getVersion()
    {
       return server.getVersion();
@@ -228,19 +227,39 @@
       return configuration.isSecurityEnabled();
    }
 
-   public boolean addDestination(String address) throws Exception
+   public boolean addAddress(String address) throws Exception
    {
+      sendNotification(NotificationType.ADDRESS_ADDED, address);
       return server.addDestination(new SimpleString(address));
    }
 
    public void createQueue(String address, String name) throws Exception
    {
       server.createQueue(new SimpleString(address), new SimpleString(name));
+      sendNotification(NotificationType.ADDRESS_ADDED, address);
+      sendNotification(NotificationType.QUEUE_CREATED, name);
    }
 
+   public void createQueue(String address, String name, String filter,
+         boolean durable, boolean temporary) throws Exception
+   {
+      if (temporary && durable)
+      {
+         throw new IllegalArgumentException("A queue can not be both temporary and durable");
+      }
+      
+      SimpleString simpleFilter = (filter == null || filter.length() == 0) ? null
+            : new SimpleString(filter);
+      server.createQueue(new SimpleString(address), new SimpleString(name),
+            simpleFilter, durable, temporary);
+      sendNotification(NotificationType.ADDRESS_ADDED, address);
+      sendNotification(NotificationType.QUEUE_CREATED, name);
+   }
+
    public void destroyQueue(String name) throws Exception
    {
       server.destroyQueue(new SimpleString(name));
+      sendNotification(NotificationType.QUEUE_DESTROYED, name);
    }
 
    public int getConnectionCount()
@@ -248,12 +267,12 @@
       return server.getConnectionCount();
    }
 
-   public boolean removeDestination(String address) throws Exception
+   public boolean removeAddress(String address) throws Exception
    {
+      sendNotification(NotificationType.ADDRESS_REMOVED, address);
       return server.removeDestination(new SimpleString(address));
    }
 
-
    // NotificationEmitter implementation ----------------------------
 
    public void removeNotificationListener(NotificationListener listener,
@@ -300,11 +319,11 @@
             .incrementAndGet(), message);
       broadcaster.sendNotification(notif);
    }
-   
+
    // Inner classes -------------------------------------------------
-   
-   private enum NotificationType
+
+   public static enum NotificationType
    {
-      QUEUE_CREATED, QUEUE_DESTROYED, ROLE_ADDED, ROLE_REMOVED, ADDRESS_ADDED, ADDRESS_REMOVED;
+      QUEUE_CREATED, QUEUE_DESTROYED, ADDRESS_ADDED, ADDRESS_REMOVED;
    }
 }

Modified: branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/MessagingServerManagementImpl.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/MessagingServerManagementImpl.java	2008-07-24 12:39:56 UTC (rev 4722)
+++ branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/MessagingServerManagementImpl.java	2008-07-24 13:11:19 UTC (rev 4723)
@@ -27,6 +27,8 @@
 import java.util.Set;
 
 import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.filter.Filter;
+import org.jboss.messaging.core.filter.impl.FilterImpl;
 import org.jboss.messaging.core.management.MessagingServerManagement;
 import org.jboss.messaging.core.persistence.StorageManager;
 import org.jboss.messaging.core.postoffice.Binding;
@@ -118,6 +120,19 @@
       }
    }
    
+   public void createQueue(SimpleString address, SimpleString name, SimpleString filterStr, boolean durable, boolean temporary) throws Exception
+   {
+      if (postOffice.getBinding(name) == null)
+      {
+         Filter filter = null;
+         if (filterStr != null)
+         {
+            filter = new FilterImpl(filterStr);
+         }
+         postOffice.addBinding(address, name, filter, durable, temporary);
+      }
+   }
+   
    public int getConnectionCount()
    {
       return connectionManager.size();

Modified: branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/QueueControl.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/QueueControl.java	2008-07-24 12:39:56 UTC (rev 4722)
+++ branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/QueueControl.java	2008-07-24 13:11:19 UTC (rev 4723)
@@ -53,7 +53,7 @@
 
    // Attributes ----------------------------------------------------
 
-   private final Queue queue;
+   public final Queue queue;
    private final StorageManager storageManager;
 
    // Static --------------------------------------------------------
@@ -108,6 +108,36 @@
       return queue.getMaxSizeBytes();
    }
 
+   public int getConsumerCount()
+   {
+      return queue.getConsumerCount();
+   }
+
+   public int getDeliveringCount()
+   {
+      return queue.getDeliveringCount();
+   }
+
+   public int getMessagesAdded()
+   {
+      return queue.getMessagesAdded();
+   }
+
+   public long getPersistenceID()
+   {
+      return queue.getPersistenceID();
+   }
+
+   public long getScheduledCount()
+   {
+      return queue.getScheduledCount();
+   }
+
+   public long getSizeBytes()
+   {
+      return queue.getSizeBytes();
+   }
+
    public TabularData listAllMessages() throws Exception
    {
       return listMessages(null);

Modified: branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/server/Queue.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/server/Queue.java	2008-07-24 12:39:56 UTC (rev 4722)
+++ branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/server/Queue.java	2008-07-24 13:11:19 UTC (rev 4723)
@@ -71,8 +71,6 @@
    
    Filter getFilter();
    
-   void setFilter(Filter filter);
-   
    int getMessageCount();
    
    int getDeliveringCount();

Modified: branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java	2008-07-24 12:39:56 UTC (rev 4722)
+++ branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java	2008-07-24 13:11:19 UTC (rev 4723)
@@ -383,11 +383,6 @@
       return filter;
    }
 
-   public void setFilter(final Filter filter)
-   {
-      this.filter = filter;
-   }
-
    public synchronized int getMessageCount()
    {
       //log.info("mr: " + messageReferences.size() + " sc:" + getScheduledCount() + " dc:" + getDeliveringCount());

Modified: branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java	2008-07-24 12:39:56 UTC (rev 4722)
+++ branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java	2008-07-24 13:11:19 UTC (rev 4723)
@@ -22,6 +22,7 @@
 
 package org.jboss.messaging.tests.unit.core.management.impl;
 
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static org.easymock.EasyMock.createMock;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
@@ -31,16 +32,25 @@
 import static org.jboss.messaging.tests.util.RandomUtil.randomLong;
 import static org.jboss.messaging.tests.util.RandomUtil.randomString;
 
+import java.lang.management.ManagementFactory;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.CountDownLatch;
 
+import javax.management.MBeanServer;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+
 import junit.framework.TestCase;
 
 import org.jboss.messaging.core.client.Location;
 import org.jboss.messaging.core.client.impl.LocationImpl;
 import org.jboss.messaging.core.config.Configuration;
 import org.jboss.messaging.core.management.MessagingServerManagement;
+import org.jboss.messaging.core.management.impl.ManagementRegistrationImpl;
 import org.jboss.messaging.core.management.impl.MessagingServerControl;
+import org.jboss.messaging.core.management.impl.MessagingServerControl.NotificationType;
 import org.jboss.messaging.core.server.JournalType;
 import org.jboss.messaging.util.SimpleString;
 
@@ -54,12 +64,26 @@
  */
 public class MessagingServerControlTest extends TestCase
 {
+   private MBeanServer mbeanServer;
+   private ObjectName serverON;
+
    // Constants -----------------------------------------------------
 
    // Attributes ----------------------------------------------------
 
    // Static --------------------------------------------------------
 
+   private static void assertGotNotification(NotificationType expectedType,
+         NotificationListenerWithLatch listener, CountDownLatch latch)
+         throws Exception
+   {
+      boolean gotNotification = latch.await(500, MILLISECONDS);
+      assertTrue(gotNotification);
+      Notification notification = listener.getNotification();
+      assertNotNull(notification);
+      assertEquals(expectedType.toString(), notification.getType());
+   }
+
    // Constructors --------------------------------------------------
 
    // Public --------------------------------------------------------
@@ -144,7 +168,7 @@
 
       verify(server, configuration);
    }
-   
+
    public void testGetJournalAIOTimeout() throws Exception
    {
       long timeout = System.currentTimeMillis();
@@ -497,29 +521,57 @@
 
       MessagingServerControl control = new MessagingServerControl(server,
             configuration);
-      assertEquals(added, control.addDestination(address));
+      mbeanServer.registerMBean(control, serverON);
 
+      final CountDownLatch latch = new CountDownLatch(1);
+      NotificationListenerWithLatch listener = new NotificationListenerWithLatch(
+            latch);
+      mbeanServer.addNotificationListener(serverON, listener, null, null);
+
+      assertEquals(added, control.addAddress(address));
+
+      assertGotNotification(
+            MessagingServerControl.NotificationType.ADDRESS_ADDED, listener,
+            latch);
+
       verify(server, configuration);
+
+      mbeanServer.removeNotificationListener(serverON, listener);
+
+      verify(server, configuration);
    }
 
-   
-   public void testRemoveDestination() throws Exception
+   public void testRemoveAddress() throws Exception
    {
       String address = randomString();
       boolean removed = randomBoolean();
 
       MessagingServerManagement server = createMock(MessagingServerManagement.class);
-      expect(server.removeDestination(new SimpleString(address))).andReturn(removed);
+      expect(server.removeDestination(new SimpleString(address))).andReturn(
+            removed);
       Configuration configuration = createMock(Configuration.class);
       replay(server, configuration);
 
       MessagingServerControl control = new MessagingServerControl(server,
             configuration);
-      assertEquals(removed, control.removeDestination(address));
+      mbeanServer.registerMBean(control, serverON);
 
+      final CountDownLatch latch = new CountDownLatch(1);
+      NotificationListenerWithLatch listener = new NotificationListenerWithLatch(
+            latch);
+      mbeanServer.addNotificationListener(serverON, listener, null, null);
+
+      assertEquals(removed, control.removeAddress(address));
+
+      assertGotNotification(
+            MessagingServerControl.NotificationType.ADDRESS_REMOVED, listener,
+            latch);
+
       verify(server, configuration);
+
+      mbeanServer.removeNotificationListener(serverON, listener);
    }
-   
+
    public void testCreateQueue() throws Exception
    {
       String address = randomString();
@@ -536,27 +588,158 @@
 
       verify(server, configuration);
    }
-   
-   public void testDestroyQueue() throws Exception
+
+   public void testCreateQueueAndReceiveNotification() throws Exception
    {
+      String address = randomString();
       String name = randomString();
 
       MessagingServerManagement server = createMock(MessagingServerManagement.class);
       Configuration configuration = createMock(Configuration.class);
+      server.createQueue(new SimpleString(address), new SimpleString(name));
+      replay(server, configuration);
+
+      MessagingServerControl control = new MessagingServerControl(server,
+            configuration);
+      mbeanServer.registerMBean(control, serverON);
+
+      final CountDownLatch latch = new CountDownLatch(1);
+      NotificationListenerWithLatch listener = new NotificationListenerWithLatch(
+            latch);
+
+      mbeanServer.addNotificationListener(serverON, listener, null, null);
+      control.createQueue(address, name);
+
+      assertGotNotification(
+            MessagingServerControl.NotificationType.QUEUE_CREATED, listener,
+            latch);
+
+      verify(server, configuration);
+
+      mbeanServer.removeNotificationListener(serverON, listener);
+   }
+
+   public void testCreateQueueWithAllParameters() throws Exception
+   {
+      String address = randomString();
+      String name = randomString();
+      String filter = "color = 'green'";
+      boolean durable = true;
+      boolean temporary = false;
+
+      MessagingServerManagement server = createMock(MessagingServerManagement.class);
+      Configuration configuration = createMock(Configuration.class);
+      server.createQueue(new SimpleString(address), new SimpleString(name),
+            new SimpleString(filter), durable, temporary);
+      replay(server, configuration);
+
+      MessagingServerControl control = new MessagingServerControl(server,
+            configuration);
+      control.createQueue(address, name, filter, durable, temporary);
+
+      verify(server, configuration);
+   }
+
+   public void testCreateQueueWithEmptyFilter() throws Exception
+   {
+      String address = randomString();
+      String name = randomString();
+      String filter = "";
+      boolean durable = true;
+      boolean temporary = false;
+
+      MessagingServerManagement server = createMock(MessagingServerManagement.class);
+      Configuration configuration = createMock(Configuration.class);
+      server.createQueue(new SimpleString(address), new SimpleString(name),
+            null, durable, temporary);
+      replay(server, configuration);
+
+      MessagingServerControl control = new MessagingServerControl(server,
+            configuration);
+      control.createQueue(address, name, filter, durable, temporary);
+
+      verify(server, configuration);
+   }
+
+   public void testCreateQueueWithNullFilter() throws Exception
+   {
+      String address = randomString();
+      String name = randomString();
+      String filter = null;
+      boolean durable = true;
+      boolean temporary = false;
+
+      MessagingServerManagement server = createMock(MessagingServerManagement.class);
+      Configuration configuration = createMock(Configuration.class);
+      server.createQueue(new SimpleString(address), new SimpleString(name),
+            null, durable, temporary);
+      replay(server, configuration);
+
+      MessagingServerControl control = new MessagingServerControl(server,
+            configuration);
+      control.createQueue(address, name, filter, durable, temporary);
+
+      verify(server, configuration);
+   }
+
+   public void testCreateQueueWithBothDurableAndTemporarySetToTrueFails()
+         throws Exception
+   {
+      String address = randomString();
+      String name = randomString();
+      boolean durable = true;
+      boolean temporary = true;
+
+      MessagingServerManagement server = createMock(MessagingServerManagement.class);
+      Configuration configuration = createMock(Configuration.class);
+      replay(server, configuration);
+
+      MessagingServerControl control = new MessagingServerControl(server,
+            configuration);
+      try
+      {
+         control.createQueue(address, name, null, durable, temporary);
+         fail("a queue can not be both durable and temporary");
+      } catch (IllegalArgumentException e)
+      {
+      }
+
+      verify(server, configuration);
+   }
+
+   public void testDestroyQueueAndReceiveNotification() throws Exception
+   {
+      String name = randomString();
+
+      MessagingServerManagement server = createMock(MessagingServerManagement.class);
+      Configuration configuration = createMock(Configuration.class);
       server.destroyQueue(new SimpleString(name));
       replay(server, configuration);
 
       MessagingServerControl control = new MessagingServerControl(server,
             configuration);
+      mbeanServer.registerMBean(control, serverON);
+
+      final CountDownLatch latch = new CountDownLatch(1);
+      NotificationListenerWithLatch listener = new NotificationListenerWithLatch(
+            latch);
+
+      mbeanServer.addNotificationListener(serverON, listener, null, null);
       control.destroyQueue(name);
 
+      assertGotNotification(
+            MessagingServerControl.NotificationType.QUEUE_DESTROYED, listener,
+            latch);
+
       verify(server, configuration);
+
+      mbeanServer.removeNotificationListener(serverON, listener);
    }
-   
+
    public void testGetConnectionCount() throws Exception
    {
       int count = randomInt();
-      
+
       MessagingServerManagement server = createMock(MessagingServerManagement.class);
       Configuration configuration = createMock(Configuration.class);
       expect(server.getConnectionCount()).andReturn(count);
@@ -565,16 +748,62 @@
       MessagingServerControl control = new MessagingServerControl(server,
             configuration);
       assertEquals(count, control.getConnectionCount());
-      
+
       verify(server, configuration);
    }
-   
-   
+
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------
 
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+
+      mbeanServer = ManagementFactory.getPlatformMBeanServer();
+      serverON = ManagementRegistrationImpl.getMessagingServerObjectName();
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      if (mbeanServer.isRegistered(serverON))
+      {
+         mbeanServer.unregisterMBean(serverON);
+      }
+
+      serverON = null;
+      mbeanServer = null;
+
+      super.tearDown();
+   }
+
    // Private -------------------------------------------------------
 
    // Inner classes -------------------------------------------------
+
+   private final class NotificationListenerWithLatch implements
+         NotificationListener
+   {
+      private final CountDownLatch latch;
+      private Notification notification;
+
+      private NotificationListenerWithLatch(CountDownLatch latch)
+      {
+         this.latch = latch;
+      }
+
+      public void handleNotification(Notification notification, Object handback)
+      {
+         this.notification = notification;
+         latch.countDown();
+      }
+
+      public Notification getNotification()
+      {
+         return notification;
+      }
+   }
+
 }

Modified: branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/management/impl/QueueControlTest.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/management/impl/QueueControlTest.java	2008-07-24 12:39:56 UTC (rev 4722)
+++ branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/management/impl/QueueControlTest.java	2008-07-24 13:11:19 UTC (rev 4723)
@@ -44,15 +44,14 @@
 
 import junit.framework.TestCase;
 
-import org.easymock.EasyMock;
 import org.jboss.messaging.core.exception.MessagingException;
 import org.jboss.messaging.core.filter.Filter;
+import org.jboss.messaging.core.management.QueueControlMBean;
 import org.jboss.messaging.core.management.impl.QueueControl;
 import org.jboss.messaging.core.persistence.StorageManager;
 import org.jboss.messaging.core.server.MessageReference;
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.ServerMessage;
-import org.jboss.messaging.tests.util.RandomUtil;
 import org.jboss.messaging.util.SimpleString;
 
 /**
@@ -83,7 +82,7 @@
 
       replay(queue, storageManager);
 
-      QueueControl control = new QueueControl(queue, storageManager);
+      QueueControlMBean control = new QueueControl(queue, storageManager);
       assertEquals(name, control.getName());
 
       verify(queue, storageManager);
@@ -100,7 +99,7 @@
 
       replay(queue, storageManager, filter);
 
-      QueueControl control = new QueueControl(queue, storageManager);
+      QueueControlMBean control = new QueueControl(queue, storageManager);
       assertEquals(filterStr, control.getFilter());
 
       verify(queue, storageManager, filter);
@@ -114,7 +113,7 @@
 
       replay(queue, storageManager);
 
-      QueueControl control = new QueueControl(queue, storageManager);
+      QueueControlMBean control = new QueueControl(queue, storageManager);
       assertNull(control.getFilter());
 
       verify(queue, storageManager);
@@ -130,7 +129,7 @@
 
       replay(queue, storageManager);
 
-      QueueControl control = new QueueControl(queue, storageManager);
+      QueueControlMBean control = new QueueControl(queue, storageManager);
       assertEquals(clustered, control.isClustered());
 
       verify(queue, storageManager);
@@ -146,7 +145,7 @@
 
       replay(queue, storageManager);
 
-      QueueControl control = new QueueControl(queue, storageManager);
+      QueueControlMBean control = new QueueControl(queue, storageManager);
       assertEquals(durable, control.isDurable());
 
       verify(queue, storageManager);
@@ -162,7 +161,7 @@
 
       replay(queue, storageManager);
 
-      QueueControl control = new QueueControl(queue, storageManager);
+      QueueControlMBean control = new QueueControl(queue, storageManager);
       assertEquals(temp, control.isTemporary());
 
       verify(queue, storageManager);
@@ -184,6 +183,22 @@
       verify(queue, storageManager);
    }
 
+   public void testGetMessagesAdded() throws Exception
+   {
+      int count = randomInt();
+
+      Queue queue = createMock(Queue.class);
+      expect(queue.getMessagesAdded()).andReturn(count);
+      StorageManager storageManager = createMock(StorageManager.class);
+
+      replay(queue, storageManager);
+
+      QueueControl control = new QueueControl(queue, storageManager);
+      assertEquals(count, control.getMessagesAdded());
+
+      verify(queue, storageManager);
+   }
+
    public void testGetMaxSizeBytes() throws Exception
    {
       int size = randomInt();
@@ -200,17 +215,97 @@
       verify(queue, storageManager);
    }
 
+   public void testGetSizeBytes() throws Exception
+   {
+      int size = randomInt();
+
+      Queue queue = createMock(Queue.class);
+      expect(queue.getSizeBytes()).andReturn(size);
+      StorageManager storageManager = createMock(StorageManager.class);
+
+      replay(queue, storageManager);
+
+      QueueControl control = new QueueControl(queue, storageManager);
+      assertEquals(size, control.getSizeBytes());
+
+      verify(queue, storageManager);
+   }
+
+   public void testGetScheduledCount() throws Exception
+   {
+      int count = randomInt();
+
+      Queue queue = createMock(Queue.class);
+      expect(queue.getScheduledCount()).andReturn(count);
+      StorageManager storageManager = createMock(StorageManager.class);
+
+      replay(queue, storageManager);
+
+      QueueControl control = new QueueControl(queue, storageManager);
+      assertEquals(count, control.getScheduledCount());
+
+      verify(queue, storageManager);
+   }
+
+   public void testGetConsumerCount() throws Exception
+   {
+      int count = randomInt();
+
+      Queue queue = createMock(Queue.class);
+      expect(queue.getConsumerCount()).andReturn(count);
+      StorageManager storageManager = createMock(StorageManager.class);
+
+      replay(queue, storageManager);
+
+      QueueControl control = new QueueControl(queue, storageManager);
+      assertEquals(count, control.getConsumerCount());
+
+      verify(queue, storageManager);
+   }
+
+   public void testGetDeliveringCount() throws Exception
+   {
+      int count = randomInt();
+
+      Queue queue = createMock(Queue.class);
+      expect(queue.getDeliveringCount()).andReturn(count);
+      StorageManager storageManager = createMock(StorageManager.class);
+
+      replay(queue, storageManager);
+
+      QueueControl control = new QueueControl(queue, storageManager);
+      assertEquals(count, control.getDeliveringCount());
+
+      verify(queue, storageManager);
+   }
+
+   public void testGetPersistenceID() throws Exception
+   {
+      long id = randomLong();
+
+      Queue queue = createMock(Queue.class);
+      expect(queue.getPersistenceID()).andReturn(id);
+      StorageManager storageManager = createMock(StorageManager.class);
+
+      replay(queue, storageManager);
+
+      QueueControl control = new QueueControl(queue, storageManager);
+      assertEquals(id, control.getPersistenceID());
+
+      verify(queue, storageManager);
+   }
+
    public void testRemoveAllMessages() throws Exception
    {
       Queue queue = createMock(Queue.class);
       StorageManager storageManager = createMock(StorageManager.class);
       queue.deleteAllReferences(storageManager);
-      
+
       replay(queue, storageManager);
 
-      QueueControl control = new QueueControl(queue, storageManager);
+      QueueControlMBean control = new QueueControl(queue, storageManager);
       control.removeAllMessages();
-      
+
       verify(queue, storageManager);
    }
 
@@ -223,7 +318,7 @@
 
       replay(queue, storageManager);
 
-      QueueControl control = new QueueControl(queue, storageManager);
+      QueueControlMBean control = new QueueControl(queue, storageManager);
       try
       {
          control.removeAllMessages();
@@ -248,7 +343,7 @@
 
       replay(queue, storageManager);
 
-      QueueControl control = new QueueControl(queue, storageManager);
+      QueueControlMBean control = new QueueControl(queue, storageManager);
       assertEquals(deleted, control.removeMessage(messageID));
 
       verify(queue, storageManager);
@@ -265,7 +360,7 @@
 
       replay(queue, storageManager);
 
-      QueueControl control = new QueueControl(queue, storageManager);
+      QueueControlMBean control = new QueueControl(queue, storageManager);
       try
       {
          control.removeMessage(messageID);
@@ -277,13 +372,12 @@
 
       verify(queue, storageManager);
    }
-   
-   
+
    public void testListMessages() throws Exception
    {
       String filterStr = "color = 'green'";
       List<MessageReference> refs = new ArrayList<MessageReference>();
-      
+
       MessageReference ref = createMock(MessageReference.class);
       ServerMessage message = createMock(ServerMessage.class);
       expect(message.getMessageID()).andStubReturn(randomLong());
@@ -304,10 +398,10 @@
 
       replay(queue, storageManager, ref, message);
 
-      QueueControl control = new QueueControl(queue, storageManager);
+      QueueControlMBean control = new QueueControl(queue, storageManager);
       TabularData data = control.listMessages(filterStr);
       assertEquals(1, data.size());
-      CompositeData info = data.get(new Object[] { message.getMessageID()});
+      CompositeData info = data.get(new Object[] { message.getMessageID() });
       assertNotNull(info);
       assertEquals(message.getMessageID(), info.get("id"));
       assertEquals(message.getDestination().toString(), info.get("destination"));

Modified: branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/PostOfficeImplTest.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/PostOfficeImplTest.java	2008-07-24 12:39:56 UTC (rev 4722)
+++ branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/PostOfficeImplTest.java	2008-07-24 13:11:19 UTC (rev 4723)
@@ -22,6 +22,11 @@
 
 package org.jboss.messaging.tests.unit.core.postoffice.impl;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 import org.easymock.EasyMock;
 import org.easymock.IAnswer;
 import org.jboss.messaging.core.exception.MessagingException;
@@ -40,11 +45,6 @@
 import org.jboss.messaging.tests.util.UnitTestCase;
 import org.jboss.messaging.util.SimpleString;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
 /**
  * A PostOfficeTest
  *
@@ -499,7 +499,7 @@
 
       final long id = 324;
       final SimpleString name = new SimpleString("wibb22");
-      final Filter filter = new FakeFilter();
+      final Filter filter = EasyMock.createMock(Filter.class);
       final boolean durable = true;
       final boolean temporary = true;
 
@@ -513,29 +513,22 @@
 
       pm.addBinding(EasyMock.eq(expected));
 
-      EasyMock.replay(qf);
+      EasyMock.replay(qf, pm, filter);
 
-      EasyMock.replay(pm);
-
       po.addBinding(condition, name, filter, durable, temporary);
 
-      EasyMock.verify(qf);
+      EasyMock.verify(qf, pm, filter);
 
-      EasyMock.verify(pm);
+      EasyMock.reset(qf, pm, filter);
 
-      EasyMock.reset(qf);
-
-      EasyMock.reset(pm);
-
       final boolean durable2 = false;
 
       queue = queueFactory.createQueue(id, name, filter, durable2, temporary);
 
       EasyMock.expect(qf.createQueue(-1, name, filter, durable2, temporary)).andReturn(queue);
 
-      EasyMock.replay(qf);
+      EasyMock.replay(qf, pm, filter);
 
-      EasyMock.replay(pm);
    }
 
    public void testRemoveQueue() throws Exception
@@ -548,7 +541,7 @@
 
       final long id = 324;
       final SimpleString name = new SimpleString("wibb22");
-      final Filter filter = new FakeFilter();
+      final Filter filter = EasyMock.createMock(Filter.class);
       final boolean durable = true;
       final boolean temporary = true;
 
@@ -564,39 +557,29 @@
 
       pm.deleteBinding(EasyMock.eq(expected));
 
-      EasyMock.replay(qf);
+      EasyMock.replay(qf, pm, filter);
 
-      EasyMock.replay(pm);
-
       po.addBinding(condition, name, filter, durable, temporary);
 
       po.removeBinding(name);
 
-      EasyMock.verify(qf);
+      EasyMock.verify(qf, pm, filter);
 
-      EasyMock.verify(pm);
+      EasyMock.reset(qf, pm, filter);
 
-      EasyMock.reset(qf);
-
-      EasyMock.reset(pm);
-
       final boolean durable2 = false;
 
       queue = queueFactory.createQueue(id, name, filter, durable2, temporary);
 
       EasyMock.expect(qf.createQueue(-1, name, filter, durable2, temporary)).andReturn(queue);
 
-      EasyMock.replay(qf);
+      EasyMock.replay(qf, pm, filter);
 
-      EasyMock.replay(pm);
-
       po.addBinding(condition, name, filter, durable2, temporary);
 
       po.removeBinding(name);
 
-      EasyMock.verify(qf);
-
-      EasyMock.verify(pm);
+      EasyMock.verify(qf, pm, filter);
    }
 
    public void testAddRemoveMultipleWithDifferentConditions() throws Exception
@@ -1423,21 +1406,6 @@
          assertEquals(messageReference3, references.get(1));
       }
 
-
-   class FakeFilter implements Filter
-   {
-      public SimpleString getFilterString()
-      {
-         return new SimpleString("aardvark");
-      }
-
-      public boolean match(ServerMessage message)
-      {
-         return true;
-      }
-
-   }
-
    class LoadBindingsIAnswer implements IAnswer
    {
       List<Binding> bindings;

Modified: branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueImplTest.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueImplTest.java	2008-07-24 12:39:56 UTC (rev 4722)
+++ branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueImplTest.java	2008-07-24 13:11:19 UTC (rev 4723)
@@ -22,10 +22,27 @@
 
 package org.jboss.messaging.tests.unit.core.server.impl;
 
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
 import org.easymock.EasyMock;
 import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.persistence.StorageManager;
-import org.jboss.messaging.core.server.*;
+import org.jboss.messaging.core.server.Consumer;
+import org.jboss.messaging.core.server.DistributionPolicy;
+import org.jboss.messaging.core.server.HandleStatus;
+import org.jboss.messaging.core.server.MessageReference;
+import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.impl.QueueImpl;
 import org.jboss.messaging.core.server.impl.RoundRobinDistributionPolicy;
 import org.jboss.messaging.tests.unit.core.server.impl.fakes.FakeConsumer;
@@ -33,11 +50,6 @@
 import org.jboss.messaging.tests.util.UnitTestCase;
 import org.jboss.messaging.util.SimpleString;
 
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.*;
-
 /**
  * A QueueTest
  *
@@ -183,21 +195,20 @@
       assertEquals(policy, queue.getDistributionPolicy());
    }
 
-   public void testGetSetFilter()
+   public void testGetFilter()
    {
       Queue queue = new QueueImpl(1, queue1, null, false, true, false, -1, scheduledExecutor);
 
       assertNull(queue.getFilter());
 
-      Filter filter = new FakeFilter();
+      Filter filter = createMock(Filter.class);
+      replay(filter);
 
-      queue.setFilter(filter);
-
-      assertEquals(filter, queue.getFilter());
-
       queue = new QueueImpl(1, queue1, filter, false, true, false, -1, scheduledExecutor);
 
       assertEquals(filter, queue.getFilter());
+      
+      verify(filter);
    }
 
    public void testDefaultMaxSize()




More information about the jboss-cvs-commits mailing list