Search in sources :

Example 16 with PagingStore

use of org.apache.activemq.artemis.core.paging.PagingStore in project activemq-artemis by apache.

the class PagingTest method testExpireLargeMessageOnPaging.

@Test
public void testExpireLargeMessageOnPaging() throws Exception {
    clearDataRecreateServerDirs();
    Configuration config = createDefaultInVMConfig().setMessageExpiryScanPeriod(500).setJournalSyncNonTransactional(false);
    Map<String, AddressSettings> settings = new HashMap<>();
    AddressSettings dla = new AddressSettings().setMaxDeliveryAttempts(5).setDeadLetterAddress(new SimpleString("DLA")).setExpiryAddress(new SimpleString("DLA"));
    settings.put(ADDRESS.toString(), dla);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX, settings);
    server.start();
    final int messageSize = 20;
    try {
        ServerLocator locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
        ClientSessionFactory sf = locator.createSessionFactory();
        ClientSession session = sf.createSession(false, false, false);
        session.createQueue(ADDRESS, ADDRESS, true);
        session.createQueue("DLA", "DLA", true);
        PagingStore pgStoreAddress = server.getPagingManager().getPageStore(ADDRESS);
        pgStoreAddress.startPaging();
        PagingStore pgStoreDLA = server.getPagingManager().getPageStore(new SimpleString("DLA"));
        ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
        ClientMessage message = null;
        for (int i = 0; i < 500; i++) {
            if (i % 100 == 0)
                log.info("send message #" + i);
            message = session.createMessage(true);
            message.putStringProperty("id", "str" + i);
            message.setExpiration(System.currentTimeMillis() + 2000);
            if (i % 2 == 0) {
                message.setBodyInputStream(createFakeLargeStream(messageSize));
            } else {
                byte[] bytes = new byte[messageSize];
                for (int s = 0; s < bytes.length; s++) {
                    bytes[s] = getSamplebyte(s);
                }
                message.getBodyBuffer().writeBytes(bytes);
            }
            producer.send(message);
            if ((i + 1) % 2 == 0) {
                session.commit();
                if (i < 400) {
                    pgStoreAddress.forceAnotherPage();
                }
            }
        }
        session.commit();
        sf.close();
        locator.close();
        server.stop();
        Thread.sleep(3000);
        server.start();
        locator = createInVMNonHALocator();
        sf = locator.createSessionFactory();
        session = sf.createSession(false, false);
        session.start();
        ClientConsumer consAddr = session.createConsumer(ADDRESS);
        assertNull(consAddr.receive(1000));
        ClientConsumer cons = session.createConsumer("DLA");
        for (int i = 0; i < 500; i++) {
            log.info("Received message " + i);
            message = cons.receive(10000);
            assertNotNull(message);
            message.acknowledge();
            message.saveToOutputStream(new OutputStream() {

                @Override
                public void write(int b) throws IOException {
                }
            });
        }
        assertNull(cons.receiveImmediate());
        session.commit();
        cons.close();
        long timeout = System.currentTimeMillis() + 5000;
        pgStoreAddress = server.getPagingManager().getPageStore(ADDRESS);
        while (timeout > System.currentTimeMillis() && pgStoreAddress.isPaging()) {
            Thread.sleep(50);
        }
        assertFalse(pgStoreAddress.isPaging());
        session.close();
    } finally {
        locator.close();
        try {
            server.stop();
        } catch (Throwable ignored) {
        }
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) IOException(java.io.IOException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 17 with PagingStore

use of org.apache.activemq.artemis.core.paging.PagingStore in project activemq-artemis by apache.

the class PagingTest method testSyncPage.

@Test
public void testSyncPage() throws Exception {
    Configuration config = createDefaultInVMConfig();
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    try {
        server.addAddressInfo(new AddressInfo(PagingTest.ADDRESS, RoutingType.ANYCAST));
        server.createQueue(PagingTest.ADDRESS, RoutingType.ANYCAST, PagingTest.ADDRESS, null, true, false);
        final CountDownLatch pageUp = new CountDownLatch(0);
        final CountDownLatch pageDone = new CountDownLatch(1);
        OperationContext ctx = new DummyOperationContext(pageUp, pageDone);
        OperationContextImpl.setContext(ctx);
        PagingManager paging = server.getPagingManager();
        PagingStore store = paging.getPageStore(ADDRESS);
        store.sync();
        assertTrue(pageUp.await(10, TimeUnit.SECONDS));
        assertTrue(pageDone.await(10, TimeUnit.SECONDS));
        server.stop();
    } finally {
        try {
            server.stop();
        } catch (Throwable ignored) {
        }
        OperationContextImpl.clearContext();
    }
}
Also used : OperationContext(org.apache.activemq.artemis.core.persistence.OperationContext) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) PagingManager(org.apache.activemq.artemis.core.paging.PagingManager) CountDownLatch(java.util.concurrent.CountDownLatch) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 18 with PagingStore

use of org.apache.activemq.artemis.core.paging.PagingStore in project activemq-artemis by apache.

the class PagingTest method testTwoQueuesAndOneInativeQueue.

@Test
public void testTwoQueuesAndOneInativeQueue() throws Exception {
    boolean persistentMessages = true;
    clearDataRecreateServerDirs();
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    try {
        ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(120000).setConnectionTTL(5000000).setCallTimeout(120000).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
        ClientSessionFactory sf = locator.createSessionFactory();
        ClientSession session = sf.createSession(false, false, false);
        session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS.concat("=1"), null, true);
        session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS.concat("=2"), null, true);
        // A queue with an impossible filter
        session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS.concat("-3"), new SimpleString("nothing='something'"), true);
        PagingStore store = server.getPagingManager().getPageStore(ADDRESS);
        Queue queue = server.locateQueue(PagingTest.ADDRESS.concat("=1"));
        queue.getPageSubscription().getPagingStore().startPaging();
        ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
        ClientMessage message = session.createMessage(persistentMessages);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(new byte[1024]);
        producer.send(message);
        session.commit();
        session.start();
        for (int msg = 1; msg <= 2; msg++) {
            ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS.concat("=" + msg));
            message = consumer.receive(5000);
            assertNotNull(message);
            message.acknowledge();
            assertNull(consumer.receiveImmediate());
            consumer.close();
        }
        session.commit();
        session.close();
        store.getCursorProvider().cleanup();
        waitForNotPaging(server.locateQueue(PagingTest.ADDRESS.concat("=1")));
        sf.close();
        locator.close();
    } finally {
        try {
            server.stop();
        } catch (Throwable ignored) {
        }
    }
}
Also used : DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) Queue(org.apache.activemq.artemis.core.server.Queue) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 19 with PagingStore

use of org.apache.activemq.artemis.core.paging.PagingStore in project activemq-artemis by apache.

the class PagingTest method testPageHole.

// We send messages to pages, create a big hole (a few pages without any messages), ack everything
// and expect it to move to the next page
@Test
public void testPageHole() throws Throwable {
    clearDataRecreateServerDirs();
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    try {
        ServerLocator locator = createInVMNonHALocator().setBlockOnDurableSend(true);
        ClientSessionFactory sf = locator.createSessionFactory();
        ClientSession session = sf.createSession(true, true, 0);
        session.createQueue(ADDRESS.toString(), "Q1", "dest=1", true);
        session.createQueue(ADDRESS.toString(), "Q2", "dest=2", true);
        PagingStore store = server.getPagingManager().getPageStore(ADDRESS);
        store.startPaging();
        ClientProducer prod = session.createProducer(ADDRESS);
        ClientMessage msg = session.createMessage(true);
        msg.putIntProperty("dest", 1);
        prod.send(msg);
        for (int i = 0; i < 100; i++) {
            msg = session.createMessage(true);
            msg.putIntProperty("dest", 2);
            prod.send(msg);
            if (i > 0 && i % 10 == 0) {
                store.forceAnotherPage();
            }
        }
        session.start();
        ClientConsumer cons1 = session.createConsumer("Q1");
        ClientMessage msgReceivedCons1 = cons1.receive(5000);
        assertNotNull(msgReceivedCons1);
        msgReceivedCons1.acknowledge();
        ClientConsumer cons2 = session.createConsumer("Q2");
        for (int i = 0; i < 100; i++) {
            ClientMessage msgReceivedCons2 = cons2.receive(1000);
            assertNotNull(msgReceivedCons2);
            msgReceivedCons2.acknowledge();
            session.commit();
            // It will send another message when it's mid consumed
            if (i == 20) {
                // wait at least one page to be deleted before sending a new one
                for (long timeout = System.currentTimeMillis() + 5000; timeout > System.currentTimeMillis() && store.checkPageFileExists(2); ) {
                    Thread.sleep(10);
                }
                msg = session.createMessage(true);
                msg.putIntProperty("dest", 1);
                prod.send(msg);
            }
        }
        msgReceivedCons1 = cons1.receive(5000);
        assertNotNull(msgReceivedCons1);
        msgReceivedCons1.acknowledge();
        assertNull(cons1.receiveImmediate());
        assertNull(cons2.receiveImmediate());
        session.commit();
        session.close();
        waitForNotPaging(store);
    } finally {
        server.stop();
    }
}
Also used : DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 20 with PagingStore

use of org.apache.activemq.artemis.core.paging.PagingStore in project activemq-artemis by apache.

the class PagingTest method internalTestPageOnScheduling.

public void internalTestPageOnScheduling(final boolean restart) throws Exception {
    clearDataRecreateServerDirs();
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    final int numberOfMessages = 1000;
    final int numberOfBytes = 1024;
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
    sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(null, null, false, true, true, false, 0);
    session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);
    ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
    ClientMessage message = null;
    byte[] body = new byte[numberOfBytes];
    for (int j = 0; j < numberOfBytes; j++) {
        body[j] = ActiveMQTestBase.getSamplebyte(j);
    }
    long scheduledTime = System.currentTimeMillis() + 5000;
    for (int i = 0; i < numberOfMessages; i++) {
        message = session.createMessage(true);
        message.getBodyBuffer().writeBytes(body);
        message.putIntProperty(new SimpleString("id"), i);
        PagingStore store = server.getPagingManager().getPageStore(PagingTest.ADDRESS);
        // Worse scenario possible... only schedule what's on pages
        if (store.getCurrentPage() != null) {
            message.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, scheduledTime);
        }
        producer.send(message);
    }
    if (restart) {
        session.close();
        server.stop();
        server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
        server.start();
        sf = createSessionFactory(locator);
        session = sf.createSession(null, null, false, true, true, false, 0);
    }
    ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS);
    session.start();
    for (int i = 0; i < numberOfMessages; i++) {
        ClientMessage message2 = consumer.receive(PagingTest.RECEIVE_TIMEOUT);
        Assert.assertNotNull(message2);
        message2.acknowledge();
        Assert.assertNotNull(message2);
        Long scheduled = (Long) message2.getObjectProperty(Message.HDR_SCHEDULED_DELIVERY_TIME);
        if (scheduled != null) {
            Assert.assertTrue("Scheduling didn't work", System.currentTimeMillis() >= scheduledTime);
        }
        try {
            assertBodiesEqual(body, message2.getBodyBuffer());
        } catch (AssertionError e) {
            PagingTest.log.info("Expected buffer:" + ActiveMQTestBase.dumpBytesHex(body, 40));
            PagingTest.log.info("Arriving buffer:" + ActiveMQTestBase.dumpBytesHex(message2.getBodyBuffer().toByteBuffer().array(), 40));
            throw e;
        }
    }
    consumer.close();
    session.close();
}
Also used : DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore)

Aggregations

PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)48 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)31 Test (org.junit.Test)24 Configuration (org.apache.activemq.artemis.core.config.Configuration)19 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)17 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)17 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)17 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)17 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)16 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)15 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)15 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)15 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)11 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)11 HashMap (java.util.HashMap)9 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)9 Queue (org.apache.activemq.artemis.core.server.Queue)9 PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)8 ArrayList (java.util.ArrayList)7 Page (org.apache.activemq.artemis.core.paging.impl.Page)6