Search in sources :

Example 66 with ActiveMQBuffer

use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.

the class PagingTest method testMissingTXEverythingAcked2.

@Test
public void testMissingTXEverythingAcked2() throws Exception {
    clearDataRecreateServerDirs();
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    final int numberOfMessages = 6;
    final int numberOfTX = 2;
    final int messagesPerTX = numberOfMessages / numberOfTX;
    try {
        locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
        sf = createSessionFactory(locator);
        ClientSession session = sf.createSession(false, false, false);
        session.createQueue(ADDRESS.toString(), "q1", true);
        session.createQueue(ADDRESS.toString(), "q2", true);
        server.getPagingManager().getPageStore(ADDRESS).startPaging();
        ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
        ClientMessage message = null;
        byte[] body = new byte[MESSAGE_SIZE];
        ByteBuffer bb = ByteBuffer.wrap(body);
        for (int j = 1; j <= MESSAGE_SIZE; j++) {
            bb.put(getSamplebyte(j));
        }
        for (int i = 0; i < numberOfMessages; i++) {
            message = session.createMessage(true);
            ActiveMQBuffer bodyLocal = message.getBodyBuffer();
            bodyLocal.writeBytes(body);
            message.putStringProperty("id", "str-" + i);
            producer.send(message);
            if ((i + 1) % messagesPerTX == 0) {
                session.commit();
            }
        }
        session.commit();
        session.start();
        for (int i = 1; i <= 2; i++) {
            ClientConsumer cons = session.createConsumer("q" + i);
            for (int j = 0; j < 3; j++) {
                ClientMessage msg = cons.receive(5000);
                assertNotNull(msg);
                assertEquals("str-" + j, msg.getStringProperty("id"));
                msg.acknowledge();
            }
            session.commit();
        }
        session.close();
    } finally {
        locator.close();
        try {
            server.stop();
        } catch (Throwable ignored) {
        }
    }
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    locator = createInVMNonHALocator();
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
    ClientSessionFactory csf = createSessionFactory(locator);
    ClientSession session = csf.createSession();
    session.start();
    for (int i = 1; i <= 2; i++) {
        ClientConsumer cons = session.createConsumer("q" + i);
        for (int j = 3; j < 6; j++) {
            ClientMessage msg = cons.receive(5000);
            assertNotNull(msg);
            assertEquals("str-" + j, msg.getStringProperty("id"));
            msg.acknowledge();
        }
        session.commit();
        assertNull(cons.receive(500));
    }
    session.close();
    long timeout = System.currentTimeMillis() + 5000;
    while (System.currentTimeMillis() < timeout && server.getPagingManager().getPageStore(ADDRESS).isPaging()) {
        Thread.sleep(100);
    }
}
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) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ByteBuffer(java.nio.ByteBuffer) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 67 with ActiveMQBuffer

use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.

the class PagingTest method testMissingTXEverythingAcked.

@Test
public void testMissingTXEverythingAcked() throws Exception {
    clearDataRecreateServerDirs();
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    final int numberOfMessages = 5000;
    final int numberOfTX = 10;
    final int messagesPerTX = numberOfMessages / numberOfTX;
    try {
        locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
        sf = createSessionFactory(locator);
        ClientSession session = sf.createSession(false, false, false);
        session.createQueue(ADDRESS.toString(), "q1", true);
        session.createQueue(ADDRESS.toString(), "q2", true);
        ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
        ClientMessage message = null;
        byte[] body = new byte[MESSAGE_SIZE];
        ByteBuffer bb = ByteBuffer.wrap(body);
        for (int j = 1; j <= MESSAGE_SIZE; j++) {
            bb.put(getSamplebyte(j));
        }
        for (int i = 0; i < numberOfMessages; i++) {
            message = session.createMessage(true);
            ActiveMQBuffer bodyLocal = message.getBodyBuffer();
            bodyLocal.writeBytes(body);
            message.putIntProperty(new SimpleString("id"), i);
            producer.send(message);
            if (i % messagesPerTX == 0) {
                session.commit();
            }
        }
        session.commit();
        session.close();
        ArrayList<RecordInfo> records = new ArrayList<>();
        List<PreparedTransactionInfo> list = new ArrayList<>();
        server.getStorageManager().getMessageJournal().stop();
        Journal jrn = server.getStorageManager().getMessageJournal();
        jrn.start();
        jrn.load(records, list, null);
        // Delete everything from the journal
        for (RecordInfo info : records) {
            if (!info.isUpdate && info.getUserRecordType() != JournalRecordIds.PAGE_CURSOR_COUNTER_VALUE && info.getUserRecordType() != JournalRecordIds.PAGE_CURSOR_COUNTER_INC && info.getUserRecordType() != JournalRecordIds.PAGE_CURSOR_COMPLETE) {
                jrn.appendDeleteRecord(info.id, false);
            }
        }
        jrn.stop();
    } finally {
        try {
            server.stop();
        } catch (Throwable ignored) {
        }
    }
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    ClientSessionFactory csf = createSessionFactory(locator);
    ClientSession sess = csf.createSession();
    sess.start();
    ClientConsumer cons = sess.createConsumer("q1");
    assertNull(cons.receiveImmediate());
    ClientConsumer cons2 = sess.createConsumer("q2");
    assertNull(cons2.receiveImmediate());
    Queue q1 = server.locateQueue(new SimpleString("q1"));
    Queue q2 = server.locateQueue(new SimpleString("q2"));
    q1.getPageSubscription().cleanupEntries(false);
    q2.getPageSubscription().cleanupEntries(false);
    PageCursorProvider provider = q1.getPageSubscription().getPagingStore().getCursorProvider();
    provider.cleanup();
    waitForNotPaging(q1);
    sess.close();
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) 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) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Journal(org.apache.activemq.artemis.core.journal.Journal) DescribeJournal(org.apache.activemq.artemis.core.persistence.impl.journal.DescribeJournal) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ByteBuffer(java.nio.ByteBuffer) 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) PageCursorProvider(org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 68 with ActiveMQBuffer

use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.

the class PagingTest method testParialConsume.

@Test
public void testParialConsume() throws Exception {
    clearDataRecreateServerDirs();
    Configuration config = createDefaultInVMConfig();
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    final int numberOfMessages = 1000;
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
    sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(null, null, false, false, false, false, 0);
    session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);
    ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
    ClientMessage message = null;
    for (int i = 0; i < numberOfMessages; i++) {
        message = session.createMessage(true);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(new byte[1024]);
        message.putIntProperty(new SimpleString("id"), i);
        producer.send(message);
    }
    session.commit();
    session.close();
    locator.close();
    server.stop();
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    locator = createInVMNonHALocator();
    sf = createSessionFactory(locator);
    session = sf.createSession(null, null, false, false, false, false, 0);
    ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS);
    session.start();
    // 347 = I just picked any odd number, not rounded, to make sure it's not at the beginning of any page
    for (int i = 0; i < 347; i++) {
        ClientMessage msg = consumer.receive(5000);
        assertEquals(i, msg.getIntProperty("id").intValue());
        Assert.assertNotNull(msg);
        msg.acknowledge();
        session.commit();
    }
    session.close();
    locator.close();
    server.stop();
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    locator = createInVMNonHALocator();
    sf = createSessionFactory(locator);
    session = sf.createSession(null, null, false, false, false, false, 0);
    consumer = session.createConsumer(PagingTest.ADDRESS);
    session.start();
    for (int i = 347; i < numberOfMessages; i++) {
        ClientMessage msg = consumer.receive(5000);
        assertEquals(i, msg.getIntProperty("id").intValue());
        Assert.assertNotNull(msg);
        msg.acknowledge();
        session.commit();
    }
    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) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 69 with ActiveMQBuffer

use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.

the class PagingTest method testDeletePhysicalPages.

/**
 * This test will remove all the page directories during a restart, simulating a crash scenario. The server should still start after this
 */
@Test
public void testDeletePhysicalPages() throws Exception {
    clearDataRecreateServerDirs();
    Configuration config = createDefaultInVMConfig().setPersistDeliveryCountBeforeDelivery(true);
    config.setJournalSyncNonTransactional(false);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    final int numberOfMessages = 1000;
    locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
    sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, false, false);
    session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);
    ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
    ClientMessage message = null;
    byte[] body = new byte[MESSAGE_SIZE];
    ByteBuffer bb = ByteBuffer.wrap(body);
    for (int j = 1; j <= MESSAGE_SIZE; j++) {
        bb.put(getSamplebyte(j));
    }
    for (int i = 0; i < numberOfMessages; i++) {
        message = session.createMessage(true);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(body);
        message.putIntProperty(new SimpleString("id"), i);
        producer.send(message);
        if (i % 1000 == 0) {
            session.commit();
        }
    }
    session.commit();
    session.close();
    session = null;
    sf.close();
    locator.close();
    server.stop();
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    locator = createInVMNonHALocator();
    sf = createSessionFactory(locator);
    Queue queue = server.locateQueue(ADDRESS);
    assertEquals(numberOfMessages, getMessageCount(queue));
    int msgReceived = 0;
    ClientSession sessionConsumer = sf.createSession(false, false, false);
    sessionConsumer.start();
    ClientConsumer consumer = sessionConsumer.createConsumer(PagingTest.ADDRESS);
    for (int msgCount = 0; msgCount < numberOfMessages; msgCount++) {
        log.info("Received " + msgCount);
        msgReceived++;
        ClientMessage msg = consumer.receiveImmediate();
        if (msg == null) {
            log.info("It's null. leaving now");
            sessionConsumer.commit();
            fail("Didn't receive a message");
        }
        msg.acknowledge();
        if (msgCount % 5 == 0) {
            log.info("commit");
            sessionConsumer.commit();
        }
    }
    sessionConsumer.commit();
    sessionConsumer.close();
    sf.close();
    locator.close();
    assertEquals(0, getMessageCount(queue));
    long timeout = System.currentTimeMillis() + 5000;
    while (timeout > System.currentTimeMillis() && queue.getPageSubscription().getPagingStore().isPaging()) {
        Thread.sleep(100);
    }
    assertFalse(queue.getPageSubscription().getPagingStore().isPaging());
    server.stop();
    // Deleting the paging data. Simulating a failure
    // a dumb user, or anything that will remove the data
    deleteDirectory(new File(getPageDir()));
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
    sf = createSessionFactory(locator);
    queue = server.locateQueue(ADDRESS);
    sf = createSessionFactory(locator);
    session = sf.createSession(false, false, false);
    producer = session.createProducer(PagingTest.ADDRESS);
    for (int i = 0; i < numberOfMessages * 2; i++) {
        message = session.createMessage(true);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(body);
        message.putIntProperty(new SimpleString("theid"), i);
        producer.send(message);
        if (i % 1000 == 0) {
            session.commit();
        }
    }
    session.commit();
    server.stop();
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    locator = createInVMNonHALocator();
    sf = createSessionFactory(locator);
    queue = server.locateQueue(ADDRESS);
    // assertEquals(numberOfMessages, getMessageCount(queue));
    msgReceived = 0;
    sessionConsumer = sf.createSession(false, false, false);
    sessionConsumer.start();
    consumer = sessionConsumer.createConsumer(PagingTest.ADDRESS);
    for (int msgCount = 0; msgCount < numberOfMessages; msgCount++) {
        log.info("Received " + msgCount);
        msgReceived++;
        ClientMessage msg = consumer.receive(5000);
        if (msg == null) {
            log.info("It's null. leaving now");
            sessionConsumer.commit();
            fail("Didn't receive a message");
        }
        System.out.println("Message " + msg.getIntProperty(SimpleString.toSimpleString("theid")));
        msg.acknowledge();
        if (msgCount % 5 == 0) {
            log.info("commit");
            sessionConsumer.commit();
        }
    }
    sessionConsumer.commit();
    sessionConsumer.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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ByteBuffer(java.nio.ByteBuffer) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) File(java.io.File) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 70 with ActiveMQBuffer

use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.

the class PagingTest method testTwoQueuesConsumeOneRestart.

@Test
public void testTwoQueuesConsumeOneRestart() throws Exception {
    boolean persistentMessages = true;
    clearDataRecreateServerDirs();
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    final int messageSize = 1024;
    final int numberOfMessages = 1000;
    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);
        ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
        ClientMessage message = null;
        byte[] body = new byte[messageSize];
        for (int i = 0; i < numberOfMessages; i++) {
            message = session.createMessage(persistentMessages);
            ActiveMQBuffer bodyLocal = message.getBodyBuffer();
            bodyLocal.writeBytes(body);
            message.putIntProperty("propTest", i % 2 == 0 ? 1 : 2);
            producer.send(message);
            if (i % 1000 == 0) {
                session.commit();
            }
        }
        session.commit();
        session.start();
        session.deleteQueue(PagingTest.ADDRESS.concat("=1"));
        sf = locator.createSessionFactory();
        session = sf.createSession(false, false, false);
        session.start();
        ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS.concat("=2"));
        for (int i = 0; i < numberOfMessages; i++) {
            message = consumer.receive(5000);
            assertNotNull(message);
            message.acknowledge();
        }
        session.commit();
        assertNull(consumer.receiveImmediate());
        consumer.close();
        long timeout = System.currentTimeMillis() + 10000;
        PagingStore store = server.getPagingManager().getPageStore(ADDRESS);
        // It's async, so need to wait a bit for it happening
        while (timeout > System.currentTimeMillis() && store.isPaging()) {
            Thread.sleep(100);
        }
        assertFalse(server.getPagingManager().getPageStore(ADDRESS).isPaging());
        server.stop();
        server.start();
        server.stop();
        server.start();
        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) 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) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Aggregations

ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)150 Test (org.junit.Test)81 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)49 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)44 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)39 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)38 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)35 ByteBuffer (java.nio.ByteBuffer)34 Configuration (org.apache.activemq.artemis.core.config.Configuration)34 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)27 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)25 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)25 ArrayList (java.util.ArrayList)21 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)21 Queue (org.apache.activemq.artemis.core.server.Queue)18 HashMap (java.util.HashMap)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)15 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)15 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)14