use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.
the class QueueCommandTest method testUpdateCoreQueueCannotChangeRoutingType.
@Test
public void testUpdateCoreQueueCannotChangeRoutingType() throws Exception {
final String queueName = "updateQueue";
final SimpleString queueNameString = new SimpleString(queueName);
final String addressName = "address";
final SimpleString addressSimpleString = new SimpleString(addressName);
final int oldMaxConsumers = 10;
final RoutingType oldRoutingType = RoutingType.MULTICAST;
final boolean oldPurgeOnNoConsumers = false;
final Set<RoutingType> supportedRoutingTypes = EnumSet.of(oldRoutingType);
final AddressInfo addressInfo = new AddressInfo(addressSimpleString, EnumSet.copyOf(supportedRoutingTypes));
server.addAddressInfo(addressInfo);
server.createQueue(addressSimpleString, oldRoutingType, queueNameString, null, true, false, oldMaxConsumers, oldPurgeOnNoConsumers, false);
final RoutingType newRoutingType = RoutingType.ANYCAST;
final UpdateQueue updateQueue = new UpdateQueue();
updateQueue.setName(queueName);
updateQueue.setAnycast(true);
updateQueue.setMulticast(false);
updateQueue.setMaxConsumers(-1);
updateQueue.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error)));
checkExecutionFailure(updateQueue, "AMQ119211");
final QueueQueryResult queueQueryResult = server.queueQuery(queueNameString);
assertEquals("maxConsumers", oldMaxConsumers, queueQueryResult.getMaxConsumers());
assertEquals("routingType", oldRoutingType, queueQueryResult.getRoutingType());
assertTrue("purgeOnNoConsumers", oldPurgeOnNoConsumers == queueQueryResult.isPurgeOnNoConsumers());
}
use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.
the class CreateQueueTest method testUnsupportedRoutingType.
@Test
public void testUnsupportedRoutingType() throws Exception {
ClientSession sendSession = cf.createSession(false, true, true);
server.getAddressSettingsRepository().addMatch(addressA.toString(), new AddressSettings().setAutoCreateAddresses(false));
server.getAddressSettingsRepository().addMatch(addressB.toString(), new AddressSettings().setAutoCreateAddresses(false));
EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST);
sendSession.createAddress(addressA, routingTypes, false);
try {
sendSession.createQueue(addressA, RoutingType.MULTICAST, queueA);
fail("Creating a queue here should fail since the queue routing type differs from what is supported on the address.");
} catch (Exception e) {
assertTrue(e instanceof ActiveMQException);
ActiveMQException ae = (ActiveMQException) e;
assertEquals(ActiveMQExceptionType.INTERNAL_ERROR, ae.getType());
}
routingTypes = EnumSet.of(RoutingType.MULTICAST);
sendSession.createAddress(addressB, routingTypes, false);
try {
sendSession.createQueue(addressB, RoutingType.ANYCAST, queueB);
fail("Creating a queue here should fail since the queue routing type differs from what is supported on the address.");
} catch (Exception e) {
assertTrue(e instanceof ActiveMQException);
ActiveMQException ae = (ActiveMQException) e;
assertEquals(ActiveMQExceptionType.INTERNAL_ERROR, ae.getType());
}
sendSession.close();
}
use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.
the class HangConsumerTest method testHangDuplicateQueues.
/**
* This would recreate the scenario where a queue was duplicated
*
* @throws Exception
*/
@Test
public void testHangDuplicateQueues() throws Exception {
final Semaphore blocked = new Semaphore(1);
final CountDownLatch latchDelete = new CountDownLatch(1);
class MyQueueWithBlocking extends QueueImpl {
/**
* @param id
* @param address
* @param name
* @param filter
* @param pageSubscription
* @param durable
* @param temporary
* @param scheduledExecutor
* @param postOffice
* @param storageManager
* @param addressSettingsRepository
* @param executor
*/
MyQueueWithBlocking(final long id, final SimpleString address, final SimpleString name, final Filter filter, final SimpleString user, final PageSubscription pageSubscription, final boolean durable, final boolean temporary, final boolean autoCreated, final RoutingType deliveryMode, final Integer maxConsumers, final Boolean purgeOnNoConsumers, final ScheduledExecutorService scheduledExecutor, final PostOffice postOffice, final StorageManager storageManager, final HierarchicalRepository<AddressSettings> addressSettingsRepository, final ArtemisExecutor executor, final ActiveMQServer server) {
super(id, address, name, filter, pageSubscription, user, durable, temporary, autoCreated, deliveryMode, maxConsumers, purgeOnNoConsumers, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executor, server, null);
}
@Override
public synchronized int deleteMatchingReferences(final int flushLimit, final Filter filter) throws Exception {
latchDelete.countDown();
blocked.acquire();
blocked.release();
return super.deleteMatchingReferences(flushLimit, filter);
}
@Override
public void deliverScheduledMessages() {
}
}
class LocalFactory extends QueueFactoryImpl {
LocalFactory(final ExecutorFactory executorFactory, final ScheduledExecutorService scheduledExecutor, final HierarchicalRepository<AddressSettings> addressSettingsRepository, final StorageManager storageManager, final ActiveMQServer server) {
super(executorFactory, scheduledExecutor, addressSettingsRepository, storageManager, server);
}
@Override
public Queue createQueueWith(final QueueConfig config) {
queue = new MyQueueWithBlocking(config.id(), config.address(), config.name(), config.filter(), config.user(), config.pageSubscription(), config.isDurable(), config.isTemporary(), config.isAutoCreated(), config.deliveryMode(), config.maxConsumers(), config.isPurgeOnNoConsumers(), scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executorFactory.getExecutor(), server);
return queue;
}
@Deprecated
@Override
public Queue createQueue(final long persistenceID, final SimpleString address, final SimpleString name, final Filter filter, final PageSubscription pageSubscription, final SimpleString user, final boolean durable, final boolean temporary, final boolean autoCreated) {
queue = new MyQueueWithBlocking(persistenceID, address, name, filter, user, pageSubscription, durable, temporary, autoCreated, RoutingType.MULTICAST, null, null, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executorFactory.getExecutor(), server);
return queue;
}
}
LocalFactory queueFactory = new LocalFactory(server.getExecutorFactory(), server.getScheduledPool(), server.getAddressSettingsRepository(), server.getStorageManager(), server);
queueFactory.setPostOffice(server.getPostOffice());
((ActiveMQServerImpl) server).replaceQueueFactory(queueFactory);
queue = server.createQueue(QUEUE, RoutingType.ANYCAST, QUEUE, null, true, false);
blocked.acquire();
ClientSessionFactory factory = locator.createSessionFactory();
ClientSession session = factory.createSession(false, false, false);
ClientProducer producer = session.createProducer(QUEUE);
producer.send(session.createMessage(true));
session.commit();
Thread tDelete = new Thread() {
@Override
public void run() {
try {
server.destroyQueue(QUEUE);
} catch (Exception e) {
e.printStackTrace();
}
}
};
tDelete.start();
Assert.assertTrue(latchDelete.await(10, TimeUnit.SECONDS));
try {
server.createQueue(QUEUE, RoutingType.ANYCAST, QUEUE, null, true, false);
} catch (Exception expected) {
}
blocked.release();
server.stop();
tDelete.join();
session.close();
// a duplicate binding would impede the server from starting
server.start();
waitForServerToStart(server);
server.stop();
}
use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.
the class FileConfigurationTest method verifyAddresses.
private void verifyAddresses() {
assertEquals(3, conf.getAddressConfigurations().size());
// Addr 1
CoreAddressConfiguration addressConfiguration = conf.getAddressConfigurations().get(0);
assertEquals("addr1", addressConfiguration.getName());
Set<RoutingType> routingTypes = new HashSet<>();
routingTypes.add(RoutingType.ANYCAST);
assertEquals(routingTypes, addressConfiguration.getRoutingTypes());
assertEquals(2, addressConfiguration.getQueueConfigurations().size());
// Addr 1 Queue 1
CoreQueueConfiguration queueConfiguration = addressConfiguration.getQueueConfigurations().get(0);
assertEquals("q1", queueConfiguration.getName());
assertFalse(queueConfiguration.isDurable());
assertEquals("color='blue'", queueConfiguration.getFilterString());
assertEquals(ActiveMQDefaultConfiguration.getDefaultPurgeOnNoConsumers(), queueConfiguration.getPurgeOnNoConsumers());
assertEquals("addr1", queueConfiguration.getAddress());
assertEquals(ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers(), queueConfiguration.getMaxConsumers());
// Addr 1 Queue 2
queueConfiguration = addressConfiguration.getQueueConfigurations().get(1);
assertEquals("q2", queueConfiguration.getName());
assertTrue(queueConfiguration.isDurable());
assertEquals("color='green'", queueConfiguration.getFilterString());
assertEquals(Queue.MAX_CONSUMERS_UNLIMITED, queueConfiguration.getMaxConsumers());
assertFalse(queueConfiguration.getPurgeOnNoConsumers());
assertEquals("addr1", queueConfiguration.getAddress());
// Addr 2
addressConfiguration = conf.getAddressConfigurations().get(1);
assertEquals("addr2", addressConfiguration.getName());
routingTypes = new HashSet<>();
routingTypes.add(RoutingType.MULTICAST);
assertEquals(routingTypes, addressConfiguration.getRoutingTypes());
assertEquals(2, addressConfiguration.getQueueConfigurations().size());
// Addr 2 Queue 1
queueConfiguration = addressConfiguration.getQueueConfigurations().get(0);
assertEquals("q3", queueConfiguration.getName());
assertTrue(queueConfiguration.isDurable());
assertEquals("color='red'", queueConfiguration.getFilterString());
assertEquals(10, queueConfiguration.getMaxConsumers());
assertEquals(ActiveMQDefaultConfiguration.getDefaultPurgeOnNoConsumers(), queueConfiguration.getPurgeOnNoConsumers());
assertEquals("addr2", queueConfiguration.getAddress());
// Addr 2 Queue 2
queueConfiguration = addressConfiguration.getQueueConfigurations().get(1);
assertEquals("q4", queueConfiguration.getName());
assertTrue(queueConfiguration.isDurable());
assertNull(queueConfiguration.getFilterString());
assertEquals(ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers(), queueConfiguration.getMaxConsumers());
assertTrue(queueConfiguration.getPurgeOnNoConsumers());
assertEquals("addr2", queueConfiguration.getAddress());
// Addr 3
addressConfiguration = conf.getAddressConfigurations().get(2);
assertEquals("addr2", addressConfiguration.getName());
routingTypes = new HashSet<>();
routingTypes.add(RoutingType.MULTICAST);
routingTypes.add(RoutingType.ANYCAST);
assertEquals(routingTypes, addressConfiguration.getRoutingTypes());
}
use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.
the class MQTTTest method testAmbiguousRoutingWithMQTT.
@Test(timeout = 60 * 1000)
public void testAmbiguousRoutingWithMQTT() throws Exception {
String anycastAddress = "foo/bar";
EnumSet<RoutingType> routingTypeSet = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
getServer().addAddressInfo(new AddressInfo(SimpleString.toSimpleString("foo.bar"), routingTypeSet));
String clientId = "testMqtt";
Topic[] mqttSubscription = new Topic[] { new Topic(anycastAddress, QoS.AT_LEAST_ONCE) };
MQTT mqtt = createMQTTConnection();
mqtt.setClientId(clientId);
BlockingConnection connection1 = mqtt.blockingConnection();
connection1.connect();
connection1.subscribe(mqttSubscription);
MQTT mqtt2 = createMQTTConnection();
mqtt2.setClientId(clientId + "2");
BlockingConnection connection2 = mqtt2.blockingConnection();
connection2.connect();
connection2.subscribe(mqttSubscription);
String message1 = "TestMessage1";
String message2 = "TestMessage2";
connection1.publish(anycastAddress, message1.getBytes(), QoS.AT_LEAST_ONCE, false);
connection2.publish(anycastAddress, message2.getBytes(), QoS.AT_LEAST_ONCE, false);
assertNotNull(connection1.receive(1000, TimeUnit.MILLISECONDS));
assertNotNull(connection1.receive(1000, TimeUnit.MILLISECONDS));
assertNotNull(connection2.receive(1000, TimeUnit.MILLISECONDS));
assertNotNull(connection2.receive(1000, TimeUnit.MILLISECONDS));
}
Aggregations