use of org.apache.activemq.artemis.tests.unit.util.FakePagingManager 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) {
}
}
}
}
Aggregations