Search in sources :

Example 6 with FakeSequentialFileFactory

use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory in project activemq-artemis by apache.

the class AlignedJournalImplTest method testInconsistentAlignment.

@Test
public void testInconsistentAlignment() throws Exception {
    factory = new FakeSequentialFileFactory(512, true);
    try {
        journalImpl = new JournalImpl(2000, 2, 2, 0, 0, factory, "tt", "tt", 1000);
        Assert.fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException ignored) {
    // expected
    }
}
Also used : FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 7 with FakeSequentialFileFactory

use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory in project activemq-artemis by apache.

the class PagingStoreImplTest method testDepageOnCurrentPage.

@Test
public void testDepageOnCurrentPage() throws Exception {
    SequentialFileFactory factory = new FakeSequentialFileFactory();
    SimpleString destination = new SimpleString("test");
    PagingStoreFactory storeFactory = new FakeStoreFactory(factory);
    PagingStoreImpl storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, PagingStoreImplTest.destinationTestName, new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE), getExecutorFactory().getExecutor(), true);
    storeImpl.start();
    Assert.assertEquals(0, storeImpl.getNumberOfPages());
    storeImpl.startPaging();
    List<ActiveMQBuffer> buffers = new ArrayList<>();
    int numMessages = 10;
    for (int i = 0; i < numMessages; i++) {
        ActiveMQBuffer buffer = createRandomBuffer(i + 1L, 10);
        buffers.add(buffer);
        Message msg = createMessage(i, storeImpl, destination, buffer);
        final RoutingContextImpl ctx = new RoutingContextImpl(null);
        Assert.assertTrue(storeImpl.page(msg, ctx.getTransaction(), ctx.getContextListing(storeImpl.getStoreName()), lock));
    }
    Assert.assertEquals(1, storeImpl.getNumberOfPages());
    storeImpl.sync();
    Page page = storeImpl.depage();
    page.open();
    List<PagedMessage> msg = page.read(new NullStorageManager());
    Assert.assertEquals(numMessages, msg.size());
    Assert.assertEquals(1, storeImpl.getNumberOfPages());
    page = storeImpl.depage();
    Assert.assertNull(page);
    Assert.assertEquals(0, storeImpl.getNumberOfPages());
    for (int i = 0; i < numMessages; i++) {
        ActiveMQBuffer horn1 = buffers.get(i);
        ActiveMQBuffer horn2 = msg.get(i).getMessage().toCore().getBodyBuffer();
        horn1.resetReaderIndex();
        horn2.resetReaderIndex();
        for (int j = 0; j < horn1.writerIndex(); j++) {
            Assert.assertEquals(horn1.readByte(), horn2.readByte());
        }
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) Message(org.apache.activemq.artemis.api.core.Message) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Page(org.apache.activemq.artemis.core.paging.impl.Page) FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) PagingStoreImpl(org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) PagingStoreFactory(org.apache.activemq.artemis.core.paging.PagingStoreFactory) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 8 with FakeSequentialFileFactory

use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory in project activemq-artemis by apache.

the class PagingStoreImplTest method testDoubleStart.

@Test
public void testDoubleStart() throws Exception {
    SequentialFileFactory factory = new FakeSequentialFileFactory();
    PagingStore storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, new FakeStoreFactory(factory), PagingStoreImplTest.destinationTestName, new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE), getExecutorFactory().getExecutor(), true);
    storeImpl.start();
    // this is not supposed to throw an exception.
    // As you could have start being called twice as Stores are dynamically
    // created, on a multi-thread environment
    storeImpl.start();
    storeImpl.stop();
}
Also used : FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) PagingStoreImpl(org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) Test(org.junit.Test)

Example 9 with FakeSequentialFileFactory

use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory in project activemq-artemis by apache.

the class PagingStoreImplTest method testDepageMultiplePages.

@Test
public void testDepageMultiplePages() throws Exception {
    SequentialFileFactory factory = new FakeSequentialFileFactory();
    SimpleString destination = new SimpleString("test");
    PagingStoreFactory storeFactory = new FakeStoreFactory(factory);
    PagingStoreImpl store = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, PagingStoreImplTest.destinationTestName, new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE), getExecutorFactory().getExecutor(), true);
    store.start();
    Assert.assertEquals(0, store.getNumberOfPages());
    store.startPaging();
    Assert.assertEquals(1, store.getNumberOfPages());
    List<ActiveMQBuffer> buffers = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        ActiveMQBuffer buffer = createRandomBuffer(i + 1L, 10);
        buffers.add(buffer);
        if (i == 5) {
            store.forceAnotherPage();
        }
        Message msg = createMessage(i, store, destination, buffer);
        final RoutingContextImpl ctx = new RoutingContextImpl(null);
        Assert.assertTrue(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock));
    }
    Assert.assertEquals(2, store.getNumberOfPages());
    store.sync();
    int sequence = 0;
    for (int pageNr = 0; pageNr < 2; pageNr++) {
        Page page = store.depage();
        System.out.println("numberOfPages = " + store.getNumberOfPages());
        page.open();
        List<PagedMessage> msg = page.read(new NullStorageManager());
        page.close();
        Assert.assertEquals(5, msg.size());
        for (int i = 0; i < 5; i++) {
            Assert.assertEquals(sequence++, msg.get(i).getMessage().getMessageID());
            ActiveMQTestBase.assertEqualsBuffers(18, buffers.get(pageNr * 5 + i), msg.get(i).getMessage().toCore().getBodyBuffer());
        }
    }
    Assert.assertEquals(1, store.getNumberOfPages());
    Assert.assertTrue(store.isPaging());
    Message msg = createMessage(1, store, destination, buffers.get(0));
    final RoutingContextImpl ctx = new RoutingContextImpl(null);
    Assert.assertTrue(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock));
    Page newPage = store.depage();
    newPage.open();
    Assert.assertEquals(1, newPage.read(new NullStorageManager()).size());
    newPage.delete(null);
    Assert.assertEquals(1, store.getNumberOfPages());
    Assert.assertTrue(store.isPaging());
    Assert.assertNull(store.depage());
    Assert.assertFalse(store.isPaging());
    {
        final RoutingContextImpl ctx2 = new RoutingContextImpl(null);
        Assert.assertFalse(store.page(msg, ctx2.getTransaction(), ctx2.getContextListing(store.getStoreName()), lock));
    }
    store.startPaging();
    {
        final RoutingContextImpl ctx2 = new RoutingContextImpl(null);
        Assert.assertTrue(store.page(msg, ctx2.getTransaction(), ctx2.getContextListing(store.getStoreName()), lock));
    }
    Page page = store.depage();
    page.open();
    List<PagedMessage> msgs = page.read(new NullStorageManager());
    Assert.assertEquals(1, msgs.size());
    Assert.assertEquals(1L, msgs.get(0).getMessage().getMessageID());
    ActiveMQTestBase.assertEqualsBuffers(18, buffers.get(0), msgs.get(0).getMessage().toCore().getBodyBuffer());
    Assert.assertEquals(1, store.getNumberOfPages());
    Assert.assertTrue(store.isPaging());
    Assert.assertNull(store.depage());
    Assert.assertEquals(0, store.getNumberOfPages());
    page.open();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) Message(org.apache.activemq.artemis.api.core.Message) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Page(org.apache.activemq.artemis.core.paging.impl.Page) FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) PagingStoreImpl(org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) PagingStoreFactory(org.apache.activemq.artemis.core.paging.PagingStoreFactory) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 10 with FakeSequentialFileFactory

use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory in project activemq-artemis by apache.

the class PagingStoreImplTest method testStore.

@Test
public void testStore() throws Exception {
    SequentialFileFactory factory = new FakeSequentialFileFactory();
    PagingStoreFactory storeFactory = new FakeStoreFactory(factory);
    AddressSettings addressSettings = new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
    PagingStore storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, PagingStoreImplTest.destinationTestName, addressSettings, getExecutorFactory().getExecutor(), true);
    storeImpl.start();
    Assert.assertEquals(0, storeImpl.getNumberOfPages());
    storeImpl.startPaging();
    Assert.assertEquals(1, storeImpl.getNumberOfPages());
    List<ActiveMQBuffer> buffers = new ArrayList<>();
    ActiveMQBuffer buffer = createRandomBuffer(0, 10);
    buffers.add(buffer);
    SimpleString destination = new SimpleString("test");
    Message msg = createMessage(1, storeImpl, destination, buffer);
    Assert.assertTrue(storeImpl.isPaging());
    final RoutingContextImpl ctx = new RoutingContextImpl(null);
    Assert.assertTrue(storeImpl.page(msg, ctx.getTransaction(), ctx.getContextListing(storeImpl.getStoreName()), lock));
    Assert.assertEquals(1, storeImpl.getNumberOfPages());
    storeImpl.sync();
    storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, PagingStoreImplTest.destinationTestName, addressSettings, getExecutorFactory().getExecutor(), true);
    storeImpl.start();
    Assert.assertEquals(1, storeImpl.getNumberOfPages());
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) Message(org.apache.activemq.artemis.api.core.Message) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) PagingStoreImpl(org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl) PagingStoreFactory(org.apache.activemq.artemis.core.paging.PagingStoreFactory) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Aggregations

FakeSequentialFileFactory (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory)11 Test (org.junit.Test)9 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)6 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)6 ArrayList (java.util.ArrayList)4 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)4 PagingStoreImpl (org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl)4 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)4 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)3 Message (org.apache.activemq.artemis.api.core.Message)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)3 PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)3 PagingStoreFactory (org.apache.activemq.artemis.core.paging.PagingStoreFactory)3 RoutingContextImpl (org.apache.activemq.artemis.core.server.impl.RoutingContextImpl)3 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)2 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)2 Page (org.apache.activemq.artemis.core.paging.impl.Page)2 NullStorageManager (org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager)2 ByteBuffer (java.nio.ByteBuffer)1