Search in sources :

Example 16 with QueueImpl

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

the class AddressControlTest method testGetNumberOfPages.

@Test
public void testGetNumberOfPages() throws Exception {
    session.close();
    server.stop();
    server.getConfiguration().setPersistenceEnabled(true);
    SimpleString address = RandomUtil.randomSimpleString();
    AddressSettings addressSettings = new AddressSettings().setPageSizeBytes(1024).setMaxSizeBytes(10 * 1024);
    final int NUMBER_MESSAGES_BEFORE_PAGING = 7;
    server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
    server.start();
    ServerLocator locator2 = createInVMNonHALocator();
    addServerLocator(locator2);
    ClientSessionFactory sf2 = createSessionFactory(locator2);
    session = sf2.createSession(false, true, false);
    session.start();
    session.createQueue(address, address, true);
    QueueImpl serverQueue = (QueueImpl) server.locateQueue(address);
    ClientProducer producer = session.createProducer(address);
    for (int i = 0; i < NUMBER_MESSAGES_BEFORE_PAGING; i++) {
        ClientMessage msg = session.createMessage(true);
        msg.getBodyBuffer().writeBytes(new byte[896]);
        producer.send(msg);
    }
    session.commit();
    AddressControl addressControl = createManagementControl(address);
    Assert.assertEquals(0, addressControl.getNumberOfPages());
    ClientMessage msg = session.createMessage(true);
    msg.getBodyBuffer().writeBytes(new byte[896]);
    producer.send(msg);
    session.commit();
    Assert.assertEquals(1, addressControl.getNumberOfPages());
    msg = session.createMessage(true);
    msg.getBodyBuffer().writeBytes(new byte[896]);
    producer.send(msg);
    session.commit();
    Assert.assertEquals(1, addressControl.getNumberOfPages());
    msg = session.createMessage(true);
    msg.getBodyBuffer().writeBytes(new byte[896]);
    producer.send(msg);
    session.commit();
    Assert.assertEquals("# of pages is 2", 2, addressControl.getNumberOfPages());
    System.out.println("Address size=" + addressControl.getAddressSize());
    Assert.assertEquals(serverQueue.getPageSubscription().getPagingStore().getAddressSize(), addressControl.getAddressSize());
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Example 17 with QueueImpl

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

the class FailoverConsumerUnconsumedTest method assureQueueMessages.

private void assureQueueMessages(int num, SimpleString queueName) {
    QueueImpl queue = (QueueImpl) broker.getActiveMQServer().getPostOffice().getBinding(queueName).getBindable();
    Assert.assertEquals(num, queue.getMessageCount());
}
Also used : QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl)

Example 18 with QueueImpl

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

the class AMQ1925Test method assertQueueLength.

private void assertQueueLength(int len) throws Exception, IOException {
    QueueImpl queue = (QueueImpl) bs.getActiveMQServer().getPostOffice().getBinding(new SimpleString(QUEUE_NAME)).getBindable();
    if (len > queue.getMessageCount()) {
        // we wait for a moment as the tx might still in afterCommit stage (async op)
        Thread.sleep(5000);
    }
    Assert.assertEquals(len, queue.getMessageCount());
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl)

Example 19 with QueueImpl

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

the class AmqpPurgeOnNoConsumersTest method testQueueReceiverReadMessage.

@Test(timeout = 60000)
public void testQueueReceiverReadMessage() throws Exception {
    AmqpConnection connection = null;
    String queue = "purgeQueue";
    SimpleString ssQueue = new SimpleString(queue);
    server.addAddressInfo(new AddressInfo(ssQueue, RoutingType.ANYCAST));
    server.createQueue(ssQueue, RoutingType.ANYCAST, ssQueue, null, true, false, 1, true, false);
    AmqpClient client = createAmqpClient();
    connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    final AmqpReceiver receiver = session.createReceiver(queue);
    QueueImpl queueView = (QueueImpl) getProxyToQueue(queue);
    assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
    assertEquals(0, queueView.getMessageCount());
    sendMessages(queue, 5, null, true);
    Wait.assertEquals(5, queueView::getMessageCount);
    receiver.flow(5);
    for (int i = 0; i < 4; i++) {
        try {
            AmqpMessage receive = receiver.receive(5, TimeUnit.SECONDS);
            receive.accept();
            assertNotNull(receive);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    try {
        receiver.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Wait.assertEquals(0, queueView::getMessageCount);
    assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
    connection.close();
    server.stop();
    server.start();
    queueView = (QueueImpl) getProxyToQueue(queue);
    assertEquals(0, queueView.getMessageCount());
    assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) IOException(java.io.IOException) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) IOException(java.io.IOException) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Test(org.junit.Test)

Example 20 with QueueImpl

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

the class AmqpPurgeOnNoConsumersTest method testPurgeQueueCoreRollback.

// I'm adding the core test here to compare semantics between AMQP and core on this test.
@Test(timeout = 60000)
public void testPurgeQueueCoreRollback() throws Exception {
    String queue = "purgeQueue";
    SimpleString ssQueue = new SimpleString(queue);
    server.addAddressInfo(new AddressInfo(ssQueue, RoutingType.ANYCAST));
    server.createQueue(ssQueue, RoutingType.ANYCAST, ssQueue, null, true, false, 1, true, false);
    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:5672");
    Connection connection = cf.createConnection();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    MessageProducer producer = session.createProducer(session.createQueue("purgeQueue"));
    javax.jms.Queue jmsQueue = session.createQueue(queue);
    MessageConsumer consumer = session.createConsumer(jmsQueue);
    for (int i = 0; i < 10; i++) {
        Message message = session.createTextMessage("hello " + i);
        producer.send(message);
    }
    session.commit();
    QueueImpl queueView = (QueueImpl) getProxyToQueue(queue);
    Wait.assertEquals(10, queueView::getMessageCount);
    connection.start();
    for (int i = 0; i < 10; i++) {
        TextMessage txt = (TextMessage) consumer.receive(1000);
        assertNotNull(txt);
        assertEquals("hello " + i, txt.getText());
    }
    consumer.close();
    session.rollback();
    connection.close();
    Wait.assertEquals(0, queueView::getMessageCount);
    server.stop();
    server.start();
    queueView = (QueueImpl) getProxyToQueue(queue);
    assertEquals(0, queueView.getMessageCount());
    assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) 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) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Session(javax.jms.Session) 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