Package org.hornetq.jms.bridge.impl

Examples of org.hornetq.jms.bridge.impl.JMSBridgeImpl


    */
   public void testStopBridgeWithFailureWhenStarted() throws Exception
   {
      jmsServer1.stop();

      JMSBridgeImpl bridge = new JMSBridgeImpl(cff0,
                                               cff1,
                                               sourceQueueFactory,
                                               targetQueueFactory,
                                               null,
                                               null,
                                               null,
                                               null,
                                               null,
                                               500,
                                               -1,
                                               QualityOfServiceMode.DUPLICATES_OK,
                                               10,
                                               -1,
                                               null,
                                               null,
                                               false);
      bridge.setTransactionManager(newTransactionManager());

      bridge.start();
      Assert.assertFalse(bridge.isStarted());
      Assert.assertTrue(bridge.isFailed());

      bridge.stop();
      Assert.assertFalse(bridge.isStarted());

      // Thread.sleep(3000);
     
      // we restart and setup the server for the test's tearDown checks
      jmsServer1.start();
View Full Code Here


    */
   private void testCrashAndReconnectDestBasic(final QualityOfServiceMode qosMode,
                                               final boolean persistent,
                                               final boolean largeMessage) throws Exception
   {
      JMSBridgeImpl bridge = null;

      try
      {
         bridge = new JMSBridgeImpl(cff0,
                                    cff1,
                                    sourceQueueFactory,
                                    targetQueueFactory,
                                    null,
                                    null,
                                    null,
                                    null,
                                    null,
                                    1000,
                                    -1,
                                    qosMode,
                                    10,
                                    -1,
                                    null,
                                    null,
                                    false);
         bridge.setTransactionManager(newTransactionManager());
         bridge.start();

         final int NUM_MESSAGES = 10;

         // Send some messages

         sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES / 2, persistent, largeMessage);

         // Verify none are received

         checkEmpty(targetQueue, 1);

         // Now crash the dest server

         JMSBridgeReconnectionTest.log.info("About to crash server");

         jmsServer1.stop();

         // Wait a while before starting up to simulate the dest being down for a while
         JMSBridgeReconnectionTest.log.info("Waiting 5 secs before bringing server back up");
         Thread.sleep(10000);
         JMSBridgeReconnectionTest.log.info("Done wait");

         // Restart the server
         JMSBridgeReconnectionTest.log.info("Restarting server");
         jmsServer1.start();

         jmsServer1.createQueue(false, "targetQueue", null, true, "queue/targetQueue");

         createQueue("targetQueue", 1);

         setUpAdministeredObjects();

         // Send some more messages

         JMSBridgeReconnectionTest.log.info("Sending more messages");

         sendMessages(cf0, sourceQueue, NUM_MESSAGES / 2, NUM_MESSAGES / 2, persistent, largeMessage);

         JMSBridgeReconnectionTest.log.info("Sent messages");

         checkMessagesReceived(cf1, targetQueue, qosMode, NUM_MESSAGES, false, largeMessage);
      }
      finally
      {

         if (bridge != null)
         {
            try
            {
               bridge.stop();
            }
            catch (Exception e)
            {
               JMSBridgeReconnectionTest.log.error("Failed to stop bridge", e);
            }
View Full Code Here

    * Send some more messages
    * Verify all messages are received
    */
   private void testCrashAndReconnectDestCrashBeforePrepare(final boolean persistent) throws Exception
   {
      JMSBridgeImpl bridge = null;

      try
      {
         bridge = new JMSBridgeImpl(cff0,
                                    cff1,
                                    sourceQueueFactory,
                                    targetQueueFactory,
                                    null,
                                    null,
                                    null,
                                    null,
                                    null,
                                    1000,
                                    -1,
                                    QualityOfServiceMode.ONCE_AND_ONLY_ONCE,
                                    10,
                                    5000,
                                    null,
                                    null,
                                    false);
         bridge.setTransactionManager(newTransactionManager());

         bridge.start();

         final int NUM_MESSAGES = 10;
         // Send some messages

         sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES / 2, persistent, false);

         // verify none are received

         checkEmpty(targetQueue, 1);

         // Now crash the dest server

         JMSBridgeReconnectionTest.log.info("About to crash server");

         jmsServer1.stop();

         // Wait a while before starting up to simulate the dest being down for a while
         JMSBridgeReconnectionTest.log.info("Waiting 5 secs before bringing server back up");
         Thread.sleep(10000);
         JMSBridgeReconnectionTest.log.info("Done wait");

         // Restart the server
         jmsServer1.start();

         createQueue("targetQueue", 1);

         setUpAdministeredObjects();

         sendMessages(cf0, sourceQueue, NUM_MESSAGES / 2, NUM_MESSAGES / 2, persistent, false);

         checkMessagesReceived(cf1, targetQueue, QualityOfServiceMode.ONCE_AND_ONLY_ONCE, NUM_MESSAGES, false, false);
      }
      finally
      {

         if (bridge != null)
         {
            try
            {
               bridge.stop();
            }
            catch (Exception e)
            {
               JMSBridgeReconnectionTest.log.error("Failed to stop bridge", e);
            }
View Full Code Here

      testStressSameServer(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false, 1);
   }

   public void testParams() throws Exception
   {
      JMSBridgeImpl bridge = null;

      try
      {
         QualityOfServiceMode qosMode = QualityOfServiceMode.AT_MOST_ONCE;

         int batchSize = 10;

         int maxBatchTime = -1;

         String sourceUsername = null;

         String sourcePassword = null;

         String destUsername = null;

         String destPassword = null;

         String selector = null;

         long failureRetryInterval = 5000;

         int maxRetries = 10;

         String subName = null;

         String clientID = null;

         try
         {
            bridge = new JMSBridgeImpl(null,
                                       cff1,
                                       sourceQueueFactory,
                                       targetQueueFactory,
                                       sourceUsername,
                                       sourcePassword,
                                       destUsername,
                                       destPassword,
                                       selector,
                                       failureRetryInterval,
                                       maxRetries,
                                       qosMode,
                                       batchSize,
                                       maxBatchTime,
                                       subName,
                                       clientID,
                                       false);
         }
         catch (IllegalArgumentException e)
         {
            // Ok
         }

         try
         {
            bridge = new JMSBridgeImpl(cff0,
                                       null,
                                       sourceQueueFactory,
                                       targetQueueFactory,
                                       sourceUsername,
                                       sourcePassword,
                                       destUsername,
                                       destPassword,
                                       selector,
                                       failureRetryInterval,
                                       maxRetries,
                                       qosMode,
                                       batchSize,
                                       maxBatchTime,
                                       subName,
                                       clientID,
                                       false);
         }
         catch (IllegalArgumentException e)
         {
            // Ok
         }

         try
         {
            bridge = new JMSBridgeImpl(cff0,
                                       cff1,
                                       null,
                                       targetQueueFactory,
                                       sourceUsername,
                                       sourcePassword,
                                       destUsername,
                                       destPassword,
                                       selector,
                                       failureRetryInterval,
                                       maxRetries,
                                       qosMode,
                                       batchSize,
                                       maxBatchTime,
                                       subName,
                                       clientID,
                                       false);
         }
         catch (IllegalArgumentException e)
         {
            // Ok
         }

         try
         {
            bridge = new JMSBridgeImpl(cff0,
                                       cff1,
                                       sourceQueueFactory,
                                       null,
                                       sourceUsername,
                                       sourcePassword,
                                       destUsername,
                                       destPassword,
                                       selector,
                                       failureRetryInterval,
                                       maxRetries,
                                       qosMode,
                                       batchSize,
                                       maxBatchTime,
                                       subName,
                                       clientID,
                                       false);
         }
         catch (IllegalArgumentException e)
         {
            // Ok
         }

         try
         {
            bridge = new JMSBridgeImpl(cff0,
                                       cff1,
                                       sourceQueueFactory,
                                       targetQueueFactory,
                                       sourceUsername,
                                       sourcePassword,
                                       destUsername,
                                       destPassword,
                                       selector,
                                       -2,
                                       maxRetries,
                                       qosMode,
                                       batchSize,
                                       maxBatchTime,
                                       subName,
                                       clientID,
                                       false);
         }
         catch (IllegalArgumentException e)
         {
            // Ok
         }

         try
         {
            bridge = new JMSBridgeImpl(cff0,
                                       cff1,
                                       sourceQueueFactory,
                                       targetQueueFactory,
                                       sourceUsername,
                                       sourcePassword,
                                       destUsername,
                                       destPassword,
                                       selector,
                                       -1,
                                       10,
                                       qosMode,
                                       batchSize,
                                       maxBatchTime,
                                       subName,
                                       clientID,
                                       false);
         }
         catch (IllegalArgumentException e)
         {
            // Ok
         }

         try
         {
            bridge = new JMSBridgeImpl(cff0,
                                       cff1,
                                       sourceQueueFactory,
                                       null,
                                       sourceUsername,
                                       sourcePassword,
                                       destUsername,
                                       destPassword,
                                       selector,
                                       failureRetryInterval,
                                       maxRetries,
                                       qosMode,
                                       0,
                                       maxBatchTime,
                                       subName,
                                       clientID,
                                       false);
         }
         catch (IllegalArgumentException e)
         {
            // Ok
         }

         try
         {
            bridge = new JMSBridgeImpl(cff0,
                                       cff1,
                                       sourceQueueFactory,
                                       null,
                                       sourceUsername,
                                       sourcePassword,
                                       destUsername,
                                       destPassword,
                                       selector,
                                       failureRetryInterval,
                                       maxRetries,
                                       qosMode,
                                       batchSize,
                                       -2,
                                       subName,
                                       clientID,
                                       false);
         }
         catch (IllegalArgumentException e)
         {
            // Ok
         }
      }
      finally
      {
         if (bridge != null)
         {
            bridge.stop();
         }
      }
   }
View Full Code Here

      }
   }

   public void testStartStopStart() throws Exception
   {
      JMSBridgeImpl bridge = null;

      Connection connSource = null;

      Connection connTarget = null;

      try
      {
         final int NUM_MESSAGES = 10;

         bridge = new JMSBridgeImpl(cff0,
                                    cff1,
                                    sourceQueueFactory,
                                    targetQueueFactory,
                                    null,
                                    null,
                                    null,
                                    null,
                                    null,
                                    5000,
                                    10,
                                    QualityOfServiceMode.AT_MOST_ONCE,
                                    1,
                                    -1,
                                    null,
                                    null,
                                    false);
         bridge.setTransactionManager(newTransactionManager());

         bridge.start();

         bridge.stop();
        
         bridge.start();
        
         connSource = cf0.createConnection();

         Session sessSend = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);

         MessageProducer prod = sessSend.createProducer(sourceQueue);

         for (int i = 0; i < NUM_MESSAGES; i++)
         {
            TextMessage tm = sessSend.createTextMessage("message" + i);
            prod.send(tm);
         }

         connTarget = cf1.createConnection();
         Session sessRec = connTarget.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageConsumer cons = sessRec.createConsumer(targetQueue);

         connTarget.start();

         for (int i = 0; i < NUM_MESSAGES; i++)
         {
            TextMessage tm = (TextMessage)cons.receive(10000);
            Assert.assertNotNull(tm);
            Assert.assertEquals("message" + i, tm.getText());
         }

         Message m = cons.receiveNoWait();
         Assert.assertNull(m);
      }
      finally
      {
         if (connSource != null)
         {
            connSource.close();
         }

         if (connTarget != null)
         {
            connTarget.close();
         }

         if (bridge != null)
         {
            bridge.stop();
         }

         removeAllMessages(sourceQueue.getQueueName(), 0);
      }
   }
View Full Code Here

      }
   }
  
   public void testSelector() throws Exception
   {
      JMSBridgeImpl bridge = null;

      Connection connSource = null;

      Connection connTarget = null;

      try
      {
         final int NUM_MESSAGES = 10;

         String selector = "vegetable='radish'";

         bridge = new JMSBridgeImpl(cff0,
                                    cff1,
                                    sourceQueueFactory,
                                    targetQueueFactory,
                                    null,
                                    null,
                                    null,
                                    null,
                                    selector,
                                    5000,
                                    10,
                                    QualityOfServiceMode.AT_MOST_ONCE,
                                    1,
                                    -1,
                                    null,
                                    null,
                                    false);
         bridge.setTransactionManager(newTransactionManager());

         bridge.start();

         connSource = cf0.createConnection();

         Session sessSend = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);

         MessageProducer prod = sessSend.createProducer(sourceQueue);

         for (int i = 0; i < NUM_MESSAGES; i++)
         {
            TextMessage tm = sessSend.createTextMessage("message" + i);

            if (i >= NUM_MESSAGES / 2)
            {
               tm.setStringProperty("vegetable", "radish");
            }
            else
            {
               tm.setStringProperty("vegetable", "cauliflower");
            }

            prod.send(tm);
         }

         connTarget = cf1.createConnection();

         Session sessRec = connTarget.createSession(false, Session.AUTO_ACKNOWLEDGE);

         MessageConsumer cons = sessRec.createConsumer(targetQueue);

         connTarget.start();

         for (int i = NUM_MESSAGES / 2; i < NUM_MESSAGES; i++)
         {
            TextMessage tm = (TextMessage)cons.receive(10000);

            Assert.assertNotNull(tm);

            Assert.assertEquals("message" + i, tm.getText());
         }

         Message m = cons.receiveNoWait();

         Assert.assertNull(m);

      }
      finally
      {
         if (connSource != null)
         {
            connSource.close();
         }

         if (connTarget != null)
         {
            connTarget.close();
         }

         if (bridge != null)
         {
            bridge.stop();
         }

         removeAllMessages(sourceQueue.getQueueName(), 0);
      }
   }
View Full Code Here

      internalTestStartBridgeWithJTATransactionAlreadyRunning(false);
   }

   public void internalTestStartBridgeWithJTATransactionAlreadyRunning(final boolean largeMessage) throws Exception
   {
      JMSBridgeImpl bridge = null;

      Transaction toResume = null;

      Transaction started = null;

      TransactionManager mgr = newTransactionManager();

      try
      {

         toResume = mgr.suspend();

         mgr.begin();

         started = mgr.getTransaction();

         final int NUM_MESSAGES = 10;

         bridge = new JMSBridgeImpl(cff0,
                                    cff1,
                                    sourceTopicFactory,
                                    targetQueueFactory,
                                    null,
                                    null,
                                    null,
                                    null,
                                    null,
                                    5000,
                                    10,
                                    QualityOfServiceMode.AT_MOST_ONCE,
                                    1,
                                    -1,
                                    null,
                                    null,
                                    false);
         bridge.setTransactionManager(mgr);
         bridge.start();

         sendMessages(cf0, sourceTopic, 0, NUM_MESSAGES, false, largeMessage);

         checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES, largeMessage);
      }
      finally
      {
         if (started != null)
         {
            try
            {
               started.rollback();
            }
            catch (Exception e)
            {
               JMSBridgeTest.log.error("Failed to rollback", e);
            }
         }

         if (toResume != null)
         {
            try
            {
               mgr.resume(toResume);
            }
            catch (Exception e)
            {
               JMSBridgeTest.log.error("Failed to resume", e);
            }
         }
         if (bridge != null)
         {
            bridge.stop();
         }
      }
   }
View Full Code Here

      internalTestNonDurableSubscriber(false, 1);
   }

   public void internalTestNonDurableSubscriber(final boolean largeMessage, final int batchSize) throws Exception
   {
      JMSBridgeImpl bridge = null;

      try
      {
         final int NUM_MESSAGES = 10;

         bridge = new JMSBridgeImpl(cff0,
                                    cff1,
                                    sourceTopicFactory,
                                    targetQueueFactory,
                                    null,
                                    null,
                                    null,
                                    null,
                                    null,
                                    5000,
                                    10,
                                    QualityOfServiceMode.AT_MOST_ONCE,
                                    batchSize,
                                    -1,
                                    null,
                                    null,
                                    false);
         bridge.setTransactionManager(newTransactionManager());

         bridge.start();

         sendMessages(cf0, sourceTopic, 0, NUM_MESSAGES, false, largeMessage);

         checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES, largeMessage);
      }
      finally
      {
         if (bridge != null)
         {
            bridge.stop();
         }
      }
   }
View Full Code Here

      internalTestDurableSubscriber(false, 1);
   }

   public void internalTestDurableSubscriber(final boolean largeMessage, final int batchSize) throws Exception
   {
      JMSBridgeImpl bridge = null;

      try
      {
         final int NUM_MESSAGES = 10;

         bridge = new JMSBridgeImpl(cff0,
                                    cff1,
                                    sourceTopicFactory,
                                    targetQueueFactory,
                                    null,
                                    null,
                                    null,
                                    null,
                                    null,
                                    5000,
                                    10,
                                    QualityOfServiceMode.AT_MOST_ONCE,
                                    batchSize,
                                    -1,
                                    "subTest",
                                    "clientid123",
                                    false);
         bridge.setTransactionManager(newTransactionManager());

         bridge.start();

         sendMessages(cf0, sourceTopic, 0, NUM_MESSAGES, true, largeMessage);

         checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES, largeMessage);
      }
      finally
      {
         if (bridge != null)
         {
            bridge.stop();
         }

         // Now unsubscribe
         Connection conn = cf0.createConnection();
         conn.setClientID("clientid123");
View Full Code Here

      messageIDInHeader(false);
   }

   private void messageIDInHeader(final boolean on) throws Exception
   {
      JMSBridgeImpl bridge = null;

      Connection connSource = null;

      Connection connTarget = null;

      try
      {
         final int NUM_MESSAGES = 10;

         bridge = new JMSBridgeImpl(cff0,
                                    cff1,
                                    sourceQueueFactory,
                                    targetQueueFactory,
                                    null,
                                    null,
                                    null,
                                    null,
                                    null,
                                    5000,
                                    10,
                                    QualityOfServiceMode.AT_MOST_ONCE,
                                    1,
                                    -1,
                                    null,
                                    null,
                                    on);
         bridge.setTransactionManager(newTransactionManager());

         bridge.start();

         connSource = cf0.createConnection();

         connTarget = cf1.createConnection();

         JMSBridgeTest.log.trace("Sending " + NUM_MESSAGES + " messages");

         List ids1 = new ArrayList();

         Session sessSource = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);

         MessageProducer prod = sessSource.createProducer(sourceQueue);

         for (int i = 0; i < NUM_MESSAGES; i++)
         {
            TextMessage tm = sessSource.createTextMessage("message" + i);

            // We add some properties to make sure they get passed through ok
            tm.setStringProperty("wib", "uhuh");
            tm.setBooleanProperty("cheese", true);
            tm.setIntProperty("Sausages", 23);
            tm.setByteProperty("bacon", (byte)12);
            tm.setDoubleProperty("toast", 17261762.12121d);
            tm.setFloatProperty("orange", 1212.1212f);
            tm.setLongProperty("blurg", 817217827l);
            tm.setShortProperty("stst", (short)26363);
           
            //Set some JMS headers too
           
            //And also set a core props
            ((HornetQMessage)tm).getCoreMessage().putBytesProperty("bytes", new byte[] { 1, 2, 3});

            // We add some JMSX ones too

            tm.setStringProperty("JMSXGroupID", "mygroup543");

            prod.send(tm);

            ids1.add(tm.getJMSMessageID());
         }

         JMSBridgeTest.log.trace("Sent the first messages");

         Session sessTarget = connTarget.createSession(false, Session.AUTO_ACKNOWLEDGE);

         MessageConsumer cons = sessTarget.createConsumer(targetQueue);

         connTarget.start();

         List msgs = new ArrayList();

         for (int i = 0; i < NUM_MESSAGES; i++)
         {
            TextMessage tm = (TextMessage)cons.receive(5000);

            Assert.assertNotNull(tm);

            Assert.assertEquals("message" + i, tm.getText());

            Assert.assertEquals("uhuh", tm.getStringProperty("wib"));
            Assert.assertTrue(tm.getBooleanProperty("cheese"));
            Assert.assertEquals(23, tm.getIntProperty("Sausages"));
            assertEquals((byte)12, tm.getByteProperty("bacon"));
            assertEquals(17261762.12121d, tm.getDoubleProperty("toast"));
            assertEquals(1212.1212f, tm.getFloatProperty("orange"));
            assertEquals(817217827l, tm.getLongProperty("blurg"));
            assertEquals((short)26363, tm.getShortProperty("stst"));
           
            assertEqualsByteArrays(new byte[] { 1,2, 3}, ((HornetQMessage)tm).getCoreMessage().getBytesProperty("bytes"));

            Assert.assertEquals("mygroup543", tm.getStringProperty("JMSXGroupID"));

            if (on)
            {
               String header = tm.getStringProperty(HornetQJMSConstants.JBOSS_MESSAGING_BRIDGE_MESSAGE_ID_LIST);

               Assert.assertNotNull(header);

               Assert.assertEquals(ids1.get(i), header);

               msgs.add(tm);
            }
         }

         if (on)
         {
            // Now we send them again back to the source

            Iterator iter = msgs.iterator();

            List ids2 = new ArrayList();

            while (iter.hasNext())
            {
               Message msg = (Message)iter.next();

               prod.send(msg);

               ids2.add(msg.getJMSMessageID());
            }

            // And consume them again

            for (int i = 0; i < NUM_MESSAGES; i++)
            {
               TextMessage tm = (TextMessage)cons.receive(5000);

               Assert.assertNotNull(tm);

               Assert.assertEquals("message" + i, tm.getText());

               Assert.assertEquals("uhuh", tm.getStringProperty("wib"));
               Assert.assertTrue(tm.getBooleanProperty("cheese"));
               Assert.assertEquals(23, tm.getIntProperty("Sausages"));
               assertEquals((byte)12, tm.getByteProperty("bacon"));
               assertEquals(17261762.12121d, tm.getDoubleProperty("toast"));
               assertEquals(1212.1212f, tm.getFloatProperty("orange"));
               assertEquals(817217827l, tm.getLongProperty("blurg"));
               assertEquals((short)26363, tm.getShortProperty("stst"));
              
               assertEqualsByteArrays(new byte[] { 1,2, 3}, ((HornetQMessage)tm).getCoreMessage().getBytesProperty("bytes"));

               Assert.assertEquals("mygroup543", tm.getStringProperty("JMSXGroupID"));

               String header = tm.getStringProperty(HornetQJMSConstants.JBOSS_MESSAGING_BRIDGE_MESSAGE_ID_LIST);

               Assert.assertNotNull(header);

               Assert.assertEquals(ids1.get(i) + "," + ids2.get(i), header);
            }
         }

      }
      finally
      {
         if (bridge != null)
         {
            bridge.stop();
         }

         if (connSource != null)
         {
            connSource.close();
View Full Code Here

TOP

Related Classes of org.hornetq.jms.bridge.impl.JMSBridgeImpl

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.