use of javax.jms.TemporaryQueue in project activemq-artemis by apache.
the class TemporaryDestinationTest method testTemporaryQueueDeleted.
@Test
public void testTemporaryQueueDeleted() throws Exception {
Connection conn = null;
try {
conn = createConnection();
Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Make sure temporary queue cannot be used after it has been deleted
TemporaryQueue tempQueue = producerSession.createTemporaryQueue();
MessageProducer producer = producerSession.createProducer(tempQueue);
MessageConsumer consumer = consumerSession.createConsumer(tempQueue);
conn.start();
final String messageText = "This is a message";
Message m = producerSession.createTextMessage(messageText);
producer.send(m);
TextMessage m2 = (TextMessage) consumer.receive(2000);
ProxyAssertSupport.assertNotNull(m2);
ProxyAssertSupport.assertEquals(messageText, m2.getText());
consumer.close();
tempQueue.delete();
conn.close();
conn = createConnection("guest", "guest");
try {
producer.send(m);
ProxyAssertSupport.fail();
} catch (JMSException e) {
}
} finally {
if (conn != null) {
conn.close();
}
}
}
use of javax.jms.TemporaryQueue in project activemq-artemis by apache.
the class TemporaryDestinationTest method testTemporaryQueueDeleteWithConsumer.
@Test
public void testTemporaryQueueDeleteWithConsumer() throws Exception {
Connection conn = null;
try {
conn = createConnection();
Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue tempQueue = producerSession.createTemporaryQueue();
MessageConsumer consumer = consumerSession.createConsumer(tempQueue);
try {
tempQueue.delete();
ProxyAssertSupport.fail("Should throw JMSException");
} catch (JMSException e) {
// Should fail - you can't delete a temp queue if it has active consumers
}
consumer.close();
} finally {
if (conn != null) {
conn.close();
}
}
}
use of javax.jms.TemporaryQueue in project activemq-artemis by apache.
the class TemporaryDestinationTest method testTemporaryQueueBasic.
@Test
public void testTemporaryQueueBasic() throws Exception {
Connection conn = null;
try {
conn = createConnection();
Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue tempQueue = producerSession.createTemporaryQueue();
MessageProducer producer = producerSession.createProducer(tempQueue);
MessageConsumer consumer = consumerSession.createConsumer(tempQueue);
conn.start();
final String messageText = "This is a message";
Message m = producerSession.createTextMessage(messageText);
producer.send(m);
TextMessage m2 = (TextMessage) consumer.receive(2000);
ProxyAssertSupport.assertNotNull(m2);
ProxyAssertSupport.assertEquals(messageText, m2.getText());
} finally {
if (conn != null) {
conn.close();
}
}
}
use of javax.jms.TemporaryQueue in project activemq-artemis by apache.
the class MemoryAllocationTest method releaseDestination.
protected void releaseDestination(Destination dest) throws JMSException {
if (dest instanceof TemporaryTopic) {
TemporaryTopic tt = (TemporaryTopic) dest;
tt.delete();
} else if (dest instanceof TemporaryQueue) {
TemporaryQueue tq = (TemporaryQueue) dest;
tq.delete();
}
}
use of javax.jms.TemporaryQueue in project activemq-artemis by apache.
the class ThreeBrokerTempQueueNetworkTest method testTempQueueCleanup.
/**
* BrokerA -> BrokerB -> BrokerC
*/
public void testTempQueueCleanup() throws Exception {
// Setup broker networks
bridgeBrokers("BrokerA", "BrokerB", false, 2);
bridgeBrokers("BrokerB", "BrokerC", false, 2);
startAllBrokers();
BrokerItem brokerItem = brokers.get("BrokerC");
Connection conn = brokerItem.createConnection();
conn.start();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue tempQ = sess.createTemporaryQueue();
Thread.sleep(5000);
for (Iterator<BrokerItem> i = brokers.values().iterator(); i.hasNext(); ) {
BrokerItem bi = i.next();
assertEquals("No queues on broker " + bi.broker.getBrokerName(), 1, bi.broker.getAdminView().getTemporaryQueues().length);
}
tempQ.delete();
Thread.sleep(2000);
for (Iterator<BrokerItem> i = brokers.values().iterator(); i.hasNext(); ) {
BrokerItem bi = i.next();
assertEquals("Temp queue left behind on broker " + bi.broker.getBrokerName(), 0, bi.broker.getAdminView().getTemporaryQueues().length);
}
}
Aggregations