public void checkRoutingSemantics(String destination, RoutingType routingType) throws ActiveMQStompException { AddressInfo addressInfo = manager.getServer().getAddressInfo(SimpleString.toSimpleString(destination)); // may be null here if, for example, the management address is being checked if (addressInfo != null) { Set<RoutingType> actualDeliveryModesOfAddress = addressInfo.getRoutingTypes(); if (routingType != null && !actualDeliveryModesOfAddress.contains(routingType)) { throw BUNDLE.illegalSemantics(routingType.toString(), actualDeliveryModesOfAddress.toString()); } } }
public void checkRoutingSemantics(String destination, RoutingType routingType) throws ActiveMQStompException { AddressInfo addressInfo = manager.getServer().getAddressInfo(SimpleString.toSimpleString(destination)); // may be null here if, for example, the management address is being checked if (addressInfo != null) { Set<RoutingType> actualDeliveryModesOfAddress = addressInfo.getRoutingTypes(); if (routingType != null && !actualDeliveryModesOfAddress.contains(routingType)) { throw BUNDLE.illegalSemantics(routingType.toString(), actualDeliveryModesOfAddress.toString()); } } }
@Override public String getAddressInfo(String address) throws ActiveMQAddressDoesNotExistException { checkStarted(); clearIO(); try { final AddressInfo addressInfo = server.getAddressInfo(SimpleString.toSimpleString(address)); if (addressInfo == null) { throw ActiveMQMessageBundle.BUNDLE.addressDoesNotExist(SimpleString.toSimpleString(address)); } else { return AddressInfoTextFormatter.Long.format(addressInfo, new StringBuilder()).toString(); } } finally { blockOnIO(); } }
@Override public AddressInfo createAddress(AddressInfo addressInfo, boolean autoCreated) throws Exception { AddressInfo art = getAddressAndRoutingType(addressInfo); securityCheck(art.getName(), CheckType.CREATE_ADDRESS, this); server.addOrUpdateAddressInfo(art.setAutoCreated(autoCreated)); return server.getAddressInfo(art.getName()); }
@Test public void testCreateAddressAlreadyExistsShowsError() throws Exception { String address = "address"; CreateAddress command = new CreateAddress(); command.setName(address); command.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error))); checkExecutionPassed(command); assertNotNull(server.getAddressInfo(new SimpleString(address))); command.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error))); checkExecutionFailure(command, "Address already exists"); }
@Test public void testAutoCreateSendToTopic() throws Exception { Connection connection = null; try { connection = factory.createConnection("admin", "password"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Topic trash = session.createTopic("trash"); final MessageProducer producer = session.createProducer(trash); producer.send(session.createTextMessage("foo")); } finally { if (connection != null) { connection.close(); } } assertNotNull(server.getAddressInfo(new SimpleString("trash"))); assertEquals(0, server.getTotalMessageCount()); }
@Test public void testAutoDeleteAutoCreatedAddress() throws Exception { // auto-delete-addresses defaults to true server.createQueue(addressA, RoutingType.ANYCAST, queueA, null, null, true, false, false, false, true, 1, false, true); assertNotNull(server.getAddressInfo(addressA)); cf.createSession().createConsumer(queueA).close(); assertNull(server.getAddressInfo(addressA)); }
@Test public void testShowAddress() throws Exception { String address = "address"; CreateAddress command = new CreateAddress(); command.setName(address); command.execute(new ActionContext()); assertNotNull(server.getAddressInfo(new SimpleString(address))); ShowAddress showAddress = new ShowAddress(); showAddress.setName(address); showAddress.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error))); System.out.println(output.toString()); }
@Test public void testAutoCreatedMulticastAddress() throws Exception { conn.connect(defUser, defPass); String queueName = UUID.randomUUID().toString(); SimpleString simpleQueueName = SimpleString.toSimpleString(queueName); Assert.assertNull(server.getAddressInfo(simpleQueueName)); Assert.assertNull(server.locateQueue(simpleQueueName)); send(conn, queueName, null, "Hello MULTICAST"); assertTrue("Address should be created now", Wait.waitFor(() -> (server.getAddressInfo(simpleQueueName) != null), 2000, 200)); assertTrue(server.getAddressInfo(simpleQueueName).getRoutingTypes().contains(RoutingType.MULTICAST)); Assert.assertNull(server.locateQueue(simpleQueueName)); } }
@Test public void testAutoCreateSendToQueue() throws Exception { Connection connection = null; try { connection = factory.createConnection("admin", "password"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue trash = session.createQueue("trash"); final MessageProducer producer = session.createProducer(trash); producer.send(session.createTextMessage("foo")); } finally { if (connection != null) { connection.close(); } } assertNotNull(server.getAddressInfo(new SimpleString("trash"))); assertNotNull(server.locateQueue(new SimpleString("trash"))); assertEquals(1, server.getTotalMessageCount()); }
@Test public void testDeleteAddress() throws Exception { String address = "address"; CreateAddress command = new CreateAddress(); command.setName(address); command.execute(new ActionContext()); assertNotNull(server.getAddressInfo(new SimpleString(address))); DeleteAddress deleteAddress = new DeleteAddress(); deleteAddress.setName(address); deleteAddress.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error))); checkExecutionPassed(deleteAddress); assertNull(server.getAddressInfo(new SimpleString(address))); }
@Override public AddressInfo createAddress(final SimpleString address, EnumSet<RoutingType> routingTypes, final boolean autoCreated) throws Exception { SimpleString realAddress = CompositeAddress.extractAddressName(address); Pair<SimpleString, EnumSet<RoutingType>> art = getAddressAndRoutingTypes(realAddress, routingTypes); securityCheck(art.getA(), CheckType.CREATE_ADDRESS, this); server.addOrUpdateAddressInfo(new AddressInfo(art.getA(), art.getB()).setAutoCreated(autoCreated)); return server.getAddressInfo(art.getA()); }
@Test public void testCreateAddress() throws Exception { String address = "address"; CreateAddress command = new CreateAddress(); command.setName(address); command.setAnycast(true); command.setMulticast(true); command.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error))); checkExecutionPassed(command); AddressInfo addressInfo = server.getAddressInfo(new SimpleString(address)); assertNotNull(addressInfo); assertTrue(addressInfo.getRoutingTypes().contains(RoutingType.ANYCAST)); assertTrue(addressInfo.getRoutingTypes().contains(RoutingType.MULTICAST)); }
@Test public void testUpdateAddressRoutingTypes() throws Exception { final String addressName = "address"; final SimpleString address = new SimpleString(addressName); server.addAddressInfo(new AddressInfo(address, RoutingType.ANYCAST)); final UpdateAddress updateAddress = new UpdateAddress(); updateAddress.setName(addressName); updateAddress.setAnycast(true); updateAddress.setMulticast(true); updateAddress.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error))); checkExecutionPassed(updateAddress); final AddressInfo addressInfo = server.getAddressInfo(address); assertNotNull(addressInfo); assertEquals(EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST), addressInfo.getRoutingTypes()); }
@Test public void persistAddressConfigTest() throws Exception { server.createQueue(SimpleString.toSimpleString("myAddress"), RoutingType.MULTICAST, SimpleString.toSimpleString("myQueue"), null, true, false); server.stop(); server.start(); AddressInfo addressInfo = server.getAddressInfo(SimpleString.toSimpleString("myAddress")); assertNotNull(addressInfo); Set<RoutingType> routingTypeSet = new HashSet<>(); routingTypeSet.add(RoutingType.MULTICAST); assertEquals(routingTypeSet, addressInfo.getRoutingTypes()); } }
@Test public void testAutoCreatedAnycastAddress() throws Exception { conn.connect(defUser, defPass); String queueName = UUID.randomUUID().toString(); SimpleString simpleQueueName = SimpleString.toSimpleString(queueName); Assert.assertNull(server.getAddressInfo(simpleQueueName)); Assert.assertNull(server.locateQueue(simpleQueueName)); server.getAddressSettingsRepository().addMatch(queueName, new AddressSettings() .setDefaultAddressRoutingType(RoutingType.ANYCAST) .setDefaultQueueRoutingType(RoutingType.ANYCAST) ); send(conn, queueName, null, "Hello ANYCAST"); assertTrue("Address and queue should be created now", Wait.waitFor(() -> (server.getAddressInfo(simpleQueueName) != null) && (server.locateQueue(simpleQueueName) != null), 2000, 200)); assertTrue(server.getAddressInfo(simpleQueueName).getRoutingTypes().contains(RoutingType.ANYCAST)); assertEquals(RoutingType.ANYCAST, server.locateQueue(simpleQueueName).getRoutingType()); }
@Test public void testNegativeAutoDeleteAutoCreatedAddress() throws Exception { server.getAddressSettingsRepository().addMatch(addressA.toString(), new AddressSettings().setAutoDeleteAddresses(false)); server.createQueue(addressA, RoutingType.ANYCAST, queueA, null, null, true, false, false, false, true, 1, false, true); assertNotNull(server.getAddressInfo(addressA)); cf.createSession().createConsumer(queueA).close(); assertNotNull(server.getAddressInfo(addressA)); } }
@Test public void autoDestroyAddress() throws Exception { AddressSettings addressSettings = new AddressSettings(); addressSettings.setAutoDeleteAddresses(true); server.getAddressSettingsRepository().addMatch("foo.bar", addressSettings); final MQTTClientProvider subscriptionProvider = getMQTTClientProvider(); initializeConnection(subscriptionProvider); subscriptionProvider.subscribe("foo/bar", AT_MOST_ONCE); assertNotNull(server.getAddressInfo(SimpleString.toSimpleString("foo.bar"))); subscriptionProvider.disconnect(); assertNull(server.getAddressInfo(SimpleString.toSimpleString("foo.bar"))); } }
@Test public void testCreateCoreQueueAutoCreateAddressDefaultAddress() throws Exception { String queueName = UUID.randomUUID().toString(); CreateQueue command = new CreateQueue(); command.setName(queueName); command.setAutoCreateAddress(true); command.setMulticast(true); command.setAnycast(false); command.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error))); checkExecutionPassed(command); assertNotNull(server.getAddressInfo(new SimpleString(queueName))); Queue queue = server.locateQueue(new SimpleString(queueName)); assertEquals(-1, queue.getMaxConsumers()); assertEquals(false, queue.isPurgeOnNoConsumers()); assertTrue(server.queueQuery(new SimpleString(queueName)).isExists()); }
@Test public void testDefaultAddressQueueDeleteDelay() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); SimpleString queue = RandomUtil.randomSimpleString(); final long fudge = 200; session.createQueue(address, RoutingType.MULTICAST, queue, null, true, true); assertTrue(Wait.waitFor(() -> server.locateQueue(queue) != null, 2000, 100)); ClientProducer producer = session.createProducer(address); ClientMessage message = session.createMessage(true); producer.send(message); ClientConsumer consumer = session.createConsumer(queue); session.start(); ClientMessage m = consumer.receive(500); assertNotNull(m); m.acknowledge(); session.commit(); consumer.close(); assertTrue(Wait.waitFor(() -> server.locateQueue(queue) == null, fudge, 50)); assertTrue(Wait.waitFor(() -> server.getAddressInfo(address) == null, fudge, 50)); }