[jboss-cvs] JBoss Messaging SVN: r4534 - in trunk: tests/src/org/jboss/messaging/tests/unit/core/remoting/impl and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jun 20 08:54:34 EDT 2008


Author: ataylor
Date: 2008-06-20 08:54:34 -0400 (Fri, 20 Jun 2008)
New Revision: 4534

Added:
   trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/ResponseHandlerImplTest.java
Removed:
   trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/timing/
Modified:
   trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingConfigurationValidator.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingServiceImpl.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/RemotingConfigurationValidatorTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/RemotingServiceImplTest.java
Log:
more tests and tweaks

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingConfigurationValidator.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingConfigurationValidator.java	2008-06-20 11:40:31 UTC (rev 4533)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingConfigurationValidator.java	2008-06-20 12:54:34 UTC (rev 4534)
@@ -22,10 +22,9 @@
 
 package org.jboss.messaging.core.remoting.impl;
 
-import static org.jboss.messaging.core.remoting.TransportType.INVM;
-
 import org.jboss.messaging.core.config.Configuration;
 import org.jboss.messaging.core.logging.Logger;
+import static org.jboss.messaging.core.remoting.TransportType.INVM;
 
 /**
  * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -45,6 +44,10 @@
 
    public static void validate(Configuration configuration)
    {
+      if(configuration == null)
+      {
+         throw new IllegalStateException("Config must not be null");
+      }
       if (configuration.getTransport() == INVM
             && !configuration.getConnectionParams().isInVMOptimisationEnabled())
       {

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingServiceImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingServiceImpl.java	2008-06-20 11:40:31 UTC (rev 4533)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingServiceImpl.java	2008-06-20 12:54:34 UTC (rev 4534)
@@ -77,8 +77,6 @@
 
    public RemotingServiceImpl(Configuration config)
    {
-      assert config != null;
-
       validate(config);
 
       this.config = config;
@@ -104,14 +102,20 @@
 
    public void addRemotingSessionListener(RemotingSessionListener listener)
    {
-      assert listener != null;
+      if(listener == null)
+      {
+         throw new IllegalArgumentException("listener can not be null");
+      }
 
       listeners.add(listener);
    }
 
    public void removeRemotingSessionListener(RemotingSessionListener listener)
    {
-      assert listener != null;
+      if(listener == null)
+      {
+         throw new IllegalArgumentException("listener can not be null");
+      }
 
       listeners.remove(listener);
    }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/RemotingConfigurationValidatorTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/RemotingConfigurationValidatorTest.java	2008-06-20 11:40:31 UTC (rev 4533)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/RemotingConfigurationValidatorTest.java	2008-06-20 12:54:34 UTC (rev 4534)
@@ -43,6 +43,18 @@
    // Constructors --------------------------------------------------
 
    // Public --------------------------------------------------------
+   public void testNullonfigurationThrowsException()
+   {
+      try
+      {
+         validate(null);
+         fail("should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //pass
+      }
+   }
 
    public void testINVMConfiguration()
    {

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/RemotingServiceImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/RemotingServiceImplTest.java	2008-06-20 11:40:31 UTC (rev 4533)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/RemotingServiceImplTest.java	2008-06-20 12:54:34 UTC (rev 4534)
@@ -62,6 +62,7 @@
       EasyMock.verify(acceptor);
       assertEquals(1, remotingService.getAcceptors().size());
       assertEquals(config, remotingService.getConfiguration());
+      assertTrue(remotingService.isStarted());
    }
 
    public void testSingleAcceptorStartedTwiceIsIgnored() throws Exception
@@ -203,6 +204,38 @@
       EasyMock.verify(interceptor);
    }
 
+   public void testAddingNullListernerThrowsException() throws Exception
+   {
+      ConfigurationImpl config = new ConfigurationImpl();
+      config.setTransport(TransportType.INVM);
+      RemotingServiceImpl remotingService = new RemotingServiceImpl(config);
+      try
+      {
+         remotingService.addRemotingSessionListener(null);
+         fail("should throw exception");
+      }
+      catch (IllegalArgumentException e)
+      {
+         //pass
+      }
+   }
+
+   public void testRemovingNullInterceptorThrowsException() throws Exception
+   {
+      ConfigurationImpl config = new ConfigurationImpl();
+      config.setTransport(TransportType.INVM);
+      RemotingServiceImpl remotingService = new RemotingServiceImpl(config);
+      try
+      {
+         remotingService.removeRemotingSessionListener(null);
+         fail("should throw exception");
+      }
+      catch (IllegalArgumentException e)
+      {
+         //pass
+      }
+   }
+
    public void testMultipleInterceptorsAddedToDispatcher() throws Exception
    {
       ConfigurationImpl config = new ConfigurationImpl();
@@ -285,6 +318,7 @@
       {
          e.printStackTrace();
       }
+      assertTrue(remotingService.isSession(1l));
       remotingService.unregisterPinger(1l);
       assertTrue(dummySession.count > 10);
    }

Copied: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/ResponseHandlerImplTest.java (from rev 4531, trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/timing/ResponseHandlerImplTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/ResponseHandlerImplTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/ResponseHandlerImplTest.java	2008-06-20 12:54:34 UTC (rev 4534)
@@ -0,0 +1,122 @@
+/*
+ * 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.unit.core.remoting.impl;
+
+import junit.framework.TestCase;
+import org.jboss.messaging.core.remoting.Packet;
+import org.jboss.messaging.core.remoting.ResponseHandler;
+import org.jboss.messaging.core.remoting.impl.ResponseHandlerImpl;
+import org.jboss.messaging.core.remoting.impl.wireformat.Ping;
+import static org.jboss.messaging.tests.util.RandomUtil.randomLong;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executors;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ * 
+ */
+public class ResponseHandlerImplTest extends TestCase
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   protected static final long TIMEOUT = 500;
+
+
+   public void testReceiveResponseInTime() throws Exception
+   {
+      long id = randomLong();
+      final ResponseHandler handler = new ResponseHandlerImpl(id);
+
+      final AtomicReference<Packet> receivedPacket = new AtomicReference<Packet>();
+      final CountDownLatch latch = new CountDownLatch(1);
+
+      Executors.newSingleThreadExecutor().execute(new Runnable() {
+         public void run()
+         {
+            Packet response = handler.waitForResponse(TIMEOUT);
+            receivedPacket.set(response);
+            latch.countDown();
+         }         
+      });
+
+      Packet ping = new Ping(id);
+      handler.handle(ping, null);
+
+      boolean gotPacketBeforeTimeout = latch.await(TIMEOUT, MILLISECONDS);
+      assertTrue(gotPacketBeforeTimeout);
+      assertNotNull(receivedPacket.get());
+   }
+
+   public void testReceiveResponseTooLate() throws Exception
+   {
+      final ResponseHandler handler = new ResponseHandlerImpl(randomLong());
+      final AtomicReference<Packet> receivedPacket = new AtomicReference<Packet>();
+
+      Executors.newSingleThreadExecutor().execute(new Runnable() {
+
+         public void run()
+         {
+            Packet response = handler.waitForResponse(TIMEOUT);
+            receivedPacket.set(response);
+         }         
+      });
+      // pause for twice the timeout before handling the packet
+      Thread.sleep(TIMEOUT * 2);
+      handler.handle(new Ping(handler.getID()), null);
+
+      assertNull(receivedPacket.get());
+   }
+
+   public void testSetFailed() throws Exception
+   {
+      ResponseHandler handler = new ResponseHandlerImpl(randomLong());
+      handler.setFailed();
+      try {
+         handler.waitForResponse(TIMEOUT);
+         fail("should throw a IllegalStateException");
+      } catch (IllegalStateException e)
+      {
+      }
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}




More information about the jboss-cvs-commits mailing list