[jboss-cvs] JBoss Messaging SVN: r2228 - in branches/Branch_1_0_1_SP/tests/src/org/jboss/test: thirdparty/remoting and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 8 21:43:52 EST 2007


Author: ovidiu.feodorov at jboss.com
Date: 2007-02-08 21:43:52 -0500 (Thu, 08 Feb 2007)
New Revision: 2228

Added:
   branches/Branch_1_0_1_SP/tests/src/org/jboss/test/thirdparty/remoting/RemotingTest.java
   branches/Branch_1_0_1_SP/tests/src/org/jboss/test/thirdparty/remoting/TestClientInvoker.java
Removed:
   branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/util/RemotingTest.java
   branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/util/TestClientInvoker.java
Log:
moved extra Remoting tests under thirdparty.remoting, where they belong

Deleted: branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/util/RemotingTest.java
===================================================================
--- branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/util/RemotingTest.java	2007-02-09 02:30:39 UTC (rev 2227)
+++ branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/util/RemotingTest.java	2007-02-09 02:43:52 UTC (rev 2228)
@@ -1,494 +0,0 @@
-/*
-  * 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.test.messaging.util;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.Destination;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.management.MBeanServer;
-import javax.naming.InitialContext;
-
-import org.jboss.logging.Logger;
-import org.jboss.remoting.Client;
-import org.jboss.remoting.ConnectionListener;
-import org.jboss.remoting.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.ServerInvocationHandler;
-import org.jboss.remoting.ServerInvoker;
-import org.jboss.remoting.callback.InvokerCallbackHandler;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-import org.jboss.test.messaging.tools.jmx.ServiceContainer;
-
-import EDU.oswego.cs.dl.util.concurrent.Slot;
-
-/**
- * @author <a href="tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
- *
- * @version 1.1
- *
- * RemotingTest.java,v 1.1 2006/03/28 14:26:20 timfox Exp
- */
-public class RemotingTest extends MessagingTestCase
-{
-   // Constants -----------------------------------------------------
-
-   private static final Logger log = Logger.getLogger(RemotingTest.class);
-
-   // Static --------------------------------------------------------
-
-   // Attributes ----------------------------------------------------
-
-   InitialContext ic;
-   private boolean connListenerCalled;
-
-   // Constructors --------------------------------------------------
-
-   public RemotingTest(String name)
-   {
-      super(name);
-   }
-
-   // Public --------------------------------------------------------
-
-   public void testInvokerThreadSafety() throws Exception
-   {
-      Connector serverConnector = new Connector();
-
-      InvokerLocator serverLocator = new InvokerLocator("socket://localhost:9099");
-
-      serverConnector.setInvokerLocator(serverLocator.getLocatorURI());
-
-      serverConnector.create();
-
-      SimpleServerInvocationHandler invocationHandler = new SimpleServerInvocationHandler();
-
-      serverConnector.addInvocationHandler("JMS", invocationHandler);
-
-      serverConnector.start();
-
-      // Create n clients each firing requests in their own thread, using the same locator
-
-      try
-      {
-
-      final int NUM_CLIENTS = 3;
-
-      Thread[] threads = new Thread[NUM_CLIENTS];
-      Invoker[] invokers = new Invoker[NUM_CLIENTS];
-
-      Object obj = new Object();
-
-      for (int i = 0; i < NUM_CLIENTS; i++)
-      {
-         invokers[i] = new Invoker(serverLocator, obj);
-         threads[i] = new Thread(invokers[i]);
-         threads[i].start();
-      }
-
-      synchronized (obj)
-      {
-         obj.wait();
-      }
-
-      for (int i = 0; i < NUM_CLIENTS; i++)
-      {
-         if (invokers[i].failed)
-         {
-            fail();
-            for (int j = 0; j < NUM_CLIENTS; j++)
-            {
-               threads[j].interrupt();
-            }
-         }
-      }
-
-      for (int i = 0; i < NUM_CLIENTS; i++)
-      {
-         threads[i].join();
-      }
-
-      for (int i = 0; i < NUM_CLIENTS; i++)
-      {
-         if (invokers[i].failed)
-         {
-            fail();
-         }
-      }
-      }
-      finally
-      {
-         serverConnector.stop();
-         serverConnector.destroy();
-      }
-   }
-
-   /**
-    * TODO: Commented out until fixed. See http://jira.jboss.org/jira/browse/JBMESSAGING-287
-    */
-//   public void testConnectionListener() throws Throwable
-//   {
-//      // Start a server
-//
-//      Connector serverConnector = new Connector();
-//
-//      InvokerLocator serverLocator = new InvokerLocator("socket://localhost:9099");
-//
-//      serverConnector.setInvokerLocator(serverLocator.getLocatorURI());
-//
-//      serverConnector.create();
-//
-//      SimpleServerInvocationHandler invocationHandler = new SimpleServerInvocationHandler();
-//
-//      serverConnector.addInvocationHandler("JMS", invocationHandler);
-//
-//      serverConnector.setLeasePeriod(1000);
-//
-//      serverConnector.addConnectionListener(new SimpleConnectionListener());
-//
-//      serverConnector.start();
-//
-//      try
-//      {
-//         Client client = new Client(serverLocator);
-//
-//         client.connect();
-//
-//         Thread.sleep(5000);
-//
-//         client.disconnect();
-//
-//         // Connection Listener should now be called
-//
-//         Thread.sleep(5000);
-//
-//         assertTrue(connListenerCalled);
-//      }
-//      finally
-//      {
-//         serverConnector.stop();
-//         serverConnector.destroy();
-//      }
-//
-//   }
-
-   /**
-    * JIRA issue: http://jira.jboss.org/jira/browse/JBMESSAGING-371
-    */
-   public void testMessageListenerTimeout() throws Exception
-   {
-      ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-      Destination topic = (Destination)ic.lookup("/topic/ATopic");
-
-      Connection conn = cf.createConnection();
-      Slot slot = new Slot();
-
-      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-      MessageConsumer consumer = session.createConsumer(topic);
-      consumer.setMessageListener(new SimpleMessageListener(slot));
-
-      conn.start();
-
-      Connection conn2 = cf.createConnection();
-      Session session2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-      MessageProducer prod = session2.createProducer(topic);
-      Message m = session.createTextMessage("blah");
-
-      prod.send(m);
-
-      TextMessage rm = (TextMessage)slot.poll(5000);
-
-      assertEquals("blah", rm.getText());
-
-      // Only for JBoss Remoting > 2.0.0.Beta1
-      long sleepTime = ServerInvoker.DEFAULT_TIMEOUT_PERIOD + 60000;
-      log.info("sleeping " + (sleepTime / 60000) + " minutes");
-
-      Thread.sleep(sleepTime);
-
-      log.info("after sleep");
-
-      // send the second message. In case of remoting timeout, the callback server won't forward
-      // this message to the MessageCallbackHandler, and the test will fail
-
-      Message m2 = session.createTextMessage("blah2");
-      prod.send(m2);
-
-      TextMessage rm2 = (TextMessage)slot.poll(5000);
-
-      assertEquals("blah2", rm2.getText());
-
-      conn.close();
-      conn2.close();
-   }
-
-   /**
-    * See http://jira.jboss.org/jira/browse/JBMESSAGING-748.
-    *
-    * This test should always pass (we're not testing potential failure conditions), but it produces
-    * useful server-side logs.
-    */
-   public void testServerLockup() throws Throwable
-   {
-      // this test only makes sense in a remote configuration
-      if (!isRemote())
-      {
-         return;
-      }
-
-      // get the remote server locator
-
-      String s = (String)ServerManagement.
-         getAttribute(ServiceContainer.REMOTING_OBJECT_NAME, "InvokerLocator");
-
-      final InvokerLocator serverInvokerLocator = new InvokerLocator(s);
-
-      // open a socket but don't do anything else. This locks the server with a pre
-      // http://jira.jboss.org/jira/browse/JBMESSAGING-748 code base
-
-      new Thread(new Runnable()
-      {
-         public void run()
-         {
-            try
-            {
-               log.debug("rogue connection into the server");
-
-               TestClientInvoker rogueInvoker = new TestClientInvoker(serverInvokerLocator);
-
-               rogueInvoker.connect();
-               rogueInvoker.openConnectionButDontSendAnything();
-
-
-               log.debug("sleeping for 30 secs");
-
-               Thread.sleep(30000);
-
-               log.debug("woke up and exiting");
-            }
-            catch(Throwable t)
-            {
-               log.error("Failed to establish rogue connection", t);
-            }
-
-         }
-      }, "Rogue thread").start();
-
-
-      final Slot rendezVous = new Slot();
-
-      // create a second "real" connection and send an invocation from a different thread,
-      // simulating a real client trying to connect.
-
-      new Thread(new Runnable()
-      {
-         public void run()
-         {
-            try
-            {
-
-               Thread.sleep(5000);
-
-               log.debug("trying to connect to the server");
-
-               TestClientInvoker honestInvoker = new TestClientInvoker(serverInvokerLocator);
-
-               honestInvoker.connect();
-               honestInvoker.openConnectionAndSendJunk();
-
-               log.debug("sent junk");
-
-               rendezVous.put(Boolean.TRUE);
-            }
-            catch(Throwable t)
-            {
-               log.error("Failed to connect to server", t);
-            }
-
-         }
-      }, "Honest thread").start();
-
-
-      // wait for the honest invoker to finish its invocation
-      Boolean b = (Boolean)rendezVous.poll(10000);
-      assertNotNull(b);
-   }
-
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   protected void setUp() throws Exception
-   {
-      super.setUp();
-
-      ServerManagement.start("all");
-
-      ic = new InitialContext(ServerManagement.getJNDIEnvironment());
-
-      ServerManagement.deployTopic("ATopic");
-
-      log.debug("setup done");
-
-   }
-
-   protected void tearDown() throws Exception
-   {
-      ServerManagement.undeployTopic("ATopic");
-
-      ic.close();
-
-      super.tearDown();
-   }
-
-   // Private -------------------------------------------------------
-
-   // Inner classes -------------------------------------------------
-
-
-   class Invoker implements Runnable
-   {
-      boolean failed;
-      InvokerLocator locator;
-      Object o;
-      Invoker(InvokerLocator locator, Object o)
-      {
-         this.locator = locator;
-         this.o = o;
-      }
-      public void run()
-      {
-         try
-         {
-            for (int i = 0; i < 5000; i++)
-            {
-               Client cl = new Client(locator);
-               cl.connect();
-               cl.invoke("aardvark");
-               cl.disconnect();
-            }
-            synchronized (o)
-            {
-               o.notify();
-            }
-         }
-         catch (Throwable t)
-         {
-            failed = true;
-            log.error("Caught throwable", t);
-            synchronized (o)
-            {
-               o.notify();
-            }
-         }
-      }
-   }
-
-   class SimpleConnectionListener implements ConnectionListener
-   {
-      public void handleConnectionException(Throwable t, Client client)
-      {
-         connListenerCalled = true;
-      }
-   }
-
-   class SimpleServerInvocationHandler implements ServerInvocationHandler
-   {
-      InvokerCallbackHandler handler;
-
-
-      public void addListener(InvokerCallbackHandler callbackHandler)
-      {
-         this.handler = callbackHandler;
-
-      }
-
-      public Object invoke(InvocationRequest invocation) throws Throwable
-      {
-         //log.info("Received invocation:" + invocation);
-
-         return "Sausages";
-      }
-
-      public void removeListener(InvokerCallbackHandler callbackHandler)
-      {
-         // FIXME removeListener
-
-      }
-
-      public void setInvoker(ServerInvoker invoker)
-      {
-         // FIXME setInvoker
-
-      }
-
-      public void setMBeanServer(MBeanServer server)
-      {
-         // FIXME setMBeanServer
-
-      }
-   }
-
-
-   private class SimpleMessageListener implements MessageListener
-   {
-      private Slot slot;
-      private boolean failure;
-
-      public SimpleMessageListener(Slot slot)
-      {
-         this.slot = slot;
-         failure = false;
-     }
-
-      public void onMessage(Message m)
-      {
-         log.info("received " + m);
-         try
-         {
-            slot.put(m);
-         }
-         catch(Exception e)
-         {
-            log.error("failed to put message in slot", e);
-            failure = true;
-         }
-      }
-
-      public boolean isFailure()
-      {
-         return failure;
-      }
-   }
-
-}
-
-
-

Deleted: branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/util/TestClientInvoker.java
===================================================================
--- branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/util/TestClientInvoker.java	2007-02-09 02:30:39 UTC (rev 2227)
+++ branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/util/TestClientInvoker.java	2007-02-09 02:43:52 UTC (rev 2228)
@@ -1,80 +0,0 @@
-/**
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.test.messaging.util;
-
-import org.jboss.remoting.transport.socket.MicroSocketClientInvoker;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.logging.Logger;
-
-import java.net.Socket;
-import java.io.OutputStream;
-
-/**
- * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
- * @version <tt>$Revision: 1.1.2.1 $</tt>
- *
- * $Id: TestClientInvoker.java,v 1.1.2.1 2007/01/16 00:29:29 ovidiu Exp $
- */
-class TestClientInvoker extends MicroSocketClientInvoker
-{
-   // Constants ------------------------------------------------------------------------------------
-
-   private static final Logger log = Logger.getLogger(TestClientInvoker.class);
-
-   // Static ---------------------------------------------------------------------------------------
-
-   // Attributes -----------------------------------------------------------------------------------
-
-   // Constructors ---------------------------------------------------------------------------------
-
-   public TestClientInvoker(InvokerLocator locator)
-   {
-      super(locator);
-   }
-
-   // Public ---------------------------------------------------------------------------------------
-
-   public String toString()
-   {
-      return "TestClientInvoker[" + Integer.toHexString(hashCode()) + "]";
-   }
-
-   // Package protected ----------------------------------------------------------------------------
-
-   Socket openConnectionButDontSendAnything() throws Exception
-   {
-      log.debug(this + " creating simple socket");
-
-      Socket socket = new Socket(locator.getHost(), locator.getPort());
-
-      log.debug(this + " created socket " + socket);
-
-      return socket;
-   }
-
-   void openConnectionAndSendJunk() throws Exception
-   {
-      Socket socket = openConnectionButDontSendAnything();
-
-      OutputStream os = socket.getOutputStream();
-
-      os.write((byte)-1);
-
-      log.debug(this + " wrote junk on socket");
-
-//      os.flush();
-//
-//      log.debug(this + " flushed the stream");
-   }
-
-
-   // Protected ------------------------------------------------------------------------------------
-
-   // Private --------------------------------------------------------------------------------------
-
-   // Inner classes --------------------------------------------------------------------------------
-}

Added: branches/Branch_1_0_1_SP/tests/src/org/jboss/test/thirdparty/remoting/RemotingTest.java
===================================================================
--- branches/Branch_1_0_1_SP/tests/src/org/jboss/test/thirdparty/remoting/RemotingTest.java	                        (rev 0)
+++ branches/Branch_1_0_1_SP/tests/src/org/jboss/test/thirdparty/remoting/RemotingTest.java	2007-02-09 02:43:52 UTC (rev 2228)
@@ -0,0 +1,494 @@
+/*
+  * 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.test.thirdparty.remoting;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.management.MBeanServer;
+import javax.naming.InitialContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ConnectionListener;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.test.messaging.MessagingTestCase;
+import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.test.messaging.tools.jmx.ServiceContainer;
+
+import EDU.oswego.cs.dl.util.concurrent.Slot;
+
+/**
+ * @author <a href="tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ *
+ * @version 1.1
+ *
+ * RemotingTest.java,v 1.1 2006/03/28 14:26:20 timfox Exp
+ */
+public class RemotingTest extends MessagingTestCase
+{
+   // Constants -----------------------------------------------------
+
+   private static final Logger log = Logger.getLogger(RemotingTest.class);
+
+   // Static --------------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   InitialContext ic;
+   private boolean connListenerCalled;
+
+   // Constructors --------------------------------------------------
+
+   public RemotingTest(String name)
+   {
+      super(name);
+   }
+
+   // Public --------------------------------------------------------
+
+   public void testInvokerThreadSafety() throws Exception
+   {
+      Connector serverConnector = new Connector();
+
+      InvokerLocator serverLocator = new InvokerLocator("socket://localhost:9099");
+
+      serverConnector.setInvokerLocator(serverLocator.getLocatorURI());
+
+      serverConnector.create();
+
+      SimpleServerInvocationHandler invocationHandler = new SimpleServerInvocationHandler();
+
+      serverConnector.addInvocationHandler("JMS", invocationHandler);
+
+      serverConnector.start();
+
+      // Create n clients each firing requests in their own thread, using the same locator
+
+      try
+      {
+
+      final int NUM_CLIENTS = 3;
+
+      Thread[] threads = new Thread[NUM_CLIENTS];
+      Invoker[] invokers = new Invoker[NUM_CLIENTS];
+
+      Object obj = new Object();
+
+      for (int i = 0; i < NUM_CLIENTS; i++)
+      {
+         invokers[i] = new Invoker(serverLocator, obj);
+         threads[i] = new Thread(invokers[i]);
+         threads[i].start();
+      }
+
+      synchronized (obj)
+      {
+         obj.wait();
+      }
+
+      for (int i = 0; i < NUM_CLIENTS; i++)
+      {
+         if (invokers[i].failed)
+         {
+            fail();
+            for (int j = 0; j < NUM_CLIENTS; j++)
+            {
+               threads[j].interrupt();
+            }
+         }
+      }
+
+      for (int i = 0; i < NUM_CLIENTS; i++)
+      {
+         threads[i].join();
+      }
+
+      for (int i = 0; i < NUM_CLIENTS; i++)
+      {
+         if (invokers[i].failed)
+         {
+            fail();
+         }
+      }
+      }
+      finally
+      {
+         serverConnector.stop();
+         serverConnector.destroy();
+      }
+   }
+
+   /**
+    * TODO: Commented out until fixed. See http://jira.jboss.org/jira/browse/JBMESSAGING-287
+    */
+//   public void testConnectionListener() throws Throwable
+//   {
+//      // Start a server
+//
+//      Connector serverConnector = new Connector();
+//
+//      InvokerLocator serverLocator = new InvokerLocator("socket://localhost:9099");
+//
+//      serverConnector.setInvokerLocator(serverLocator.getLocatorURI());
+//
+//      serverConnector.create();
+//
+//      SimpleServerInvocationHandler invocationHandler = new SimpleServerInvocationHandler();
+//
+//      serverConnector.addInvocationHandler("JMS", invocationHandler);
+//
+//      serverConnector.setLeasePeriod(1000);
+//
+//      serverConnector.addConnectionListener(new SimpleConnectionListener());
+//
+//      serverConnector.start();
+//
+//      try
+//      {
+//         Client client = new Client(serverLocator);
+//
+//         client.connect();
+//
+//         Thread.sleep(5000);
+//
+//         client.disconnect();
+//
+//         // Connection Listener should now be called
+//
+//         Thread.sleep(5000);
+//
+//         assertTrue(connListenerCalled);
+//      }
+//      finally
+//      {
+//         serverConnector.stop();
+//         serverConnector.destroy();
+//      }
+//
+//   }
+
+   /**
+    * JIRA issue: http://jira.jboss.org/jira/browse/JBMESSAGING-371
+    */
+   public void testMessageListenerTimeout() throws Exception
+   {
+      ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
+      Destination topic = (Destination)ic.lookup("/topic/ATopic");
+
+      Connection conn = cf.createConnection();
+      Slot slot = new Slot();
+
+      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      MessageConsumer consumer = session.createConsumer(topic);
+      consumer.setMessageListener(new SimpleMessageListener(slot));
+
+      conn.start();
+
+      Connection conn2 = cf.createConnection();
+      Session session2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      MessageProducer prod = session2.createProducer(topic);
+      Message m = session.createTextMessage("blah");
+
+      prod.send(m);
+
+      TextMessage rm = (TextMessage)slot.poll(5000);
+
+      assertEquals("blah", rm.getText());
+
+      // Only for JBoss Remoting > 2.0.0.Beta1
+      long sleepTime = ServerInvoker.DEFAULT_TIMEOUT_PERIOD + 60000;
+      log.info("sleeping " + (sleepTime / 60000) + " minutes");
+
+      Thread.sleep(sleepTime);
+
+      log.info("after sleep");
+
+      // send the second message. In case of remoting timeout, the callback server won't forward
+      // this message to the MessageCallbackHandler, and the test will fail
+
+      Message m2 = session.createTextMessage("blah2");
+      prod.send(m2);
+
+      TextMessage rm2 = (TextMessage)slot.poll(5000);
+
+      assertEquals("blah2", rm2.getText());
+
+      conn.close();
+      conn2.close();
+   }
+
+   /**
+    * See http://jira.jboss.org/jira/browse/JBMESSAGING-748.
+    *
+    * This test should always pass (we're not testing potential failure conditions), but it produces
+    * useful server-side logs.
+    */
+   public void testServerLockup() throws Throwable
+   {
+      // this test only makes sense in a remote configuration
+      if (!isRemote())
+      {
+         return;
+      }
+
+      // get the remote server locator
+
+      String s = (String)ServerManagement.
+         getAttribute(ServiceContainer.REMOTING_OBJECT_NAME, "InvokerLocator");
+
+      final InvokerLocator serverInvokerLocator = new InvokerLocator(s);
+
+      // open a socket but don't do anything else. This locks the server with a pre
+      // http://jira.jboss.org/jira/browse/JBMESSAGING-748 code base
+
+      new Thread(new Runnable()
+      {
+         public void run()
+         {
+            try
+            {
+               log.debug("rogue connection into the server");
+
+               TestClientInvoker rogueInvoker = new TestClientInvoker(serverInvokerLocator);
+
+               rogueInvoker.connect();
+               rogueInvoker.openConnectionButDontSendAnything();
+
+
+               log.debug("sleeping for 30 secs");
+
+               Thread.sleep(30000);
+
+               log.debug("woke up and exiting");
+            }
+            catch(Throwable t)
+            {
+               log.error("Failed to establish rogue connection", t);
+            }
+
+         }
+      }, "Rogue thread").start();
+
+
+      final Slot rendezVous = new Slot();
+
+      // create a second "real" connection and send an invocation from a different thread,
+      // simulating a real client trying to connect.
+
+      new Thread(new Runnable()
+      {
+         public void run()
+         {
+            try
+            {
+
+               Thread.sleep(5000);
+
+               log.debug("trying to connect to the server");
+
+               TestClientInvoker honestInvoker = new TestClientInvoker(serverInvokerLocator);
+
+               honestInvoker.connect();
+               honestInvoker.openConnectionAndSendJunk();
+
+               log.debug("sent junk");
+
+               rendezVous.put(Boolean.TRUE);
+            }
+            catch(Throwable t)
+            {
+               log.error("Failed to connect to server", t);
+            }
+
+         }
+      }, "Honest thread").start();
+
+
+      // wait for the honest invoker to finish its invocation
+      Boolean b = (Boolean)rendezVous.poll(10000);
+      assertNotNull(b);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+
+      ServerManagement.start("all");
+
+      ic = new InitialContext(ServerManagement.getJNDIEnvironment());
+
+      ServerManagement.deployTopic("ATopic");
+
+      log.debug("setup done");
+
+   }
+
+   protected void tearDown() throws Exception
+   {
+      ServerManagement.undeployTopic("ATopic");
+
+      ic.close();
+
+      super.tearDown();
+   }
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+
+   class Invoker implements Runnable
+   {
+      boolean failed;
+      InvokerLocator locator;
+      Object o;
+      Invoker(InvokerLocator locator, Object o)
+      {
+         this.locator = locator;
+         this.o = o;
+      }
+      public void run()
+      {
+         try
+         {
+            for (int i = 0; i < 5000; i++)
+            {
+               Client cl = new Client(locator);
+               cl.connect();
+               cl.invoke("aardvark");
+               cl.disconnect();
+            }
+            synchronized (o)
+            {
+               o.notify();
+            }
+         }
+         catch (Throwable t)
+         {
+            failed = true;
+            log.error("Caught throwable", t);
+            synchronized (o)
+            {
+               o.notify();
+            }
+         }
+      }
+   }
+
+   class SimpleConnectionListener implements ConnectionListener
+   {
+      public void handleConnectionException(Throwable t, Client client)
+      {
+         connListenerCalled = true;
+      }
+   }
+
+   class SimpleServerInvocationHandler implements ServerInvocationHandler
+   {
+      InvokerCallbackHandler handler;
+
+
+      public void addListener(InvokerCallbackHandler callbackHandler)
+      {
+         this.handler = callbackHandler;
+
+      }
+
+      public Object invoke(InvocationRequest invocation) throws Throwable
+      {
+         //log.info("Received invocation:" + invocation);
+
+         return "Sausages";
+      }
+
+      public void removeListener(InvokerCallbackHandler callbackHandler)
+      {
+         // FIXME removeListener
+
+      }
+
+      public void setInvoker(ServerInvoker invoker)
+      {
+         // FIXME setInvoker
+
+      }
+
+      public void setMBeanServer(MBeanServer server)
+      {
+         // FIXME setMBeanServer
+
+      }
+   }
+
+
+   private class SimpleMessageListener implements MessageListener
+   {
+      private Slot slot;
+      private boolean failure;
+
+      public SimpleMessageListener(Slot slot)
+      {
+         this.slot = slot;
+         failure = false;
+     }
+
+      public void onMessage(Message m)
+      {
+         log.info("received " + m);
+         try
+         {
+            slot.put(m);
+         }
+         catch(Exception e)
+         {
+            log.error("failed to put message in slot", e);
+            failure = true;
+         }
+      }
+
+      public boolean isFailure()
+      {
+         return failure;
+      }
+   }
+
+}
+
+
+


Property changes on: branches/Branch_1_0_1_SP/tests/src/org/jboss/test/thirdparty/remoting/RemotingTest.java
___________________________________________________________________
Name: svn:executable
   + *

Added: branches/Branch_1_0_1_SP/tests/src/org/jboss/test/thirdparty/remoting/TestClientInvoker.java
===================================================================
--- branches/Branch_1_0_1_SP/tests/src/org/jboss/test/thirdparty/remoting/TestClientInvoker.java	                        (rev 0)
+++ branches/Branch_1_0_1_SP/tests/src/org/jboss/test/thirdparty/remoting/TestClientInvoker.java	2007-02-09 02:43:52 UTC (rev 2228)
@@ -0,0 +1,80 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.thirdparty.remoting;
+
+import org.jboss.remoting.transport.socket.MicroSocketClientInvoker;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.logging.Logger;
+
+import java.net.Socket;
+import java.io.OutputStream;
+
+/**
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @version <tt>$Revision: 1.1.2.1 $</tt>
+ *
+ * $Id: TestClientInvoker.java,v 1.1.2.1 2007/01/16 00:29:29 ovidiu Exp $
+ */
+class TestClientInvoker extends MicroSocketClientInvoker
+{
+   // Constants ------------------------------------------------------------------------------------
+
+   private static final Logger log = Logger.getLogger(TestClientInvoker.class);
+
+   // Static ---------------------------------------------------------------------------------------
+
+   // Attributes -----------------------------------------------------------------------------------
+
+   // Constructors ---------------------------------------------------------------------------------
+
+   public TestClientInvoker(InvokerLocator locator)
+   {
+      super(locator);
+   }
+
+   // Public ---------------------------------------------------------------------------------------
+
+   public String toString()
+   {
+      return "TestClientInvoker[" + Integer.toHexString(hashCode()) + "]";
+   }
+
+   // Package protected ----------------------------------------------------------------------------
+
+   Socket openConnectionButDontSendAnything() throws Exception
+   {
+      log.debug(this + " creating simple socket");
+
+      Socket socket = new Socket(locator.getHost(), locator.getPort());
+
+      log.debug(this + " created socket " + socket);
+
+      return socket;
+   }
+
+   void openConnectionAndSendJunk() throws Exception
+   {
+      Socket socket = openConnectionButDontSendAnything();
+
+      OutputStream os = socket.getOutputStream();
+
+      os.write((byte)-1);
+
+      log.debug(this + " wrote junk on socket");
+
+//      os.flush();
+//
+//      log.debug(this + " flushed the stream");
+   }
+
+
+   // Protected ------------------------------------------------------------------------------------
+
+   // Private --------------------------------------------------------------------------------------
+
+   // Inner classes --------------------------------------------------------------------------------
+}


Property changes on: branches/Branch_1_0_1_SP/tests/src/org/jboss/test/thirdparty/remoting/TestClientInvoker.java
___________________________________________________________________
Name: svn:executable
   + *




More information about the jboss-cvs-commits mailing list