예제 #1
0
  /**
   * Basic fail-back test.
   *
   * @throws Exception
   */
  @Test
  public void testFailBack() throws Exception {
    createSessionFactory();
    ClientSession session = sendAndConsume(sf, true);

    ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);

    sendMessages(session, producer, NUM_MESSAGES);
    session.commit();

    crash(session);

    session.start();
    ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
    receiveMessages(consumer, 0, NUM_MESSAGES, true);
    producer = session.createProducer(FailoverTestBase.ADDRESS);
    sendMessages(session, producer, 2 * NUM_MESSAGES);
    session.commit();
    assertFalse("must NOT be a backup", liveServer.getServer().getConfiguration().isBackup());
    adaptLiveConfigForReplicatedFailBack(liveServer.getServer().getConfiguration());

    CountDownSessionFailureListener listener = new CountDownSessionFailureListener();
    session.addFailureListener(listener);

    liveServer.start();

    assertTrue(listener.getLatch().await(5, TimeUnit.SECONDS));
    assertTrue(
        "live initialized after restart",
        liveServer.getServer().waitForActivation(15, TimeUnit.SECONDS));

    session.start();
    receiveMessages(consumer, 0, NUM_MESSAGES, true);
  }
예제 #2
0
  @Test
  public void testLargeMessageCompression2() throws Exception {
    final int messageSize = (int) (3.5 * HornetQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);

    HornetQServer server = createServer(true, isNetty());

    server.start();

    ClientSessionFactory sf = createSessionFactory(locator);

    ClientSession session = addClientSession(sf.createSession(false, false, false));

    session.createTemporaryQueue(ADDRESS, ADDRESS);

    ClientProducer producer = session.createProducer(ADDRESS);

    Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);

    producer.send(clientFile);

    session.commit();

    session.start();

    ClientConsumer consumer = session.createConsumer(ADDRESS);
    ClientMessage msg1 = consumer.receive(1000);
    Assert.assertNotNull(msg1);

    String testDir = getTestDir();
    File testFile = new File(testDir, "async_large_message");
    FileOutputStream output = new FileOutputStream(testFile);

    msg1.setOutputStream(output);

    msg1.waitOutputStreamCompletion(0);

    msg1.acknowledge();

    output.close();

    session.commit();

    consumer.close();

    session.close();

    // verify
    FileInputStream input = new FileInputStream(testFile);
    for (int i = 0; i < messageSize; i++) {
      byte b = (byte) input.read();
      assertEquals("position = " + i, getSamplebyte(i), b);
    }
    input.close();
    testFile.delete();
    validateNoFilesOnLargeDir();
  }
예제 #3
0
  // https://jira.jboss.org/jira/browse/HORNETQ-111
  // Test that, on rollback credits are released for messages cleared in the buffer
  public void testConsumerCreditsOnRollbackLargeMessages() throws Exception {

    locator.setConsumerWindowSize(10000);
    locator.setMinLargeMessageSize(1000);

    ClientSessionFactory sf = createSessionFactory(locator);

    ClientSession session = sf.createTransactedSession();

    session.createQueue(QUEUE, QUEUE, null, false);

    ClientProducer producer = session.createProducer(QUEUE);

    final int numMessages = 100;

    final byte[] bytes = new byte[10000];

    for (int i = 0; i < numMessages; i++) {
      ClientMessage message = session.createMessage(false);

      message.getBodyBuffer().writeBytes(bytes);

      message.putIntProperty("count", i);

      producer.send(message);
    }

    session.commit();

    ClientConsumer consumer = session.createConsumer(QUEUE);
    session.start();

    for (int i = 0; i < 110; i++) {
      ClientMessage message = consumer.receive();

      int count = message.getIntProperty("count");

      boolean redelivered = message.getDeliveryCount() > 1;

      if (count % 2 == 0 && !redelivered) {
        session.rollback();
      } else {
        session.commit();
      }
    }

    session.close();
  }
예제 #4
0
  private void receiveMessages() throws Exception {
    ClientSession session = sf.createSession(true, true);
    session.start();
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    for (int i = 0; i < numMessages; i++) {
      ClientMessage message = consumer.receive(100);
      assertNotNull("Expecting a message " + i, message);
      assertMessageBody(i, message);
      assertEquals(i, message.getIntProperty("int").intValue());
      assertEquals((short) i, message.getShortProperty("short").shortValue());
      assertEquals((byte) i, message.getByteProperty("byte").byteValue());
      assertEquals(floatValue(i), message.getFloatProperty("float").floatValue(), 0.001);
      assertEquals(
          new SimpleString(Integer.toString(i)),
          message.getSimpleStringProperty(SIMPLE_STRING_KEY.toString()));
      assertEqualsByteArrays(byteArray(i), message.getBytesProperty("byte[]"));

      assertTrue(message.containsProperty("null-value"));
      assertEquals(message.getObjectProperty("null-value"), null);

      message.acknowledge();
    }
    assertNull("no more messages", consumer.receive(50));
    consumer.close();
    session.commit();
  }
예제 #5
0
  /**
   * This would force a journal duplication on bindings even with the scenario that generated fixed,
   * the server shouldn't hold of from starting
   *
   * @throws Exception
   */
  @Test
  public void testForceDuplicationOnBindings() throws Exception {
    queue = server.createQueue(QUEUE, QUEUE, null, true, false);

    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession(false, false, false);

    ClientProducer producer = session.createProducer(QUEUE);

    producer.send(session.createMessage(true));
    session.commit();

    long queueID = server.getStorageManager().generateUniqueID();
    long txID = server.getStorageManager().generateUniqueID();

    // Forcing a situation where the server would unexpectedly create a duplicated queue. The server
    // should still start normally
    LocalQueueBinding newBinding =
        new LocalQueueBinding(
            QUEUE,
            new QueueImpl(queueID, QUEUE, QUEUE, null, true, false, null, null, null, null, null),
            server.getNodeID());
    server.getStorageManager().addQueueBinding(txID, newBinding);
    server.getStorageManager().commitBindings(txID);

    server.stop();

    // a duplicate binding would impede the server from starting
    server.start();
    waitForServer(server);

    server.stop();
  }
예제 #6
0
  public void sendMessages(final int start, final int end) throws Exception {
    ClientSession session = null;
    try {

      session = factory.createSession(false, false);

      try {
        session.createQueue(QUEUE, QUEUE, true);
      } catch (Exception ignored) {
      }

      ClientProducer prod = session.createProducer(QUEUE);

      for (int i = start; i < end; i++) {
        ClientMessage msg = session.createMessage(true);
        msg.putIntProperty(new SimpleString("key"), i);
        msg.getBodyBuffer().writeUTF("message " + i);
        prod.send(msg);
      }

      session.commit();
      session.close();
      // server.stop(); -- this test was not supposed to stop the server, it should crash
    } finally {
      session.close();
    }
  }
    @Override
    public void run() {
      try {
        if (shareConnectionFactory) {
          session = sharedSf.createSession(false, false);
        } else {
          locator = createInVMNonHALocator();
          sf = createSessionFactory(locator);
          session = sf.createSession(false, false);
        }

        ClientProducer prod = session.createProducer(MultipleConsumersPageStressTest.ADDRESS);

        int count = 0;

        while (enabled()) {
          int numberOfMessages = getNumberOfMessages();

          for (int i = 0; i < numberOfMessages; i++) {
            ClientMessage msg = session.createMessage(true);
            msg.putStringProperty("Test", "This is a simple test");
            msg.putIntProperty("count", count++);
            prod.send(msg);
          }

          messagesAvailable.addAndGet(numberOfMessages);
          session.commit();
        }
      } catch (Throwable e) {
        exceptionHappened(e);
      }
    }
예제 #8
0
 protected void callCommit() throws Exception {
   pendingCommit = true;
   session.commit(activeXid, false);
   pendingCommit = false;
   activeXid = null;
   onCommit();
 }
예제 #9
0
  // An exception during delivery shouldn't make the message disappear
  @Test
  public void testExceptionWhileDelivering() throws Exception {
    queue = server.createQueue(QUEUE, QUEUE, null, true, false);

    HangInterceptor hangInt = new HangInterceptor();
    try {
      locator.addInterceptor(hangInt);

      ClientSessionFactory factory = locator.createSessionFactory();
      ClientSession session = factory.createSession(false, false, false);

      ClientProducer producer = session.createProducer(QUEUE);

      ClientConsumer consumer = session.createConsumer(QUEUE);

      producer.send(session.createMessage(true));
      session.commit();

      hangInt.close();

      session.start();

      Assert.assertTrue(hangInt.reusableLatch.await(10, TimeUnit.SECONDS));

      hangInt.pendingException = new HornetQException();

      hangInt.open();

      session.close();

      session = factory.createSession(false, false);
      session.start();

      consumer = session.createConsumer(QUEUE);

      ClientMessage msg = consumer.receive(5000);
      Assert.assertNotNull(msg);
      msg.acknowledge();

      session.commit();
    } finally {
      hangInt.open();
    }
  }
예제 #10
0
    private boolean checkCommit(final ClientSession session) throws Exception {
      if (perfParams.isSessionTransacted()) {
        if (count.longValue() % perfParams.getBatchSize() == 0) {
          session.commit();

          return true;
        }
      }
      return false;
    }
예제 #11
0
  @Test
  public void testLargeMessageCompression() throws Exception {
    final int messageSize = (int) (3.5 * HornetQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);

    HornetQServer server = createServer(true, isNetty());

    server.start();

    ClientSessionFactory sf = createSessionFactory(locator);

    ClientSession session = addClientSession(sf.createSession(false, false, false));

    session.createTemporaryQueue(ADDRESS, ADDRESS);

    ClientProducer producer = session.createProducer(ADDRESS);

    Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);

    producer.send(clientFile);

    session.commit();

    session.start();

    ClientConsumer consumer = session.createConsumer(ADDRESS);
    ClientMessage msg1 = consumer.receive(1000);
    Assert.assertNotNull(msg1);

    for (int i = 0; i < messageSize; i++) {
      byte b = msg1.getBodyBuffer().readByte();
      assertEquals("position = " + i, getSamplebyte(i), b);
    }

    msg1.acknowledge();
    session.commit();

    consumer.close();

    session.close();

    validateNoFilesOnLargeDir();
  }
예제 #12
0
  @Test
  public void testDelayedRedeliveryDefaultOnRollback() throws Exception {
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    ClientSession session = sessionFactory.createSession(false, false, false);

    session.createQueue(qName, qName, null, true);
    session.close();

    ClientSession session1 = sessionFactory.createSession(false, true, true);
    ClientProducer producer = session1.createProducer(qName);

    final int NUM_MESSAGES = 5;

    for (int i = 0; i < NUM_MESSAGES; i++) {
      ClientMessage tm = createDurableMessage(session1, "message" + i);
      producer.send(tm);
    }
    session1.close();

    ClientSession session2 = sessionFactory.createSession(false, false, false);
    ClientConsumer consumer2 = session2.createConsumer(qName);

    session2.start();

    for (int i = 0; i < NUM_MESSAGES; i++) {
      ClientMessage tm = consumer2.receive(500);
      Assert.assertNotNull(tm);
      Assert.assertEquals("message" + i, tm.getBodyBuffer().readString());
    }

    // Now rollback
    long now = System.currentTimeMillis();

    session2.rollback();

    // This should redeliver with a delayed redelivery

    for (int i = 0; i < NUM_MESSAGES; i++) {
      ClientMessage tm = consumer2.receive(DelayedMessageTest.DELAY + 1000);
      Assert.assertNotNull(tm);

      long time = System.currentTimeMillis();

      Assert.assertTrue(time - now >= DelayedMessageTest.DELAY);

      // Hudson can introduce a large degree of indeterminism
      Assert.assertTrue(
          time - now + ">" + (DelayedMessageTest.DELAY + 1000),
          time - now < DelayedMessageTest.DELAY + 1000);
    }

    session2.commit();
    session2.close();
  }
예제 #13
0
  public void acknowledge() throws JMSException {
    if (session != null) {
      try {
        if (individualAck) {
          message.individualAcknowledge();
        }

        session.commit();
      } catch (HornetQException e) {
        throw JMSExceptionHelper.convertFromHornetQException(e);
      }
    }
  }
예제 #14
0
      @Override
      public void run() {
        ClientSession session = null;
        ClientSession sessionSlow = null;
        latchReady.countDown();
        try {
          UnitTestCase.waitForLatch(latchStart);
          session = sf.createSession(true, true);
          sessionSlow = sf.createSession(false, false);
          ClientProducer prod = session.createProducer(CompactingStressTest.AD2);
          ClientProducer slowProd = sessionSlow.createProducer(CompactingStressTest.AD1);
          for (int i = 0; i < NUMBER_OF_FAST_MESSAGES; i++) {
            if (i % SLOW_INTERVAL == 0) {
              if (numberOfMessages.incrementAndGet() % 5 == 0) {
                sessionSlow.commit();
              }
              slowProd.send(session.createMessage(true));
            }
            ClientMessage msg = session.createMessage(true);

            prod.send(msg);
          }
          sessionSlow.commit();
        } catch (Throwable e) {
          this.e = e;
        } finally {
          try {
            session.close();
          } catch (Throwable e) {
            this.e = e;
          }
          try {
            sessionSlow.close();
          } catch (Throwable e) {
            this.e = e;
          }
        }
      }
예제 #15
0
 /**
  * @throws Exception
  * @throws HornetQException
  */
 private void verifyMessageOnServer(final int server, final int numberOfMessages)
     throws Exception, HornetQException {
   ServerLocator backupLocator = createInVMLocator(server);
   ClientSessionFactory factorybkp = addSessionFactory(createSessionFactory(backupLocator));
   ClientSession sessionbkp = factorybkp.createSession(false, false);
   sessionbkp.start();
   ClientConsumer consumerbkp = sessionbkp.createConsumer(ADDRESS);
   for (int i = 0; i < numberOfMessages; i++) {
     ClientMessage msg = consumerbkp.receive(1000);
     assertNotNull(msg);
     msg.acknowledge();
     sessionbkp.commit();
   }
   sessionbkp.close();
   factorybkp.close();
   backupLocator.close();
 }
예제 #16
0
  private void sendMessages() throws Exception {
    ClientSession session = sf.createSession(true, true);
    session.createQueue(ADDRESS, ADDRESS, null, true);
    ClientProducer producer = session.createProducer(ADDRESS);

    for (int i = 0; i < numMessages; i++) {
      ClientMessage message = session.createMessage(true);
      setBody(i, message);
      message.putIntProperty("int", i);
      message.putShortProperty("short", (short) i);
      message.putByteProperty("byte", (byte) i);
      message.putFloatProperty("float", floatValue(i));
      message.putStringProperty(SIMPLE_STRING_KEY, new SimpleString(Integer.toString(i)));
      message.putBytesProperty("byte[]", byteArray(i));
      message.putObjectProperty("null-value", null);
      producer.send(message);
    }
    session.commit();
  }
예제 #17
0
  @Test
  public void testMultipleMessagesAfterRecovery() throws Exception {
    Xid xid = new XidImpl("bq1".getBytes(), 4, "gtid1".getBytes());
    ClientProducer producer = clientSessionXa.createProducer(address);
    SimpleString messageId1 = new SimpleString("SMID1");
    SimpleString messageId2 = new SimpleString("SMID2");
    clientSessionXa.start(xid, XAResource.TMNOFLAGS);
    ClientMessage m1 = createTextMessage(clientSession, "m1");
    m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, messageId1);
    ClientMessage m2 = createTextMessage(clientSession, "m2");
    m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, messageId2);
    ClientMessage m3 = createTextMessage(clientSession, "m3");
    m3.putStringProperty(Message.HDR_LAST_VALUE_NAME, messageId1);
    ClientMessage m4 = createTextMessage(clientSession, "m4");
    m4.putStringProperty(Message.HDR_LAST_VALUE_NAME, messageId2);
    producer.send(m1);
    producer.send(m2);
    producer.send(m3);
    producer.send(m4);
    clientSessionXa.end(xid, XAResource.TMSUCCESS);
    clientSessionXa.prepare(xid);

    clientSession.close();
    clientSessionXa.close();
    restartServer();

    clientSessionXa.commit(xid, false);
    ClientConsumer consumer = clientSession.createConsumer(qName1);
    clientSession.start();
    ClientMessage m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
  }
예제 #18
0
  @Test
  public void testGetNumberOfPages() throws Exception {
    session.close();
    server.stop();
    server.getConfiguration().setPersistenceEnabled(true);

    SimpleString address = RandomUtil.randomSimpleString();

    AddressSettings addressSettings = new AddressSettings();
    addressSettings.setPageSizeBytes(1024);
    addressSettings.setMaxSizeBytes(10 * 1024);
    final int NUMBER_MESSAGES_BEFORE_PAGING = 5;

    server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
    server.start();
    ServerLocator locator2 =
        HornetQClient.createServerLocatorWithoutHA(
            new TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY));
    addServerLocator(locator2);
    ClientSessionFactory sf2 = createSessionFactory(locator2);

    session = sf2.createSession(false, true, false);
    session.start();
    session.createQueue(address, address, true);

    QueueImpl serverQueue = (QueueImpl) server.locateQueue(address);

    ClientProducer producer = session.createProducer(address);

    for (int i = 0; i < NUMBER_MESSAGES_BEFORE_PAGING; i++) {
      ClientMessage msg = session.createMessage(true);
      msg.getBodyBuffer().writeBytes(new byte[512]);
      producer.send(msg);
    }
    session.commit();

    AddressControl addressControl = createManagementControl(address);
    Assert.assertEquals(0, addressControl.getNumberOfPages());

    ClientMessage msg = session.createMessage(true);
    msg.getBodyBuffer().writeBytes(new byte[512]);
    producer.send(msg);

    session.commit();
    Assert.assertEquals(1, addressControl.getNumberOfPages());

    msg = session.createMessage(true);
    msg.getBodyBuffer().writeBytes(new byte[512]);
    producer.send(msg);

    session.commit();
    Assert.assertEquals(1, addressControl.getNumberOfPages());

    msg = session.createMessage(true);
    msg.getBodyBuffer().writeBytes(new byte[512]);
    producer.send(msg);

    session.commit();

    Assert.assertEquals("# of pages is 2", 2, addressControl.getNumberOfPages());

    System.out.println("Address size=" + addressControl.getAddressSize());

    Assert.assertEquals(
        serverQueue.getPageSubscription().getPagingStore().getAddressSize(),
        addressControl.getAddressSize());
  }
  @Test
  public void testHighVolume() throws Exception {
    final String FILE_NAME = getTestDir() + "/export.out";

    final String QUEUE_NAME = "A1";
    HornetQServer server = createServer(true);
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession(false, false, false);

    session.createQueue(QUEUE_NAME, QUEUE_NAME, true);

    ClientProducer producer = session.createProducer(QUEUE_NAME);

    ClientMessage msg = session.createMessage(true);
    final int SIZE = 10240;
    final int COUNT = 20000;
    byte[] bodyTst = new byte[SIZE];
    for (int i = 0; i < SIZE; i++) {
      bodyTst[i] = (byte) (i + 1);
    }

    msg.getBodyBuffer().writeBytes(bodyTst);
    assertEquals(bodyTst.length, msg.getBodySize());

    for (int i = 0; i < COUNT; i++) {
      producer.send(msg);
      if (i % 500 == 0) session.commit();
      System.out.println("Sent " + i);
    }

    session.commit();

    session.close();
    locator.close();
    server.stop();

    System.out.println("Writing XML...");
    FileOutputStream xmlOutputStream = new FileOutputStream(FILE_NAME);
    BufferedOutputStream bufferOut = new BufferedOutputStream(xmlOutputStream);
    XmlDataExporter xmlDataExporter =
        new XmlDataExporter(
            bufferOut, getBindingsDir(), getJournalDir(), getPageDir(), getLargeMessagesDir());
    xmlDataExporter.writeXMLData();
    bufferOut.close();
    System.out.println("Done writing XML.");

    deleteDirectory(new File(getJournalDir()));
    deleteDirectory(new File(getBindingsDir()));
    deleteDirectory(new File(getPageDir()));
    deleteDirectory(new File(getLargeMessagesDir()));
    server.start();
    locator = createInVMNonHALocator();
    factory = locator.createSessionFactory();
    session = factory.createSession(false, false, true);
    ClientSession managementSession = factory.createSession(false, true, true);

    System.out.println("Reading XML...");
    FileInputStream xmlInputStream = new FileInputStream(FILE_NAME);
    XmlDataImporter xmlDataImporter =
        new XmlDataImporter(xmlInputStream, session, managementSession);
    xmlDataImporter.processXml();
    xmlInputStream.close();
    System.out.println("Done reading XML.");

    ClientConsumer consumer = session.createConsumer(QUEUE_NAME);
    session.start();

    for (int i = 0; i < COUNT; i++) {
      msg = consumer.receive(CONSUMER_TIMEOUT);
      System.out.println("Received " + i);
      Assert.assertNotNull(msg);
      assertEquals(msg.getBodySize(), bodyTst.length);
      byte[] bodyRead = new byte[bodyTst.length];
      msg.getBodyBuffer().readBytes(bodyRead);
      assertEqualsByteArrays(bodyTst, bodyRead);
    }

    session.close();
    locator.close();
    server.stop();
    File temp = new File(FILE_NAME);
    temp.delete();
  }
예제 #20
0
  public void doTestStressSend(final boolean netty) throws Exception {
    HornetQServer server = createServer(false, netty);
    server.start();
    ServerLocator locator = createNonHALocator(netty);
    ClientSessionFactory sf = createSessionFactory(locator);

    ClientSession session = null;

    final int batchSize = 2000;

    final int numberOfMessages = 100000;

    try {
      server.start();

      session = sf.createSession(false, false);

      session.createQueue("address", "queue");

      ClientProducer producer = session.createProducer("address");

      ClientMessage message = session.createMessage(false);

      message.getBodyBuffer().writeBytes(new byte[1024]);

      for (int i = 0; i < numberOfMessages; i++) {
        producer.send(message);
        if (i % batchSize == 0) {
          System.out.println("Sent " + i);
          session.commit();
        }
      }

      session.commit();

      session.close();

      session = sf.createSession(false, false);

      ClientConsumer consumer = session.createConsumer("queue");

      session.start();

      for (int i = 0; i < numberOfMessages; i++) {
        ClientMessage msg = consumer.receive(5000);
        Assert.assertNotNull(msg);
        msg.acknowledge();

        if (i % batchSize == 0) {
          System.out.println("Consumed " + i);
          session.commit();
        }
      }

      session.commit();
    } finally {
      if (session != null) {
        try {
          sf.close();
          session.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
      locator.close();
      server.stop();
    }
  }
예제 #21
0
  public void internalTestMultiProducer(final JournalType journalType) throws Throwable {

    setupServer(journalType);

    ClientSession session = sf.createSession(false, false);

    try {
      ClientProducer producer = session.createProducer(CompactingStressTest.AD3);

      ClientMessage msg = session.createMessage(true);

      for (int i = 0; i < CompactingStressTest.TOT_AD3; i++) {
        producer.send(msg);
        if (i % 100 == 0) {
          session.commit();
        }
      }

      session.commit();
    } finally {
      session.close();
    }

    server.stop();

    setupServer(journalType);

    final AtomicInteger numberOfMessages = new AtomicInteger(0);
    final int NUMBER_OF_FAST_MESSAGES = 100000;
    final int SLOW_INTERVAL = 100;

    final CountDownLatch latchReady = new CountDownLatch(2);
    final CountDownLatch latchStart = new CountDownLatch(1);

    class FastProducer extends Thread {
      Throwable e;

      FastProducer() {
        super("Fast-Thread");
      }

      @Override
      public void run() {
        ClientSession session = null;
        ClientSession sessionSlow = null;
        latchReady.countDown();
        try {
          UnitTestCase.waitForLatch(latchStart);
          session = sf.createSession(true, true);
          sessionSlow = sf.createSession(false, false);
          ClientProducer prod = session.createProducer(CompactingStressTest.AD2);
          ClientProducer slowProd = sessionSlow.createProducer(CompactingStressTest.AD1);
          for (int i = 0; i < NUMBER_OF_FAST_MESSAGES; i++) {
            if (i % SLOW_INTERVAL == 0) {
              if (numberOfMessages.incrementAndGet() % 5 == 0) {
                sessionSlow.commit();
              }
              slowProd.send(session.createMessage(true));
            }
            ClientMessage msg = session.createMessage(true);

            prod.send(msg);
          }
          sessionSlow.commit();
        } catch (Throwable e) {
          this.e = e;
        } finally {
          try {
            session.close();
          } catch (Throwable e) {
            this.e = e;
          }
          try {
            sessionSlow.close();
          } catch (Throwable e) {
            this.e = e;
          }
        }
      }
    }

    class FastConsumer extends Thread {
      Throwable e;

      FastConsumer() {
        super("Fast-Consumer");
      }

      @Override
      public void run() {
        ClientSession session = null;
        latchReady.countDown();
        try {
          UnitTestCase.waitForLatch(latchStart);
          session = sf.createSession(true, true);
          session.start();
          ClientConsumer cons = session.createConsumer(CompactingStressTest.Q2);
          for (int i = 0; i < NUMBER_OF_FAST_MESSAGES; i++) {
            ClientMessage msg = cons.receive(60 * 1000);
            msg.acknowledge();
          }

          Assert.assertNull(cons.receiveImmediate());
        } catch (Throwable e) {
          this.e = e;
        } finally {
          try {
            session.close();
          } catch (Throwable e) {
            this.e = e;
          }
        }
      }
    }

    FastConsumer f1 = new FastConsumer();
    f1.start();

    FastProducer p1 = new FastProducer();
    p1.start();

    UnitTestCase.waitForLatch(latchReady);
    latchStart.countDown();

    p1.join();

    if (p1.e != null) {
      throw p1.e;
    }

    f1.join();

    if (f1.e != null) {
      throw f1.e;
    }

    sf.close();

    server.stop();

    setupServer(journalType);

    ClientSession sess = null;

    try {

      sess = sf.createSession(true, true);

      ClientConsumer cons = sess.createConsumer(CompactingStressTest.Q1);

      sess.start();

      for (int i = 0; i < numberOfMessages.intValue(); i++) {
        ClientMessage msg = cons.receive(60000);
        Assert.assertNotNull(msg);
        msg.acknowledge();
      }

      Assert.assertNull(cons.receiveImmediate());

      cons.close();

      cons = sess.createConsumer(CompactingStressTest.Q2);

      Assert.assertNull(cons.receiveImmediate());

      cons.close();

      cons = sess.createConsumer(CompactingStressTest.Q3);

      for (int i = 0; i < CompactingStressTest.TOT_AD3; i++) {
        ClientMessage msg = cons.receive(60000);
        Assert.assertNotNull(msg);
        msg.acknowledge();
      }

      Assert.assertNull(cons.receiveImmediate());

    } finally {
      try {
        sess.close();
      } catch (Throwable ignored) {
      }
    }
  }
예제 #22
0
  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();
  }
예제 #23
0
  private void internalTestCleanup(final JournalType journalType) throws Throwable {
    setupServer(journalType);

    ClientSession session = sf.createSession(false, true, true);

    ClientProducer prod = session.createProducer(CompactingStressTest.AD1);

    for (int i = 0; i < 500; i++) {
      prod.send(session.createMessage(true));
    }

    session.commit();

    prod.close();

    ClientConsumer cons = session.createConsumer(CompactingStressTest.Q2);
    prod = session.createProducer(CompactingStressTest.AD2);

    session.start();

    for (int i = 0; i < 200; i++) {
      System.out.println("Iteration " + i);
      // Sending non transactionally, so it would test non transactional stuff on the journal
      for (int j = 0; j < 1000; j++) {
        Message msg = session.createMessage(true);
        msg.getBodyBuffer().writeBytes(new byte[1024]);

        prod.send(msg);
      }

      // I need to guarantee a roundtrip to the server, to make sure everything is persisted
      session.commit();

      for (int j = 0; j < 1000; j++) {
        ClientMessage msg = cons.receive(2000);
        Assert.assertNotNull(msg);
        msg.acknowledge();
      }

      // I need to guarantee a roundtrip to the server, to make sure everything is persisted
      session.commit();
    }

    Assert.assertNull(cons.receiveImmediate());

    session.close();

    server.stop();

    setupServer(journalType);

    server.start();

    session = sf.createSession(false, true, true);
    cons = session.createConsumer(CompactingStressTest.Q1);
    session.start();

    for (int i = 0; i < 500; i++) {
      ClientMessage msg = cons.receive(1000);
      Assert.assertNotNull(msg);
      msg.acknowledge();
    }

    Assert.assertNull(cons.receiveImmediate());

    prod = session.createProducer(CompactingStressTest.AD2);

    session.close();
  }
예제 #24
0
  @Test
  public void testLargeMessageCompressionRestartAndCheckSize() throws Exception {
    final int messageSize = 1024 * 1024;

    HornetQServer server = createServer(true, isNetty());

    server.start();

    ClientSessionFactory sf = createSessionFactory(locator);

    ClientSession session = addClientSession(sf.createSession(false, false, false));

    session.createQueue(ADDRESS, ADDRESS, true);

    ClientProducer producer = session.createProducer(ADDRESS);

    byte[] msgs = new byte[1024 * 1024];
    for (int i = 0; i < msgs.length; i++) {
      msgs[i] = RandomUtil.randomByte();
    }

    Message clientFile = createLargeClientMessage(session, msgs, true);

    producer.send(clientFile);

    session.commit();

    session.close();

    sf.close();

    locator.close();

    server.stop();

    server = createServer(true, isNetty());

    server.start();

    locator = createFactory(isNetty());

    sf = createSessionFactory(locator);

    session = sf.createSession();

    session.start();

    ClientConsumer consumer = session.createConsumer(ADDRESS);
    ClientMessage msg1 = consumer.receive(1000);
    Assert.assertNotNull(msg1);

    assertEquals(messageSize, msg1.getBodySize());

    String testDir = getTestDir();
    File testFile = new File(testDir, "async_large_message");
    FileOutputStream output = new FileOutputStream(testFile);

    msg1.saveToOutputStream(output);

    msg1.acknowledge();

    session.commit();

    consumer.close();

    session.close();

    // verify
    FileInputStream input = new FileInputStream(testFile);
    for (int i = 0; i < messageSize; i++) {
      byte b = (byte) input.read();
      assertEquals("position = " + i, msgs[i], b);
    }
    input.close();

    testFile.delete();
    validateNoFilesOnLargeDir();
  }
예제 #25
0
  // This test will send 1 Gig of spaces. There shouldn't be enough memory to uncompress the file in
  // memory
  // but this will make sure we can work through compressed channels on saving it to stream
  @Test
  public void testHugeStreamingSpacesCompressed() throws Exception {
    final long messageSize = 1024L * 1024L * 1024L;

    System.out.println("Message size = " + messageSize);

    HornetQServer server = createServer(true, isNetty());

    server.start();

    // big enough to hold the whole message compressed on a single message (about 1M on our tests)
    locator.setMinLargeMessageSize(100 * 1024 * 1024);

    ClientSessionFactory sf = createSessionFactory(locator);

    ClientSession session = addClientSession(sf.createSession(false, false, false));

    session.createQueue(ADDRESS, ADDRESS);

    ClientProducer producer = session.createProducer(ADDRESS);

    ClientMessage clientMessage = session.createMessage(true);

    clientMessage.setBodyInputStream(
        new InputStream() {
          private long count;

          private boolean closed = false;

          @Override
          public void close() throws IOException {
            super.close();
            closed = true;
          }

          @Override
          public int read() throws IOException {
            if (closed) {
              throw new IOException("Stream was closed");
            }

            if (count++ < messageSize) {
              return ' ';
            } else {
              return -1;
            }
          }
        });

    producer.send(clientMessage);

    session.commit();

    // this is to make sure the message was sent as a regular message (not taking a file on server)
    validateNoFilesOnLargeDir();

    session.start();

    ClientConsumer consumer = session.createConsumer(ADDRESS);
    ClientMessage msg1 = consumer.receive(1000);
    Assert.assertNotNull(msg1);

    final AtomicLong numberOfSpaces = new AtomicLong();

    msg1.saveToOutputStream(
        new OutputStream() {
          @Override
          public void write(int content) {
            if (content == ' ') {
              numberOfSpaces.incrementAndGet();
            }
          }
        });

    assertEquals(messageSize, numberOfSpaces.get());

    msg1.acknowledge();

    session.commit();

    session.close();
  }
예제 #26
0
  @Test
  public void testHangOnDelivery() throws Exception {
    queue = server.createQueue(QUEUE, QUEUE, null, true, false);
    try {

      ClientSessionFactory factory = locator.createSessionFactory();
      ClientSession sessionProducer = factory.createSession(false, false, false);

      ServerLocator consumerLocator = createInVMNonHALocator();
      ClientSessionFactory factoryConsumer = consumerLocator.createSessionFactory();
      ClientSession sessionConsumer = factoryConsumer.createSession();

      ClientProducer producer = sessionProducer.createProducer(QUEUE);

      ClientConsumer consumer = sessionConsumer.createConsumer(QUEUE);

      producer.send(sessionProducer.createMessage(true));

      blockConsumers();

      sessionProducer.commit();

      sessionConsumer.start();

      awaitBlocking();

      // this shouldn't lock
      producer.send(sessionProducer.createMessage(true));
      sessionProducer.commit();

      // These two operations should finish without the test hanging
      queue.getMessagesAdded(1);
      queue.getMessageCount(1);

      releaseConsumers();

      // a rollback to make sure everything will be reset on the deliveries
      // and that both consumers will receive each a message
      // this is to guarantee the server will have both consumers regsitered
      sessionConsumer.rollback();

      // a flush to guarantee any pending task is finished on flushing out delivery and pending msgs
      queue.flushExecutor();
      Assert.assertEquals(2, queue.getMessageCount());
      Assert.assertEquals(2, queue.getMessagesAdded());

      ClientMessage msg = consumer.receive(5000);
      Assert.assertNotNull(msg);
      msg.acknowledge();

      msg = consumer.receive(5000);
      Assert.assertNotNull(msg);
      msg.acknowledge();

      sessionProducer.commit();
      sessionConsumer.commit();

      sessionProducer.close();
      sessionConsumer.close();
    } finally {
      releaseConsumers();
    }
  }
예제 #27
0
  private void sendMessages(
      final int numberOfMessages,
      final int txBatchSize,
      final boolean durable,
      final boolean transacted,
      final boolean display,
      final int throttleRate,
      final int messageSize,
      final boolean useSendAcks)
      throws Exception {
    ClientSession session = null;

    try {
      session = factory.createSession(!transacted, !transacted);

      CountDownLatch theLatch = null;

      if (useSendAcks) {
        final CountDownLatch latch = new CountDownLatch(numberOfMessages);

        class MySendAckHandler implements SendAcknowledgementHandler {
          public void sendAcknowledged(Message message) {
            latch.countDown();
          }
        }

        session.setSendAcknowledgementHandler(new MySendAckHandler());

        theLatch = latch;
      }

      ClientProducer producer = session.createProducer(perfParams.getAddress());

      ClientMessage message = session.createMessage(durable);

      byte[] payload = PerfBase.randomByteArray(messageSize);

      message.getBodyBuffer().writeBytes(payload);

      final int modulo = 2000;

      TokenBucketLimiter tbl =
          throttleRate != -1 ? new TokenBucketLimiterImpl(throttleRate, false) : null;

      boolean committed = false;

      for (int i = 1; i <= numberOfMessages; i++) {
        producer.send(message);

        if (transacted) {
          if (i % txBatchSize == 0) {
            session.commit();
            committed = true;
          } else {
            committed = false;
          }
        }
        if (display && i % modulo == 0) {
          double duration = (1.0 * System.currentTimeMillis() - start) / 1000;
          PerfBase.log.info(String.format("sent %6d messages in %2.2fs", i, duration));
        }

        // log.info("sent message " + i);

        if (tbl != null) {
          tbl.limit();
        }
      }

      if (transacted && !committed) {
        session.commit();
      }

      session.close();

      if (useSendAcks) {
        theLatch.await();
      }
    } finally {
      if (session != null) {
        session.close();
      }
    }
  }
예제 #28
0
  /**
   * This would recreate the scenario where a queue was duplicated
   *
   * @throws Exception
   */
  @Test
  public void testHangDuplicateQueues() throws Exception {
    final Semaphore blocked = new Semaphore(1);
    final CountDownLatch latchDelete = new CountDownLatch(1);
    class MyQueueWithBlocking extends QueueImpl {

      /**
       * @param id
       * @param address
       * @param name
       * @param filter
       * @param pageSubscription
       * @param durable
       * @param temporary
       * @param scheduledExecutor
       * @param postOffice
       * @param storageManager
       * @param addressSettingsRepository
       * @param executor
       */
      public MyQueueWithBlocking(
          final long id,
          final SimpleString address,
          final SimpleString name,
          final Filter filter,
          final PageSubscription pageSubscription,
          final boolean durable,
          final boolean temporary,
          final ScheduledExecutorService scheduledExecutor,
          final PostOffice postOffice,
          final StorageManager storageManager,
          final HierarchicalRepository<AddressSettings> addressSettingsRepository,
          final Executor executor) {
        super(
            id,
            address,
            name,
            filter,
            pageSubscription,
            durable,
            temporary,
            scheduledExecutor,
            postOffice,
            storageManager,
            addressSettingsRepository,
            executor);
      }

      @Override
      public synchronized int deleteMatchingReferences(final int flushLimit, final Filter filter)
          throws Exception {
        latchDelete.countDown();
        blocked.acquire();
        blocked.release();
        return super.deleteMatchingReferences(flushLimit, filter);
      }
    }

    class LocalFactory extends QueueFactoryImpl {
      public LocalFactory(
          final ExecutorFactory executorFactory,
          final ScheduledExecutorService scheduledExecutor,
          final HierarchicalRepository<AddressSettings> addressSettingsRepository,
          final StorageManager storageManager) {
        super(executorFactory, scheduledExecutor, addressSettingsRepository, storageManager);
      }

      @Override
      public Queue createQueue(
          final long persistenceID,
          final SimpleString address,
          final SimpleString name,
          final Filter filter,
          final PageSubscription pageSubscription,
          final boolean durable,
          final boolean temporary) {
        queue =
            new MyQueueWithBlocking(
                persistenceID,
                address,
                name,
                filter,
                pageSubscription,
                durable,
                temporary,
                scheduledExecutor,
                postOffice,
                storageManager,
                addressSettingsRepository,
                executorFactory.getExecutor());
        return queue;
      }
    }

    LocalFactory queueFactory =
        new LocalFactory(
            server.getExecutorFactory(),
            server.getScheduledPool(),
            server.getAddressSettingsRepository(),
            server.getStorageManager());

    queueFactory.setPostOffice(server.getPostOffice());

    ((HornetQServerImpl) server).replaceQueueFactory(queueFactory);

    queue = server.createQueue(QUEUE, QUEUE, null, true, false);

    blocked.acquire();

    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession(false, false, false);

    ClientProducer producer = session.createProducer(QUEUE);

    producer.send(session.createMessage(true));
    session.commit();

    Thread tDelete =
        new Thread() {
          @Override
          public void run() {
            try {
              server.destroyQueue(QUEUE);
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        };

    tDelete.start();

    Assert.assertTrue(latchDelete.await(10, TimeUnit.SECONDS));

    try {
      server.createQueue(QUEUE, QUEUE, null, true, false);
    } catch (Exception expected) {
    }

    blocked.release();

    server.stop();

    tDelete.join();

    session.close();

    // a duplicate binding would impede the server from starting
    server.start();
    waitForServer(server);

    server.stop();
  }
예제 #29
0
  public void internalTestPage(final boolean transacted, final boolean failBeforeConsume)
      throws Exception {
    locator.setBlockOnNonDurableSend(true);
    locator.setBlockOnDurableSend(true);
    locator.setReconnectAttempts(-1);

    sf = createSessionFactoryAndWaitForTopology(locator, 2);
    session = sf.createSession(!transacted, !transacted, 0);

    session.createQueue(PagingFailoverTest.ADDRESS, PagingFailoverTest.ADDRESS, true);

    ClientProducer prod = session.createProducer(PagingFailoverTest.ADDRESS);

    final int TOTAL_MESSAGES = 2000;

    for (int i = 0; i < TOTAL_MESSAGES; i++) {
      if (transacted && i % 10 == 0) {
        session.commit();
      }
      ClientMessage msg = session.createMessage(true);
      msg.putIntProperty(new SimpleString("key"), i);
      prod.send(msg);
    }

    session.commit();

    if (failBeforeConsume) {
      crash(session);
      waitForBackup(null, 30);
    }

    session.close();

    session = sf.createSession(!transacted, !transacted, 0);

    session.start();

    ClientConsumer cons = session.createConsumer(PagingFailoverTest.ADDRESS);

    final int MIDDLE = TOTAL_MESSAGES / 2;

    for (int i = 0; i < MIDDLE; i++) {
      ClientMessage msg = cons.receive(20000);
      Assert.assertNotNull(msg);
      msg.acknowledge();
      if (transacted && i % 10 == 0) {
        session.commit();
      }
      Assert.assertEquals(i, msg.getObjectProperty(new SimpleString("key")));
    }

    session.commit();

    cons.close();

    Thread.sleep(1000);

    if (!failBeforeConsume) {
      crash(session);
      // failSession(session, latch);
    }

    session.close();

    session = sf.createSession(true, true, 0);

    cons = session.createConsumer(PagingFailoverTest.ADDRESS);

    session.start();

    for (int i = MIDDLE; i < TOTAL_MESSAGES; i++) {
      ClientMessage msg = cons.receive(5000);
      Assert.assertNotNull(msg);

      msg.acknowledge();
      int result = (Integer) msg.getObjectProperty(new SimpleString("key"));
      Assert.assertEquals(i, result);
    }
  }
    @Override
    public void run() {
      try {
        if (shareConnectionFactory) {
          session = sharedSf.createSession(false, false);
        } else {
          locator = createInVMNonHALocator();
          sf = createSessionFactory(locator);
          session = sf.createSession(false, false);
        }

        long timeOut = System.currentTimeMillis() + MultipleConsumersPageStressTest.TIME_TO_RUN;

        session.start();

        if (!openConsumerOnEveryLoop) {
          consumer = session.createConsumer(MultipleConsumersPageStressTest.ADDRESS);
        }

        int count = 0;

        while (enabled() && timeOut > System.currentTimeMillis()) {

          if (openConsumerOnEveryLoop) {
            consumer = session.createConsumer(MultipleConsumersPageStressTest.ADDRESS);
          }

          int numberOfMessages = getNumberOfMessages();

          for (int i = 0; i < numberOfMessages; i++) {
            ClientMessage msg = consumer.receive(10000);
            if (msg == null) {
              log.warn(
                  "msg "
                      + count
                      + " was null, currentBatchSize="
                      + numberOfMessages
                      + ", current msg being read="
                      + i);
            }
            Assert.assertNotNull(
                "msg "
                    + count
                    + " was null, currentBatchSize="
                    + numberOfMessages
                    + ", current msg being read="
                    + i,
                msg);

            if (numberOfConsumers == 1 && numberOfProducers == 1) {
              Assert.assertEquals(count, msg.getIntProperty("count").intValue());
            }

            count++;

            msg.acknowledge();
          }

          session.commit();

          if (openConsumerOnEveryLoop) {
            consumer.close();
          }
        }
      } catch (Throwable e) {
        exceptionHappened(e);
      }
    }