Search in sources :

Example 1 with ConsumerThread

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

the class ProxyFailoverTest method testFailover.

public void testFailover() throws Exception {
    ActiveMQConnectionFactory producerFactory = new ActiveMQConnectionFactory("failover:(tcp://localhost:61616,tcp://localhost:61626)?randomize=false");
    Connection producerConnection = producerFactory.createConnection();
    producerConnection.start();
    Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ProducerThread producer = new ProducerThread(producerSession, producerSession.createQueue("ProxyTest"));
    producer.setSleep(10);
    producer.start();
    ActiveMQConnectionFactory consumerFactory = new ActiveMQConnectionFactory("tcp://localhost:51618");
    Connection consumerConnection = consumerFactory.createConnection();
    consumerConnection.start();
    Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ConsumerThread consumer = new ConsumerThread(consumerSession, consumerSession.createQueue("ProxyTest"));
    consumer.start();
    TimeUnit.SECONDS.sleep(15);
    remoteBroker.stop();
    remoteBroker.waitUntilStopped();
    startRemoteBroker(false);
    producer.join();
    consumer.join();
    assertEquals(1000, consumer.getReceived());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ProducerThread(org.apache.activemq.util.ProducerThread) ConsumerThread(org.apache.activemq.util.ConsumerThread) Connection(javax.jms.Connection) Session(javax.jms.Session)

Example 2 with ConsumerThread

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

the class NIOSSLLoadTest method testLoad.

public void testLoad() throws Exception {
    Queue dest = session.createQueue("TEST");
    for (int i = 0; i < PRODUCER_COUNT; i++) {
        ProducerThread producer = new ProducerThread(session, dest);
        producer.setMessageCount(MESSAGE_COUNT);
        producer.start();
    }
    for (int i = 0; i < CONSUMER_COUNT; i++) {
        ConsumerThread consumer = new ConsumerThread(session, dest);
        consumer.setMessageCount(MESSAGE_COUNT);
        consumer.start();
        consumers[i] = consumer;
    }
    Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return getReceived() == PRODUCER_COUNT * MESSAGE_COUNT;
        }
    }, 60000);
    assertEquals(PRODUCER_COUNT * MESSAGE_COUNT, getReceived());
}
Also used : ProducerThread(org.apache.activemq.util.ProducerThread) ConsumerThread(org.apache.activemq.util.ConsumerThread) Wait(org.apache.activemq.util.Wait) Queue(javax.jms.Queue)

Example 3 with ConsumerThread

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

the class MemoryLimitTest method testLimit.

/**
 * Handy test for manually checking what's going on
 */
@Ignore
@Test(timeout = 120000)
public void testLimit() throws Exception {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost?jms.prefetchPolicy.all=10");
    factory.setOptimizeAcknowledge(true);
    Connection conn = factory.createConnection();
    conn.start();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final ProducerThread producer = new ProducerThread(sess, sess.createQueue("STORE.1")) {

        @Override
        protected Message createMessage(int i) throws Exception {
            return sess.createTextMessage(Arrays.toString(payload) + "::" + i);
        }
    };
    producer.setMessageCount(1000);
    final ProducerThread producer2 = new ProducerThread(sess, sess.createQueue("STORE.2")) {

        @Override
        protected Message createMessage(int i) throws Exception {
            return sess.createTextMessage(Arrays.toString(payload) + "::" + i);
        }
    };
    producer2.setMessageCount(1000);
    ConsumerThread consumer = new ConsumerThread(sess, sess.createQueue("STORE.1"));
    consumer.setBreakOnNull(false);
    consumer.setMessageCount(1000);
    producer.start();
    producer.join();
    producer2.start();
    Thread.sleep(300);
    consumer.start();
    consumer.join();
    producer2.join();
    assertEquals("consumer got all produced messages", producer.getMessageCount(), consumer.getReceived());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ProducerThread(org.apache.activemq.util.ProducerThread) ConsumerThread(org.apache.activemq.util.ConsumerThread) Connection(javax.jms.Connection) Session(javax.jms.Session) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with ConsumerThread

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

the class MessageRedistributionTest method closeConsumerAndConnectionConcurrently.

private void closeConsumerAndConnectionConcurrently(int targetNode, int remoteNode) throws Exception {
    String targetUri = getServerUri(targetNode);
    System.out.println("uri is " + targetUri);
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(targetUri);
    Connection conn = null;
    CountDownLatch active = new CountDownLatch(1);
    try {
        conn = factory.createConnection();
        conn.start();
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination dest = ActiveMQDestination.createDestination("queue0", ActiveMQDestination.QUEUE_TYPE);
        ConsumerThread consumer = new ConsumerThread(session, dest);
        consumer.setMessageCount(0);
        consumer.setFinished(active);
        consumer.start();
        assertTrue("consumer takes too long to finish!", active.await(5, TimeUnit.SECONDS));
    } finally {
        conn.close();
    }
    Wait.waitFor(() -> getRemoteQueueBinding(servers[remoteNode]) != null);
    // check remote server's consumer count
    RemoteQueueBinding remoteBinding = getRemoteQueueBinding(servers[remoteNode]);
    assertNotNull(remoteBinding);
    Wait.waitFor(() -> remoteBinding.consumerCount() >= 0);
    int count = remoteBinding.consumerCount();
    assertTrue("consumer count should never be negative " + count, count >= 0);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Destination(javax.jms.Destination) ConsumerThread(org.apache.activemq.util.ConsumerThread) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) Session(javax.jms.Session) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)

Aggregations

ConsumerThread (org.apache.activemq.util.ConsumerThread)4 Connection (javax.jms.Connection)3 Session (javax.jms.Session)3 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)3 ProducerThread (org.apache.activemq.util.ProducerThread)3 CountDownLatch (java.util.concurrent.CountDownLatch)1 Destination (javax.jms.Destination)1 Queue (javax.jms.Queue)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 RemoteQueueBinding (org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)1 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)1 Wait (org.apache.activemq.util.Wait)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1