Search in sources :

Example 36 with QueueImpl

use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.

the class QueueImplTest method testName.

@Test
public void testName() {
    final SimpleString name = new SimpleString("oobblle");
    QueueImpl queue = getNamedQueue(name);
    Assert.assertEquals(name, queue.getName());
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Example 37 with QueueImpl

use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.

the class QueueImplTest method testRate.

@Test
public void testRate() throws InterruptedException {
    QueueImpl queue = getTemporaryQueue();
    final int numMessages = 10;
    for (int i = 0; i < numMessages; i++) {
        MessageReference ref = generateReference(queue, i);
        queue.addTail(ref);
    }
    Thread.sleep(1000);
    float rate = queue.getRate();
    Assert.assertTrue(rate <= 10.0f);
    System.out.println("Rate: " + rate);
}
Also used : MessageReference(org.apache.activemq.artemis.core.server.MessageReference) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Example 38 with QueueImpl

use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.

the class QueueImplTest method testResetMessagesAdded.

@Test
public void testResetMessagesAdded() throws Exception {
    QueueImpl queue = getTemporaryQueue();
    MessageReference messageReference = generateReference(queue, 1);
    MessageReference messageReference2 = generateReference(queue, 2);
    queue.addTail(messageReference);
    queue.addTail(messageReference2);
    Assert.assertEquals(2, getMessagesAdded(queue));
    queue.resetMessagesAdded();
    Assert.assertEquals(0, getMessagesAdded(queue));
}
Also used : MessageReference(org.apache.activemq.artemis.core.server.MessageReference) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Example 39 with QueueImpl

use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.

the class OptimizedAckTest method testReceivedMessageNotInFlightAfterScheduledAckFires.

public void testReceivedMessageNotInFlightAfterScheduledAckFires() throws Exception {
    connection.setOptimizedAckScheduledAckInterval(TimeUnit.SECONDS.toMillis(10));
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue("test");
    MessageProducer producer = session.createProducer(queue);
    for (int i = 0; i < 10; i++) {
        producer.send(session.createTextMessage("Hello" + i));
    }
    MessageConsumer consumer = session.createConsumer(queue);
    ArtemisBrokerWrapper broker = (ArtemisBrokerWrapper) ArtemisBrokerHelper.getBroker().getBroker();
    Binding binding = broker.getServer().getPostOffice().getBinding(new SimpleString("test"));
    final QueueImpl coreQueue = (QueueImpl) binding.getBindable();
    assertTrue("prefetch full", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return 10 == coreQueue.getDeliveringCount();
        }
    }));
    for (int i = 0; i < 6; i++) {
        javax.jms.Message msg = consumer.receive(4000);
        assertNotNull(msg);
        assertEquals("all prefetch is still in flight: " + i, 10, coreQueue.getDeliveringCount());
    }
    for (int i = 6; i < 10; i++) {
        javax.jms.Message msg = consumer.receive(4000);
        assertNotNull(msg);
        assertTrue("most are acked but 3 remain", Wait.waitFor(new Wait.Condition() {

            @Override
            public boolean isSatisified() throws Exception {
                return 3 == coreQueue.getDeliveringCount();
            }
        }));
    }
    assertTrue("After delay the scheduled ack should ack all inflight.", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            LOG.info("inflight count: " + coreQueue.getDeliveringCount());
            return 0 == coreQueue.getDeliveringCount();
        }
    }));
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) MessageConsumer(javax.jms.MessageConsumer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) ArtemisBrokerWrapper(org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Session(javax.jms.Session)

Example 40 with QueueImpl

use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.

the class OptimizedAckTest method testReceivedMessageStillInflight.

public void testReceivedMessageStillInflight() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue("test");
    MessageProducer producer = session.createProducer(queue);
    for (int i = 0; i < 10; i++) {
        producer.send(session.createTextMessage("Hello" + i));
    }
    MessageConsumer consumer = session.createConsumer(queue);
    // check queue delivering count is 10
    ArtemisBrokerWrapper broker = (ArtemisBrokerWrapper) ArtemisBrokerHelper.getBroker().getBroker();
    Binding binding = broker.getServer().getPostOffice().getBinding(new SimpleString("test"));
    final QueueImpl coreQueue = (QueueImpl) binding.getBindable();
    assertTrue("delivering count is 10", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return 10 == coreQueue.getDeliveringCount();
        }
    }));
    for (int i = 0; i < 6; i++) {
        javax.jms.Message msg = consumer.receive(4000);
        assertNotNull(msg);
        assertEquals("all prefetch is still in flight: " + i, 10, coreQueue.getDeliveringCount());
    }
    for (int i = 6; i < 10; i++) {
        javax.jms.Message msg = consumer.receive(4000);
        assertNotNull(msg);
        assertTrue("most are acked but 3 remain", Wait.waitFor(new Wait.Condition() {

            @Override
            public boolean isSatisified() throws Exception {
                return 3 == coreQueue.getDeliveringCount();
            }
        }));
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) MessageConsumer(javax.jms.MessageConsumer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) ArtemisBrokerWrapper(org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Session(javax.jms.Session)

Aggregations

QueueImpl (org.apache.activemq.artemis.core.server.impl.QueueImpl)48 Test (org.junit.Test)41 MessageReference (org.apache.activemq.artemis.core.server.MessageReference)26 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)21 FakeConsumer (org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer)21 ArrayList (java.util.ArrayList)17 MessageConsumer (javax.jms.MessageConsumer)6 MessageProducer (javax.jms.MessageProducer)6 Session (javax.jms.Session)6 Filter (org.apache.activemq.artemis.core.filter.Filter)6 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)5 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)5 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)5 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)4 StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)4 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)4 FakeFilter (org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeFilter)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 Connection (javax.jms.Connection)3 Queue (javax.jms.Queue)3