[jboss-cvs] JBoss Messaging SVN: r2168 - in trunk: tests/src/org/jboss/test/messaging/tools/jmx and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Feb 3 15:24:57 EST 2007


Author: ovidiu.feodorov at jboss.com
Date: 2007-02-03 15:24:56 -0500 (Sat, 03 Feb 2007)
New Revision: 2168

Modified:
   trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java
   trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java
   trunk/tests/src/org/jboss/test/thirdparty/remoting/CallbackServerTimeoutTest.java
Log:
Made thirdparty.remoting.CallbackServerTimeoutTest pass for all transports.
The trick was to configure the connector to NOT use JMSWireFormat, as it
is not relevant for the test, and it doesn't accept free format invocations.
For that, I modularized configuration code on the client a little bit better.


Modified: trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java	2007-02-03 20:24:20 UTC (rev 2167)
+++ trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java	2007-02-03 20:24:56 UTC (rev 2168)
@@ -31,6 +31,7 @@
 import org.jboss.remoting.InvokerLocator;
 import org.jboss.remoting.ServerInvoker;
 import org.jboss.remoting.callback.CallbackPoller;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
 import org.jboss.remoting.transport.socket.MicroSocketClientInvoker;
 import org.jboss.remoting.transport.socket.SocketServerInvoker;
 
@@ -56,81 +57,38 @@
 
    // Static ---------------------------------------------------------------------------------------
 
-   // Attributes -----------------------------------------------------------------------------------
-
-   private Client client;
-   private boolean clientPing;
-   private InvokerLocator serverLocator;
-   private CallbackManager callbackManager;
-
-   // When a failover is performed, this flag is set to true
-   protected boolean failed = false;
-
-   // Maintaining a reference to the remoting connection listener for cases when we need to
-   // explicitly remove it from the remoting client
-   private ConsolidatedRemotingConnectionListener remotingConnectionListener;
-
-   // Constructors ---------------------------------------------------------------------------------
-
-   public JMSRemotingConnection(String serverLocatorURI, boolean clientPing) throws Throwable
+   /**
+    * Build the configuration we need to use to make sure a callback server works the way we want.
+    *
+    * @param doPushCallbacks - whether the callback should be push or pull. For socket transport
+    *        allow true push callbacks, with callback Connector. For http transport, simulate push
+    *        callbacks.
+    * @param metadata - metadata that should be added to the metadata map being created. Can be
+    *        null.
+    *
+    * @return a Map to be used when adding a listener to a client, thus enabling a callback server.
+    */
+   public static Map createCallbackMetadata(boolean doPushCallbacks, Map metadata,
+                                            InvokerLocator serverLocator)
    {
-      serverLocator = new InvokerLocator(serverLocatorURI);
-      this.clientPing = clientPing;
+      if (metadata == null)
+      {
+         metadata = new HashMap();
+      }
 
-      log.debug(this + " created");
-   }
-
-   // Public ---------------------------------------------------------------------------------------
-
-   public void start() throws Throwable
-   {
-      // Enable client pinging. Server leasing is enabled separately on the server side
-
-      Map config = new HashMap();
-      
-      config.put(Client.ENABLE_LEASE, String.valueOf(clientPing));
-
-      client = new Client(serverLocator, config);
-
-      client.setSubsystem(ServerPeer.REMOTING_JMS_SUBSYSTEM);
-
-      if (log.isTraceEnabled()) { log.trace(this + " created client"); }
-
-      callbackManager = new CallbackManager();
-      client.connect();
-
-      // We explicitly set the Marshaller since otherwise remoting tries to resolve the marshaller
-      // every time which is very slow - see org.jboss.remoting.transport.socket.ProcessInvocation
-      // This can make a massive difference on performance. We also do this in
-      // ServerConnectionEndpoint.setCallbackClient.
-
-      client.setMarshaller(new JMSWireFormat());
-      client.setUnMarshaller(new JMSWireFormat());
-      
-      HashMap metadata = new HashMap();
-      
       // Use our own direct thread pool that basically does nothing.
       // Note! This needs to be done irrespective of the transport and is used even for INVM
       //       invocations.
       metadata.put(ServerInvoker.ONEWAY_THREAD_POOL_CLASS_KEY,
                    "org.jboss.jms.server.remoting.DirectThreadPool");
 
-      // For socket transport allow true push callbacks, with callback Connector.
-      // For http transport, simulate push callbacks.
-      boolean doPushCallbacks = "socket".equals(serverLocator.getProtocol());
-
       if (doPushCallbacks)
       {
-         if (log.isTraceEnabled()) log.trace("doing push callbacks");
-
-         metadata.put(InvokerLocator.DATATYPE, "jms");
-         // Not actually used at present - but it does no harm
-         metadata.put(InvokerLocator.SERIALIZATIONTYPE, "jms");
          metadata.put(MicroSocketClientInvoker.CLIENT_SOCKET_CLASS_FLAG,
                       "org.jboss.jms.client.remoting.ClientSocketWrapper");
          metadata.put(SocketServerInvoker.SERVER_SOCKET_CLASS_FLAG,
-                      "org.jboss.jms.server.remoting.ServerSocketWrapper");         
-         
+                      "org.jboss.jms.server.remoting.ServerSocketWrapper");
+
          String bindAddress = System.getProperty("jboss.messaging.callback.bind.address");
          if (bindAddress != null)
          {
@@ -142,16 +100,13 @@
          {
             metadata.put(Client.CALLBACK_SERVER_PORT, propertyPort);
          }
-
-         client.addListener(callbackManager, metadata, null, true);
       }
       else
       {
-         if (log.isTraceEnabled()) log.trace("simulating push callbacks");
-
          // "jboss.messaging.callback.pollPeriod" system property, if set, has the
          // highest priority ...
          String callbackPollPeriod = System.getProperty("jboss.messaging.callback.pollPeriod");
+
          if (callbackPollPeriod == null)
          {
             // followed by the value configured on the HTTP connector ("callbackPollPeriod") ...
@@ -172,10 +127,102 @@
          {
             metadata.put(CallbackPoller.REPORT_STATISTICS, reportPollingStatistics);
          }
+      }
 
-         client.addListener(callbackManager, metadata);
+      return metadata;
+   }
+
+   /**
+    * Configures and add the invokerCallbackHandler the right way (push or pull).
+    *
+    * @param configurer - passed for logging purposes only.
+    * @param initialMetadata - some initial metadata that we might want to pass along when
+    *        registering invoker callback handler.
+    */
+   public static void addInvokerCallbackHandler(Object configurer,
+                                                Client client,
+                                                Map initialMetadata,
+                                                InvokerLocator serverLocator,
+                                                InvokerCallbackHandler invokerCallbackHandler)
+      throws Throwable
+   {
+
+      // For socket transport allow true push callbacks, with callback Connector.
+      // For http transport, simulate push callbacks.
+      boolean doPushCallbacks = "socket".equals(serverLocator.getProtocol());
+      Map metadata = createCallbackMetadata(doPushCallbacks, initialMetadata, serverLocator);
+
+      if (doPushCallbacks)
+      {
+         log.debug(configurer + " is doing push callbacks");
+         client.addListener(invokerCallbackHandler, metadata, null, true);
       }
+      else
+      {
+         log.debug(configurer + " is simulating push callbacks");
+         client.addListener(invokerCallbackHandler, metadata);
+      }
+   }
 
+   // Attributes -----------------------------------------------------------------------------------
+
+   private Client client;
+   private boolean clientPing;
+   private InvokerLocator serverLocator;
+   private CallbackManager callbackManager;
+
+   // When a failover is performed, this flag is set to true
+   protected boolean failed = false;
+
+   // Maintaining a reference to the remoting connection listener for cases when we need to
+   // explicitly remove it from the remoting client
+   private ConsolidatedRemotingConnectionListener remotingConnectionListener;
+
+   // Constructors ---------------------------------------------------------------------------------
+
+   public JMSRemotingConnection(String serverLocatorURI, boolean clientPing) throws Throwable
+   {
+      serverLocator = new InvokerLocator(serverLocatorURI);
+      this.clientPing = clientPing;
+
+      log.debug(this + " created");
+   }
+
+   // Public ---------------------------------------------------------------------------------------
+
+   public void start() throws Throwable
+   {
+      // Enable client pinging. Server leasing is enabled separately on the server side.
+
+      Map config = new HashMap();
+      
+      config.put(Client.ENABLE_LEASE, String.valueOf(clientPing));
+
+      client = new Client(serverLocator, config);
+
+      client.setSubsystem(ServerPeer.REMOTING_JMS_SUBSYSTEM);
+
+      if (log.isTraceEnabled()) { log.trace(this + " created client"); }
+
+      callbackManager = new CallbackManager();
+      client.connect();
+
+      // We explicitly set the Marshaller since otherwise remoting tries to resolve the marshaller
+      // every time which is very slow - see org.jboss.remoting.transport.socket.ProcessInvocation
+      // This can make a massive difference on performance. We also do this in
+      // ServerConnectionEndpoint.setCallbackClient.
+
+      client.setMarshaller(new JMSWireFormat());
+      client.setUnMarshaller(new JMSWireFormat());
+
+      Map metadata = new HashMap();
+
+      metadata.put(InvokerLocator.DATATYPE, "jms");
+      // Not actually used at present - but it does no harm
+      metadata.put(InvokerLocator.SERIALIZATIONTYPE, "jms");
+
+      addInvokerCallbackHandler(this, client, metadata, serverLocator, callbackManager);
+      
       log.debug(this + " started");
    }
 

Modified: trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java	2007-02-03 20:24:20 UTC (rev 2167)
+++ trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java	2007-02-03 20:24:56 UTC (rev 2168)
@@ -109,6 +109,8 @@
 
    private static final String CONFIGURATION_FILE_NAME = "container.xml";
 
+   public static final String DO_NOT_USE_MESSAGING_MARSHALLERS = "DO_NOT_USE_MESSAGING_MARSHALLERS";
+
    // Static ---------------------------------------------------------------------------------------
 
    public static ObjectName SERVICE_CONTROLLER_OBJECT_NAME;
@@ -1265,14 +1267,15 @@
 
       // some tests may want specific locator URI overrides to simulate special conditions; use
       // that with priority, if available
+      Map overrideMap = null;
 
       if (attrOverrides != null)
       {
-         Map m = attrOverrides.get(REMOTING_OBJECT_NAME);
+         overrideMap = attrOverrides.get(REMOTING_OBJECT_NAME);
 
-         if (m != null)
+         if (overrideMap != null)
          {
-            locatorURI = (String)m.get("LocatorURI");
+            locatorURI = (String)overrideMap.get("LocatorURI");
          }
       }
 
@@ -1291,10 +1294,26 @@
 
          long clientLeasePeriod = 20000;
 
-         String params = "/?marshaller=org.jboss.jms.server.remoting.JMSWireFormat&" +
-            "unmarshaller=org.jboss.jms.server.remoting.JMSWireFormat&" +
+         String marshallers =
+            "marshaller=org.jboss.jms.server.remoting.JMSWireFormat&" +
+            "unmarshaller=org.jboss.jms.server.remoting.JMSWireFormat&";
+         String dataType = "dataType=jms&";
+
+         // We use this from thirdparty remoting tests when we don't want to send stuff through
+         // JMSWireFormat, but we want everything else in the connector's configuration to be
+         // identical with what we use in Messaging
+         if (overrideMap != null && overrideMap.get(DO_NOT_USE_MESSAGING_MARSHALLERS) != null)
+         {
+            marshallers = "";
+            dataType = "";
+            serializationType = "java";
+         }
+
+         String params =
+            "/?" +
+            marshallers +
             "serializationtype=" + serializationType + "&" +
-            "dataType=jms&" +
+            dataType +
             "socket.check_connection=false&" +
             "clientLeasePeriod=" + clientLeasePeriod + "&" +
             "callbackStore=org.jboss.remoting.callback.BlockingCallbackStore&" +

Modified: trunk/tests/src/org/jboss/test/thirdparty/remoting/CallbackServerTimeoutTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/thirdparty/remoting/CallbackServerTimeoutTest.java	2007-02-03 20:24:20 UTC (rev 2167)
+++ trunk/tests/src/org/jboss/test/thirdparty/remoting/CallbackServerTimeoutTest.java	2007-02-03 20:24:56 UTC (rev 2168)
@@ -9,6 +9,7 @@
 import org.jboss.test.messaging.MessagingTestCase;
 import org.jboss.test.messaging.tools.ServerManagement;
 import org.jboss.test.messaging.tools.jmx.ServiceContainer;
+import org.jboss.test.messaging.tools.jmx.ServiceAttributeOverrides;
 import org.jboss.test.thirdparty.remoting.util.RemotingTestSubsystemService;
 import org.jboss.test.thirdparty.remoting.util.OnewayCallbackTrigger;
 import org.jboss.logging.Logger;
@@ -18,6 +19,7 @@
 import org.jboss.remoting.callback.Callback;
 import org.jboss.remoting.callback.InvokerCallbackHandler;
 import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.jms.client.remoting.JMSRemotingConnection;
 
 import javax.management.ObjectName;
 
@@ -29,7 +31,7 @@
  * http://jira.jboss.org/jira/browse/JBMESSAGING-371. The callback server seems to timeout never
  * to be heard from it again.
  *
- * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @author <a href="mailto:ovidiu at svjboss.org">Ovidiu Feodorov</a>
  *
  * @version <tt>$Revision$</tt>
  *
@@ -77,7 +79,8 @@
 
          client.connect();
 
-         client.addListener(callbackHandler, null, null, true);
+         JMSRemotingConnection.
+            addInvokerCallbackHandler("test", client, null, serverLocator, callbackHandler);
 
          client.invoke(new OnewayCallbackTrigger("blip"));
 
@@ -138,7 +141,8 @@
 
          client.connect();
 
-         client.addListener(callbackHandler, null, null, true);
+         JMSRemotingConnection.
+            addInvokerCallbackHandler("test", client, null, serverLocator, callbackHandler);
 
          log.info("added listener");
 
@@ -189,8 +193,14 @@
    {
       super.setUp();
 
-      ServerManagement.start(0, "remoting", null, true, false);
+      // start a "standard" (messaging-enabled) remoting, we need to strip off the
+      // marshaller/unmarshaller, though, since it can only bring trouble to this test ...
+      ServiceAttributeOverrides sao = new ServiceAttributeOverrides();
+      sao.put(ServiceContainer.REMOTING_OBJECT_NAME,
+              ServiceContainer.DO_NOT_USE_MESSAGING_MARSHALLERS, Boolean.TRUE);
 
+      ServerManagement.start(0, "remoting", sao, true, false);
+
       String s = (String)ServerManagement.
          getAttribute(ServiceContainer.REMOTING_OBJECT_NAME, "InvokerLocator");
 




More information about the jboss-cvs-commits mailing list