use of javax.jms.InvalidDestinationException in project activemq-artemis by apache.
the class JmsTempDestinationTest method testTempDestOnlyConsumedByLocalConn.
/**
* Make sure Temp destination can only be consumed by local connection
*
* @throws JMSException
*/
@Test
public void testTempDestOnlyConsumedByLocalConn() throws JMSException {
connection.start();
Session tempSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue queue = tempSession.createTemporaryQueue();
MessageProducer producer = tempSession.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage message = tempSession.createTextMessage("First");
producer.send(message);
// temp destination should not be consume when using another connection
Connection otherConnection = factory.createConnection();
connections.add(otherConnection);
Session otherSession = otherConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue otherQueue = otherSession.createTemporaryQueue();
MessageConsumer consumer = otherSession.createConsumer(otherQueue);
Message msg = consumer.receive(3000);
Assert.assertNull(msg);
// destination from another connection
try {
consumer = otherSession.createConsumer(queue);
Assert.fail("Send should fail since temp destination should be used from another connection");
} catch (InvalidDestinationException e) {
Assert.assertTrue("failed to throw an exception", true);
}
// should be able to consume temp destination from the same connection
consumer = tempSession.createConsumer(queue);
msg = consumer.receive(3000);
Assert.assertNotNull(msg);
}
use of javax.jms.InvalidDestinationException in project activemq-artemis by apache.
the class AmqpFullyQualifiedNameTest method testFQQNTopicWhenQueueDoesNotExist.
@Test
public void testFQQNTopicWhenQueueDoesNotExist() throws Exception {
Exception e = null;
String queueName = "testQueue";
Connection connection = createConnection(false);
try {
connection.setClientID("FQQNconn");
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(multicastAddress.toString() + "::" + queueName);
session.createConsumer(topic);
} catch (InvalidDestinationException ide) {
e = ide;
} finally {
connection.close();
}
assertNotNull(e);
assertTrue(e.getMessage().contains("Queue: '" + queueName + "' does not exist"));
}
use of javax.jms.InvalidDestinationException in project activemq-artemis by apache.
the class AmqpFullyQualifiedNameTest method testConsumeQueueToFQQNWrongQueueAttachedToAnotherAddress.
@Test
public void testConsumeQueueToFQQNWrongQueueAttachedToAnotherAddress() throws Exception {
// Create 2 Queues: address1::queue1, address2::queue2
String address1 = "a1";
String address2 = "a2";
String queue1 = "q1";
String queue2 = "q2";
server.createQueue(SimpleString.toSimpleString(address1), RoutingType.ANYCAST, SimpleString.toSimpleString(queue1), null, true, false, -1, false, true);
server.createQueue(SimpleString.toSimpleString(address2), RoutingType.ANYCAST, SimpleString.toSimpleString(queue2), null, true, false, -1, false, true);
Exception e = null;
// Wrong FQQN. Attempt to subscribe to a queue belonging to a different address than given in the FQQN.
String wrongFQQN = address1 + "::" + queue2;
Connection connection = createConnection(false);
try {
connection.setClientID("FQQNconn");
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = session.createQueue(wrongFQQN);
session.createConsumer(queue);
} catch (InvalidDestinationException ide) {
e = ide;
} finally {
connection.close();
}
assertNotNull(e);
assertTrue(e.getMessage().contains("Queue: '" + queue2 + "' does not exist for address '" + address1 + "'"));
}
use of javax.jms.InvalidDestinationException in project activemq-artemis by apache.
the class AmqpFullyQualifiedNameTest method testQueueSpecial.
/**
* Broker should return exception if no address is passed in FQQN.
* @throws Exception
*/
@Test
public void testQueueSpecial() throws Exception {
server.createQueue(anycastAddress, RoutingType.ANYCAST, anycastQ1, null, true, false, -1, false, true);
Connection connection = createConnection();
Exception expectedException = null;
try {
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// ::queue ok!
String specialName = CompositeAddress.toFullQN(new SimpleString(""), anycastQ1).toString();
javax.jms.Queue q1 = session.createQueue(specialName);
session.createConsumer(q1);
} catch (InvalidDestinationException e) {
expectedException = e;
}
assertNotNull(expectedException);
assertTrue(expectedException.getMessage().contains("Queue: 'q1' does not exist for address ''"));
}
use of javax.jms.InvalidDestinationException in project activemq-artemis by apache.
the class MessageProducerTest method testCreateProducerOnInexistentDestination.
@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();
}
}
Aggregations