Search in sources :

Example 6 with Wait

use of org.apache.activemq.util.Wait in project activemq-artemis by apache.

the class JmsSchedulerTest method testJobSchedulerStoreUsage.

@Test
public void testJobSchedulerStoreUsage() throws Exception {
    // Shrink the store limit down so we get the producer to block
    broker.getSystemUsage().getJobSchedulerUsage().setLimit(10 * 1024);
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
    Connection conn = factory.createConnection();
    conn.start();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final long time = 5000;
    final ProducerThread producer = new ProducerThread(sess, destination) {

        @Override
        protected Message createMessage(int i) throws Exception {
            Message message = super.createMessage(i);
            message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, time);
            return message;
        }
    };
    producer.setMessageCount(100);
    producer.start();
    MessageConsumer consumer = sess.createConsumer(destination);
    final CountDownLatch latch = new CountDownLatch(100);
    consumer.setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message message) {
            latch.countDown();
        }
    });
    // wait for the producer to block, which should happen immediately, and also wait long
    // enough for the delay to elapse.  We should see no deliveries as the send should block
    // on the first message.
    Thread.sleep(10000L);
    assertEquals(100, latch.getCount());
    // Increase the store limit so the producer unblocks.  Everything should enqueue at this point.
    broker.getSystemUsage().getJobSchedulerUsage().setLimit(1024 * 1024 * 33);
    // Wait long enough that the messages are enqueued and the delivery delay has elapsed.
    Thread.sleep(10000L);
    // Make sure we sent all the messages we expected to send
    Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return producer.getSentCount() == producer.getMessageCount();
        }
    }, 20000L);
    assertEquals("Producer didn't send all messages", producer.getMessageCount(), producer.getSentCount());
    // Make sure we got all the messages we expected to get
    latch.await(20000L, TimeUnit.MILLISECONDS);
    assertEquals("Consumer did not receive all messages.", 0, latch.getCount());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) ScheduledMessage(org.apache.activemq.ScheduledMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) MessageListener(javax.jms.MessageListener) CountDownLatch(java.util.concurrent.CountDownLatch) JMSException(javax.jms.JMSException) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ProducerThread(org.apache.activemq.util.ProducerThread) Wait(org.apache.activemq.util.Wait) Session(javax.jms.Session) Test(org.junit.Test)

Example 7 with Wait

use of org.apache.activemq.util.Wait in project activemq-artemis by apache.

the class JobSchedulerStoreUsageTest method testJmx.

public void testJmx() throws Exception {
    LOG.info("Initial scheduler usage: {}", broker.getAdminView().getJobSchedulerStorePercentUsage());
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
    Connection conn = factory.createConnection();
    conn.start();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination dest = sess.createQueue(this.getClass().getName());
    final ProducerThread producer = new ProducerThread(sess, dest) {

        @Override
        protected Message createMessage(int i) throws Exception {
            Message message = super.createMessage(i);
            message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, WAIT_TIME_MILLS / 2);
            return message;
        }
    };
    producer.setMessageCount(100);
    producer.start();
    assertEquals(7 * 1024, broker.getAdminView().getJobSchedulerStoreLimit());
    // wait for the producer to block
    Thread.sleep(WAIT_TIME_MILLS / 2);
    assertTrue(broker.getAdminView().getJobSchedulerStorePercentUsage() > 100);
    broker.getAdminView().setJobSchedulerStoreLimit(1024 * 1024 * 33);
    Thread.sleep(WAIT_TIME_MILLS);
    Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return producer.getSentCount() == producer.getMessageCount();
        }
    }, WAIT_TIME_MILLS * 2);
    assertEquals("Producer didn't send all messages", producer.getMessageCount(), producer.getSentCount());
    LOG.info("Final scheduler usage: {}", broker.getAdminView().getJobSchedulerStorePercentUsage());
    assertTrue(broker.getAdminView().getJobSchedulerStorePercentUsage() < 100);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Destination(javax.jms.Destination) ProducerThread(org.apache.activemq.util.ProducerThread) ScheduledMessage(org.apache.activemq.ScheduledMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) Wait(org.apache.activemq.util.Wait) Session(javax.jms.Session)

Example 8 with Wait

use of org.apache.activemq.util.Wait in project activemq-artemis by apache.

the class StoreUsageTest method testJmx.

public void testJmx() throws Exception {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
    Connection conn = factory.createConnection();
    conn.start();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination dest = sess.createQueue(this.getClass().getName());
    final ProducerThread producer = new ProducerThread(sess, dest);
    producer.start();
    // wait for the producer to block
    Thread.sleep(WAIT_TIME_MILLS / 2);
    broker.getAdminView().setStoreLimit(1024 * 1024);
    Thread.sleep(WAIT_TIME_MILLS);
    Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return producer.getSentCount() == producer.getMessageCount();
        }
    }, WAIT_TIME_MILLS * 2);
    assertEquals("Producer didn't send all messages", producer.getMessageCount(), producer.getSentCount());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Destination(javax.jms.Destination) ProducerThread(org.apache.activemq.util.ProducerThread) Connection(javax.jms.Connection) Wait(org.apache.activemq.util.Wait) Session(javax.jms.Session)

Aggregations

Wait (org.apache.activemq.util.Wait)8 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)4 Connection (javax.jms.Connection)3 Session (javax.jms.Session)3 ProducerThread (org.apache.activemq.util.ProducerThread)3 IOException (java.io.IOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Destination (javax.jms.Destination)2 JMSException (javax.jms.JMSException)2 Message (javax.jms.Message)2 MessageConsumer (javax.jms.MessageConsumer)2 ScheduledMessage (org.apache.activemq.ScheduledMessage)2 BrokerPluginSupport (org.apache.activemq.broker.BrokerPluginSupport)2 BrokerService (org.apache.activemq.broker.BrokerService)2 KahaDBPersistenceAdapter (org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)2 Test (org.junit.Test)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 MessageListener (javax.jms.MessageListener)1