Search in sources :

Example 41 with QueueImpl

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

the class OptimizedAckTest method testVerySlowReceivedMessageStillInflight.

public void testVerySlowReceivedMessageStillInflight() 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("prefetch full", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return 10 == coreQueue.getDeliveringCount();
        }
    }));
    for (int i = 0; i < 6; i++) {
        Thread.sleep(400);
        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++) {
        Thread.sleep(400);
        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)

Example 42 with QueueImpl

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

the class ClusteredGroupingTest method testGroupingGroupTimeoutWithUnproposal.

@Test
public void testGroupingGroupTimeoutWithUnproposal() throws Exception {
    setupServer(0, isFileStorage(), isNetty());
    setupServer(1, isFileStorage(), isNetty());
    setupServer(2, isFileStorage(), isNetty());
    setupClusterConnection("cluster0", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 0, 1, 2);
    setupClusterConnection("cluster1", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 1, 0, 2);
    setupClusterConnection("cluster2", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 2, 0, 1);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.LOCAL, 0, 2000, 1000, 100);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.REMOTE, 1, 2000, 1000, 100);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.REMOTE, 2, 2000, 1000, 100);
    startServers(0, 1, 2);
    setupSessionFactory(0, isNetty());
    setupSessionFactory(1, isNetty());
    setupSessionFactory(2, isNetty());
    createQueue(0, "queues.testaddress", "queue0", null, false);
    createQueue(1, "queues.testaddress", "queue0", null, false);
    createQueue(2, "queues.testaddress", "queue0", null, false);
    addConsumer(0, 2, "queue0", null);
    waitForBindings(0, "queues.testaddress", 1, 0, true);
    waitForBindings(1, "queues.testaddress", 1, 0, true);
    waitForBindings(2, "queues.testaddress", 1, 1, true);
    waitForBindings(0, "queues.testaddress", 2, 1, false);
    waitForBindings(1, "queues.testaddress", 2, 1, false);
    waitForBindings(2, "queues.testaddress", 2, 0, false);
    final CountDownLatch latch = new CountDownLatch(4);
    getServer(1).getManagementService().addNotificationListener(new NotificationListener() {

        @Override
        public void onNotification(Notification notification) {
            if (!(notification.getType() instanceof CoreNotificationType))
                return;
            if (notification.getType() == CoreNotificationType.UNPROPOSAL) {
                latch.countDown();
            }
        }
    });
    getServer(2).getManagementService().addNotificationListener(new NotificationListener() {

        @Override
        public void onNotification(Notification notification) {
            if (!(notification.getType() instanceof CoreNotificationType))
                return;
            if (notification.getType() == CoreNotificationType.UNPROPOSAL) {
                latch.countDown();
            }
        }
    });
    sendWithProperty(0, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id1"));
    verifyReceiveAll(10, 0);
    sendWithProperty(0, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id2"));
    verifyReceiveAll(10, 0);
    QueueImpl queue0Server2 = (QueueImpl) servers[2].locateQueue(SimpleString.toSimpleString("queue0"));
    assertEquals(2, queue0Server2.getGroupsUsed().size());
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    long timeLimit = System.currentTimeMillis() + 5000;
    while (timeLimit > System.currentTimeMillis() && queue0Server2.getGroupsUsed().size() != 0) {
        Thread.sleep(10);
    }
    assertEquals("Unproposal should cleanup the queue group as well", 0, queue0Server2.getGroupsUsed().size());
    removeConsumer(0);
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    addConsumer(0, 0, "queue0", null);
    waitForBindings(0, "queues.testaddress", 1, 1, true);
    waitForBindings(1, "queues.testaddress", 1, 0, true);
    waitForBindings(2, "queues.testaddress", 1, 0, true);
    waitForBindings(0, "queues.testaddress", 2, 0, false);
    waitForBindings(1, "queues.testaddress", 2, 1, false);
    waitForBindings(2, "queues.testaddress", 2, 1, false);
    sendWithProperty(0, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id1"));
    verifyReceiveAll(10, 0);
    sendWithProperty(0, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id2"));
    verifyReceiveAll(10, 0);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) CoreNotificationType(org.apache.activemq.artemis.api.core.management.CoreNotificationType) Notification(org.apache.activemq.artemis.core.server.management.Notification) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) NotificationListener(org.apache.activemq.artemis.core.server.management.NotificationListener) Test(org.junit.Test)

Example 43 with QueueImpl

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

the class MessageRedistributionTest method testRedistributionStopsWhenConsumerAdded.

// https://issues.jboss.org/browse/HORNETQ-1057
@Test
public void testRedistributionStopsWhenConsumerAdded() throws Exception {
    setupCluster(MessageLoadBalancingType.ON_DEMAND);
    MessageRedistributionTest.log.info("Doing test");
    startServers(0, 1, 2);
    setupSessionFactory(0, isNetty());
    setupSessionFactory(1, isNetty());
    setupSessionFactory(2, isNetty());
    createQueue(0, "queues.testaddress", "queue0", null, false);
    createQueue(1, "queues.testaddress", "queue0", null, false);
    createQueue(2, "queues.testaddress", "queue0", null, false);
    addConsumer(0, 0, "queue0", null);
    waitForBindings(0, "queues.testaddress", 1, 1, true);
    waitForBindings(1, "queues.testaddress", 1, 0, true);
    waitForBindings(2, "queues.testaddress", 1, 0, true);
    waitForBindings(0, "queues.testaddress", 2, 0, false);
    waitForBindings(1, "queues.testaddress", 2, 1, false);
    waitForBindings(2, "queues.testaddress", 2, 1, false);
    send(0, "queues.testaddress", 2000, false, null);
    removeConsumer(0);
    addConsumer(0, 0, "queue0", null);
    Bindable bindable = servers[0].getPostOffice().getBinding(new SimpleString("queue0")).getBindable();
    String debug = ((QueueImpl) bindable).debug();
    Assert.assertFalse(debug.contains(Redistributor.class.getName()));
    MessageRedistributionTest.log.info("Test done");
}
Also used : Bindable(org.apache.activemq.artemis.core.server.Bindable) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Example 44 with QueueImpl

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

the class QueueImplTest method testScheduledNoConsumer.

// The tests ----------------------------------------------------------------
@Test
public void testScheduledNoConsumer() throws Exception {
    QueueImpl queue = new QueueImpl(1, new SimpleString("address1"), new SimpleString("queue1"), null, null, false, true, false, scheduledExecutor, null, null, null, ArtemisExecutor.delegate(executor), null, null);
    // Send one scheduled
    long now = System.currentTimeMillis();
    MessageReference ref1 = generateReference(queue, 1);
    ref1.setScheduledDeliveryTime(now + 700);
    queue.addTail(ref1);
    // Send some non scheduled messages
    MessageReference ref2 = generateReference(queue, 2);
    queue.addTail(ref2);
    MessageReference ref3 = generateReference(queue, 3);
    queue.addTail(ref3);
    MessageReference ref4 = generateReference(queue, 4);
    queue.addTail(ref4);
    // Now send some more scheduled messages
    MessageReference ref5 = generateReference(queue, 5);
    ref5.setScheduledDeliveryTime(now + 500);
    queue.addTail(ref5);
    MessageReference ref6 = generateReference(queue, 6);
    ref6.setScheduledDeliveryTime(now + 400);
    queue.addTail(ref6);
    MessageReference ref7 = generateReference(queue, 7);
    ref7.setScheduledDeliveryTime(now + 300);
    queue.addTail(ref7);
    MessageReference ref8 = generateReference(queue, 8);
    ref8.setScheduledDeliveryTime(now + 600);
    queue.addTail(ref8);
    List<MessageReference> refs = new ArrayList<>();
    // Scheduled refs are added back to *FRONT* of queue - otherwise if there were many messages in the queue
    // They may get stranded behind a big backlog
    refs.add(ref1);
    refs.add(ref8);
    refs.add(ref5);
    refs.add(ref6);
    refs.add(ref7);
    refs.add(ref2);
    refs.add(ref3);
    refs.add(ref4);
    Thread.sleep(750);
    FakeConsumer consumer = new FakeConsumer();
    queue.addConsumer(consumer);
    queue.deliverNow();
    assertRefListsIdenticalRefs(refs, consumer.getReferences());
}
Also used : FakeConsumer(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Example 45 with QueueImpl

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

the class QueueImplTest method testDeliveryScheduled.

@Test
public void testDeliveryScheduled() throws Exception {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    Consumer consumer = new FakeConsumer() {

        @Override
        public synchronized HandleStatus handle(final MessageReference reference) {
            countDownLatch.countDown();
            return HandleStatus.HANDLED;
        }

        @Override
        public void disconnect() {
        }
    };
    QueueImpl queue = new QueueImpl(1, new SimpleString("address1"), QueueImplTest.queue1, null, null, false, true, false, scheduledExecutor, null, null, null, ArtemisExecutor.delegate(executor), null, null);
    MessageReference messageReference = generateReference(queue, 1);
    queue.addConsumer(consumer);
    messageReference.setScheduledDeliveryTime(System.currentTimeMillis() + 200);
    queue.addHead(messageReference, false);
    boolean gotLatch = countDownLatch.await(3000, TimeUnit.MILLISECONDS);
    Assert.assertTrue(gotLatch);
}
Also used : FakeConsumer(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer) Consumer(org.apache.activemq.artemis.core.server.Consumer) FakeConsumer(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

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