コード例 #1
0
  private void setupServer(final JournalType journalType) throws Exception, HornetQException {
    Configuration config = createDefaultConfig();
    config.setJournalSyncNonTransactional(false);
    config.setJournalFileSize(HornetQDefaultConfiguration.getDefaultJournalFileSize());

    config.setJournalType(journalType);

    config.setJournalCompactMinFiles(10);
    config.setJournalCompactPercentage(50);

    server = createServer(true, config);

    server.start();

    ServerLocator locator = createInVMNonHALocator();
    locator.setBlockOnDurableSend(false);
    locator.setBlockOnAcknowledge(false);

    sf = createSessionFactory(locator);
    ClientSession sess = addClientSession(sf.createSession());

    try {
      sess.createQueue(CompactingStressTest.AD1, CompactingStressTest.Q1, true);
    } catch (Exception ignored) {
    }

    try {
      sess.createQueue(CompactingStressTest.AD2, CompactingStressTest.Q2, true);
    } catch (Exception ignored) {
    }

    try {
      sess.createQueue(CompactingStressTest.AD3, CompactingStressTest.Q3, true);
    } catch (Exception ignored) {
    }

    sess.close();
  }
コード例 #2
0
  @Test
  public void testOrder1() throws Throwable {
    boolean persistentMessages = true;

    Configuration config = createDefaultConfig();

    config.setJournalSyncNonTransactional(false);

    HornetQServer server =
        createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());

    server.start();

    final int messageSize = 1024;

    final int numberOfMessages = 500;
    ServerLocator locator = createInVMNonHALocator();

    locator.setClientFailureCheckPeriod(1000);
    locator.setConnectionTTL(2000);
    locator.setReconnectAttempts(0);

    locator.setBlockOnNonDurableSend(true);
    locator.setBlockOnDurableSend(true);
    locator.setBlockOnAcknowledge(true);
    locator.setConsumerWindowSize(1024 * 1024);

    ClientSessionFactory sf = createSessionFactory(locator);

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

    server.createQueue(ADDRESS, ADDRESS, null, true, false);

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

    byte[] body = new byte[messageSize];

    ByteBuffer bb = ByteBuffer.wrap(body);

    for (int j = 1; j <= messageSize; j++) {
      bb.put(getSamplebyte(j));
    }

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

      HornetQBuffer bodyLocal = message.getBodyBuffer();

      bodyLocal.writeBytes(body);

      message.putIntProperty(new SimpleString("id"), i);

      producer.send(message);
      if (i % 1000 == 0) {
        session.commit();
      }
    }

    session.commit();

    session.close();

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

    session.start();

    ClientConsumer consumer = session.createConsumer(ADDRESS);

    for (int i = 0; i < numberOfMessages / 2; i++) {
      ClientMessage message = consumer.receive(5000);
      assertNotNull(message);
      assertEquals(i, message.getIntProperty("id").intValue());

      if (i < 100) {
        // Do not consume the last one so we could restart
        message.acknowledge();
      }
    }

    session.close();

    session = null;

    sf.close();
    sf = createSessionFactory(locator);

    locator = createInVMNonHALocator();

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

    session.start();

    consumer = session.createConsumer(ADDRESS);

    for (int i = 100; i < numberOfMessages; i++) {
      ClientMessage message = consumer.receive(5000);
      assertNotNull(message);
      assertEquals(i, message.getIntProperty("id").intValue());
      message.acknowledge();
    }

    session.close();
  }
コード例 #3
0
  @Test
  public void testPagingOverCreatedDestinationQueues() throws Exception {

    Configuration config = createDefaultConfig();

    config.setJournalSyncNonTransactional(false);

    HornetQServer server =
        createServer(
            true,
            config,
            -1,
            -1,
            AddressFullMessagePolicy.BLOCK,
            new HashMap<String, AddressSettings>());

    JMSServerManagerImpl jmsServer = new JMSServerManagerImpl(server);
    InVMNamingContext context = new InVMNamingContext();
    jmsServer.setContext(context);
    jmsServer.start();

    server
        .getHornetQServerControl()
        .addAddressSettings(
            "jms.queue.Q1",
            "DLQ",
            "DLQ",
            -1,
            false,
            5,
            100 * 1024,
            10 * 1024,
            5,
            5,
            1,
            1000,
            0,
            false,
            "PAGE",
            -1,
            10,
            "KILL");

    jmsServer.createQueue(true, "Q1", null, true, "/queue/Q1");

    HornetQJMSConnectionFactory cf =
        (HornetQJMSConnectionFactory)
            HornetQJMSClient.createConnectionFactoryWithoutHA(
                JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));

    conn = cf.createConnection();
    conn.setClientID("tst");
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    javax.jms.Queue queue = (javax.jms.Queue) context.lookup("/queue/Q1");

    MessageProducer prod = sess.createProducer(queue);
    prod.setDeliveryMode(DeliveryMode.PERSISTENT);
    BytesMessage bmt = sess.createBytesMessage();

    bmt.writeBytes(new byte[1024]);

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

    PagingStore store = server.getPagingManager().getPageStore(new SimpleString("jms.queue.Q1"));

    assertEquals(100 * 1024, store.getMaxSize());
    assertEquals(10 * 1024, store.getPageSizeBytes());
    assertEquals(AddressFullMessagePolicy.PAGE, store.getAddressFullMessagePolicy());

    jmsServer.stop();

    server =
        createServer(
            true,
            config,
            -1,
            -1,
            AddressFullMessagePolicy.BLOCK,
            new HashMap<String, AddressSettings>());

    jmsServer = new JMSServerManagerImpl(server);
    context = new InVMNamingContext();
    jmsServer.setContext(context);
    jmsServer.start();

    AddressSettings settings = server.getAddressSettingsRepository().getMatch("jms.queue.Q1");

    assertEquals(100 * 1024, settings.getMaxSizeBytes());
    assertEquals(10 * 1024, settings.getPageSizeBytes());
    assertEquals(AddressFullMessagePolicy.PAGE, settings.getAddressFullMessagePolicy());

    store = server.getPagingManager().getPageStore(new SimpleString("jms.queue.Q1"));
    assertEquals(100 * 1024, store.getMaxSize());
    assertEquals(10 * 1024, store.getPageSizeBytes());
    assertEquals(AddressFullMessagePolicy.PAGE, store.getAddressFullMessagePolicy());
  }
コード例 #4
0
  @Test
  public void testPagingOverCreatedDestinationTopics() throws Exception {

    Configuration config = createDefaultConfig();

    config.setJournalSyncNonTransactional(false);

    HornetQServer server =
        createServer(true, config, PAGE_SIZE, -1, new HashMap<String, AddressSettings>());

    JMSServerManagerImpl jmsServer = new JMSServerManagerImpl(server);
    InVMNamingContext context = new InVMNamingContext();
    jmsServer.setContext(context);
    jmsServer.start();

    jmsServer.createTopic(true, "tt", "/topic/TT");

    server
        .getHornetQServerControl()
        .addAddressSettings(
            "jms.topic.TT",
            "DLQ",
            "DLQ",
            -1,
            false,
            5,
            1024 * 1024,
            1024 * 10,
            5,
            5,
            1,
            1000,
            0,
            false,
            "PAGE",
            -1,
            10,
            "KILL");

    HornetQJMSConnectionFactory cf =
        (HornetQJMSConnectionFactory)
            HornetQJMSClient.createConnectionFactoryWithoutHA(
                JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));

    Connection conn = cf.createConnection();
    conn.setClientID("tst");
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic topic = (Topic) context.lookup("/topic/TT");
    sess.createDurableSubscriber(topic, "t1");

    MessageProducer prod = sess.createProducer(topic);
    prod.setDeliveryMode(DeliveryMode.PERSISTENT);
    TextMessage txt = sess.createTextMessage("TST");
    prod.send(txt);

    PagingStore store = server.getPagingManager().getPageStore(new SimpleString("jms.topic.TT"));

    assertEquals(1024 * 1024, store.getMaxSize());
    assertEquals(10 * 1024, store.getPageSizeBytes());

    jmsServer.stop();

    server = createServer(true, config, PAGE_SIZE, -1, new HashMap<String, AddressSettings>());

    jmsServer = new JMSServerManagerImpl(server);
    context = new InVMNamingContext();
    jmsServer.setContext(context);
    jmsServer.start();

    AddressSettings settings = server.getAddressSettingsRepository().getMatch("jms.topic.TT");

    assertEquals(1024 * 1024, settings.getMaxSizeBytes());
    assertEquals(10 * 1024, settings.getPageSizeBytes());
    assertEquals(AddressFullMessagePolicy.PAGE, settings.getAddressFullMessagePolicy());

    store = server.getPagingManager().getPageStore(new SimpleString("TT"));

    conn.close();

    server.stop();
  }
コード例 #5
0
  @Test
  public void testOrderOverRollback2() throws Throwable {
    boolean persistentMessages = true;

    Configuration config = createDefaultConfig();

    config.setJournalSyncNonTransactional(false);

    HornetQServer server =
        createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());

    server.start();

    final int messageSize = 1024;

    final int numberOfMessages = 200;

    ServerLocator locator = createInVMNonHALocator();

    locator.setClientFailureCheckPeriod(1000);
    locator.setConnectionTTL(2000);
    locator.setReconnectAttempts(0);

    locator.setBlockOnNonDurableSend(true);
    locator.setBlockOnDurableSend(true);
    locator.setBlockOnAcknowledge(true);
    locator.setConsumerWindowSize(0);

    ClientSessionFactory sf = createSessionFactory(locator);

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

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

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

    byte[] body = new byte[messageSize];

    ByteBuffer bb = ByteBuffer.wrap(body);

    for (int j = 1; j <= messageSize; j++) {
      bb.put(getSamplebyte(j));
    }

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

      HornetQBuffer bodyLocal = message.getBodyBuffer();

      bodyLocal.writeBytes(body);

      message.putIntProperty(new SimpleString("id"), i);

      producer.send(message);
      if (i % 1000 == 0) {
        session.commit();
      }
    }

    session.commit();

    session.close();

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

    session.start();

    ClientConsumer consumer = session.createConsumer(ADDRESS);

    // number of references without paging
    int numberOfRefs = queue.getNumberOfReferences();

    // consume all non-paged references
    for (int ref = 0; ref < numberOfRefs; ref++) {
      ClientMessage msg = consumer.receive(5000);
      assertNotNull(msg);
      msg.acknowledge();
    }

    session.commit();

    session.close();

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

    session.start();

    consumer = session.createConsumer(ADDRESS);

    ClientMessage msg = consumer.receive(5000);
    assertNotNull(msg);
    int msgIDRolledBack = msg.getIntProperty("id").intValue();
    msg.acknowledge();

    session.rollback();

    msg = consumer.receive(5000);

    assertNotNull(msg);

    assertEquals(msgIDRolledBack, msg.getIntProperty("id").intValue());

    session.rollback();

    session.close();

    sf.close();
    locator.close();

    server.stop();

    server.start();

    locator = createInVMNonHALocator();

    locator.setClientFailureCheckPeriod(1000);
    locator.setConnectionTTL(2000);
    locator.setReconnectAttempts(0);

    locator.setBlockOnNonDurableSend(true);
    locator.setBlockOnDurableSend(true);
    locator.setBlockOnAcknowledge(true);
    locator.setConsumerWindowSize(0);

    sf = createSessionFactory(locator);

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

    session.start();

    consumer = session.createConsumer(ADDRESS);

    for (int i = msgIDRolledBack; i < numberOfMessages; i++) {
      ClientMessage message = consumer.receive(5000);
      assertNotNull(message);
      assertEquals(i, message.getIntProperty("id").intValue());
      message.acknowledge();
    }

    session.commit();

    session.close();
  }
コード例 #6
0
  @Test
  public void testPageCounter2() throws Throwable {
    boolean persistentMessages = true;

    Configuration config = createDefaultConfig();

    config.setJournalSyncNonTransactional(false);

    HornetQServer server =
        createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());

    server.start();

    final int messageSize = 1024;

    final int numberOfMessages = 500;

    ServerLocator locator = createInVMNonHALocator();

    locator.setClientFailureCheckPeriod(1000);
    locator.setConnectionTTL(2000);
    locator.setReconnectAttempts(0);

    locator.setBlockOnNonDurableSend(true);
    locator.setBlockOnDurableSend(true);
    locator.setBlockOnAcknowledge(true);
    locator.setConsumerWindowSize(1024 * 1024);

    ClientSessionFactory sf = createSessionFactory(locator);

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

    Queue q1 = server.createQueue(ADDRESS, ADDRESS, null, true, false);

    Queue q2 = server.createQueue(ADDRESS, new SimpleString("inactive"), null, true, false);

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

    byte[] body = new byte[messageSize];

    ByteBuffer bb = ByteBuffer.wrap(body);

    for (int j = 1; j <= messageSize; j++) {
      bb.put(getSamplebyte(j));
    }

    final AtomicInteger errors = new AtomicInteger(0);

    Thread t1 =
        new Thread() {
          @Override
          public void run() {
            try {
              ServerLocator sl = createInVMNonHALocator();
              ClientSessionFactory sf = sl.createSessionFactory();
              ClientSession sess = sf.createSession(true, true, 0);
              sess.start();
              ClientConsumer cons = sess.createConsumer(ADDRESS);
              for (int i = 0; i < 100; i++) {
                ClientMessage msg = cons.receive(5000);
                assertNotNull(msg);
                assertEquals(i, msg.getIntProperty("id").intValue());
                msg.acknowledge();
              }
              sess.close();
              sl.close();
            } catch (Throwable e) {
              e.printStackTrace();
              errors.incrementAndGet();
            }
          }
        };

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

      HornetQBuffer bodyLocal = message.getBodyBuffer();

      bodyLocal.writeBytes(body);

      message.putIntProperty(new SimpleString("id"), i);

      producer.send(message);
      if (i % 20 == 0) {
        session.commit();
      }
    }

    session.commit();

    t1.start();
    t1.join();

    assertEquals(0, errors.get());
    long timeout = System.currentTimeMillis() + 10000;
    while (numberOfMessages - 100 != q1.getMessageCount() && System.currentTimeMillis() < timeout) {
      Thread.sleep(500);
    }

    assertEquals(numberOfMessages, q2.getMessageCount());
    assertEquals(numberOfMessages, q2.getMessagesAdded());
    assertEquals(numberOfMessages - 100, q1.getMessageCount());
    assertEquals(numberOfMessages, q2.getMessagesAdded());
  }
コード例 #7
0
  @Test
  public void testPageCounter() throws Throwable {
    boolean persistentMessages = true;

    Configuration config = createDefaultConfig();

    config.setJournalSyncNonTransactional(false);

    HornetQServer server =
        createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());

    server.start();

    final int messageSize = 1024;

    final int numberOfMessages = 500;

    ServerLocator locator = createInVMNonHALocator();

    locator.setClientFailureCheckPeriod(1000);
    locator.setConnectionTTL(2000);
    locator.setReconnectAttempts(0);

    locator.setBlockOnNonDurableSend(true);
    locator.setBlockOnDurableSend(true);
    locator.setBlockOnAcknowledge(true);
    locator.setConsumerWindowSize(1024 * 1024);

    ClientSessionFactory sf = createSessionFactory(locator);

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

    Queue q1 = server.createQueue(ADDRESS, ADDRESS, null, true, false);

    Queue q2 = server.createQueue(ADDRESS, new SimpleString("inactive"), null, true, false);

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

    byte[] body = new byte[messageSize];

    ByteBuffer bb = ByteBuffer.wrap(body);

    for (int j = 1; j <= messageSize; j++) {
      bb.put(getSamplebyte(j));
    }

    final AtomicInteger errors = new AtomicInteger(0);

    Thread t1 =
        new Thread() {
          @Override
          public void run() {
            try {
              ServerLocator sl = createInVMNonHALocator();
              ClientSessionFactory sf = sl.createSessionFactory();
              ClientSession sess = sf.createSession(true, true, 0);
              sess.start();
              ClientConsumer cons = sess.createConsumer(ADDRESS);
              for (int i = 0; i < numberOfMessages; i++) {
                ClientMessage msg = cons.receive(5000);
                assertNotNull(msg);
                assertEquals(i, msg.getIntProperty("id").intValue());
                msg.acknowledge();
              }

              assertNull(cons.receiveImmediate());
              sess.close();
              sl.close();
            } catch (Throwable e) {
              e.printStackTrace();
              errors.incrementAndGet();
            }
          }
        };

    t1.start();

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

      HornetQBuffer bodyLocal = message.getBodyBuffer();

      bodyLocal.writeBytes(body);

      message.putIntProperty(new SimpleString("id"), i);

      producer.send(message);
      if (i % 20 == 0) {
        session.commit();
      }
    }

    session.commit();

    t1.join();

    assertEquals(0, errors.get());

    assertEquals(numberOfMessages, q2.getMessageCount());
    assertEquals(numberOfMessages, q2.getMessagesAdded());
    assertEquals(0, q1.getMessageCount());
    assertEquals(numberOfMessages, q1.getMessagesAdded());

    session.close();
    sf.close();
    locator.close();

    server.stop();

    server.start();

    Bindings bindings = server.getPostOffice().getBindingsForAddress(ADDRESS);

    q1 = null;
    q2 = null;

    for (Binding bind : bindings.getBindings()) {
      if (bind instanceof LocalQueueBinding) {
        LocalQueueBinding qb = (LocalQueueBinding) bind;
        if (qb.getQueue().getName().equals(ADDRESS)) {
          q1 = qb.getQueue();
        }

        if (qb.getQueue().getName().equals(new SimpleString("inactive"))) {
          q2 = qb.getQueue();
        }
      }
    }

    assertNotNull(q1);

    assertNotNull(q2);

    assertEquals("q2 msg count", numberOfMessages, q2.getMessageCount());
    assertEquals("q2 msgs added", numberOfMessages, q2.getMessagesAdded());
    assertEquals("q1 msg count", 0, q1.getMessageCount());
    // 0, since nothing was sent to the queue after the server was restarted
    assertEquals("q1 msgs added", 0, q1.getMessagesAdded());
  }