Package org.jboss.test.messaging.jms.clustering

Source Code of org.jboss.test.messaging.jms.clustering.ClusteredConnectionFactoryTest

/*
   * 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.clustering;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.management.ObjectName;

import org.jboss.jms.client.JBossConnection;
import org.jboss.jms.client.JBossConnectionFactory;
import org.jboss.jms.client.delegate.ClientClusteredConnectionFactoryDelegate;
import org.jboss.jms.client.delegate.ClientConnectionDelegate;
import org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate;
import org.jboss.jms.client.state.ConnectionState;
import org.jboss.jms.exception.MessagingNetworkFailureException;
import org.jboss.test.messaging.tools.ServerManagement;
import org.jboss.test.messaging.tools.aop.PoisonInterceptor;
import org.jboss.test.messaging.tools.container.ServiceAttributeOverrides;
import org.jboss.test.messaging.tools.container.ServiceContainer;

/**
* @author <a href="mailto:clebert.suconic@jboss.org">Clebert Suconic</a>
* @version <tt>$Revision: 8356 $</tt>
*          $Id: ClusteredConnectionFactoryTest.java 8356 2011-06-21 02:45:54Z gaohoward $
*/
public class ClusteredConnectionFactoryTest extends ClusteringTestBase
{

   // Constants ------------------------------------------------------------------------------------

   // Attributes -----------------------------------------------------------------------------------

   // Static ---------------------------------------------------------------------------------------

   // Constructors ---------------------------------------------------------------------------------

   public ClusteredConnectionFactoryTest(String name)
   {
      super(name);
   }

   // Public ---------------------------------------------------------------------------------------

  
   protected void setUp() throws Exception
   {
     nodeCount = 2;
    
     super.setUp();
   }
  
   public void testGetAOPBroken() throws Exception
   {     
      ServerManagement.kill(1);
      ServerManagement.kill(0);

      try
      {
         assertNotNull(((JBossConnectionFactory)cf).getDelegate().getClientAOPStack());
         fail("This should throw an exception as every server is down");
      }
      catch (MessagingNetworkFailureException e)
      {
         log.trace(e.toString(), e);
      }
   }
  
   public void testLoadAOP() throws Exception
   {
      Connection conn = null;

      try
      {
         ServerManagement.kill(1);
        
         assertNotNull(((JBossConnectionFactory)cf).getDelegate().getClientAOPStack());

         conn = cf.createConnection();
         assertEquals(0, getServerId(conn));
      }
      finally
      {
         if (conn != null)
         {
            try
            {
               conn.close();
            }
            catch (Exception ignored)
            {
            }
         }
      }
   }
     
   public void testCreateConnectionOnBrokenServer() throws Exception
   {
      Connection conn = null;

      try
      {
         conn = createConnectionOnServer(cf, 0);
         conn.close();
         conn = null;
        
         ServerManagement.kill(1);
        
         conn = cf.createConnection();
        
         assertEquals(0, getServerId(conn));
        
         conn.close();
        
         conn = cf.createConnection();
        
         assertEquals(0, getServerId(conn));
        
         conn.close();
      }
      finally
      {
         if (conn != null)
         {
            conn.close();
         }
      }
   }

   public void testPoisonCFs() throws Exception
   {
      Connection conn = null;

      try
      {
         conn = createConnectionOnServer(cf, 0);
         conn.close();
        
         // Poison the server
         ServerManagement.poisonTheServer(1, PoisonInterceptor.CF_CREATE_CONNECTION);

         // this should break on server1
         conn = cf.createConnection();
        
         assertEquals(0, getServerId(conn));
        
         conn.close();
        
         conn = cf.createConnection();
        
         assertEquals(0, getServerId(conn));
        
         conn.close();
      }
      finally
      {
         if (conn != null)
         {
            conn.close();
         }
      }
   }

   public void testRestartServer() throws Exception
   {
      JBossConnectionFactory cf2 = (JBossConnectionFactory) ic[1].lookup("/ConnectionFactory");

      ClientClusteredConnectionFactoryDelegate clusterCF = (ClientClusteredConnectionFactoryDelegate)cf.getDelegate();
      ClientConnectionFactoryDelegate delegates[] = clusterCF.getDelegates();
      clusterCF.closeCallback(false);

      ServerManagement.kill(1);

      //Restart the server on the same place
      ServiceAttributeOverrides attr = new ServiceAttributeOverrides();
      attr.put(ServiceContainer.REMOTING_OBJECT_NAME, "LocatorURI",delegates[1].getServerLocatorURI());
      ServerManagement.start(1,config,attr,false);

      // The server back on the same remoting port as before
      startDefaultServer(1, attr, false);

      Connection conn = null;
      try
      {
         conn = cf2.createConnection();
      }
      finally
      {
         try
         {
            if (conn != null)
            {
               conn.close();
            }
         }
         catch (Throwable ignored)
         {
         }

         // The next test will fail If I don't kill the server started here on this test
         ServerManagement.kill(1);
      }
     
   }

   //https://issues.jboss.org/browse/JBMESSAGING-1851
   public void testChangeRateConfigSettings() throws Exception
   {
      Connection c = null;

      try
      {
         String mbeanConfig = "<mbean code=\"org.jboss.jms.server.connectionfactory.ConnectionFactory\"\n" + "       name=\"jboss.messaging.connectionfactory:service=TestChangeRateConfigSettingsFactory\"\n"
                              + "       xmbean-dd=\"xmdesc/ConnectionFactory-xmbean.xml\">\n"
                              + "       <depends optional-attribute-name=\"ServerPeer\">jboss.messaging:service=ServerPeer</depends>\n"
                              + "       <depends optional-attribute-name=\"Connector\">jboss.messaging:service=Connector,transport=bisocket</depends>\n"
                              + "       <attribute name=\"JNDIBindings\">\n"
                              + "          <bindings>\n"
                              + "            <binding>/ClusteredTestChangeRateConfigSettingsFactory</binding>\n"
                              + "          </bindings>\n"
                              + "       </attribute>\n"
                              + "       <attribute name=\"SupportsFailover\">true</attribute>"
                              + "       <attribute name=\"SupportsLoadBalancing\">true</attribute>"
                              + "       <attribute name=\"MaxRetryChangeRate\">10</attribute>\n"
                              + "       <attribute name=\"RetryChangeRateInterval\">2345</attribute>\n"
                              + " </mbean>";

         ObjectName on = ServerManagement.deploy(mbeanConfig);
         ServerManagement.invoke(on, "create", new Object[0], new String[0]);
         ServerManagement.invoke(on, "start", new Object[0], new String[0]);

         ConnectionFactory cf = (ConnectionFactory)ic[0].lookup("/ClusteredTestChangeRateConfigSettingsFactory");
         c = cf.createConnection();
        
         ClientConnectionDelegate del1 = (ClientConnectionDelegate)((JBossConnection)c).getDelegate();
        
         ConnectionState state1 = (ConnectionState)del1.getState();
        
         long maxRetry = state1.getMaxRetryChangeRate();
        
         assertEquals(10, maxRetry);
        
         long retryInterval = state1.getRetryChangeRateInterval();
        
         assertEquals(2345, retryInterval);
      }
      finally
      {
         try
         {
            if (c != null)
            {
               log.info("Closing connection");
               c.close();
               log.info("Closed connection");
            }
         }
         catch (Exception e)
         {
            log.warn(e.toString(), e);
         }
      }
   }

   //https://issues.jboss.org/browse/JBMESSAGING-1851
   public void testChangeRateConfigSettings2() throws Exception
   {
      Connection c = null;

      try
      {
         String mbeanConfig = "<mbean code=\"org.jboss.jms.server.connectionfactory.ConnectionFactory\"\n" + "       name=\"jboss.messaging.connectionfactory:service=TestChangeRateConfigSettingsFactory\"\n"
                              + "       xmbean-dd=\"xmdesc/ConnectionFactory-xmbean.xml\">\n"
                              + "       <depends optional-attribute-name=\"ServerPeer\">jboss.messaging:service=ServerPeer</depends>\n"
                              + "       <depends optional-attribute-name=\"Connector\">jboss.messaging:service=Connector,transport=bisocket</depends>\n"
                              + "       <attribute name=\"JNDIBindings\">\n"
                              + "          <bindings>\n"
                              + "            <binding>/ClusteredTestChangeRateConfigSettingsFactory</binding>\n"
                              + "          </bindings>\n"
                              + "       </attribute>\n"
                              + "       <attribute name=\"SupportsFailover\">false</attribute>"
                              + "       <attribute name=\"SupportsLoadBalancing\">true</attribute>"
                              + "       <attribute name=\"MaxRetryChangeRate\">10</attribute>\n"
                              + "       <attribute name=\"RetryChangeRateInterval\">2345</attribute>\n"
                              + " </mbean>";

         ObjectName on = ServerManagement.deploy(mbeanConfig);
         ServerManagement.invoke(on, "create", new Object[0], new String[0]);
         ServerManagement.invoke(on, "start", new Object[0], new String[0]);

         ConnectionFactory cf = (ConnectionFactory)ic[0].lookup("/ClusteredTestChangeRateConfigSettingsFactory");
         c = cf.createConnection();
        
         ClientConnectionDelegate del1 = (ClientConnectionDelegate)((JBossConnection)c).getDelegate();
        
         ConnectionState state1 = (ConnectionState)del1.getState();
        
         long maxRetry = state1.getMaxRetryChangeRate();
        
         assertEquals(10, maxRetry);
        
         long retryInterval = state1.getRetryChangeRateInterval();
        
         assertEquals(2345, retryInterval);
      }
      finally
      {
         try
         {
            if (c != null)
            {
               log.info("Closing connection");
               c.close();
               log.info("Closed connection");
            }
         }
         catch (Exception e)
         {
            log.warn(e.toString(), e);
         }
      }
   }

   //https://issues.jboss.org/browse/JBMESSAGING-1851
   public void testChangeRateConfigDefaults() throws Exception
   {
      Connection c = null;

      try
      {
         String mbeanConfig = "<mbean code=\"org.jboss.jms.server.connectionfactory.ConnectionFactory\"\n" + "       name=\"jboss.messaging.connectionfactory:service=TestChangeRateConfigDefaultsFactory\"\n"
                              + "       xmbean-dd=\"xmdesc/ConnectionFactory-xmbean.xml\">\n"
                              + "       <depends optional-attribute-name=\"ServerPeer\">jboss.messaging:service=ServerPeer</depends>\n"
                              + "       <depends optional-attribute-name=\"Connector\">jboss.messaging:service=Connector,transport=bisocket</depends>\n"
                              + "       <attribute name=\"JNDIBindings\">\n"
                              + "          <bindings>\n"
                              + "            <binding>/ClusteredTestChangeRateConfigDefaultsFactory</binding>\n"
                              + "          </bindings>\n"
                              + "       </attribute>\n"
                              + "       <attribute name=\"SupportsFailover\">true</attribute>"
                              + "       <attribute name=\"SupportsLoadBalancing\">true</attribute>"
                              + " </mbean>";

         ObjectName on = ServerManagement.deploy(mbeanConfig);
         ServerManagement.invoke(on, "create", new Object[0], new String[0]);
         ServerManagement.invoke(on, "start", new Object[0], new String[0]);

         ConnectionFactory cf = (ConnectionFactory)ic[0].lookup("/ClusteredTestChangeRateConfigDefaultsFactory");
         c = cf.createConnection();
        
         ClientConnectionDelegate del1 = (ClientConnectionDelegate)((JBossConnection)c).getDelegate();
        
         ConnectionState state1 = (ConnectionState)del1.getState();
        
         long maxRetry = state1.getMaxRetryChangeRate();
        
         assertEquals(0, maxRetry);
        
         long retryInterval = state1.getRetryChangeRateInterval();
        
         assertEquals(5000, retryInterval);
      }
      finally
      {
         try
         {
            if (c != null)
            {
               log.info("Closing connection");
               c.close();
               log.info("Closed connection");
            }
         }
         catch (Exception e)
         {
            log.warn(e.toString(), e);
         }
      }
   }

   //JBMESSAGING-1876
   public void testMinTimeoutProcessTimeSettings() throws Exception
   {
      Connection c = null;

      try
      {
         String mbeanConfig = "<mbean code=\"org.jboss.jms.server.connectionfactory.ConnectionFactory\"\n" + "       name=\"jboss.messaging.connectionfactory:service=TestChangeRateConfigSettingsFactory\"\n"
                              + "       xmbean-dd=\"xmdesc/ConnectionFactory-xmbean.xml\">\n"
                              + "       <depends optional-attribute-name=\"ServerPeer\">jboss.messaging:service=ServerPeer</depends>\n"
                              + "       <depends optional-attribute-name=\"Connector\">jboss.messaging:service=Connector,transport=bisocket</depends>\n"
                              + "       <attribute name=\"JNDIBindings\">\n"
                              + "          <bindings>\n"
                              + "            <binding>/ClusteredTestMinTimeoutProcessTimeConfigSettingsFactory</binding>\n"
                              + "          </bindings>\n"
                              + "       </attribute>\n"
                              + "       <attribute name=\"SupportsFailover\">true</attribute>"
                              + "       <attribute name=\"SupportsLoadBalancing\">true</attribute>"
                              + "       <attribute name=\"MinTimeoutProcessTime\">100</attribute>\n"
                              + " </mbean>";

         ObjectName on = ServerManagement.deploy(mbeanConfig);
         ServerManagement.invoke(on, "create", new Object[0], new String[0]);
         ServerManagement.invoke(on, "start", new Object[0], new String[0]);

         ConnectionFactory cf = (ConnectionFactory)ic[0].lookup("/ClusteredTestMinTimeoutProcessTimeConfigSettingsFactory");
         c = cf.createConnection();
        
         ClientConnectionDelegate del1 = (ClientConnectionDelegate)((JBossConnection)c).getDelegate();
        
         ConnectionState state1 = (ConnectionState)del1.getState();
        
         long minTime = state1.getMinTimeoutProcessTime();
        
         assertEquals(100, minTime);
      }
      finally
      {
         try
         {
            if (c != null)
            {
               log.info("Closing connection");
               c.close();
               log.info("Closed connection");
            }
         }
         catch (Exception e)
         {
            log.warn(e.toString(), e);
         }
      }
   }

   //https://issues.jboss.org/browse/JBMESSAGING-1876
   public void testMinTimeoutProcessTimeSettings2() throws Exception
   {
      Connection c = null;

      try
      {
         String mbeanConfig = "<mbean code=\"org.jboss.jms.server.connectionfactory.ConnectionFactory\"\n" + "       name=\"jboss.messaging.connectionfactory:service=TestChangeRateConfigSettingsFactory\"\n"
                              + "       xmbean-dd=\"xmdesc/ConnectionFactory-xmbean.xml\">\n"
                              + "       <depends optional-attribute-name=\"ServerPeer\">jboss.messaging:service=ServerPeer</depends>\n"
                              + "       <depends optional-attribute-name=\"Connector\">jboss.messaging:service=Connector,transport=bisocket</depends>\n"
                              + "       <attribute name=\"JNDIBindings\">\n"
                              + "          <bindings>\n"
                              + "            <binding>/ClusteredTestMinTimeoutProcessTimeConfigSettingsFactory</binding>\n"
                              + "          </bindings>\n"
                              + "       </attribute>\n"
                              + "       <attribute name=\"SupportsFailover\">false</attribute>"
                              + "       <attribute name=\"SupportsLoadBalancing\">true</attribute>"
                              + "       <attribute name=\"MinTimeoutProcessTime\">100</attribute>\n"
                              + "       <attribute name=\"MaxRetryChangeRate\">10</attribute>\n"
                              + "       <attribute name=\"RetryChangeRateInterval\">2345</attribute>\n"
                              + " </mbean>";

         ObjectName on = ServerManagement.deploy(mbeanConfig);
         ServerManagement.invoke(on, "create", new Object[0], new String[0]);
         ServerManagement.invoke(on, "start", new Object[0], new String[0]);

         ConnectionFactory cf = (ConnectionFactory)ic[0].lookup("/ClusteredTestMinTimeoutProcessTimeConfigSettingsFactory");
         c = cf.createConnection();
        
         ClientConnectionDelegate del1 = (ClientConnectionDelegate)((JBossConnection)c).getDelegate();
        
         ConnectionState state1 = (ConnectionState)del1.getState();
        
         long minTime = state1.getMinTimeoutProcessTime();
        
         assertEquals(100, minTime);
      }
      finally
      {
         try
         {
            if (c != null)
            {
               log.info("Closing connection");
               c.close();
               log.info("Closed connection");
            }
         }
         catch (Exception e)
         {
            log.warn(e.toString(), e);
         }
      }
   }

   //https://issues.jboss.org/browse/JBMESSAGING-1876
   public void testMinTimeoutProcessTimeDefaults() throws Exception
   {
      Connection c = null;

      try
      {
         String mbeanConfig = "<mbean code=\"org.jboss.jms.server.connectionfactory.ConnectionFactory\"\n" + "       name=\"jboss.messaging.connectionfactory:service=TestChangeRateConfigDefaultsFactory\"\n"
                              + "       xmbean-dd=\"xmdesc/ConnectionFactory-xmbean.xml\">\n"
                              + "       <depends optional-attribute-name=\"ServerPeer\">jboss.messaging:service=ServerPeer</depends>\n"
                              + "       <depends optional-attribute-name=\"Connector\">jboss.messaging:service=Connector,transport=bisocket</depends>\n"
                              + "       <attribute name=\"JNDIBindings\">\n"
                              + "          <bindings>\n"
                              + "            <binding>/ClusteredTestChangeRateConfigDefaultsFactory</binding>\n"
                              + "          </bindings>\n"
                              + "       </attribute>\n"
                              + "       <attribute name=\"SupportsFailover\">true</attribute>"
                              + "       <attribute name=\"SupportsLoadBalancing\">true</attribute>"
                              + " </mbean>";

         ObjectName on = ServerManagement.deploy(mbeanConfig);
         ServerManagement.invoke(on, "create", new Object[0], new String[0]);
         ServerManagement.invoke(on, "start", new Object[0], new String[0]);

         ConnectionFactory cf = (ConnectionFactory)ic[0].lookup("/ClusteredTestChangeRateConfigDefaultsFactory");
         c = cf.createConnection();
        
         ClientConnectionDelegate del1 = (ClientConnectionDelegate)((JBossConnection)c).getDelegate();
        
         ConnectionState state1 = (ConnectionState)del1.getState();
        
         long minTime = state1.getMinTimeoutProcessTime();
        
         assertEquals(300, minTime);
      }
      finally
      {
         try
         {
            if (c != null)
            {
               log.info("Closing connection");
               c.close();
               log.info("Closed connection");
            }
         }
         catch (Exception e)
         {
            log.warn(e.toString(), e);
         }
      }
   }

   // Package protected ----------------------------------------------------------------------------

   // Protected ------------------------------------------------------------------------------------

   // Private --------------------------------------------------------------------------------------

   // Inner classes --------------------------------------------------------------------------------

}
TOP

Related Classes of org.jboss.test.messaging.jms.clustering.ClusteredConnectionFactoryTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.