Package javax.jms

Examples of javax.jms.Connection


   /*
    * Test durable subscription state survives a restart
    */
   public void testDurableSubscriptionPersistence_2() throws Exception
   {
      Connection conn = cf.createConnection();
      conn.setClientID("Sausages");
     
      Session sessConsume = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
     
      MessageConsumer sub1 = sessConsume.createDurableSubscriber(topic, "sub1", null, false);
      MessageConsumer sub2 = sessConsume.createDurableSubscriber(topic, "sub2", null, false);
      MessageConsumer sub3 = sessConsume.createDurableSubscriber(topic, "sub3", null, false);
     
     
      Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer prod = sessSend.createProducer(topic);
      prod.setDeliveryMode(DeliveryMode.PERSISTENT);
     
      for (int i = 0; i < 10; i++)
      {
         TextMessage tm = sessSend.createTextMessage("message" + i);
         prod.send(tm);
      }
     
      conn.close();
     
      ServerManagement.stopServerPeer();

      ServerManagement.startServerPeer();

      // Messaging server restart implies new ConnectionFactory lookup
      cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");

      ServerManagement.deployTopic("Topic");
     
      conn = cf.createConnection();
      conn.setClientID("Sausages");
     
      sessConsume = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      conn.start();
     
      sub1 = sessConsume.createDurableSubscriber(topic, "sub1", null, false);
      sub2 = sessConsume.createDurableSubscriber(topic, "sub2", null, false);
      sub3 = sessConsume.createDurableSubscriber(topic, "sub3", null, false);
                 
      for (int i = 0; i < 10; i++)
      {
         TextMessage tm1 = (TextMessage)sub1.receive(3000);
         assertNotNull(tm1);
         if (tm1 == null)
         {
            break;
         }
         assertEquals("message" + i, tm1.getText());
        
         TextMessage tm2 = (TextMessage)sub2.receive(3000);
         assertNotNull(tm2);
         if (tm2 == null)
         {
            break;
         }
         assertEquals("message" + i, tm2.getText());
        
         TextMessage tm3 = (TextMessage)sub3.receive(3000);
         assertNotNull(tm3);
         if (tm3 == null)
         {
            break;
         }
         assertEquals("message" + i, tm3.getText());
      }
     
    
      conn.close();
   }
View Full Code Here


   */
  
  
   protected void simpleSendReceive(ConnectionFactory cf, Destination dest) throws Exception
   {
      Connection conn = cf.createConnection();
     
      Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
     
      MessageProducer prod = sess.createProducer(dest);
     
      MessageConsumer cons = sess.createConsumer(dest);
     
      conn.start();
     
      TextMessage tm = sess.createTextMessage("ref test");
     
      prod.send(tm);
     
      tm = (TextMessage)cons.receive(1000);
     
      assertNotNull(tm);
     
      assertEquals("ref test", tm.getText());
     
      conn.close();
        
   }
View Full Code Here

         Process p = spawnVM(serialized);

         // read the message from the queue

         Connection conn = cf.createConnection();
         conn.start();
         Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageConsumer cons = sess.createConsumer(queue);
         TextMessage tm = (TextMessage)cons.receive(5000);

         assertNotNull(tm);
         assertEquals(MESSAGE_TEXT, tm.getText());
View Full Code Here

      }
   }

   public void testCreateBrowserOnNonExistentQueue() throws Exception
   {
      Connection pconn = cf.createConnection();

      try
      {
         Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);

         try
         {
            ps.createBrowser(new JBossQueue("NoSuchQueue"));
            fail("should throw exception");
         }
         catch(InvalidDestinationException e)
         {
            // OK
         }
      }
      finally
      {
         pconn.close();
      }
   }
View Full Code Here

    * Transactional senders go through a cycle of sending and rolling back
    *
    */
   public void testQueueMultipleSenders() throws Exception
   {
      Connection conn1 = cf.createConnection();
     
      Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Session sess2 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Session sess3 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Session sess4 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Session sess5 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Session sess6 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Session sess7 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Session sess8 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
     
      Session sess9 = conn1.createSession(true, Session.SESSION_TRANSACTED);
      Session sess10 = conn1.createSession(true, Session.SESSION_TRANSACTED);
      Session sess11 = conn1.createSession(true, Session.SESSION_TRANSACTED);
      Session sess12 = conn1.createSession(true, Session.SESSION_TRANSACTED);
      Session sess13 = conn1.createSession(true, Session.SESSION_TRANSACTED);
      Session sess14 = conn1.createSession(true, Session.SESSION_TRANSACTED);
      Session sess15 = conn1.createSession(true, Session.SESSION_TRANSACTED);
      Session sess16 = conn1.createSession(true, Session.SESSION_TRANSACTED);
     
      XASession xaSess1 = ((XAConnection)conn1).createXASession();
      XASession xaSess2 = ((XAConnection)conn1).createXASession();
      XASession xaSess3 = ((XAConnection)conn1).createXASession();
      XASession xaSess4 = ((XAConnection)conn1).createXASession();
      XASession xaSess5 = ((XAConnection)conn1).createXASession();
      XASession xaSess6 = ((XAConnection)conn1).createXASession();
      XASession xaSess7 = ((XAConnection)conn1).createXASession();
      XASession xaSess8 = ((XAConnection)conn1).createXASession();
     
      Session sess17 = xaSess1.getSession();
      Session sess18 = xaSess2.getSession();
      Session sess19 = xaSess3.getSession();
      Session sess20 = xaSess4.getSession();
      Session sess21 = xaSess5.getSession();
      Session sess22 = xaSess6.getSession();
      Session sess23 = xaSess7.getSession();
      Session sess24 = xaSess8.getSession();
     
      MessageProducer prod1 = sess1.createProducer(queue1);
      prod1.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod2 = sess2.createProducer(queue1);
      prod2.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod3 = sess3.createProducer(queue1);
      prod3.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod4 = sess4.createProducer(queue1);
      prod4.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod5 = sess5.createProducer(queue1);
      prod5.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod6 = sess6.createProducer(queue1);
      prod6.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod7 = sess7.createProducer(queue1);
      prod7.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod8 = sess8.createProducer(queue1);
      prod8.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod9 = sess9.createProducer(queue1);
      prod9.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod10 = sess10.createProducer(queue1);
      prod10.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod11 = sess11.createProducer(queue1);
      prod11.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod12 = sess12.createProducer(queue1);
      prod12.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod13 = sess13.createProducer(queue1);
      prod13.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod14 = sess14.createProducer(queue1);
      prod14.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod15 = sess15.createProducer(queue1);
      prod15.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod16 = sess16.createProducer(queue1);
      prod16.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod17 = sess17.createProducer(queue1);
      prod17.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod18 = sess18.createProducer(queue1);
      prod18.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod19 = sess19.createProducer(queue1);
      prod19.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod20 = sess20.createProducer(queue1);
      prod20.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod21 = sess21.createProducer(queue1);
      prod21.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod22 = sess22.createProducer(queue1);
      prod22.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod23 = sess23.createProducer(queue1);
      prod23.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      MessageProducer prod24 = sess24.createProducer(queue1);
      prod24.setDeliveryMode(DeliveryMode.NON_PERSISTENT);


      Connection conn2 = cf.createConnection();
      conn2.start();
      Session sessReceive = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);     
      MessageConsumer cons = sessReceive.createConsumer(queue1);
     
 
      Runner[] runners = new Runner[] {
      new Sender("prod1", sess1, prod1, NUM_NON_PERSISTENT_MESSAGES),
      new Sender("prod2", sess2, prod2, NUM_PERSISTENT_MESSAGES),
      new Sender("prod3", sess3, prod3, NUM_NON_PERSISTENT_MESSAGES),
      new Sender("prod4", sess4, prod4, NUM_PERSISTENT_MESSAGES),
      new Sender("prod5", sess5, prod5, NUM_NON_PERSISTENT_MESSAGES),
      new Sender("prod6", sess6, prod6, NUM_PERSISTENT_MESSAGES),
      new Sender("prod7", sess7, prod7, NUM_NON_PERSISTENT_MESSAGES),
      new Sender("prod8", sess8, prod8, NUM_PERSISTENT_MESSAGES),
      new TransactionalSender("prod9", sess9, prod9, NUM_NON_PERSISTENT_MESSAGES, 1, 1),
      new TransactionalSender("prod10", sess10, prod10, NUM_PERSISTENT_MESSAGES, 1, 1),
      new TransactionalSender("prod11", sess11, prod11, NUM_NON_PERSISTENT_MESSAGES, 10, 7),
      new TransactionalSender("prod12", sess12, prod12, NUM_PERSISTENT_MESSAGES, 10, 7),
      new TransactionalSender("prod13", sess13, prod13, NUM_NON_PERSISTENT_MESSAGES, 50, 21),
      new TransactionalSender("prod14", sess14, prod14, NUM_PERSISTENT_MESSAGES, 50, 21),
      new TransactionalSender("prod15", sess15, prod15, NUM_NON_PERSISTENT_MESSAGES, 100, 67),
      new TransactionalSender("prod16", sess16, prod16, NUM_PERSISTENT_MESSAGES, 100, 67),           
      new Transactional2PCSender("prod17", xaSess1, prod17, NUM_NON_PERSISTENT_MESSAGES, 1, 1),
      new Transactional2PCSender("prod18", xaSess2, prod18, NUM_PERSISTENT_MESSAGES, 1, 1),
      new Transactional2PCSender("prod19", xaSess3, prod19, NUM_NON_PERSISTENT_MESSAGES, 10, 7),
      new Transactional2PCSender("prod20", xaSess4, prod20, NUM_PERSISTENT_MESSAGES, 10, 7),
      new Transactional2PCSender("prod21", xaSess5, prod21, NUM_NON_PERSISTENT_MESSAGES, 50, 21),
      new Transactional2PCSender("prod22", xaSess6, prod22, NUM_PERSISTENT_MESSAGES, 50, 21),
      new Transactional2PCSender("prod23", xaSess7, prod23, NUM_NON_PERSISTENT_MESSAGES, 100, 67),
      new Transactional2PCSender("prod24", xaSess8, prod24, NUM_PERSISTENT_MESSAGES, 100, 67),
      new Receiver(sessReceive, cons,
                   12 * NUM_NON_PERSISTENT_MESSAGES + 12 * NUM_PERSISTENT_MESSAGES, false) };
     
      runRunners(runners);
     
      conn1.close();
     
      conn2.close();     
   }
View Full Code Here

    * Half the consumers are durable and half non durable.
    *
    */
   public void testTopicMultipleReceivers() throws Exception
   {
      Connection conn1 = cf.createConnection();
     
      Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Session sess2 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);

      MessageProducer prod1 = sess1.createProducer(topic1);
      prod1.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
     
      MessageProducer prod2 = sess2.createProducer(topic1);
      prod2.setDeliveryMode(DeliveryMode.PERSISTENT);
                 
      Connection conn2 = cf.createConnection();
      conn2.setClientID("clientid1");
      conn2.start();
     
      //4 auto ack
      Session rsess1 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Session rsess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Session rsess3 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Session rsess4 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
     
      //4 dups
      Session rsess5 = conn2.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
      Session rsess6 = conn2.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
      Session rsess7 = conn2.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
      Session rsess8 = conn2.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
     
      //4 client
      Session rsess9 = conn2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
      Session rsess10 = conn2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
      Session rsess11 = conn2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
      Session rsess12 = conn2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
     
     
      //4 transactional
      Session rsess13 = conn2.createSession(true, Session.SESSION_TRANSACTED);
      Session rsess14 = conn2.createSession(true, Session.SESSION_TRANSACTED);
      Session rsess15 = conn2.createSession(true, Session.SESSION_TRANSACTED);
      Session rsess16 = conn2.createSession(true, Session.SESSION_TRANSACTED);
     
      //4 2pc transactional
      XASession rxaSess1 = ((XAConnection)conn2).createXASession();
      XASession rxaSess2 = ((XAConnection)conn2).createXASession();
      XASession rxaSess3 = ((XAConnection)conn2).createXASession();
      XASession rxaSess4 = ((XAConnection)conn2).createXASession();
        
      Session rsess17 = rxaSess1.getSession();
      Session rsess18 = rxaSess2.getSession();
      Session rsess19 = rxaSess3.getSession();
      Session rsess20 = rxaSess4.getSession();

                     
      MessageConsumer cons1 = rsess1.createConsumer(topic1);
      MessageConsumer cons2 = rsess2.createDurableSubscriber(topic1, "sub1");
      MessageConsumer cons3 = rsess3.createConsumer(topic1);
      MessageConsumer cons4 = rsess4.createDurableSubscriber(topic1, "sub2");
      MessageConsumer cons5 = rsess5.createConsumer(topic1);
      MessageConsumer cons6 = rsess6.createDurableSubscriber(topic1, "sub3");
      MessageConsumer cons7 = rsess7.createConsumer(topic1);
      MessageConsumer cons8 = rsess8.createDurableSubscriber(topic1, "sub4");
      MessageConsumer cons9 = rsess9.createConsumer(topic1);
      MessageConsumer cons10 = rsess10.createDurableSubscriber(topic1, "sub5");
      MessageConsumer cons11 = rsess11.createConsumer(topic1);
      MessageConsumer cons12 = rsess12.createDurableSubscriber(topic1, "sub6");
      MessageConsumer cons13 = rsess13.createConsumer(topic1);
      MessageConsumer cons14 = rsess14.createDurableSubscriber(topic1, "sub7");
      MessageConsumer cons15 = rsess15.createConsumer(topic1);
      MessageConsumer cons16 = rsess16.createDurableSubscriber(topic1, "sub8");
      MessageConsumer cons17 = rsess17.createConsumer(topic1);
      MessageConsumer cons18 = rsess18.createDurableSubscriber(topic1, "sub9");
      MessageConsumer cons19 = rsess19.createConsumer(topic1);
      MessageConsumer cons20 = rsess20.createDurableSubscriber(topic1, "sub10");

     
      //To make sure paging occurs first send some messages before receiving
 
      Runner[] runners = new Runner[] {
           
      new Sender("prod1", sess1, prod1, NUM_NON_PERSISTENT_PRESEND),
      new Sender("prod2", sess2, prod2, NUM_PERSISTENT_PRESEND)
      };
     
      runRunners(runners);
     
      runners = new Runner[] {
      //4 auto ack
      new Receiver(rsess1, cons1, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, false),     
      new Receiver(rsess2, cons2, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, true),
      new Receiver(rsess3, cons3, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, false),
      new Receiver(rsess4, cons4, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, true),
    
      //4 dups ok
      new Receiver(rsess5, cons5, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, false),
      new Receiver(rsess6, cons6, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, true),
      new Receiver(rsess7, cons7, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, false),
      new Receiver(rsess8, cons8, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, true),
     
      //4 client ack
      new RecoveringReceiver(rsess9, cons9, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, 1, 1, false),
      new RecoveringReceiver(rsess10, cons10, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, 10, 7, true),
      new RecoveringReceiver(rsess11, cons11, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, 50, 21, false),
      new RecoveringReceiver(rsess12, cons12, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, 100, 67, true),
      
      //4 transactional
     
      new TransactionalReceiver(rsess13, cons13, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, 1, 1, false),
      new TransactionalReceiver(rsess14, cons14, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, 10, 7, true),
      new TransactionalReceiver(rsess15, cons15, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, 50, 21, false),
      new TransactionalReceiver(rsess16, cons16, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, 100, 67, true),
     
      //4 2pc transactional
      new Transactional2PCReceiver(rxaSess1, cons17, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, 1, 1, false),
      new Transactional2PCReceiver(rxaSess2, cons18, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, 10, 7, true),
      new Transactional2PCReceiver(rxaSess3, cons19, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, 50, 21, false),
      new Transactional2PCReceiver(rxaSess4, cons20, NUM_NON_PERSISTENT_MESSAGES + NUM_PERSISTENT_MESSAGES + NUM_NON_PERSISTENT_PRESEND + NUM_PERSISTENT_PRESEND, 100, 67, true),
      
      new Sender("prod3", sess1, prod1, NUM_NON_PERSISTENT_MESSAGES),
      new Sender("prod4", sess2, prod2, NUM_PERSISTENT_MESSAGES)
      };
     
      runRunners(runners);
     
      conn1.close();
     
      conn2.close();     
   }   
View Full Code Here

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

   public void testResourceManagerMemoryLeakOnCommit() throws Exception
   {

      Connection conn = null;
     
      try
      {
         conn = cf.createConnection();
        
         JBossConnection jbConn = (JBossConnection)conn;
        
         ClientConnectionDelegate del = (ClientConnectionDelegate)jbConn.getDelegate();
        
         ConnectionState state = (ConnectionState)del.getState();
        
         ResourceManager rm = state.getResourceManager();
        
         Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
        
        
         for (int i = 0; i < 100; i++)
         {
            assertEquals(1, rm.size());
           
            session.commit();
           
            assertEquals(1, rm.size());
         }                 
        
         assertEquals(1, rm.size());
        
         conn.close();
        
         conn = null;
        
         assertEquals(0, rm.size());

      }
      finally
      {
         if (conn != null)
         {
            conn.close();
         }
      }
   }
View Full Code Here

   }
  
   public void testResourceManagerMemoryLeakOnRollback() throws Exception
   {

      Connection conn = null;
     
      try
      {
         conn = cf.createConnection();
        
         JBossConnection jbConn = (JBossConnection)conn;
        
         ClientConnectionDelegate del = (ClientConnectionDelegate)jbConn.getDelegate();
        
         ConnectionState state = (ConnectionState)del.getState();
        
         ResourceManager rm = state.getResourceManager();
        
         Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
        
        
         for (int i = 0; i < 100; i++)
         {
            assertEquals(1, rm.size());
           
            session.commit();
           
            assertEquals(1, rm.size());
         }                 
        
         assertEquals(1, rm.size());
        
         conn.close();
        
         conn = null;
        
         assertEquals(0, rm.size());

      }
      finally
      {
         if (conn != null)
         {
            conn.close();
         }
      }
   }
View Full Code Here

      conn2.close();     
   }   
  
   public void testConnectionConsumer() throws Exception
   {
      Connection conn = cf.createConnection();
      conn.start();
     
      Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
     
      Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
     
      MessageProducer prod = sessSend.createProducer(queue1);
      prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
     
      Runner[] runners = new Runner[] { new Sender("prod1", sessSend, prod, 100000),
                                        new Receiver(conn, sessReceive, 100000, queue1) };

      runRunners(runners);

      conn.close();     
   }
View Full Code Here

  

   public void testSimpleRollback() throws Exception
   {
      // send a message
      Connection conn = cf.createConnection();
      Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      s.createProducer(queue).send(s.createTextMessage("one"));

      log.debug("message sent");

      s.close();

      s = conn.createSession(true, Session.SESSION_TRANSACTED);
      MessageConsumer c = s.createConsumer(queue);
      conn.start();
      Message m = c.receive();

      assertEquals("one", ((TextMessage)m).getText());
      assertFalse(m.getJMSRedelivered());
      assertEquals(1, m.getIntProperty("JMSXDeliveryCount"));

      s.rollback();

      // get the message again
      m = c.receive();
      assertTrue(m.getJMSRedelivered());
      assertEquals(2, m.getIntProperty("JMSXDeliveryCount"));

      conn.close();
     
      //Need to pause a little while - cancelling back to the queue is async
     
      Thread.sleep(500);
View Full Code Here

TOP

Related Classes of javax.jms.Connection

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.