Search in sources :

Example 1 with FakePostOffice

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

the class DeleteMessagesOnStartupTest method testDeleteMessagesOnStartup.

@Test
public void testDeleteMessagesOnStartup() throws Exception {
    createStorage();
    Queue theQueue = new FakeQueue(new SimpleString(""));
    HashMap<Long, Queue> queues = new HashMap<>();
    queues.put(100L, theQueue);
    Message msg = new CoreMessage(1, 100);
    journal.storeMessage(msg);
    for (int i = 2; i < 100; i++) {
        journal.storeMessage(new CoreMessage(i, 100));
    }
    journal.storeReference(100, 1, true);
    journal.stop();
    journal.start();
    journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
    FakePostOffice postOffice = new FakePostOffice();
    journal.loadMessageJournal(postOffice, null, null, null, null, null, null, new PostOfficeJournalLoader(postOffice, null, journal, null, null, null, null, null, queues));
    Assert.assertEquals(98, deletedMessage.size());
    for (Long messageID : deletedMessage) {
        Assert.assertTrue("messageID = " + messageID, messageID.longValue() >= 2 && messageID <= 99);
    }
}
Also used : PostOfficeJournalLoader(org.apache.activemq.artemis.core.server.impl.PostOfficeJournalLoader) GroupingInfo(org.apache.activemq.artemis.core.persistence.GroupingInfo) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) HashMap(java.util.HashMap) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueBindingInfo(org.apache.activemq.artemis.core.persistence.QueueBindingInfo) FakePostOffice(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakePostOffice) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) FakeQueue(org.apache.activemq.artemis.tests.unit.core.postoffice.impl.FakeQueue) AddressBindingInfo(org.apache.activemq.artemis.core.persistence.AddressBindingInfo) Queue(org.apache.activemq.artemis.core.server.Queue) FakeQueue(org.apache.activemq.artemis.tests.unit.core.postoffice.impl.FakeQueue) Test(org.junit.Test)

Example 2 with FakePostOffice

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

the class StorageManagerTestBase method createStorage.

/**
 * @throws Exception
 */
protected void createStorage() throws Exception {
    if (storeType == StoreConfiguration.StoreType.DATABASE) {
        journal = createJDBCJournalStorageManager(createDefaultJDBCConfig(true));
    } else {
        journal = createJournalStorageManager(createDefaultInVMConfig());
    }
    journal.start();
    journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
    journal.loadMessageJournal(new FakePostOffice(), null, null, null, null, null, null, new FakeJournalLoader());
}
Also used : GroupingInfo(org.apache.activemq.artemis.core.persistence.GroupingInfo) FakeJournalLoader(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeJournalLoader) QueueBindingInfo(org.apache.activemq.artemis.core.persistence.QueueBindingInfo) FakePostOffice(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakePostOffice) AddressBindingInfo(org.apache.activemq.artemis.core.persistence.AddressBindingInfo)

Example 3 with FakePostOffice

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

the class DuplicateDetectionUnitTest method testReloadDuplication.

// Public --------------------------------------------------------
@Test
public void testReloadDuplication() throws Exception {
    JournalStorageManager journal = null;
    try {
        clearDataRecreateServerDirs();
        SimpleString ADDRESS = new SimpleString("address");
        Configuration configuration = createDefaultInVMConfig();
        PostOffice postOffice = new FakePostOffice();
        ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(ActiveMQDefaultConfiguration.getDefaultScheduledThreadPoolMaxSize(), ActiveMQThreadFactory.defaultThreadFactory());
        journal = new JournalStorageManager(configuration, EmptyCriticalAnalyzer.getInstance(), factory, factory);
        journal.start();
        journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
        HashMap<SimpleString, List<Pair<byte[], Long>>> mapDups = new HashMap<>();
        FakePagingManager pagingManager = new FakePagingManager();
        journal.loadMessageJournal(postOffice, pagingManager, new ResourceManagerImpl(0, 0, scheduledThreadPool), null, mapDups, null, null, new PostOfficeJournalLoader(postOffice, pagingManager, null, null, null, null, null, null));
        Assert.assertEquals(0, mapDups.size());
        DuplicateIDCacheImpl cacheID = new DuplicateIDCacheImpl(ADDRESS, 10, journal, true);
        for (int i = 0; i < 100; i++) {
            cacheID.addToCache(RandomUtil.randomBytes());
        }
        journal.stop();
        journal = new JournalStorageManager(configuration, EmptyCriticalAnalyzer.getInstance(), factory, factory);
        journal.start();
        journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
        journal.loadMessageJournal(postOffice, pagingManager, new ResourceManagerImpl(0, 0, scheduledThreadPool), null, mapDups, null, null, new PostOfficeJournalLoader(postOffice, pagingManager, null, null, null, null, null, null));
        Assert.assertEquals(1, mapDups.size());
        List<Pair<byte[], Long>> values = mapDups.get(ADDRESS);
        Assert.assertEquals(10, values.size());
        cacheID = new DuplicateIDCacheImpl(ADDRESS, 10, journal, true);
        cacheID.load(values);
        for (int i = 0; i < 100; i++) {
            cacheID.addToCache(RandomUtil.randomBytes(), null);
        }
        journal.stop();
        mapDups.clear();
        journal = new JournalStorageManager(configuration, EmptyCriticalAnalyzer.getInstance(), factory, factory);
        journal.start();
        journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
        journal.loadMessageJournal(postOffice, pagingManager, new ResourceManagerImpl(0, 0, scheduledThreadPool), null, mapDups, null, null, new PostOfficeJournalLoader(postOffice, pagingManager, null, null, null, null, null, null));
        Assert.assertEquals(1, mapDups.size());
        values = mapDups.get(ADDRESS);
        Assert.assertEquals(10, values.size());
        scheduledThreadPool.shutdown();
    } finally {
        if (journal != null) {
            try {
                journal.stop();
            } catch (Throwable ignored) {
            }
        }
    }
}
Also used : PostOfficeJournalLoader(org.apache.activemq.artemis.core.server.impl.PostOfficeJournalLoader) GroupingInfo(org.apache.activemq.artemis.core.persistence.GroupingInfo) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Configuration(org.apache.activemq.artemis.core.config.Configuration) ActiveMQDefaultConfiguration(org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration) HashMap(java.util.HashMap) ResourceManagerImpl(org.apache.activemq.artemis.core.transaction.impl.ResourceManagerImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) FakePostOffice(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakePostOffice) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) QueueBindingInfo(org.apache.activemq.artemis.core.persistence.QueueBindingInfo) FakePostOffice(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakePostOffice) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) DuplicateIDCacheImpl(org.apache.activemq.artemis.core.postoffice.impl.DuplicateIDCacheImpl) FakePagingManager(org.apache.activemq.artemis.tests.unit.util.FakePagingManager) ArrayList(java.util.ArrayList) List(java.util.List) AddressBindingInfo(org.apache.activemq.artemis.core.persistence.AddressBindingInfo) Pair(org.apache.activemq.artemis.api.core.Pair) Test(org.junit.Test)

Example 4 with FakePostOffice

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

the class RestartSMTest method testRestartStorageManager.

@Test
public void testRestartStorageManager() throws Exception {
    File testdir = new File(getTestDir());
    deleteDirectory(testdir);
    PostOffice postOffice = new FakePostOffice();
    final JournalStorageManager journal = new JournalStorageManager(createDefaultInVMConfig(), EmptyCriticalAnalyzer.getInstance(), execFactory, execFactory);
    try {
        journal.start();
        List<QueueBindingInfo> queueBindingInfos = new ArrayList<>();
        journal.loadBindingJournal(queueBindingInfos, new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
        journal.loadMessageJournal(postOffice, null, null, null, null, null, null, new FakeJournalLoader());
        journal.stop();
        deleteDirectory(testdir);
        journal.start();
        journal.loadMessageJournal(postOffice, null, null, null, null, null, null, new FakeJournalLoader());
        queueBindingInfos = new ArrayList<>();
        journal.loadBindingJournal(queueBindingInfos, new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
        journal.start();
    } finally {
        try {
            journal.stop();
        } catch (Exception ex) {
            RestartSMTest.log.warn(ex.getMessage(), ex);
        }
    }
}
Also used : GroupingInfo(org.apache.activemq.artemis.core.persistence.GroupingInfo) ArrayList(java.util.ArrayList) FakePostOffice(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakePostOffice) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) QueueBindingInfo(org.apache.activemq.artemis.core.persistence.QueueBindingInfo) FakePostOffice(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakePostOffice) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) FakeJournalLoader(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeJournalLoader) AddressBindingInfo(org.apache.activemq.artemis.core.persistence.AddressBindingInfo) File(java.io.File) Test(org.junit.Test)

Aggregations

AddressBindingInfo (org.apache.activemq.artemis.core.persistence.AddressBindingInfo)4 GroupingInfo (org.apache.activemq.artemis.core.persistence.GroupingInfo)4 QueueBindingInfo (org.apache.activemq.artemis.core.persistence.QueueBindingInfo)4 FakePostOffice (org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakePostOffice)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 JournalStorageManager (org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)2 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)2 PostOfficeJournalLoader (org.apache.activemq.artemis.core.server.impl.PostOfficeJournalLoader)2 FakeJournalLoader (org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeJournalLoader)2 File (java.io.File)1 List (java.util.List)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ActiveMQDefaultConfiguration (org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration)1 Message (org.apache.activemq.artemis.api.core.Message)1 Pair (org.apache.activemq.artemis.api.core.Pair)1 Configuration (org.apache.activemq.artemis.core.config.Configuration)1 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)1