Example #1
1
  /** Teardown the activation */
  protected synchronized void teardown() {
    HornetQRALogger.LOGGER.debug("Tearing down " + spec);

    if (resourceRecovery != null) {
      ra.getRecoveryManager().unRegister(resourceRecovery);
    }

    for (HornetQMessageHandler handler : handlers) {
      handler.interruptConsumer();
    }

    Thread threadTearDown =
        new Thread("TearDown/HornetQActivation") {
          public void run() {
            for (HornetQMessageHandler handler : handlers) {
              handler.teardown();
            }
          }
        };

    // We will first start a new thread that will call tearDown on all the instances, trying to
    // graciously shutdown everything.
    // We will then use the call-timeout to determine a timeout.
    // if that failed we will then close the connection factory, and interrupt the thread
    threadTearDown.start();

    try {
      threadTearDown.join(factory.getCallTimeout());
    } catch (InterruptedException e) {
      // nothing to be done on this context.. we will just keep going as we need to send an
      // interrupt to threadTearDown and give up
    }

    if (threadTearDown.isAlive()) {
      if (factory != null) {
        // This will interrupt any threads waiting on reconnect
        factory.close();
        factory = null;
      }
      threadTearDown.interrupt();

      try {
        threadTearDown.join(5000);
      } catch (InterruptedException e) {
        // nothing to be done here.. we are going down anyways
      }

      if (threadTearDown.isAlive()) {
        HornetQRALogger.LOGGER.warn("Thread " + threadTearDown + " couldn't be finished");
      }
    }

    if (spec.isHasBeenUpdated() && factory != null) {
      factory.close();
      factory = null;
    }

    HornetQRALogger.LOGGER.debug("Tearing down complete " + this);
  }
  @Test
  public void testCreateCF() throws Exception {
    JMSServerControl control = createJMSControl();
    control.createConnectionFactory("test", false, false, 0, "invm", "test");

    ConnectionFactoryControl controlCF = createCFControl("test");

    HornetQConnectionFactory cf = (HornetQConnectionFactory) ctx.lookup("test");

    assertFalse(cf.isCompressLargeMessage());

    controlCF.setCompressLargeMessages(true);

    cf = (HornetQConnectionFactory) ctx.lookup("test");
    assertTrue(cf.isCompressLargeMessage());

    stopServer();

    Thread.sleep(500);

    startServer();

    cf = (HornetQConnectionFactory) ctx.lookup("test");
    assertTrue(cf.isCompressLargeMessage());
  }
  /**
   * Only execution point for this application.
   *
   * @param ignored not used.
   * @throws Exception if something goes wrong.
   */
  @Test
  public void test() {
    HornetQConnectionFactory hornetQConnectionFactory = null;
    Connection connection = null;
    Session session = null;

    try {
      hornetQConnectionFactory =
          new HornetQConnectionFactory(
              false, new TransportConfiguration(NettyConnectorFactory.class.getName()));
      connection = hornetQConnectionFactory.createConnection();
      connection.start();

      session = connection.createSession(false, DeliveryMode.NON_PERSISTENT);
      final MessageProducer producer = session.createProducer(new HornetQQueue(QUEUE_NAME));
      producer.send(session.createTextMessage("Hello World!"));
      System.out.println("Message sent. Please see server console output");
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      ClientUtil.closeSession(session);
      ClientUtil.closeConnection(connection);
      ClientUtil.closeConnectionFactory(hornetQConnectionFactory);
    }
  }
Example #4
0
  @Override
  protected void tearDown() throws Exception {

    cf1.close();

    cf2.close();

    if (jmsServer != null && jmsServer.isStarted()) {
      jmsServer.stop();
    }

    super.tearDown();
  }
Example #5
0
  @Override
  @After
  public void tearDown() throws Exception {
    checkEmpty(sourceQueue, 0);
    checkEmpty(localTargetQueue, 0);
    checkEmpty(targetQueue, 1);

    // Check no subscriptions left lying around

    checkNoSubscriptions(sourceTopic, 0);
    if (cff0 instanceof HornetQConnectionFactory) {
      ((HornetQConnectionFactory) cff0).close();
    }
    if (cff1 instanceof HornetQConnectionFactory) {
      ((HornetQConnectionFactory) cff1).close();
    }
    stopComponent(jmsServer0);
    stopComponent(jmsServer1);
    cff0 = cff1 = null;
    cff0xa = cff1xa = null;

    cf0 = cf1 = null;

    cf0xa = cf1xa = null;

    sourceQueueFactory = targetQueueFactory = localTargetQueueFactory = sourceTopicFactory = null;

    sourceQueue = targetQueue = localTargetQueue = null;

    sourceTopic = null;

    server0 = null;

    jmsServer0 = null;

    server1 = null;

    jmsServer1 = null;
    if (context0 != null) context0.close();
    context0 = null;
    if (context1 != null) context1.close();
    context1 = null;

    // Shutting down Arjuna threads
    TxControl.disable(true);

    TransactionReaper.terminate(false);
    super.tearDown();
  }
Example #6
0
  /**
   * Setup the activation
   *
   * @throws Exception Thrown if an error occurs
   */
  protected synchronized void setup() throws Exception {
    HornetQRALogger.LOGGER.debug("Setting up " + spec);

    setupCF();

    setupDestination();
    for (int i = 0; i < spec.getMaxSession(); i++) {
      ClientSession session = null;

      try {
        ClientSessionFactory cf = factory.getServerLocator().createSessionFactory();
        session = setupSession(cf);
        HornetQMessageHandler handler =
            new HornetQMessageHandler(this, ra.getTM(), (ClientSessionInternal) session, cf, i);
        handler.setup();
        session.start();
        handlers.add(handler);
      } catch (Exception e) {
        if (session != null) {
          session.close();
        }

        throw e;
      }
    }

    resourceRecovery =
        ra.getRecoveryManager().register(factory, spec.getUser(), spec.getPassword());

    HornetQRALogger.LOGGER.debug("Setup complete " + this);
  }
  @Before
  public void setUp() {
    // Set up connection to the broker
    try {
      Map<String, Object> connectionParams = new HashMap<String, Object>();

      connectionParams.put(
          org.hornetq.integration.transports.netty.TransportConstants.HOST_PROP_NAME, "localhost");
      connectionParams.put(
          org.hornetq.integration.transports.netty.TransportConstants.PORT_PROP_NAME, 5445);

      TransportConfiguration transport =
          new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams);

      hornetQConnectionFactory = new HornetQConnectionFactory(false, transport);

      connection = hornetQConnectionFactory.createConnection();
      connection.start();

      session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #8
0
  // https://jira.jboss.org/jira/browse/JBMESSAGING-1702
  // Test that two failures concurrently executing and calling the same exception listener
  // don't deadlock
  public void testDeadlock() throws Exception {
    for (int i = 0; i < 100; i++) {
      final Connection conn1 = cf1.createConnection();

      Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
      RemotingConnection rc1 =
          ((ClientSessionInternal) ((HornetQSession) sess1).getCoreSession()).getConnection();

      final Connection conn2 = cf2.createConnection();

      Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
      RemotingConnection rc2 =
          ((ClientSessionInternal) ((HornetQSession) sess2).getCoreSession()).getConnection();

      ExceptionListener listener1 =
          new ExceptionListener() {
            public void onException(final JMSException exception) {
              try {
                conn2.close();
              } catch (Exception e) {
                FailureDeadlockTest.log.error("Failed to close connection2", e);
              }
            }
          };

      conn1.setExceptionListener(listener1);

      conn2.setExceptionListener(listener1);

      Failer f1 = new Failer(rc1);

      Failer f2 = new Failer(rc2);

      f1.start();

      f2.start();

      f1.join();

      f2.join();

      conn1.close();

      conn2.close();
    }
  }
  @Override
  protected void tearDown() throws Exception {

    try {
      jmsServer2.stop();

      server2.stop();

      context2.close();
    } catch (Throwable e) {
      log.warn("Can't stop server2", e);
    }

    ((HornetQConnectionFactory) cf1).close();

    ((HornetQConnectionFactory) cf2).close();

    server2 = null;

    jmsServer2 = null;

    context2 = null;

    cf1 = null;

    try {
      jmsServer1.stop();

      server1.stop();

      context1.close();
    } catch (Throwable e) {
      log.warn("Can't stop server2", e);
    }

    server1 = null;

    jmsServer1 = null;

    context1 = null;

    super.tearDown();
  }
  @Test
  public void testListConsumers() throws Exception {

    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("host", TestSuiteEnvironment.getServerAddress());
    TransportConfiguration transportConfiguration =
        new TransportConfiguration(NettyConnectorFactory.class.getName(), map);
    HornetQConnectionFactory cf =
        HornetQJMSClient.createConnectionFactoryWithoutHA(
            JMSFactoryType.CF, transportConfiguration);
    cf.setClientID("consumer");
    consumerConn = cf.createQueueConnection("guest", "guest");
    consumerConn.start();
    consumerSession = consumerConn.createQueueSession(false, TopicSession.AUTO_ACKNOWLEDGE);

    ModelNode result = execute(getQueueOperation("list-consumers-as-json"), true);
    Assert.assertTrue(result.isDefined());
    Assert.assertEquals(ModelType.STRING, result.getType());
  }
  @Before
  public void addTopic() throws Exception {

    count++;
    adminSupport.createJmsQueue(getQueueName(), getQueueJndiName());
    adminSupport.createJmsQueue(getOtherQueueName(), getOtherQueueJndiName());
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("host", TestSuiteEnvironment.getServerAddress());
    TransportConfiguration transportConfiguration =
        new TransportConfiguration(NettyConnectorFactory.class.getName(), map);
    HornetQConnectionFactory cf =
        HornetQJMSClient.createConnectionFactoryWithoutHA(
            JMSFactoryType.CF, transportConfiguration);
    cf.setClientID("sender");
    conn = cf.createQueueConnection("guest", "guest");
    conn.start();
    queue = HornetQJMSClient.createQueue(getQueueName());
    otherQueue = HornetQJMSClient.createQueue(getOtherQueueName());
    session = conn.createQueueSession(false, TopicSession.AUTO_ACKNOWLEDGE);
  }
  @After
  public void tearDown() {
    try {
      if (session != null) {
        session.close();
      }

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

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

    } catch (JMSException e) {
      e.printStackTrace();
    }
  }
Example #13
0
  // https://jira.jboss.org/jira/browse/JBMESSAGING-1703
  // Make sure that failing a connection removes it from the connection manager and can't be
  // returned in a subsequent
  // call
  public void testUsingDeadConnection() throws Exception {
    for (int i = 0; i < 100; i++) {
      final Connection conn1 = cf1.createConnection();

      Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
      RemotingConnection rc1 =
          ((ClientSessionInternal) ((HornetQSession) sess1).getCoreSession()).getConnection();

      rc1.fail(new HornetQException(HornetQException.NOT_CONNECTED, "blah"));

      try {
        conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        fail("should throw exception");
      } catch (JMSException e) {
        // pass
      }

      conn1.close();
    }
  }
  @Test
  public void testAutomaticFailover() throws Exception {
    HornetQConnectionFactory jbcf =
        HornetQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, livetc);
    jbcf.setReconnectAttempts(-1);
    jbcf.setBlockOnDurableSend(true);
    jbcf.setBlockOnNonDurableSend(true);

    // Note we set consumer window size to a value so we can verify that consumer credit re-sending
    // works properly on failover
    // The value is small enough that credits will have to be resent several time

    final int numMessages = 10;

    final int bodySize = 1000;

    jbcf.setConsumerWindowSize(numMessages * bodySize / 10);

    HornetQConnection conn = JMSUtil.createConnectionAndWaitForTopology(jbcf, 2, 5);

    MyFailoverListener listener = new MyFailoverListener();

    conn.setFailoverListener(listener);

    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

    ClientSession coreSession = ((HornetQSession) sess).getCoreSession();

    SimpleString jmsQueueName =
        new SimpleString(HornetQDestination.JMS_QUEUE_ADDRESS_PREFIX + "myqueue");

    coreSession.createQueue(jmsQueueName, jmsQueueName, null, true);

    Queue queue = sess.createQueue("myqueue");

    MessageProducer producer = sess.createProducer(queue);

    producer.setDeliveryMode(DeliveryMode.PERSISTENT);

    MessageConsumer consumer = sess.createConsumer(queue);

    byte[] body = RandomUtil.randomBytes(bodySize);

    for (int i = 0; i < numMessages; i++) {
      BytesMessage bm = sess.createBytesMessage();

      bm.writeBytes(body);

      producer.send(bm);
    }

    conn.start();

    JMSFailoverListenerTest.log.info("sent messages and started connection");

    Thread.sleep(2000);

    JMSUtil.crash(liveService, ((HornetQSession) sess).getCoreSession());

    Assert.assertEquals(FailoverEventType.FAILURE_DETECTED, listener.getEventTypeList().get(0));
    for (int i = 0; i < numMessages; i++) {
      JMSFailoverListenerTest.log.info("got message " + i);

      BytesMessage bm = (BytesMessage) consumer.receive(1000);

      Assert.assertNotNull(bm);

      Assert.assertEquals(body.length, bm.getBodyLength());
    }

    TextMessage tm = (TextMessage) consumer.receiveNoWait();

    Assert.assertNull(tm);
    Assert.assertEquals(FailoverEventType.FAILOVER_COMPLETED, listener.getEventTypeList().get(1));

    conn.close();
    Assert.assertEquals(
        "Expected 2 FailoverEvents to be triggered", 2, listener.getEventTypeList().size());
  }
  public void testDeployFullConfiguration2() throws Exception {
    JMSServerDeployer deployer = new JMSServerDeployer(jmsServer, deploymentManager);

    String conf = "hornetq-jms-for-JMSServerDeployerTest2.xml";
    URI confURL = Thread.currentThread().getContextClassLoader().getResource(conf).toURI();

    String[] connectionFactoryBindings =
        new String[] {
          "/fullConfigurationConnectionFactory",
          "/acme/fullConfigurationConnectionFactory",
          "java:/xyz/tfullConfigurationConnectionFactory",
          "java:/connectionfactories/acme/fullConfigurationConnectionFactory"
        };
    String[] queueBindings =
        new String[] {"/fullConfigurationQueue", "/queue/fullConfigurationQueue"};
    String[] topicBindings =
        new String[] {"/fullConfigurationTopic", "/topic/fullConfigurationTopic"};

    for (String binding : connectionFactoryBindings) {
      UnitTestCase.checkNoBinding(context, binding);
    }
    for (String binding : queueBindings) {
      UnitTestCase.checkNoBinding(context, binding);
    }
    for (String binding : topicBindings) {
      UnitTestCase.checkNoBinding(context, binding);
    }

    deployer.deploy(confURL);

    for (String binding : connectionFactoryBindings) {
      UnitTestCase.checkBinding(context, binding);
    }
    for (String binding : queueBindings) {
      UnitTestCase.checkBinding(context, binding);
    }
    for (String binding : topicBindings) {
      UnitTestCase.checkBinding(context, binding);
    }

    for (String binding : connectionFactoryBindings) {
      HornetQConnectionFactory cf = (HornetQConnectionFactory) context.lookup(binding);
      Assert.assertNotNull(cf);
      Assert.assertEquals(1234, cf.getClientFailureCheckPeriod());
      Assert.assertEquals(5678, cf.getCallTimeout());
      Assert.assertEquals(12345, cf.getConsumerWindowSize());
      Assert.assertEquals(6789, cf.getConsumerMaxRate());
      Assert.assertEquals(123456, cf.getConfirmationWindowSize());
      Assert.assertEquals(7712652, cf.getProducerWindowSize());
      Assert.assertEquals(789, cf.getProducerMaxRate());
      Assert.assertEquals(12, cf.getMinLargeMessageSize());
      Assert.assertEquals("TestClientID", cf.getClientID());
      Assert.assertEquals(3456, cf.getDupsOKBatchSize());
      Assert.assertEquals(4567, cf.getTransactionBatchSize());
      Assert.assertEquals(true, cf.isBlockOnAcknowledge());
      Assert.assertEquals(false, cf.isBlockOnNonDurableSend());
      Assert.assertEquals(true, cf.isBlockOnDurableSend());
      Assert.assertEquals(false, cf.isAutoGroup());
      Assert.assertEquals(true, cf.isPreAcknowledge());
      Assert.assertEquals(2345, cf.getConnectionTTL());
      assertEquals(true, cf.isFailoverOnInitialConnection());
      Assert.assertEquals(34, cf.getReconnectAttempts());
      Assert.assertEquals(5, cf.getRetryInterval());
      Assert.assertEquals(6.0, cf.getRetryIntervalMultiplier());
      Assert.assertEquals(true, cf.isCacheLargeMessagesClient());
    }

    for (String binding : queueBindings) {
      Queue queue = (Queue) context.lookup(binding);
      Assert.assertNotNull(queue);
      Assert.assertEquals("fullConfigurationQueue", queue.getQueueName());
    }

    for (String binding : topicBindings) {
      Topic topic = (Topic) context.lookup(binding);
      Assert.assertNotNull(topic);
      Assert.assertEquals("fullConfigurationTopic", topic.getTopicName());
    }
  }
  @Test
  public void testManualFailover() throws Exception {
    HornetQConnectionFactory jbcfLive =
        HornetQJMSClient.createConnectionFactoryWithoutHA(
            JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));

    jbcfLive.setBlockOnNonDurableSend(true);
    jbcfLive.setBlockOnDurableSend(true);

    HornetQConnectionFactory jbcfBackup =
        HornetQJMSClient.createConnectionFactoryWithoutHA(
            JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY, backupParams));
    jbcfBackup.setBlockOnNonDurableSend(true);
    jbcfBackup.setBlockOnDurableSend(true);
    jbcfBackup.setInitialConnectAttempts(-1);
    jbcfBackup.setReconnectAttempts(-1);

    HornetQConnection connLive = (HornetQConnection) jbcfLive.createConnection();

    MyFailoverListener listener = new MyFailoverListener();

    connLive.setFailoverListener(listener);

    Session sessLive = connLive.createSession(false, Session.AUTO_ACKNOWLEDGE);

    ClientSession coreSessionLive = ((HornetQSession) sessLive).getCoreSession();

    SimpleString jmsQueueName =
        new SimpleString(HornetQDestination.JMS_QUEUE_ADDRESS_PREFIX + "myqueue");

    coreSessionLive.createQueue(jmsQueueName, jmsQueueName, null, true);

    Queue queue = sessLive.createQueue("myqueue");

    final int numMessages = 1000;

    MessageProducer producerLive = sessLive.createProducer(queue);

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

      producerLive.send(tm);
    }

    // Note we block on P send to make sure all messages get to server before failover

    JMSUtil.crash(liveService, coreSessionLive);
    Assert.assertEquals(FailoverEventType.FAILURE_DETECTED, listener.getEventTypeList().get(0));
    connLive.close();

    // Now recreate on backup

    Connection connBackup = jbcfBackup.createConnection();

    Session sessBackup = connBackup.createSession(false, Session.AUTO_ACKNOWLEDGE);

    MessageConsumer consumerBackup = sessBackup.createConsumer(queue);

    connBackup.start();

    for (int i = 0; i < numMessages; i++) {
      TextMessage tm = (TextMessage) consumerBackup.receive(1000);

      Assert.assertNotNull(tm);

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

    TextMessage tm = (TextMessage) consumerBackup.receiveNoWait();
    Assert.assertEquals(FailoverEventType.FAILOVER_FAILED, listener.getEventTypeList().get(1));
    Assert.assertEquals(
        "Expected 2 FailoverEvents to be triggered", 2, listener.getEventTypeList().size());
    Assert.assertNull(tm);

    connBackup.close();
  }
  public void doTestStressSend(final boolean netty) throws Exception {
    // first set up the server
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(TransportConstants.PORT_PROP_NAME, 5445);
    params.put(TransportConstants.HOST_PROP_NAME, "localhost");
    params.put(TransportConstants.USE_NIO_PROP_NAME, true);
    // minimize threads to maximize possibility for deadlock
    params.put(TransportConstants.NIO_REMOTING_THREADS_PROPNAME, 1);
    params.put(TransportConstants.BATCH_DELAY, 50);
    Configuration config = createDefaultConfig(params, ServiceTestBase.NETTY_ACCEPTOR_FACTORY);
    HornetQServer server = createServer(true, config);
    server.getConfiguration().setThreadPoolMaxSize(2);
    server.start();

    // now the client side
    Map<String, Object> connectionParams = new HashMap<String, Object>();
    connectionParams.put(TransportConstants.PORT_PROP_NAME, 5445);
    connectionParams.put(TransportConstants.HOST_PROP_NAME, "localhost");
    connectionParams.put(TransportConstants.USE_NIO_PROP_NAME, true);
    connectionParams.put(TransportConstants.BATCH_DELAY, 50);
    connectionParams.put(TransportConstants.NIO_REMOTING_THREADS_PROPNAME, 6);
    final TransportConfiguration transpConf =
        new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams);
    final ServerLocator locator = createNonHALocator(netty);

    // each thread will do this number of transactions
    final int numberOfMessages = 100;

    // these must all be the same
    final int numProducers = 30;
    final int numConsumerProducers = 30;
    final int numConsumers = 30;

    // each produce, consume+produce and consume increments this counter
    final AtomicInteger totalCount = new AtomicInteger(0);

    // the total we expect if all producers, consumer-producers and
    // consumers complete normally
    int totalExpectedCount =
        (numProducers + numConsumerProducers + numConsumerProducers) * numberOfMessages;

    // each group gets a separate connection
    final Connection connectionProducer;
    final Connection connectionConsumerProducer;
    final Connection connectionConsumer;

    // create the 2 queues used in the test
    ClientSessionFactory sf = locator.createSessionFactory(transpConf);
    ClientSession session = sf.createTransactedSession();
    session.createQueue("jms.queue.queue", "jms.queue.queue");
    session.createQueue("jms.queue.queue2", "jms.queue.queue2");
    session.commit();
    sf.close();
    session.close();
    locator.close();

    // create and start JMS connections
    HornetQConnectionFactory cf =
        HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, transpConf);
    connectionProducer = cf.createConnection();
    connectionProducer.start();

    connectionConsumerProducer = cf.createConnection();
    connectionConsumerProducer.start();

    connectionConsumer = cf.createConnection();
    connectionConsumer.start();

    // these threads produce messages on the the first queue
    for (int i = 0; i < numProducers; i++) {
      new Thread() {
        @Override
        public void run() {

          Session session = null;
          try {
            session = connectionProducer.createSession(true, Session.SESSION_TRANSACTED);
            MessageProducer messageProducer =
                session.createProducer(HornetQDestination.createQueue("queue"));
            messageProducer.setDeliveryMode(DeliveryMode.PERSISTENT);

            for (int i = 0; i < numberOfMessages; i++) {
              BytesMessage message = session.createBytesMessage();
              message.writeBytes(new byte[3000]);
              message.setStringProperty("Service", "LoadShedService");
              message.setStringProperty("Action", "testAction");

              messageProducer.send(message);
              session.commit();

              totalCount.incrementAndGet();
            }
          } catch (Exception e) {
            throw new RuntimeException(e);
          } finally {
            if (session != null) {
              try {
                session.close();
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          }
        }
      }.start();
    }

    // these threads just consume from the one and produce on a second queue
    for (int i = 0; i < numConsumerProducers; i++) {
      new Thread() {
        @Override
        public void run() {
          Session session = null;
          try {
            session = connectionConsumerProducer.createSession(true, Session.SESSION_TRANSACTED);
            MessageConsumer consumer =
                session.createConsumer(HornetQDestination.createQueue("queue"));
            MessageProducer messageProducer =
                session.createProducer(HornetQDestination.createQueue("queue2"));
            messageProducer.setDeliveryMode(DeliveryMode.PERSISTENT);
            for (int i = 0; i < numberOfMessages; i++) {
              BytesMessage message = (BytesMessage) consumer.receive(5000);
              if (message == null) {
                return;
              }
              message = session.createBytesMessage();
              message.writeBytes(new byte[3000]);
              message.setStringProperty("Service", "LoadShedService");
              message.setStringProperty("Action", "testAction");
              messageProducer.send(message);
              session.commit();

              totalCount.incrementAndGet();
            }
          } catch (Exception e) {
            throw new RuntimeException(e);
          } finally {
            if (session != null) {
              try {
                session.close();
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          }
        }
      }.start();
    }

    // these threads consume from the second queue
    for (int i = 0; i < numConsumers; i++) {
      new Thread() {
        @Override
        public void run() {
          Session session = null;
          try {
            session = connectionConsumer.createSession(true, Session.SESSION_TRANSACTED);
            MessageConsumer consumer =
                session.createConsumer(HornetQDestination.createQueue("queue2"));
            for (int i = 0; i < numberOfMessages; i++) {
              BytesMessage message = (BytesMessage) consumer.receive(5000);
              if (message == null) {
                return;
              }
              session.commit();

              totalCount.incrementAndGet();
            }
          } catch (Exception e) {
            throw new RuntimeException(e);
          } finally {
            if (session != null) {
              try {
                session.close();
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          }
        }
      }.start();
    }

    // check that the overall transaction count reaches the expected number,
    // which would indicate that the system didn't stall
    int timeoutCounter = 0;
    int maxSecondsToWait = 60;
    while (timeoutCounter < maxSecondsToWait && totalCount.get() < totalExpectedCount) {
      timeoutCounter++;
      Thread.sleep(1000);
      System.out.println(
          "Not done yet.. " + (maxSecondsToWait - timeoutCounter) + "; " + totalCount.get());
    }
    System.out.println("Done.." + totalCount.get() + ", expected " + totalExpectedCount);
    Assert.assertEquals("Possible deadlock", totalExpectedCount, totalCount.get());
    System.out.println("After assert");

    // attempt cleaning up (this is not in a finally, still needs some work)
    connectionProducer.close();
    connectionConsumerProducer.close();
    connectionConsumer.close();

    server.stop();
  }