Search in sources :

Example 16 with PagedMessage

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

the class PageTest method testDamagedPage.

protected void testDamagedPage(final SequentialFileFactory factory, final int numberOfElements) throws Exception {
    SequentialFile file = factory.createSequentialFile("00010.page");
    Page impl = new Page(new SimpleString("something"), new NullStorageManager(), factory, file, 10);
    Assert.assertEquals(10, impl.getPageId());
    impl.open();
    Assert.assertEquals(1, factory.listFiles("page").size());
    SimpleString simpleDestination = new SimpleString("Test");
    addPageElements(simpleDestination, impl, numberOfElements);
    impl.sync();
    long positionA = file.position();
    // Add one record that will be damaged
    addPageElements(simpleDestination, impl, 1);
    long positionB = file.position();
    // Add more 10 as they will need to be ignored
    addPageElements(simpleDestination, impl, 10);
    // Damage data... position the file on the middle between points A and B
    file.position(positionA + (positionB - positionA) / 2);
    ByteBuffer buffer = ByteBuffer.allocate((int) (positionB - file.position()));
    for (int i = 0; i < buffer.capacity(); i++) {
        buffer.put((byte) 'Z');
    }
    buffer.rewind();
    file.writeDirect(buffer, true);
    impl.close();
    file = factory.createSequentialFile("00010.page");
    file.open();
    impl = new Page(new SimpleString("something"), new NullStorageManager(), factory, file, 10);
    List<PagedMessage> msgs = impl.read(new NullStorageManager());
    Assert.assertEquals(numberOfElements, msgs.size());
    Assert.assertEquals(numberOfElements, impl.getNumberOfMessages());
    for (int i = 0; i < msgs.size(); i++) {
        Assert.assertEquals(simpleDestination, msgs.get(i).getMessage().getAddressSimpleString());
    }
    impl.delete(null);
    Assert.assertEquals(0, factory.listFiles("page").size());
    Assert.assertEquals(1, factory.listFiles("invalidPage").size());
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Page(org.apache.activemq.artemis.core.paging.impl.Page) ByteBuffer(java.nio.ByteBuffer)

Example 17 with PagedMessage

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

the class PageTest method testAdd.

/**
 * Validate if everything we add is recovered
 */
protected void testAdd(final SequentialFileFactory factory, final int numberOfElements) throws Exception {
    SequentialFile file = factory.createSequentialFile("00010.page");
    Page impl = new Page(new SimpleString("something"), new NullStorageManager(), factory, file, 10);
    Assert.assertEquals(10, impl.getPageId());
    impl.open();
    Assert.assertEquals(1, factory.listFiles("page").size());
    SimpleString simpleDestination = new SimpleString("Test");
    addPageElements(simpleDestination, impl, numberOfElements);
    impl.sync();
    impl.close();
    file = factory.createSequentialFile("00010.page");
    file.open();
    impl = new Page(new SimpleString("something"), new NullStorageManager(), factory, file, 10);
    List<PagedMessage> msgs = impl.read(new NullStorageManager());
    Assert.assertEquals(numberOfElements, msgs.size());
    Assert.assertEquals(numberOfElements, impl.getNumberOfMessages());
    for (int i = 0; i < msgs.size(); i++) {
        Assert.assertEquals(simpleDestination, msgs.get(i).getMessage().getAddressSimpleString());
    }
    impl.delete(null);
    Assert.assertEquals(0, factory.listFiles(".page").size());
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Page(org.apache.activemq.artemis.core.paging.impl.Page)

Example 18 with PagedMessage

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

the class PagingManagerImplTest method testPagingManager.

@Test
public void testPagingManager() throws Exception {
    HierarchicalRepository<AddressSettings> addressSettings = new HierarchicalObjectRepository<>();
    addressSettings.setDefault(new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE));
    final StorageManager storageManager = new NullStorageManager();
    PagingStoreFactoryNIO storeFactory = new PagingStoreFactoryNIO(storageManager, getPageDirFile(), 100, null, getOrderedExecutor(), true, null);
    PagingManagerImpl managerImpl = new PagingManagerImpl(storeFactory, addressSettings);
    managerImpl.start();
    PagingStore store = managerImpl.getPageStore(new SimpleString("simple-test"));
    ICoreMessage msg = createMessage(1L, new SimpleString("simple-test"), createRandomBuffer(10));
    final RoutingContextImpl ctx = new RoutingContextImpl(null);
    Assert.assertFalse(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock));
    store.startPaging();
    Assert.assertTrue(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock));
    Page page = store.depage();
    page.open();
    List<PagedMessage> msgs = page.read(new NullStorageManager());
    page.close();
    Assert.assertEquals(1, msgs.size());
    ActiveMQTestBase.assertEqualsByteArrays(msg.getBodyBuffer().writerIndex(), msg.getBodyBuffer().toByteBuffer().array(), (msgs.get(0).getMessage()).toCore().getBodyBuffer().toByteBuffer().array());
    Assert.assertTrue(store.isPaging());
    Assert.assertNull(store.depage());
    final RoutingContextImpl ctx2 = new RoutingContextImpl(null);
    Assert.assertFalse(store.page(msg, ctx2.getTransaction(), ctx2.getContextListing(store.getStoreName()), lock));
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Page(org.apache.activemq.artemis.core.paging.impl.Page) HierarchicalObjectRepository(org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository) RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) PagingStoreFactoryNIO(org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO) PagingManagerImpl(org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) Test(org.junit.Test)

Example 19 with PagedMessage

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

the class ReplicationEndpoint method handlePageWrite.

/**
 * @param packet
 */
private void handlePageWrite(final ReplicationPageWriteMessage packet) throws Exception {
    PagedMessage pgdMessage = packet.getPagedMessage();
    pgdMessage.initMessage(storageManager);
    Message msg = pgdMessage.getMessage();
    Page page = getPage(msg.getAddressSimpleString(), packet.getPageNumber());
    page.write(pgdMessage);
}
Also used : PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) ReplicationResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationResponseMessage) ReplicationAddMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationAddMessage) ReplicationStartSyncMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationStartSyncMessage) ReplicationLargeMessageBeginMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationLargeMessageBeginMessage) ReplicationLargeMessageEndMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationLargeMessageEndMessage) ReplicationPageEventMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationPageEventMessage) ReplicationCommitMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationCommitMessage) ReplicationPrepareMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationPrepareMessage) ActiveMQExceptionMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ActiveMQExceptionMessage) BackupReplicationStartFailedMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupReplicationStartFailedMessage) ReplicationLargeMessageWriteMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationLargeMessageWriteMessage) ReplicationPageWriteMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationPageWriteMessage) ReplicationLiveIsStoppingMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationLiveIsStoppingMessage) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) ReplicationDeleteMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationDeleteMessage) ReplicationSyncFileMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationSyncFileMessage) ReplicationAddTXMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationAddTXMessage) ReplicationDeleteTXMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationDeleteTXMessage) Message(org.apache.activemq.artemis.api.core.Message) Page(org.apache.activemq.artemis.core.paging.impl.Page)

Example 20 with PagedMessage

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

the class ReplicationTest method testSendPackets.

@Test
public void testSendPackets() throws Exception {
    setupServer(true);
    JournalStorageManager storage = getStorage();
    manager = liveServer.getReplicationManager();
    waitForComponent(manager);
    Journal replicatedJournal = new ReplicatedJournal((byte) 1, new FakeJournal(), manager);
    replicatedJournal.appendPrepareRecord(1, new FakeData(), false);
    replicatedJournal.appendAddRecord(1, (byte) 1, new FakeData(), false);
    replicatedJournal.appendUpdateRecord(1, (byte) 2, new FakeData(), false);
    replicatedJournal.appendDeleteRecord(1, false);
    replicatedJournal.appendAddRecordTransactional(2, 2, (byte) 1, new FakeData());
    replicatedJournal.appendUpdateRecordTransactional(2, 2, (byte) 2, new FakeData());
    replicatedJournal.appendCommitRecord(2, false);
    replicatedJournal.appendDeleteRecordTransactional(3, 4, new FakeData());
    replicatedJournal.appendPrepareRecord(3, new FakeData(), false);
    replicatedJournal.appendRollbackRecord(3, false);
    blockOnReplication(storage, manager);
    Assert.assertTrue("Expecting no active tokens:" + manager.getActiveTokens(), manager.getActiveTokens().isEmpty());
    CoreMessage msg = new CoreMessage().initBuffer(1024).setMessageID(1);
    SimpleString dummy = new SimpleString("dummy");
    msg.setAddress(dummy);
    replicatedJournal.appendAddRecordTransactional(23, 24, (byte) 1, new FakeData());
    PagedMessage pgmsg = new PagedMessageImpl(msg, new long[0]);
    manager.pageWrite(pgmsg, 1);
    manager.pageWrite(pgmsg, 2);
    manager.pageWrite(pgmsg, 3);
    manager.pageWrite(pgmsg, 4);
    blockOnReplication(storage, manager);
    PagingManager pagingManager = createPageManager(backupServer.getStorageManager(), backupServer.getConfiguration(), backupServer.getExecutorFactory(), backupServer.getAddressSettingsRepository());
    PagingStore store = pagingManager.getPageStore(dummy);
    store.start();
    Assert.assertEquals(4, store.getNumberOfPages());
    store.stop();
    manager.pageDeleted(dummy, 1);
    manager.pageDeleted(dummy, 2);
    manager.pageDeleted(dummy, 3);
    manager.pageDeleted(dummy, 4);
    manager.pageDeleted(dummy, 5);
    manager.pageDeleted(dummy, 6);
    blockOnReplication(storage, manager);
    CoreMessage serverMsg = new CoreMessage();
    serverMsg.setMessageID(500);
    serverMsg.setAddress(new SimpleString("tttt"));
    ActiveMQBuffer buffer = ActiveMQBuffers.dynamicBuffer(100);
    serverMsg.encodeHeadersAndProperties(buffer.byteBuf());
    manager.largeMessageBegin(500);
    manager.largeMessageWrite(500, new byte[1024]);
    manager.largeMessageDelete(Long.valueOf(500), storage);
    blockOnReplication(storage, manager);
    store.start();
    Assert.assertEquals(0, store.getNumberOfPages());
}
Also used : PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) PagingManager(org.apache.activemq.artemis.core.paging.PagingManager) PagedMessageImpl(org.apache.activemq.artemis.core.paging.impl.PagedMessageImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ReplicatedJournal(org.apache.activemq.artemis.core.replication.ReplicatedJournal) Journal(org.apache.activemq.artemis.core.journal.Journal) ReplicatedJournal(org.apache.activemq.artemis.core.replication.ReplicatedJournal) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Aggregations

PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)20 Page (org.apache.activemq.artemis.core.paging.impl.Page)13 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)12 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)7 NullStorageManager (org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager)7 ArrayList (java.util.ArrayList)5 Message (org.apache.activemq.artemis.api.core.Message)5 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)5 RoutingContextImpl (org.apache.activemq.artemis.core.server.impl.RoutingContextImpl)5 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)5 Test (org.junit.Test)5 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)4 PagingStoreFactory (org.apache.activemq.artemis.core.paging.PagingStoreFactory)4 PagingStoreImpl (org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl)4 File (java.io.File)3 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)3 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)3 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)3 PagePosition (org.apache.activemq.artemis.core.paging.cursor.PagePosition)3 LargeServerMessage (org.apache.activemq.artemis.core.server.LargeServerMessage)3