[jboss-cvs] JBoss Messaging SVN: r1615 - branches/Branch_HTTP_Experiment/tests/src/org/jboss/test/messaging/jms
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Nov 21 20:57:34 EST 2006
Author: ron_sigal
Date: 2006-11-21 20:57:33 -0500 (Tue, 21 Nov 2006)
New Revision: 1615
Added:
branches/Branch_HTTP_Experiment/tests/src/org/jboss/test/messaging/jms/RemotingConnectionConfigurationTest.java
Log:
JBMessaging-207: Unit test for Remoting configuration in JMSRemotingConnection.
Added: branches/Branch_HTTP_Experiment/tests/src/org/jboss/test/messaging/jms/RemotingConnectionConfigurationTest.java
===================================================================
--- branches/Branch_HTTP_Experiment/tests/src/org/jboss/test/messaging/jms/RemotingConnectionConfigurationTest.java 2006-11-22 01:09:46 UTC (rev 1614)
+++ branches/Branch_HTTP_Experiment/tests/src/org/jboss/test/messaging/jms/RemotingConnectionConfigurationTest.java 2006-11-22 01:57:33 UTC (rev 1615)
@@ -0,0 +1,149 @@
+/*
+ * 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.jms;
+
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.util.Map;
+
+import javax.jms.ConnectionFactory;
+import javax.naming.InitialContext;
+
+import org.jboss.jms.client.JBossConnection;
+import org.jboss.jms.client.delegate.ClientConnectionDelegate;
+import org.jboss.jms.client.remoting.JMSRemotingConnection;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.callback.CallbackPoller;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.test.messaging.MessagingTestCase;
+import org.jboss.test.messaging.tools.ServerManagement;
+
+/**
+ *
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Nov 21, 2006
+ * </p>
+ */
+public class RemotingConnectionConfigurationTest extends MessagingTestCase
+{
+ // Constants -----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ protected ConnectionFactory cf;
+
+ // Constructors --------------------------------------------------
+
+ public RemotingConnectionConfigurationTest(String name)
+ {
+ super(name);
+ }
+
+ // TestCase overrides -------------------------------------------
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ ServerManagement.start("all");
+ InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment());
+ cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
+ log.debug("setup done");
+ }
+
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+
+ // Public --------------------------------------------------------
+
+ public void testConnectionConfiguration() throws Exception
+ {
+ log.info("entering " + getName());
+
+ JBossConnection connection = null;
+
+ try
+ {
+ if (!ServerManagement.isRemote()) return;
+
+ int freePort = PortUtil.findFreePort(InetAddress.getLocalHost().getHostName());
+ System.setProperty("jboss.messaging.callback.bind.port", Integer.toString(freePort));
+ String pollPeriod = "654";
+ System.setProperty("jboss.messaging.callback.callbackPollPeriod", pollPeriod);
+
+ connection = (JBossConnection) cf.createConnection();
+ connection.start();
+ ClientConnectionDelegate delegate = (ClientConnectionDelegate) connection.getDelegate();
+ JMSRemotingConnection remotingConnection = delegate.getRemotingConnection();
+ Client client = remotingConnection.getInvokingClient();
+ Field field = JMSRemotingConnection.class.getDeclaredField("serverLocator");
+ field.setAccessible(true);
+ InvokerLocator locator = (InvokerLocator) field.get(remotingConnection);
+ String transport = locator.getProtocol();
+
+ if ("socket".equals(transport))
+ {
+ field = Client.class.getDeclaredField("callbackConnectors");
+ field.setAccessible(true);
+ Map callbackConnectors = (Map) field.get(client);
+ InvokerCallbackHandler callbackHandler = remotingConnection.getCallbackManager();
+ Connector connector = (Connector) callbackConnectors.get(callbackHandler);
+ locator = new InvokerLocator(connector.getInvokerLocator());
+ assertEquals(freePort, locator.getPort());
+ }
+ else if ("http".equals(transport))
+ {
+ field = Client.class.getDeclaredField("callbackPollers");
+ field.setAccessible(true);
+ CallbackPoller callbackPoller = (CallbackPoller) field.get(client);
+ field = CallbackPoller.class.getDeclaredField("pollPeriod");
+ field.setAccessible(true);
+ assertEquals(((Integer) field.get(callbackPoller)).intValue(), Integer.parseInt(pollPeriod));
+ }
+ else
+ {
+ log.error("Unrecognized transport: " + transport);
+ fail();
+ }
+ }
+ catch (Exception e)
+ {
+ log.error(e);
+ log.error(getName() + " FAILS");
+ }
+ finally
+ {
+ log.trace("closing connections ...");
+ if (connection != null) connection.close();
+ log.info(getName() + " PASSES");
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list