Search in sources :

Example 6 with ArtemisBrokerWrapper

use of org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper 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)

Example 7 with ArtemisBrokerWrapper

use of org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper 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 8 with ArtemisBrokerWrapper

use of org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper in project activemq-artemis by apache.

the class BrokerTest method testQueueTransactedAck.

public void testQueueTransactedAck() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // Send the messages
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo1, destination, deliveryMode);
        connection1.send(message);
    }
    // Begin the transaction.
    LocalTransactionId txid = createLocalTransaction(sessionInfo1);
    connection1.send(createBeginTransaction(connectionInfo1, txid));
    // Acknowledge the first 2 messages.
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        MessageAck ack = createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE);
        ack.setTransactionId(txid);
        connection1.request(ack);
    }
    // Commit the transaction.
    connection1.send(createCommitTransaction1Phase(connectionInfo1, txid));
    // due to async tx operations, we need some time for message count to go down
    Thread.sleep(1000);
    ArtemisBrokerWrapper wrapper = (ArtemisBrokerWrapper) broker.getBroker();
    long messageCount = wrapper.getAMQueueMessageCount(destination);
    // The queue should now only have the remaining 2 messages
    assertEquals(2, messageCount);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) LocalTransactionId(org.apache.activemq.command.LocalTransactionId) SessionInfo(org.apache.activemq.command.SessionInfo) MessageAck(org.apache.activemq.command.MessageAck) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ArtemisBrokerWrapper(org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper)

Aggregations

ArtemisBrokerWrapper (org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper)8 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)5 MessageConsumer (javax.jms.MessageConsumer)3 MessageProducer (javax.jms.MessageProducer)3 Queue (javax.jms.Queue)3 Session (javax.jms.Session)3 Binding (org.apache.activemq.artemis.core.postoffice.Binding)3 QueueImpl (org.apache.activemq.artemis.core.server.impl.QueueImpl)3 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)2 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)2 Message (org.apache.activemq.command.Message)2 ProducerInfo (org.apache.activemq.command.ProducerInfo)2 SessionInfo (org.apache.activemq.command.SessionInfo)2 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)1 LocalTransactionId (org.apache.activemq.command.LocalTransactionId)1 MessageAck (org.apache.activemq.command.MessageAck)1