Search in sources :

Example 6 with ProducerThread

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

the class JobSchedulerBrokerShutdownTest method testSchedule.

public void testSchedule() throws Exception {
    Connection connection = createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    connection.start();
    final long time = 1000;
    ProducerThread producer = new ProducerThread(session, 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(200);
    producer.setDaemon(true);
    producer.start();
    Thread.sleep(5000);
}
Also used : ProducerThread(org.apache.activemq.util.ProducerThread) ScheduledMessage(org.apache.activemq.ScheduledMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) Session(javax.jms.Session)

Example 7 with ProducerThread

use of org.apache.activemq.util.ProducerThread 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 ProducerThread

use of org.apache.activemq.util.ProducerThread 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

ProducerThread (org.apache.activemq.util.ProducerThread)8 Connection (javax.jms.Connection)7 Session (javax.jms.Session)7 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)6 Message (javax.jms.Message)4 Wait (org.apache.activemq.util.Wait)4 ScheduledMessage (org.apache.activemq.ScheduledMessage)3 ConsumerThread (org.apache.activemq.util.ConsumerThread)3 Test (org.junit.Test)3 Destination (javax.jms.Destination)2 MessageConsumer (javax.jms.MessageConsumer)2 Queue (javax.jms.Queue)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 BytesMessage (javax.jms.BytesMessage)1 JMSException (javax.jms.JMSException)1 MessageListener (javax.jms.MessageListener)1 TextMessage (javax.jms.TextMessage)1 Destination (org.apache.activemq.broker.region.Destination)1 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)1 Ignore (org.junit.Ignore)1