Search in sources :

Example 1 with DuplicateIDCacheImpl

use of org.apache.activemq.artemis.core.postoffice.impl.DuplicateIDCacheImpl in project activemq-artemis by apache.

the class DuplicateCacheTest method testDuplicateNonPersistent.

@Test
public void testDuplicateNonPersistent() throws Exception {
    createStorage();
    DuplicateIDCache cache = new DuplicateIDCacheImpl(new SimpleString("test"), 2000, journal, false);
    TransactionImpl tx = new TransactionImpl(journal);
    for (int i = 0; i < 5000; i++) {
        byte[] bytes = RandomUtil.randomBytes();
        cache.addToCache(bytes, tx);
    }
    tx.commit();
    for (int i = 0; i < 5000; i++) {
        byte[] bytes = RandomUtil.randomBytes();
        cache.addToCache(bytes, null);
    }
}
Also used : DuplicateIDCache(org.apache.activemq.artemis.core.postoffice.DuplicateIDCache) DuplicateIDCacheImpl(org.apache.activemq.artemis.core.postoffice.impl.DuplicateIDCacheImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) Test(org.junit.Test)

Example 2 with DuplicateIDCacheImpl

use of org.apache.activemq.artemis.core.postoffice.impl.DuplicateIDCacheImpl in project activemq-artemis by apache.

the class DuplicateCacheTest method testDuplicate.

@Test
public void testDuplicate() throws Exception {
    createStorage();
    DuplicateIDCache cache = new DuplicateIDCacheImpl(new SimpleString("test"), 2000, journal, true);
    TransactionImpl tx = new TransactionImpl(journal);
    for (int i = 0; i < 5000; i++) {
        byte[] bytes = RandomUtil.randomBytes();
        cache.addToCache(bytes, tx);
    }
    tx.commit();
    tx = new TransactionImpl(journal);
    for (int i = 0; i < 5000; i++) {
        byte[] bytes = RandomUtil.randomBytes();
        cache.addToCache(bytes, tx);
    }
    tx.commit();
    byte[] id = RandomUtil.randomBytes();
    Assert.assertFalse(cache.contains(id));
    cache.addToCache(id, null);
    Assert.assertTrue(cache.contains(id));
    cache.deleteFromCache(id);
    final CountDownLatch latch = new CountDownLatch(1);
    OperationContextImpl.getContext().executeOnCompletion(new IOCallback() {

        @Override
        public void done() {
            latch.countDown();
        }

        @Override
        public void onError(int errorCode, String errorMessage) {
        }
    }, true);
    Assert.assertTrue(latch.await(1, TimeUnit.MINUTES));
    Assert.assertFalse(cache.contains(id));
}
Also used : DuplicateIDCache(org.apache.activemq.artemis.core.postoffice.DuplicateIDCache) DuplicateIDCacheImpl(org.apache.activemq.artemis.core.postoffice.impl.DuplicateIDCacheImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) IOCallback(org.apache.activemq.artemis.core.io.IOCallback) Test(org.junit.Test)

Example 3 with DuplicateIDCacheImpl

use of org.apache.activemq.artemis.core.postoffice.impl.DuplicateIDCacheImpl 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)

Aggregations

SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 DuplicateIDCacheImpl (org.apache.activemq.artemis.core.postoffice.impl.DuplicateIDCacheImpl)3 Test (org.junit.Test)3 DuplicateIDCache (org.apache.activemq.artemis.core.postoffice.DuplicateIDCache)2 TransactionImpl (org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ActiveMQDefaultConfiguration (org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration)1 Pair (org.apache.activemq.artemis.api.core.Pair)1 Configuration (org.apache.activemq.artemis.core.config.Configuration)1 IOCallback (org.apache.activemq.artemis.core.io.IOCallback)1 AddressBindingInfo (org.apache.activemq.artemis.core.persistence.AddressBindingInfo)1 GroupingInfo (org.apache.activemq.artemis.core.persistence.GroupingInfo)1 QueueBindingInfo (org.apache.activemq.artemis.core.persistence.QueueBindingInfo)1 JournalStorageManager (org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)1 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)1 PostOfficeJournalLoader (org.apache.activemq.artemis.core.server.impl.PostOfficeJournalLoader)1