[jboss-cvs] JBoss Messaging SVN: r4464 - trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jun 13 08:57:31 EDT 2008


Author: timfox
Date: 2008-06-13 08:57:31 -0400 (Fri, 13 Jun 2008)
New Revision: 4464

Added:
   trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/ClientBrowserImplTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/ClientConsumerImplTest.java
Log:
Added files


Added: trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/ClientBrowserImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/ClientBrowserImplTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/ClientBrowserImplTest.java	2008-06-13 12:57:31 UTC (rev 4464)
@@ -0,0 +1,210 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.tests.unit.core.client.impl;
+
+import org.easymock.EasyMock;
+import org.jboss.messaging.core.client.ClientBrowser;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.impl.ClientBrowserImpl;
+import org.jboss.messaging.core.client.impl.ClientConnectionInternal;
+import org.jboss.messaging.core.client.impl.ClientSessionInternal;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.RemotingConnection;
+import org.jboss.messaging.core.remoting.impl.wireformat.EmptyPacket;
+import org.jboss.messaging.core.remoting.impl.wireformat.ReceiveMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserHasNextMessageResponseMessage;
+import org.jboss.messaging.tests.util.UnitTestCase;
+
+/**
+ * 
+ * A ClientBrowserImplTest
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class ClientBrowserImplTest extends UnitTestCase
+{
+   private static final Logger log = Logger.getLogger(ClientBrowserImplTest.class);
+
+   public void testConstructor() throws Exception
+   {
+      ClientSessionInternal session = EasyMock.createStrictMock(ClientSessionInternal.class);
+      ClientConnectionInternal connection = EasyMock.createStrictMock(ClientConnectionInternal.class);
+      RemotingConnection rc = EasyMock.createStrictMock(RemotingConnection.class);
+            
+      EasyMock.expect(session.getConnection()).andReturn(connection);
+      EasyMock.expect(connection.getRemotingConnection()).andReturn(rc);
+      
+      EasyMock.replay(session, connection, rc);
+      
+      ClientBrowser browser =
+         new ClientBrowserImpl(session, 67567576);
+      
+      EasyMock.verify(session, connection, rc);            
+   }
+   
+   public void testHasNextMessage() throws Exception
+   {
+      testHasNextMessage(true);
+      testHasNextMessage(false);
+   }
+   
+   public void testNextMessage() throws Exception
+   {
+      ClientSessionInternal session = EasyMock.createStrictMock(ClientSessionInternal.class);
+      ClientConnectionInternal connection = EasyMock.createStrictMock(ClientConnectionInternal.class);
+      RemotingConnection rc = EasyMock.createStrictMock(RemotingConnection.class);
+            
+      EasyMock.expect(session.getConnection()).andReturn(connection);
+      EasyMock.expect(connection.getRemotingConnection()).andReturn(rc);
+      
+      final long targetID = 187282;
+      
+      long sessionTargetID = 198271982;
+      
+      ReceiveMessage resp = new ReceiveMessage();
+      
+      EasyMock.expect(session.getServerTargetID()).andReturn(sessionTargetID);
+      
+      EasyMock.expect(rc.sendBlocking(targetID, sessionTargetID, new EmptyPacket(EmptyPacket.SESS_BROWSER_NEXTMESSAGE))).andReturn(resp);
+      
+      EasyMock.replay(session, connection, rc);
+      
+      ClientBrowser browser =
+         new ClientBrowserImpl(session, targetID);
+            
+      ClientMessage msg2 = browser.nextMessage();
+      
+      assertTrue(msg2 == null);
+      
+      EasyMock.verify(session, connection, rc);            
+   }
+   
+   public void testReset() throws Exception
+   {
+      ClientSessionInternal session = EasyMock.createStrictMock(ClientSessionInternal.class);
+      ClientConnectionInternal connection = EasyMock.createStrictMock(ClientConnectionInternal.class);
+      RemotingConnection rc = EasyMock.createStrictMock(RemotingConnection.class);
+            
+      EasyMock.expect(session.getConnection()).andReturn(connection);
+      EasyMock.expect(connection.getRemotingConnection()).andReturn(rc);
+      
+      final long targetID = 187282;
+      
+      long sessionTargetID = 198271982;
+      
+      EasyMock.expect(session.getServerTargetID()).andReturn(sessionTargetID);
+      
+      EasyMock.expect(rc.sendBlocking(targetID, sessionTargetID, new EmptyPacket(EmptyPacket.SESS_BROWSER_RESET))).andReturn(null);
+      
+      EasyMock.replay(session, connection, rc);
+      
+      ClientBrowser browser =
+         new ClientBrowserImpl(session, targetID);
+            
+      browser.reset();
+      
+      EasyMock.verify(session, connection, rc);            
+   }
+   
+   public void testClose() throws Exception
+   {
+      ClientSessionInternal session = EasyMock.createStrictMock(ClientSessionInternal.class);
+      ClientConnectionInternal connection = EasyMock.createStrictMock(ClientConnectionInternal.class);
+      RemotingConnection rc = EasyMock.createStrictMock(RemotingConnection.class);
+            
+      EasyMock.expect(session.getConnection()).andReturn(connection);
+      EasyMock.expect(connection.getRemotingConnection()).andReturn(rc);
+      
+      EasyMock.replay(session, connection, rc);
+      
+      final long targetID = 187282;
+      
+      ClientBrowser browser =
+         new ClientBrowserImpl(session, targetID);
+      
+      EasyMock.verify(session, connection, rc);  
+      
+      EasyMock.reset(session, connection, rc);
+      
+      long sessionTargetID = 198271982;
+      
+      EasyMock.expect(session.getServerTargetID()).andReturn(sessionTargetID);
+      
+      EasyMock.expect(rc.sendBlocking(targetID, sessionTargetID, new EmptyPacket(EmptyPacket.CLOSE))).andReturn(null);
+      
+      session.removeBrowser(browser);
+      
+      EasyMock.replay(session, connection, rc);
+      
+      assertFalse(browser.isClosed());
+            
+      browser.close();
+      
+      EasyMock.verify(session, connection, rc);
+      
+      assertTrue(browser.isClosed());
+      
+      //Try and close again - nothing should happen
+      
+      EasyMock.reset(session, connection, rc);
+      
+      EasyMock.replay(session, connection, rc);
+      
+      browser.close();
+                
+      EasyMock.verify(session, connection, rc);
+   }
+
+   // Private -----------------------------------------------------------------------------------------------------------
+   
+   private void testHasNextMessage(final boolean hasNext) throws Exception
+   {
+      ClientSessionInternal session = EasyMock.createStrictMock(ClientSessionInternal.class);
+      ClientConnectionInternal connection = EasyMock.createStrictMock(ClientConnectionInternal.class);
+      RemotingConnection rc = EasyMock.createStrictMock(RemotingConnection.class);
+            
+      EasyMock.expect(session.getConnection()).andReturn(connection);
+      EasyMock.expect(connection.getRemotingConnection()).andReturn(rc);
+      
+      final long targetID = 187282;
+      
+      long sessionTargetID = 198271982;
+      
+      SessionBrowserHasNextMessageResponseMessage resp = new SessionBrowserHasNextMessageResponseMessage(hasNext);
+      
+      EasyMock.expect(session.getServerTargetID()).andReturn(sessionTargetID);
+      
+      EasyMock.expect(rc.sendBlocking(targetID, sessionTargetID, new EmptyPacket(EmptyPacket.SESS_BROWSER_HASNEXTMESSAGE))).andReturn(resp);
+      
+      EasyMock.replay(session, connection, rc);
+      
+      ClientBrowser browser =
+         new ClientBrowserImpl(session, targetID);
+            
+      boolean has = browser.hasNextMessage();
+      
+      assertEquals(has, hasNext);
+      
+      EasyMock.verify(session, connection, rc);            
+   }      
+}

Added: trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/ClientConsumerImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/ClientConsumerImplTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/ClientConsumerImplTest.java	2008-06-13 12:57:31 UTC (rev 4464)
@@ -0,0 +1,347 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.tests.unit.core.client.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+
+import org.easymock.EasyMock;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.MessageHandler;
+import org.jboss.messaging.core.client.impl.ClientConnectionInternal;
+import org.jboss.messaging.core.client.impl.ClientConsumerImpl;
+import org.jboss.messaging.core.client.impl.ClientConsumerInternal;
+import org.jboss.messaging.core.client.impl.ClientSessionInternal;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.RemotingConnection;
+import org.jboss.messaging.tests.util.UnitTestCase;
+
+/**
+ * 
+ * A ClientConsumerImplTest
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class ClientConsumerImplTest extends UnitTestCase
+{
+   private static final Logger log = Logger.getLogger(ClientConsumerImplTest.class);
+
+   public void testConstructor() throws Exception
+   {
+      testConstructor(6565, 71627162, 7676, false);
+      testConstructor(6565, 71627162, 7676, true);
+      testConstructor(6565, 71627162, -1, false);
+      testConstructor(6565, 71627162, -1, true);
+   }
+   
+   /*
+    * Test handleMessage with:
+    * 
+    * handler
+    * nohandler
+    * handler direct
+    * add handler after
+    * 
+    * 
+    * priorities
+    * closed
+    * after recovery
+    * expired messages
+    * 
+    * flowcontrol
+    */
+   
+   public void testHandleMessageNoHandler() throws Exception
+   {
+      ClientSessionInternal session = EasyMock.createStrictMock(ClientSessionInternal.class);
+      ClientConnectionInternal connection = EasyMock.createStrictMock(ClientConnectionInternal.class);
+      RemotingConnection rc = EasyMock.createStrictMock(RemotingConnection.class);
+      ExecutorService executor = EasyMock.createStrictMock(ExecutorService.class);
+      
+
+      EasyMock.expect(session.getExecutorService()).andReturn(executor);
+      EasyMock.expect(session.getConnection()).andReturn(connection);
+      EasyMock.expect(connection.getRemotingConnection()).andReturn(rc);
+      
+      final int numMessages = 10;
+      
+      List<ClientMessage> msgs = new ArrayList<ClientMessage>();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         ClientMessage msg = EasyMock.createStrictMock(ClientMessage.class);
+         
+         msgs.add(msg);
+         
+         EasyMock.expect(msg.getPriority()).andReturn((byte)4); //default priority
+      }
+            
+      EasyMock.replay(session, connection, rc, executor);
+      EasyMock.replay(msgs.toArray());
+      
+      ClientConsumerInternal consumer =
+         new ClientConsumerImpl(session, 54545, 54544, 545454, false);
+      
+      for (ClientMessage msg: msgs)
+      {
+         consumer.handleMessage(msg);
+      }
+      
+      EasyMock.verify(session, connection, rc, executor);      
+      EasyMock.verify(msgs.toArray());
+      
+      assertEquals(numMessages, consumer.getBufferSize());         
+   }
+   
+   public void testHandleMessageWithNonDirectHandler() throws Exception
+   {
+      ClientSessionInternal session = EasyMock.createStrictMock(ClientSessionInternal.class);
+      ClientConnectionInternal connection = EasyMock.createStrictMock(ClientConnectionInternal.class);
+      RemotingConnection rc = EasyMock.createStrictMock(RemotingConnection.class);
+      ExecutorService executor = EasyMock.createStrictMock(ExecutorService.class);
+      
+
+      EasyMock.expect(session.getExecutorService()).andReturn(executor);
+      EasyMock.expect(session.getConnection()).andReturn(connection);
+      EasyMock.expect(connection.getRemotingConnection()).andReturn(rc);
+      
+      final int numMessages = 10;
+      
+      List<ClientMessage> msgs = new ArrayList<ClientMessage>();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         ClientMessage msg = EasyMock.createStrictMock(ClientMessage.class);
+         
+         msgs.add(msg);
+         
+         EasyMock.expect(msg.getPriority()).andReturn((byte)4); //default priority
+         
+         executor.execute(EasyMock.isA(Runnable.class));
+      }
+            
+      EasyMock.replay(session, connection, rc, executor);
+      EasyMock.replay(msgs.toArray());
+      
+      ClientConsumerInternal consumer =
+         new ClientConsumerImpl(session, 54545, 54544, 545454, false);
+      
+      consumer.setMessageHandler(new MessageHandler()
+      {
+         public void onMessage(final ClientMessage message)
+         {            
+         }
+      });
+      
+      for (ClientMessage msg: msgs)
+      {
+         consumer.handleMessage(msg);
+      }
+      
+      EasyMock.verify(session, connection, rc, executor);      
+      EasyMock.verify(msgs.toArray());
+      
+      assertEquals(numMessages, consumer.getBufferSize());         
+   }
+   
+   public void testHandleMessageWithDirectHandler() throws Exception
+   {
+      ClientSessionInternal session = EasyMock.createStrictMock(ClientSessionInternal.class);
+      ClientConnectionInternal connection = EasyMock.createStrictMock(ClientConnectionInternal.class);
+      RemotingConnection rc = EasyMock.createStrictMock(RemotingConnection.class);
+      ExecutorService executor = EasyMock.createStrictMock(ExecutorService.class);
+      MessageHandler handler = EasyMock.createStrictMock(MessageHandler.class);
+      
+      EasyMock.expect(session.getExecutorService()).andReturn(executor);
+      EasyMock.expect(session.getConnection()).andReturn(connection);
+      EasyMock.expect(connection.getRemotingConnection()).andReturn(rc);
+      
+      final int numMessages = 10;
+      
+      List<ClientMessage> msgs = new ArrayList<ClientMessage>();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         ClientMessage msg = EasyMock.createStrictMock(ClientMessage.class);
+         
+         msgs.add(msg);
+         
+         EasyMock.expect(msg.isExpired()).andReturn(false);
+         
+         EasyMock.expect(msg.getDeliveryID()).andReturn((long)i);
+         
+         session.delivered((long)i, false);
+         
+         EasyMock.expect(msg.encodeSize()).andReturn(1);
+         
+         handler.onMessage(msg);
+      }
+            
+      EasyMock.replay(session, connection, rc, executor);
+      EasyMock.replay(msgs.toArray());
+      
+      ClientConsumerInternal consumer =
+         new ClientConsumerImpl(session, 54545, 54544, 545454, true);
+      
+      consumer.setMessageHandler(handler);
+      
+      for (ClientMessage msg: msgs)
+      {
+         consumer.handleMessage(msg);
+      }
+      
+      EasyMock.verify(session, connection, rc, executor);      
+      EasyMock.verify(msgs.toArray());
+      
+      assertEquals(0, consumer.getBufferSize());         
+   }
+   
+//   public void testSetGetHandler() throws Exception
+//   {
+//      ClientSessionInternal session = EasyMock.createStrictMock(ClientSessionInternal.class);
+//      ClientConnectionInternal connection = EasyMock.createStrictMock(ClientConnectionInternal.class);
+//      RemotingConnection rc = EasyMock.createStrictMock(RemotingConnection.class);
+//      ExecutorService executor = EasyMock.createStrictMock(ExecutorService.class);
+//      
+//      EasyMock.expect(session.getExecutorService()).andReturn(executor);
+//      EasyMock.expect(session.getConnection()).andReturn(connection);
+//      EasyMock.expect(connection.getRemotingConnection()).andReturn(rc);
+//       
+//      EasyMock.replay(session, connection, rc, executor);
+//
+//      ClientConsumerInternal consumer =
+//         new ClientConsumerImpl(session, 54545, 54544, 545454, false);
+//      
+//      EasyMock.verify(session, connection, rc, executor);      
+//      
+//      MessageHandler handler = new MessageHandler()
+//      {
+//         public void onMessage(final ClientMessage msg)
+//         {            
+//         }
+//      };
+//      
+//      consumer.setMessageHandler(handler);
+//      
+//      assertTrue(handler == consumer.getMessageHandler());
+//      
+//      consumer.setMessageHandler(null);
+//      
+//      assertNull(consumer.getMessageHandler());
+//   }
+      
+      
+   public void testSetGetHandlerWithMessagesAlreadyInBuffer() throws Exception
+   {
+      ClientSessionInternal session = EasyMock.createStrictMock(ClientSessionInternal.class);
+      ClientConnectionInternal connection = EasyMock.createStrictMock(ClientConnectionInternal.class);
+      RemotingConnection rc = EasyMock.createStrictMock(RemotingConnection.class);
+      ExecutorService executor = EasyMock.createStrictMock(ExecutorService.class);
+      
+      EasyMock.expect(session.getExecutorService()).andReturn(executor);
+      EasyMock.expect(session.getConnection()).andReturn(connection);
+      EasyMock.expect(connection.getRemotingConnection()).andReturn(rc);
+      
+      final int numMessages = 10;
+      
+      List<ClientMessage> msgs = new ArrayList<ClientMessage>();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         ClientMessage msg = EasyMock.createStrictMock(ClientMessage.class);
+         
+         msgs.add(msg);
+         
+         EasyMock.expect(msg.getPriority()).andReturn((byte)4); //default priority
+      }
+            
+      EasyMock.replay(session, connection, rc, executor);
+      EasyMock.replay(msgs.toArray());
+      
+      ClientConsumerInternal consumer =
+         new ClientConsumerImpl(session, 54545, 54544, 545454, false);
+      
+      for (ClientMessage msg: msgs)
+      {
+         consumer.handleMessage(msg);
+      }
+      
+      EasyMock.verify(session, connection, rc, executor);      
+      EasyMock.verify(msgs.toArray());
+      
+      EasyMock.reset(session, connection, rc, executor);      
+      EasyMock.reset(msgs.toArray());
+      
+      assertEquals(numMessages, consumer.getBufferSize());
+      
+      for (ClientMessage msg: msgs)
+      {
+         executor.execute(EasyMock.isA(Runnable.class));
+      }
+      
+      EasyMock.replay(session, connection, rc, executor);
+      EasyMock.replay(msgs.toArray());
+      
+      MessageHandler handler = EasyMock.createStrictMock(MessageHandler.class);
+      
+      consumer.setMessageHandler(handler);
+      
+      EasyMock.verify(session, connection, rc, executor);
+      EasyMock.verify(msgs.toArray());   
+   }
+               
+   // Private -----------------------------------------------------------------------------------------------------------
+
+   
+   private void testConstructor(final long targetID, final long clientTargetID,
+         final int windowSize, final boolean direct) throws Exception
+   {
+      ClientSessionInternal session = EasyMock.createStrictMock(ClientSessionInternal.class);
+      ClientConnectionInternal connection = EasyMock.createStrictMock(ClientConnectionInternal.class);
+      RemotingConnection rc = EasyMock.createStrictMock(RemotingConnection.class);
+      ExecutorService executor = EasyMock.createStrictMock(ExecutorService.class);
+      
+      EasyMock.expect(session.getExecutorService()).andReturn(executor);
+      EasyMock.expect(session.getConnection()).andReturn(connection);
+      EasyMock.expect(connection.getRemotingConnection()).andReturn(rc);
+      
+      EasyMock.replay(session, connection, rc);
+      
+      ClientConsumerInternal consumer =
+      new ClientConsumerImpl(session, targetID, clientTargetID, windowSize, direct);
+      
+      EasyMock.verify(session, connection, rc);
+      
+      assertEquals(direct, consumer.isDirect());
+      assertFalse(consumer.isClosed());
+      assertEquals(clientTargetID, consumer.getClientTargetID());
+      assertEquals(windowSize, consumer.getClientWindowSize());
+      assertEquals(0, consumer.getBufferSize());
+      assertEquals(-1, consumer.getIgnoreDeliveryMark());
+      assertEquals(0, consumer.getCreditsToSend());
+      assertNull(consumer.getMessageHandler());
+   }
+
+}




More information about the jboss-cvs-commits mailing list