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(); } }
addressSettingsRepository = new HierarchicalObjectRepository<>(configuration.getWildcardConfiguration(), new HierarchicalObjectRepository.MatchModifier() { @Override public String modify(String input) { securityRepository = new HierarchicalObjectRepository<>(configuration.getWildcardConfiguration());
@Override @Before public void setUp() throws Exception { super.setUp(); securityRepository = new HierarchicalObjectRepository<>(); }
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(); } }
protected void initializeJournal(Configuration configuration) throws Exception { this.config = configuration; executor = Executors.newFixedThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory()); executorFactory = new OrderedExecutorFactory(executor); scheduledExecutorService = new ScheduledThreadPoolExecutor(configuration.getScheduledThreadPoolMaxSize(), new ThreadFactory() { @Override public Thread newThread(Runnable r) { return new Thread(r); } }); HierarchicalRepository<AddressSettings> addressSettingsRepository = new HierarchicalObjectRepository<>(config.getWildcardConfiguration()); addressSettingsRepository.setDefault(new AddressSettings()); if (configuration.isJDBC()) { storageManager = new JDBCJournalStorageManager(config, null, scheduledExecutorService, executorFactory, executorFactory, null); PagingStoreFactory pageStoreFactory = new PagingStoreFactoryDatabase((DatabaseStorageConfiguration) configuration.getStoreConfiguration(), storageManager, 1000L, scheduledExecutorService, executorFactory, false, null); pagingmanager = new PagingManagerImpl(pageStoreFactory, addressSettingsRepository, configuration.getManagementAddress()); } else { storageManager = new JournalStorageManager(config, EmptyCriticalAnalyzer.getInstance(), executorFactory, executorFactory); PagingStoreFactory pageStoreFactory = new PagingStoreFactoryNIO(storageManager, config.getPagingLocation(), 1000L, scheduledExecutorService, executorFactory, true, null); pagingmanager = new PagingManagerImpl(pageStoreFactory, addressSettingsRepository, configuration.getManagementAddress()); } }
protected void initializeJournal(Configuration configuration) throws Exception { this.config = configuration; executor = Executors.newFixedThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory()); executorFactory = new OrderedExecutorFactory(executor); scheduledExecutorService = new ScheduledThreadPoolExecutor(configuration.getScheduledThreadPoolMaxSize(), new ThreadFactory() { @Override public Thread newThread(Runnable r) { return new Thread(r); } }); HierarchicalRepository<AddressSettings> addressSettingsRepository = new HierarchicalObjectRepository<>(config.getWildcardConfiguration()); addressSettingsRepository.setDefault(new AddressSettings()); if (configuration.isJDBC()) { storageManager = new JDBCJournalStorageManager(config, null, scheduledExecutorService, executorFactory, executorFactory, null); PagingStoreFactory pageStoreFactory = new PagingStoreFactoryDatabase((DatabaseStorageConfiguration) configuration.getStoreConfiguration(), storageManager, 1000L, scheduledExecutorService, executorFactory, false, null); pagingmanager = new PagingManagerImpl(pageStoreFactory, addressSettingsRepository, configuration.getManagementAddress()); } else { storageManager = new JournalStorageManager(config, EmptyCriticalAnalyzer.getInstance(), executorFactory, executorFactory); PagingStoreFactory pageStoreFactory = new PagingStoreFactoryNIO(storageManager, config.getPagingLocation(), 1000L, scheduledExecutorService, executorFactory, true, null); pagingmanager = new PagingManagerImpl(pageStoreFactory, addressSettingsRepository, configuration.getManagementAddress()); } }
@Test public void testIllegalMatches() { HierarchicalRepository<String> repository = new HierarchicalObjectRepository<>(); try { repository.addMatch("hjhjhjhjh.#.hhh", "test"); fail("expected exception"); } catch (IllegalArgumentException e) { // pass } try { repository.addMatch(null, "test"); fail("expected exception"); } catch (IllegalArgumentException e) { // pass } }
@Test public void testAddListener() { HierarchicalRepository<String> repository = new HierarchicalObjectRepository<>(); repository.addMatch("#", "1"); repository.addMatch("B", "2"); final AtomicInteger called = new AtomicInteger(0); repository.registerListener(new HierarchicalRepositoryChangeListener() { @Override public void onChange() { called.incrementAndGet(); } }); assertEquals(1, called.get()); repository.disableListeners(); repository.addMatch("C", "3"); assertEquals(1, called.get()); repository.enableListeners(); assertEquals(2, called.get()); repository.addMatch("D", "4"); assertEquals(3, called.get()); repository.removeMatch("D"); assertEquals(4, called.get()); repository.disableListeners(); repository.removeMatch("C"); assertEquals(4, called.get()); }
@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 testMatchingDocs() throws Throwable { HierarchicalObjectRepository<String> repo = new HierarchicalObjectRepository<>(); repo.addMatch("a.b.#", "ab#"); repo.addMatch("a.b.d.#", "abd#"); repo.addMatch("#", "root"); Assert.assertEquals("ab#", repo.getMatch("a.b")); Assert.assertEquals("ab#", repo.getMatch("a.b.c")); Assert.assertEquals("abd#", repo.getMatch("a.b.d.lll")); Assert.assertEquals("root", repo.getMatch("z.z.z.z.z")); Assert.assertEquals("root", repo.getMatch("a.babc")); Assert.assertEquals("ab#", repo.getMatch("a.b.dabc")); Assert.assertEquals("abd#", repo.getMatch("a.b.d")); }
@Test public void testMatchingDocsCustomUnderscorDelimiter() throws Throwable { WildcardConfiguration wildcardConfiguration = new WildcardConfiguration(); wildcardConfiguration.setDelimiter('_'); HierarchicalObjectRepository<String> repo = new HierarchicalObjectRepository<>(wildcardConfiguration); repo.addMatch("a_b_#", "ab#"); repo.addMatch("a_b_d_#", "abd#"); repo.addMatch("#", "root"); Assert.assertEquals("ab#", repo.getMatch("a_b")); Assert.assertEquals("ab#", repo.getMatch("a_b_c")); Assert.assertEquals("abd#", repo.getMatch("a_b_d_lll")); Assert.assertEquals("root", repo.getMatch("z_z_z_z_z")); Assert.assertEquals("root", repo.getMatch("a_babc")); Assert.assertEquals("ab#", repo.getMatch("a_b_dabc")); Assert.assertEquals("abd#", repo.getMatch("a_b_d")); }
@Test public void testMatchingDocsCustomForwardSlashDelimiter() throws Throwable { WildcardConfiguration wildcardConfiguration = new WildcardConfiguration(); wildcardConfiguration.setDelimiter('/'); HierarchicalObjectRepository<String> repo = new HierarchicalObjectRepository<>(wildcardConfiguration); repo.addMatch("a/b/#", "ab#"); repo.addMatch("a/b/d/#", "abd#"); repo.addMatch("#", "root"); Assert.assertEquals("ab#", repo.getMatch("a/b")); Assert.assertEquals("ab#", repo.getMatch("a/b/c")); Assert.assertEquals("abd#", repo.getMatch("a/b/d/lll")); Assert.assertEquals("root", repo.getMatch("z/z/z/z/z")); Assert.assertEquals("root", repo.getMatch("a/babc")); Assert.assertEquals("ab#", repo.getMatch("a/b/dabc")); Assert.assertEquals("abd#", repo.getMatch("a/b/d")); }
@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)); }
@Test public void testRepositoryMerge() { HierarchicalRepository<DummyMergeable> repository = new HierarchicalObjectRepository<>(); repository.addMatch("#", new DummyMergeable(1)); repository.addMatch("a.#", new DummyMergeable(2)); repository.addMatch("b.#", new DummyMergeable(3)); repository.addMatch("a.b.#", new DummyMergeable(4)); repository.addMatch("b.c.#", new DummyMergeable(5)); repository.addMatch("a.b.c.#", new DummyMergeable(6)); repository.addMatch("a.b.*.d", new DummyMergeable(7)); repository.addMatch("a.b.c.*", new DummyMergeable(8)); repository.getMatch("a.b.c.d"); Assert.assertEquals(5, DummyMergeable.timesMerged); Assert.assertTrue(DummyMergeable.contains(1)); Assert.assertTrue(DummyMergeable.contains(2)); Assert.assertTrue(DummyMergeable.contains(4)); Assert.assertTrue(DummyMergeable.contains(7)); Assert.assertTrue(DummyMergeable.contains(8)); DummyMergeable.reset(); repository.getMatch("a.b.c"); Assert.assertEquals(3, DummyMergeable.timesMerged); Assert.assertTrue(DummyMergeable.contains(1)); Assert.assertTrue(DummyMergeable.contains(2)); Assert.assertTrue(DummyMergeable.contains(4)); DummyMergeable.reset(); repository.getMatch("z"); Assert.assertEquals(0, DummyMergeable.timesMerged); DummyMergeable.reset(); }
@Test public void testMultipleWildcards() { HierarchicalRepository<String> repository = new HierarchicalObjectRepository<>(); repository.addMatch("#", "#"); repository.addMatch("a", "a");