@Override protected void addConfiguration(ActiveMQServer server) { server.getAddressSettingsRepository().addMatch(INITIAL_QUEUE_NAME, new AddressSettings().setExpiryAddress(FINAL_QUEUE_SS)); }
@Test public void testCreateNonExistentQueue() throws Exception { AddressSettings addressSettings = new AddressSettings(); addressSettings.setAutoCreateQueues(false); getJmsServer().getAddressSettingsRepository().addMatch("#", addressSettings); Connection conn = getConnectionFactory().createConnection(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); try { sess.createQueue("QueueThatDoesNotExist"); ProxyAssertSupport.fail(); } catch (JMSException e) { } conn.close(); }
@Test public void testDoubleStart() throws Exception { SequentialFileFactory factory = new FakeSequentialFileFactory(); PagingStore storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, new FakeStoreFactory(factory), PagingStoreImplTest.destinationTestName, new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE), getExecutorFactory().getExecutor(), true); storeImpl.start(); // this is not supposed to throw an exception. // As you could have start being called twice as Stores are dynamically // created, on a multi-thread environment storeImpl.start(); storeImpl.stop(); }
@Test public void testExpireWithDefaultAddressSettings() throws Exception { SimpleString ea = new SimpleString("EA"); SimpleString qName = new SimpleString("q1"); SimpleString eq = new SimpleString("EA1"); AddressSettings addressSettings = new AddressSettings().setExpiryAddress(ea); server.getAddressSettingsRepository().setDefault(addressSettings); clientSession.createQueue(ea, eq, null, false); clientSession.createQueue(qName, qName, null, false); ClientProducer producer = clientSession.createProducer(qName); ClientMessage clientMessage = createTextMessage(clientSession, "heyho!"); clientMessage.setExpiration(System.currentTimeMillis()); producer.send(clientMessage); clientSession.start(); ClientConsumer clientConsumer = clientSession.createConsumer(qName); ClientMessage m = clientConsumer.receiveImmediate(); Assert.assertNull(m); clientConsumer.close(); clientConsumer = clientSession.createConsumer(eq); m = clientConsumer.receive(500); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!"); m.acknowledge(); }
@Test public void testCreateNonExistentTopic() throws Exception { getJmsServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateQueues(false)); getJmsServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateAddresses(false)); Connection conn = getConnectionFactory().createConnection(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); try { sess.createTopic("TopicThatDoesNotExist"); ProxyAssertSupport.fail("should throw JMSException"); } catch (JMSException e) { // OK } conn.close(); }
@Test /** * When running this test from an IDE add this to the test command line so that the AssertionLoggerHandler works properly: * * -Djava.util.logging.manager=org.jboss.logmanager.LogManager -Dlogging.configuration=file:<path_to_source>/tests/config/logging.properties */ public void testBlockLogging() throws Exception { ActiveMQServer server = createServer(false, createDefaultInVMConfig()); for (int i = 0; i < 10000; i++) { server.getConfiguration().addQueueConfiguration(new CoreQueueConfiguration().setAddress(UUID.randomUUID().toString()).setName(UUID.randomUUID().toString())); } server.getConfiguration().setGlobalMaxSize(-1); server.getConfiguration().getAddressesSettings().put("#", new AddressSettings().setMaxSizeBytes(10485760 * 10)); server.start(); // Using the code only so the test doesn't fail just because someone edits the log text Assert.assertTrue("Expected to find 222205", AssertionLoggerHandler.findText("AMQ222205")); }
@Override protected void addConfiguration(ActiveMQServer server) { server.getConfiguration().setPersistenceEnabled(false); server.getAddressSettingsRepository().addMatch(NORMAL_QUEUE_NAME, new AddressSettings()); }
@Test public void testCreateTopicWhileQueueWithSameNameExists() throws Exception { getJmsServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateQueues(false)); getJmsServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateAddresses(false)); Connection conn = getConnectionFactory().createConnection(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); try { sess.createTopic("TestQueue"); ProxyAssertSupport.fail("should throw JMSException"); } catch (JMSException e) { // OK } conn.close(); }
@Test public void testStoreSecuritySettings() throws Exception { createStorage(); AddressSettings setting = new AddressSettings(); setting = new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK).setDeadLetterAddress(new SimpleString("some-test")); addAddress(journal, "a2", setting); journal.stop(); createStorage(); checkAddresses(journal); setting = new AddressSettings().setDeadLetterAddress(new SimpleString("new-adddress")); // Replacing the first setting addAddress(journal, "a1", setting); journal.stop(); createStorage(); checkAddresses(journal); journal.stop(); journal = null; }
protected void setRedistributionDelay(final long delay) { AddressSettings as = new AddressSettings().setRedistributionDelay(delay); getServer(0).getAddressSettingsRepository().addMatch("queues.*", as); getServer(1).getAddressSettingsRepository().addMatch("queues.*", as); }
@Test public void testAutoDestinationCreationOnProducerSend() throws JMSException { AddressSettings addressSetting = new AddressSettings(); addressSetting.setAutoCreateQueues(true); addressSetting.setAutoCreateAddresses(true); String address = "foo"; server.getAddressSettingsRepository().addMatch(address, addressSetting); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); TextMessage message = session.createTextMessage("bar"); Queue queue = new ActiveMQQueue(address); MessageProducer producer = session.createProducer(null); producer.send(queue, message); MessageConsumer consumer = session.createConsumer(queue); TextMessage message1 = (TextMessage) consumer.receive(1000); assertTrue(message1.getText().equals(message.getText())); }
@Test public void testConsumerWindowSizeAddressSettings() throws Exception { ActiveMQServer messagingService = createServer(false, isNetty()); final int defaultConsumerWindowSize = 1024 * 5; final AddressSettings settings = new AddressSettings(); settings.setDefaultConsumerWindowSize(defaultConsumerWindowSize); messagingService.getConfiguration() .getAddressesSettings().put(queueA.toString(), settings); messagingService.start(); messagingService.createQueue(queueA, RoutingType.ANYCAST, queueA, null, true, false); ClientSessionFactory cf = createSessionFactory(locator); ClientSession session = cf.createSession(false, true, true); ClientConsumerImpl consumer = (ClientConsumerImpl) session.createConsumer(queueA); session.start(); assertEquals(defaultConsumerWindowSize / 2, consumer.getClientWindowSize()); }
protected void setRedistributionDelay(final long delay) { AddressSettings as = new AddressSettings().setRedistributionDelay(delay); getServer(0).getAddressSettingsRepository().addMatch("queues.*", as); getServer(1).getAddressSettingsRepository().addMatch("queues.*", as); }
@Test public void testCreateQueueWhileTopicWithSameNameExists() throws Exception { AddressSettings addressSettings = new AddressSettings(); addressSettings.setAutoCreateQueues(false); addressSettings.setAutoCreateAddresses(false); getJmsServer().getAddressSettingsRepository().addMatch("#", addressSettings); Connection conn = getConnectionFactory().createConnection(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); try { sess.createQueue("TestTopic"); ProxyAssertSupport.fail("should throw JMSException"); } catch (JMSException e) { // OK } conn.close(); }
@Test public void testConsumerWindowSizeAddressSettingsWildCard() throws Exception { ActiveMQServer messagingService = createServer(false, isNetty()); final int defaultConsumerWindowSize = 1024 * 5; final AddressSettings settings = new AddressSettings(); settings.setDefaultConsumerWindowSize(defaultConsumerWindowSize); messagingService.getConfiguration() .getAddressesSettings().put("#", settings); messagingService.start(); messagingService.createQueue(queueA, RoutingType.ANYCAST, queueA, null, true, false); ClientSessionFactory cf = createSessionFactory(locator); ClientSession session = cf.createSession(false, true, true); ClientConsumerImpl consumer = (ClientConsumerImpl) session.createConsumer(queueA); ClientConsumerImpl consumer2 = (ClientConsumerImpl) session.createConsumer(queueA); session.start(); assertEquals(defaultConsumerWindowSize / 2, consumer.getClientWindowSize()); assertEquals(defaultConsumerWindowSize / 2, consumer2.getClientWindowSize()); } }
protected void setRedistributionDelay(final long delay) { AddressSettings as = new AddressSettings().setRedistributionDelay(delay); getServer(0).getAddressSettingsRepository().addMatch("queues.*", as); getServer(1).getAddressSettingsRepository().addMatch("queues.*", as); }
@Test public void testCreateProducerOnInexistentDestination() throws Exception { getJmsServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateQueues(false)); getJmsServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateAddresses(false)); Connection pconn = createConnection(); try { Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE); try { ps.createProducer(ActiveMQJMSClient.createTopic("NoSuchTopic")); ProxyAssertSupport.fail("should throw exception"); } catch (InvalidDestinationException e) { // OK } } finally { pconn.close(); } }
@Test public void testConsumerWindowSizeAddressSettingsDifferentAddressAndQueueName() throws Exception { ActiveMQServer messagingService = createServer(false, isNetty()); final int defaultConsumerWindowSize = 1024 * 5; final AddressSettings settings = new AddressSettings(); settings.setDefaultConsumerWindowSize(defaultConsumerWindowSize); messagingService.getConfiguration() .getAddressesSettings().put(addressA.toString(), settings); messagingService.start(); messagingService.createQueue(addressA, RoutingType.ANYCAST, queueA, null, true, false); ClientSessionFactory cf = createSessionFactory(locator); ClientSession session = cf.createSession(false, true, true); ClientConsumerImpl consumer = (ClientConsumerImpl) session.createConsumer(queueA); session.start(); assertEquals(defaultConsumerWindowSize / 2, consumer.getClientWindowSize()); ServerSession ss = messagingService.getSessionByID(((ClientSessionImpl)session).getName()); ServerConsumerImpl cons = (ServerConsumerImpl) ss.locateConsumer(consumer.getConsumerContext().getId()); assertTrue(Wait.waitFor(() -> cons.getAvailableCredits().get() == consumer.getClientWindowSize() * 2, 5000, 50)); }
protected void setRedistributionDelay(final long delay) { AddressSettings as = new AddressSettings().setRedistributionDelay(delay); getServer(0).getAddressSettingsRepository().addMatch("queues.*", as); getServer(1).getAddressSettingsRepository().addMatch("queues.*", as); getServer(2).getAddressSettingsRepository().addMatch("queues.*", as); }
@Test public void defaultAutoCreatedQueueConfigTest2() throws Exception { final String queueName = "q1"; server.getAddressSettingsRepository().addMatch(queueName, new AddressSettings().setDefaultMaxConsumers(5).setDefaultPurgeOnNoConsumers(true)); Connection connection = cf.createConnection(); Session session = connection.createSession(); session.createProducer(session.createQueue(queueName)); org.apache.activemq.artemis.core.server.Queue queue = server.locateQueue(SimpleString.toSimpleString(queueName)); assertEquals(5, queue.getMaxConsumers()); assertEquals(true, queue.isPurgeOnNoConsumers()); connection.close(); }