Package org.jboss.jms.client

Examples of org.jboss.jms.client.JBossConnectionFactory


    * Test that connections created using a clustered connection factory are created round robin on
    * different servers
    */
   public void testRoundRobinConnectionCreation() throws Exception
   {
      JBossConnectionFactory factory =  (JBossConnectionFactory )ic[0].lookup("/ConnectionFactory");

      ClientClusteredConnectionFactoryDelegate delegate =
         (ClientClusteredConnectionFactoryDelegate)factory.getDelegate();

      log.info ("number of delegates = " + delegate.getDelegates().length);
      log.info ("number of servers = " + ServerManagement.getServer(0).getNodeIDView().size());

      assertEquals(3, delegate.getDelegates().length);

      ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];

      ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];

      ClientConnectionFactoryDelegate cf3 = delegate.getDelegates()[2];

      assertEquals(0, cf1.getServerID());

      assertEquals(1, cf2.getServerID());

      assertEquals(2, cf3.getServerID());

      assertEquals(3, ServerManagement.getServer(0).getNodeIDView().size());

      Connection conn1 = null;

      Connection conn2 = null;

      Connection conn3 = null;

      Connection conn4 = null;

      Connection conn5 = null;

      try
      {
         conn1 = factory.createConnection()//server 0

         conn2 = factory.createConnection()//server 1

         conn3 = factory.createConnection()//server 2

         conn4 = factory.createConnection()//server 0

         conn5 = factory.createConnection()//server 1

         ConnectionState state1 = (ConnectionState)(((DelegateSupport)((JBossConnection)conn1).getDelegate()).getState());

         ConnectionState state2 = (ConnectionState)(((DelegateSupport)((JBossConnection)conn2).getDelegate()).getState());

View Full Code Here


    * or join
    */
   public void testDefaultFailoverMap() throws Exception
   {
      {
         JBossConnectionFactory factory =  (JBossConnectionFactory )ic[0].lookup("/ConnectionFactory");

         ClientClusteredConnectionFactoryDelegate delegate =
            (ClientClusteredConnectionFactoryDelegate)factory.getDelegate();

         assertEquals(3, ServerManagement.getServer(0).getNodeIDView().size());

         ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();

         ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];

         ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];

         ClientConnectionFactoryDelegate cf3 = delegate.getDelegates()[2];

         //The order here depends on the order the servers were started in

         //If any servers get stopped and then started then the order will change

         log.info("cf1 serverid=" + cf1.getServerID());

         log.info("cf2 serverid=" + cf2.getServerID());

         log.info("cf3 serverid=" + cf3.getServerID());


         assertEquals(0, cf1.getServerID());

         assertEquals(1, cf2.getServerID());

         assertEquals(2, cf3.getServerID());

         Map failoverMap = delegate.getFailoverMap();

         assertEquals(3, delegates.length);

         assertEquals(3, failoverMap.size());

         // Default failover policy just chooses the node to the right

         assertEquals(cf2.getServerID(), ((Integer)failoverMap.get(new Integer(cf1.getServerID()))).intValue());

         assertEquals(cf3.getServerID(), ((Integer)failoverMap.get(new Integer(cf2.getServerID()))).intValue());

         assertEquals(cf1.getServerID(), ((Integer)failoverMap.get(new Integer(cf3.getServerID()))).intValue());
      }

      //Now cleanly stop one of the servers

      log.info("************** STOPPING SERVER 0");
      ServerManagement.stop(0);

      log.info("server stopped");

      assertEquals(2, ServerManagement.getServer(1).getNodeIDView().size());

      {
         //Lookup another connection factory

         JBossConnectionFactory factory =  (JBossConnectionFactory )ic[1].lookup("/ConnectionFactory");

         log.info("Got connection factory");

         ClientClusteredConnectionFactoryDelegate delegate =
            (ClientClusteredConnectionFactoryDelegate)factory.getDelegate();

         ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();

         Map failoverMap = delegate.getFailoverMap();

         log.info("Got failover map");

         assertEquals(2, delegates.length);

         ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];

         ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];

         //Order here depends on order servers were started in

         log.info("cf1 serverid=" + cf1.getServerID());

         log.info("cf2 serverid=" + cf2.getServerID());

         assertEquals(1, cf1.getServerID());

         assertEquals(2, cf2.getServerID());


         assertEquals(2, failoverMap.size());

         assertEquals(cf2.getServerID(), ((Integer)failoverMap.get(new Integer(cf1.getServerID()))).intValue());

         assertEquals(cf1.getServerID(), ((Integer)failoverMap.get(new Integer(cf2.getServerID()))).intValue());
      }

      //Cleanly stop another server

      log.info("Server 1 is started: " + ServerManagement.getServer(1).isServerPeerStarted());

      ServerManagement.stop(1);

      assertEquals(1, ServerManagement.getServer(2).getNodeIDView().size());

      {
         //Lookup another connection factory

         JBossConnectionFactory factory =  (JBossConnectionFactory )ic[2].lookup("/ConnectionFactory");

         ClientClusteredConnectionFactoryDelegate delegate =
            (ClientClusteredConnectionFactoryDelegate)factory.getDelegate();

         ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();

         Map failoverMap = delegate.getFailoverMap();

         assertEquals(1, delegates.length);

         ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];

         assertEquals(2, cf1.getServerID());


         assertEquals(1, failoverMap.size());

         assertEquals(cf1.getServerID(), ((Integer)failoverMap.get(new Integer(cf1.getServerID()))).intValue());
      }

      //Restart server 0

      ServerManagement.start(0, "all");

      {
         JBossConnectionFactory factory =  (JBossConnectionFactory )ic[0].lookup("/ConnectionFactory");

         log.info("Got connection factory");

         ClientClusteredConnectionFactoryDelegate delegate =
            (ClientClusteredConnectionFactoryDelegate)factory.getDelegate();

         ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();

         Map failoverMap = delegate.getFailoverMap();

         log.info("Got failover map");

         assertEquals(2, delegates.length);

         ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];

         ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];

         log.info("cf1 serverid=" + cf1.getServerID());

         log.info("cf2 serverid=" + cf2.getServerID());

         assertEquals(0, cf1.getServerID());

         assertEquals(2, cf2.getServerID());


         assertEquals(2, failoverMap.size());

         assertEquals(cf2.getServerID(), ((Integer)failoverMap.get(new Integer(cf1.getServerID()))).intValue());

         assertEquals(cf1.getServerID(), ((Integer)failoverMap.get(new Integer(cf2.getServerID()))).intValue());
      }


      //Restart server 1

      ServerManagement.start(1, "all");

      {
         JBossConnectionFactory factory =  (JBossConnectionFactory )ic[1].lookup("/ConnectionFactory");

         log.info("Got connection factory");

         ClientClusteredConnectionFactoryDelegate delegate =
            (ClientClusteredConnectionFactoryDelegate)factory.getDelegate();

         ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();

         Map failoverMap = delegate.getFailoverMap();

View Full Code Here

      }
   }

   public void testSimpleFailover() throws Exception
   {
      JBossConnectionFactory factory =  (JBossConnectionFactory )ic[0].lookup("/ConnectionFactory");

      ClientClusteredConnectionFactoryDelegate delegate =
         (ClientClusteredConnectionFactoryDelegate)factory.getDelegate();

      Set nodeIDView = ServerManagement.getServer(0).getNodeIDView();
      assertEquals(3, nodeIDView.size());

      ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();

      ClientConnectionFactoryDelegate cf1 = delegates[0];

      ClientConnectionFactoryDelegate cf2 = delegates[1];

      ClientConnectionFactoryDelegate cf3 = delegates[2];

      int server0Id = cf1.getServerID();

      int server1Id = cf2.getServerID();

      int server2Id = cf3.getServerID();

      log.info("server 0 id: " + server0Id);

      log.info("server 1 id: " + server1Id);

      log.info("server 2 id: " + server2Id);

      Map failoverMap = delegate.getFailoverMap();

      log.info(failoverMap.get(new Integer(server0Id)));
      log.info(failoverMap.get(new Integer(server1Id)));
      log.info(failoverMap.get(new Integer(server2Id)));

      int server1FailoverId = ((Integer)failoverMap.get(new Integer(server1Id))).intValue();

      // server 1 should failover onto server 2

      assertEquals(server2Id, server1FailoverId);

      Connection conn = null;

      try
      {
         conn = factory.createConnection(); //connection on server 0

         conn.close();

         conn = factory.createConnection(); //connection on server 1

         JBossConnection jbc = (JBossConnection)conn;

         ClientConnectionDelegate del = (ClientConnectionDelegate)jbc.getDelegate();
View Full Code Here

      }
   }

   public void testFailoverWithUnackedMessagesClientAcknowledge() throws Exception
   {
      JBossConnectionFactory factory =  (JBossConnectionFactory )ic[0].lookup("/ConnectionFactory");

      ClientClusteredConnectionFactoryDelegate delegate =
         (ClientClusteredConnectionFactoryDelegate)factory.getDelegate();

      Set nodeIDView = ServerManagement.getServer(0).getNodeIDView();
      assertEquals(3, nodeIDView.size());

      ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();

      ClientConnectionFactoryDelegate cf1 = delegates[0];

      ClientConnectionFactoryDelegate cf2 = delegates[1];

      ClientConnectionFactoryDelegate cf3 = delegates[2];

      int server0Id = cf1.getServerID();

      int server1Id = cf2.getServerID();

      int server2Id = cf3.getServerID();

      log.info("server 0 id: " + server0Id);

      log.info("server 1 id: " + server1Id);

      log.info("server 2 id: " + server2Id);
     
      assertEquals(0, server0Id);
     
      assertEquals(1, server1Id);
     
      assertEquals(2, server2Id);

      Map failoverMap = delegate.getFailoverMap();

      log.info(failoverMap.get(new Integer(server0Id)));
      log.info(failoverMap.get(new Integer(server1Id)));
      log.info(failoverMap.get(new Integer(server2Id)));

      int server1FailoverId = ((Integer)failoverMap.get(new Integer(server1Id))).intValue();

      // server 1 should failover onto server 2

      assertEquals(server2Id, server1FailoverId);

      Connection conn = null;

      boolean killed = false;

      try
      {
         conn = factory.createConnection(); //connection on server 0

         conn.close();

         conn = factory.createConnection(); //connection on server 1

         JBossConnection jbc = (JBossConnection)conn;

         ClientConnectionDelegate del = (ClientConnectionDelegate)jbc.getDelegate();
View Full Code Here

                                               name3,
                                               "/TestConnectionFactory4",
                                               "clientid4",
                                               false);

      JBossConnectionFactory f1 = (JBossConnectionFactory)ic.lookup("/TestConnectionFactory1");
      ClientConnectionFactoryDelegate del1 = (ClientConnectionFactoryDelegate)f1.getDelegate();

      assertTrue(del1.getServerLocatorURI().startsWith("bisocket://localhost:1234"));

      JBossConnectionFactory f2 = (JBossConnectionFactory)ic.lookup("/TestConnectionFactory2");
      ClientConnectionFactoryDelegate del2 = (ClientConnectionFactoryDelegate)f2.getDelegate();
      assertTrue(del2.getServerLocatorURI().startsWith("bisocket://localhost:1235"));

      JBossConnectionFactory f3 = (JBossConnectionFactory)ic.lookup("/TestConnectionFactory3");
      ClientConnectionFactoryDelegate del3 = (ClientConnectionFactoryDelegate)f3.getDelegate();
      assertTrue(del3.getServerLocatorURI().startsWith("bisocket://localhost:1236"));

      JBossConnectionFactory f4 = (JBossConnectionFactory)ic.lookup("/TestConnectionFactory4");
      ClientConnectionFactoryDelegate del4 = (ClientConnectionFactoryDelegate)f4.getDelegate();
      assertTrue(del4.getServerLocatorURI().startsWith("bisocket://localhost:1236"));

      Connection con1 = f1.createConnection();
      Connection con2 = f2.createConnection();
      Connection con3 = f3.createConnection();
      Connection con4 = f4.createConnection();
      con1.close();
      con2.close();
      con3.close();
      con4.close();

      stopService(cf1);
      stopService(cf2);
      stopService(cf3);

      // Check f4 is still ok
      Connection conn5 = f4.createConnection();
      conn5.close();

      stopService(cf4);

      stopService(c1);
View Full Code Here

   {
      Connection conn0 = null;
      Connection conn1 = null;
     
      Map<String, TextMessage> msgs = new ConcurrentHashMap<String, TextMessage>();
      JBossConnectionFactory cf0;

      try
      {
         //we need to kill node 2, only leave two nodes.
         //otherwise messages may be merged to node2 and never sucked again.
         ServerManagement.kill(2);

         cf0 = (JBossConnectionFactory)ic[0].lookup("/ConnectionFactory");

         conn0 = cf0.createConnection();

         Session sess0 = conn0.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageProducer prod0 = sess0.createProducer(queue[0]);

         final int NUM_MESSAGES = 1000;

         for (int i = 0; i < NUM_MESSAGES; i++)
         {
            TextMessage tm = sess0.createTextMessage("suckmsg-" + i);
            prod0.send(tm);
         }
        
         startReceive(msgs);
         startReceive(msgs);
         startReceive(msgs);
         startReceive(msgs);
         startReceive(msgs);
        
         JBossConnectionFactory cf1 = (JBossConnectionFactory)ic[1].lookup("/ConnectionFactory");
         conn1 = cf1.createConnection();
         Session sess1 = conn1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
         MessageConsumer cons1 = sess1.createConsumer(queue[1]);
         conn1.start();
        
         TextMessage rm = (TextMessage)cons1.receive(5000);
View Full Code Here

      }
   }

   private void startReceive(final Map<String, TextMessage> msgs) throws Exception
   {
      JBossConnectionFactory cf1 = (JBossConnectionFactory)ic[1].lookup("/ConnectionFactory");
      Connection conn1 = cf1.createConnection();
      Session sess1 = conn1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
      MessageConsumer cons1 = sess1.createConsumer(queue[1]);
      cons1.setMessageListener(new MessageListener() {
         public void onMessage(Message m)
         {
View Full Code Here

   /** This method is to make sure CFs are being released on GC, validating if the callbacks
    *  are not making any hard references */
   public void testUpdateTopology() throws Throwable
   {

      JBossConnectionFactory cf = (JBossConnectionFactory)ic[0].lookup("/ClusteredConnectionFactory");
      ClientClusteredConnectionFactoryDelegate clusterDelegate = (ClientClusteredConnectionFactoryDelegate)cf.getDelegate();
      assertEquals(2, clusterDelegate.getDelegates().length);
      clusterDelegate.getTopology();
      assertEquals(2, clusterDelegate.getDelegates().length);

      // Kill the same node as the CF is connected to
View Full Code Here

   /** Case the updateCF is not captured, the hopping should run nicely.
    *  This test will disable CF callback for a connection and validate if hoping is working*/
   public void testNoUpdateCaptured() throws Exception
   {
      JBossConnectionFactory cfNoCallback = (JBossConnectionFactory)ic[0].lookup("/ClusteredConnectionFactory");
      ClientClusteredConnectionFactoryDelegate noCallbackDelegate =  (ClientClusteredConnectionFactoryDelegate )cfNoCallback.getDelegate();
      noCallbackDelegate.closeCallback(false);

      ServerManagement.kill(1);

      Connection conn = null;

      for (int i=0; i<4; i++)
      {
         try
         {
            conn = cfNoCallback.createConnection();
            // 0 is the only server alive, so.. all connection should be performed on it
            assertEquals(0, getServerId(conn));
         }
         finally
         {
View Full Code Here

  
   public void testUpdateConnectionFactoryOnKill() throws Exception
   {
      Connection conn = createConnectionOnServer(cf, 0);

      JBossConnectionFactory jbcf = (JBossConnectionFactory)cf;

      ClientClusteredConnectionFactoryDelegate cfDelegate =
         (ClientClusteredConnectionFactoryDelegate)jbcf.getDelegate();

      assertEquals(2, cfDelegate.getDelegates().length);

      Connection conn1 = cf.createConnection();
View Full Code Here

TOP

Related Classes of org.jboss.jms.client.JBossConnectionFactory

Copyright © 2018 www.massapicom. 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.