private StorageManager createStorageManagerMock() { return new NullStorageManager(); }
@Override public long storeHeuristicCompletion(final Xid xid, final boolean isCommit) throws Exception { return generateID(); }
private StorageManager getJournalStorageManager(final Journal bindingsJournal) { NullStorageManager storageManager = new NullStorageManager() { @Override public synchronized void storeID(long journalID, long id) throws Exception { bindingsJournal.appendAddRecord(journalID, JournalRecordIds.ID_COUNTER_RECORD, BatchingIDGenerator.createIDEncodingSupport(id), true); } }; try { storageManager.start(); } catch (Throwable ignored) { } return storageManager; } }
@Override public DuplicateIDCache getDuplicateIDCache(final SimpleString address) { return new DuplicateIDCacheImpl(address, 2000, new NullStorageManager(), false); }
private static void printPages(File pageDirectory, DescribeJournal describeJournal, PrintStream out, boolean safe) { try { ScheduledExecutorService scheduled = Executors.newScheduledThreadPool(1, ActiveMQThreadFactory.defaultThreadFactory()); final ExecutorService executor = Executors.newFixedThreadPool(10, ActiveMQThreadFactory.defaultThreadFactory()); ExecutorFactory execfactory = new ExecutorFactory() { @Override public ArtemisExecutor getExecutor() { return ArtemisExecutor.delegate(executor); } }; final StorageManager sm = new NullStorageManager(); PagingStoreFactory pageStoreFactory = new PagingStoreFactoryNIO(sm, pageDirectory, 1000L, scheduled, execfactory, false, null); HierarchicalRepository<AddressSettings> addressSettingsRepository = new HierarchicalObjectRepository<>(); addressSettingsRepository.setDefault(new AddressSettings()); PagingManager manager = new PagingManagerImpl(pageStoreFactory, addressSettingsRepository); printPages(describeJournal, sm, manager, out, safe); } catch (Exception e) { e.printStackTrace(); } }
private static void printPages(File pageDirectory, DescribeJournal describeJournal, PrintStream out, boolean safe) { try { ScheduledExecutorService scheduled = Executors.newScheduledThreadPool(1, ActiveMQThreadFactory.defaultThreadFactory()); final ExecutorService executor = Executors.newFixedThreadPool(10, ActiveMQThreadFactory.defaultThreadFactory()); ExecutorFactory execfactory = new ExecutorFactory() { @Override public ArtemisExecutor getExecutor() { return ArtemisExecutor.delegate(executor); } }; final StorageManager sm = new NullStorageManager(); PagingStoreFactory pageStoreFactory = new PagingStoreFactoryNIO(sm, pageDirectory, 1000L, scheduled, execfactory, false, null); HierarchicalRepository<AddressSettings> addressSettingsRepository = new HierarchicalObjectRepository<>(); addressSettingsRepository.setDefault(new AddressSettings()); PagingManager manager = new PagingManagerImpl(pageStoreFactory, addressSettingsRepository); printPages(describeJournal, sm, manager, out, safe); } catch (Exception e) { e.printStackTrace(); } }
/** * 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()); }
Page impl = new Page(new SimpleString("something"), new NullStorageManager(), factory, file, 10); impl = new Page(new SimpleString("something"), new NullStorageManager(), factory, file, 10); List<PagedMessage> msgs = impl.read(new NullStorageManager());
/** * This method is protected as it may be used as a hook for creating a custom storage manager (on tests for instance) */ protected StorageManager createStorageManager() { if (configuration.isPersistenceEnabled()) { if (configuration.getStoreConfiguration() != null && configuration.getStoreConfiguration().getStoreType() == StoreConfiguration.StoreType.DATABASE) { JDBCJournalStorageManager journal = new JDBCJournalStorageManager(configuration, getCriticalAnalyzer(), getScheduledPool(), executorFactory, ioExecutorFactory, shutdownOnCriticalIO); this.getCriticalAnalyzer().add(journal); return journal; } else { // Default to File Based Storage Manager, (Legacy default configuration). JournalStorageManager journal = new JournalStorageManager(configuration, getCriticalAnalyzer(), executorFactory, scheduledPool, ioExecutorFactory, shutdownOnCriticalIO); this.getCriticalAnalyzer().add(journal); return journal; } } return new NullStorageManager(); }
@Test public void testMoveOverPaging() throws Exception { AssertionLoggerHandler.startCapture(); ExecutorService threadPool = Executors.newCachedThreadPool(); try { manager.setMaxFolders(3); for (int i = 1; i <= 10; i++) { HierarchicalRepository<AddressSettings> addressSettings = new HierarchicalObjectRepository<>(); AddressSettings settings = new AddressSettings(); settings.setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE); addressSettings.setDefault(settings); final StorageManager storageManager = new NullStorageManager(); PagingStoreFactoryNIO storeFactory = new PagingStoreFactoryNIO(storageManager, dataLocation, 100, null, new OrderedExecutorFactory(threadPool), true, null); PagingManagerImpl managerImpl = new PagingManagerImpl(storeFactory, addressSettings, -1, ActiveMQDefaultConfiguration.getDefaultManagementAddress()); managerImpl.start(); PagingStore store = managerImpl.getPageStore(new SimpleString("simple-test")); store.startPaging(); store.stop(); managerImpl.stop(); manager.doMove(); Assert.assertEquals(Math.min(i, manager.getMaxFolders()), manager.getNumberOfFolders()); } Assert.assertFalse("The loggers are complaining about address.txt", AssertionLoggerHandler.findText("address.txt")); } finally { AssertionLoggerHandler.stopCapture(); threadPool.shutdown(); } }
@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)); }
List<PagedMessage> msg = page.read(new NullStorageManager());
List<PagedMessage> msg = page.read(new NullStorageManager()); Assert.assertEquals(1, newPage.read(new NullStorageManager()).size()); List<PagedMessage> msgs = page.read(new NullStorageManager());
List<PagedMessage> msgs = page.read(new NullStorageManager()); page.close(); List<PagedMessage> msgs = page.read(new NullStorageManager()); List<PagedMessage> lastMessages = lastPage.read(new NullStorageManager()); lastPage.close(); Assert.assertEquals(1, lastMessages.size());
@Test public void testGetResources() throws Exception { Configuration config = createBasicConfig().setJMXManagementEnabled(false); ManagementServiceImpl managementService = new ManagementServiceImpl(null, config); managementService.setStorageManager(new NullStorageManager()); SimpleString address = RandomUtil.randomSimpleString(); managementService.registerAddress(new AddressInfo(address)); Queue queue = new FakeQueue(RandomUtil.randomSimpleString()); managementService.registerQueue(queue, RandomUtil.randomSimpleString(), new FakeStorageManager()); Object[] addresses = managementService.getResources(AddressControl.class); Assert.assertEquals(1, addresses.length); Assert.assertTrue(addresses[0] instanceof AddressControl); AddressControl addressControl = (AddressControl) addresses[0]; Assert.assertEquals(address.toString(), addressControl.getAddress()); Object[] queues = managementService.getResources(QueueControl.class); Assert.assertEquals(1, queues.length); Assert.assertTrue(queues[0] instanceof QueueControl); QueueControl queueControl = (QueueControl) queues[0]; Assert.assertEquals(queue.getName().toString(), queueControl.getName()); }