Repository: activemq Updated Branches: refs/heads/master 8e6a404d5 -> 85d9d4e94
https://issues.apache.org/jira/browse/AMQ-5666 Test that a receiver can also create temporary destinations when it has a Source configured as dynamic, also test that link close destroys the temporary destinations. Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/85d9d4e9 Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/85d9d4e9 Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/85d9d4e9 Branch: refs/heads/master Commit: 85d9d4e941a08f31630df13e8aad5e967363a361 Parents: 8e6a404 Author: Timothy Bish <[email protected]> Authored: Thu Mar 19 10:40:46 2015 -0400 Committer: Timothy Bish <[email protected]> Committed: Thu Mar 19 10:40:46 2015 -0400 ---------------------------------------------------------------------- .../amqp/interop/AmqpTempDestinationTest.java | 94 ++++++++++++++++++++ 1 file changed, 94 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/85d9d4e9/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/interop/AmqpTempDestinationTest.java ---------------------------------------------------------------------- diff --git a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/interop/AmqpTempDestinationTest.java b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/interop/AmqpTempDestinationTest.java index 18ef7dd..dfbbc0b 100644 --- a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/interop/AmqpTempDestinationTest.java +++ b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/interop/AmqpTempDestinationTest.java @@ -29,10 +29,12 @@ import org.apache.activemq.broker.jmx.BrokerViewMBean; import org.apache.activemq.transport.amqp.client.AmqpClient; import org.apache.activemq.transport.amqp.client.AmqpClientTestSupport; import org.apache.activemq.transport.amqp.client.AmqpConnection; +import org.apache.activemq.transport.amqp.client.AmqpReceiver; import org.apache.activemq.transport.amqp.client.AmqpSender; import org.apache.activemq.transport.amqp.client.AmqpSession; import org.apache.qpid.proton.amqp.Symbol; import org.apache.qpid.proton.amqp.messaging.DeleteOnClose; +import org.apache.qpid.proton.amqp.messaging.Source; import org.apache.qpid.proton.amqp.messaging.Target; import org.apache.qpid.proton.amqp.messaging.TerminusDurability; import org.apache.qpid.proton.amqp.messaging.TerminusExpiryPolicy; @@ -113,6 +115,98 @@ public class AmqpTempDestinationTest extends AmqpClientTestSupport { connection.close(); } + @Test(timeout = 60000) + public void testCreateDynamicReceiverToTopic() throws Exception { + doTestCreateDynamicSender(true); + } + + @Test(timeout = 60000) + public void testCreateDynamicReceiverToQueue() throws Exception { + doTestCreateDynamicSender(false); + } + + protected void doTestCreateDynamicReceiver(boolean topic) throws Exception { + Source source = createDynamicSource(topic); + + final BrokerViewMBean brokerView = getProxyToBroker(); + + AmqpClient client = createAmqpClient(); + AmqpConnection connection = client.connect(); + AmqpSession session = connection.createSession(); + + AmqpReceiver receiver = session.createReceiver(source); + assertNotNull(receiver); + + if (topic) { + assertEquals(1, brokerView.getTemporaryTopics().length); + } else { + assertEquals(1, brokerView.getTemporaryQueues().length); + } + + connection.close(); + } + + @Test(timeout = 60000) + public void testDynamicReceiverLifetimeBoundToLinkTopic() throws Exception { + doTestDynamicReceiverLifetimeBoundToLinkQueue(true); + } + + @Test(timeout = 60000) + public void testDynamicReceiverLifetimeBoundToLinkQueue() throws Exception { + doTestDynamicReceiverLifetimeBoundToLinkQueue(false); + } + + protected void doTestDynamicReceiverLifetimeBoundToLinkQueue(boolean topic) throws Exception { + Source source = createDynamicSource(topic); + + final BrokerViewMBean brokerView = getProxyToBroker(); + + AmqpClient client = createAmqpClient(); + AmqpConnection connection = client.connect(); + AmqpSession session = connection.createSession(); + + AmqpReceiver receiver = session.createReceiver(source); + assertNotNull(receiver); + + if (topic) { + assertEquals(1, brokerView.getTemporaryTopics().length); + } else { + assertEquals(1, brokerView.getTemporaryQueues().length); + } + + receiver.close(); + + if (topic) { + assertEquals(0, brokerView.getTemporaryTopics().length); + } else { + assertEquals(0, brokerView.getTemporaryQueues().length); + } + + connection.close(); + } + + protected Source createDynamicSource(boolean topic) { + + Source source = new Source(); + source.setDynamic(true); + source.setDurable(TerminusDurability.NONE); + source.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH); + + // Set the dynamic node lifetime-policy + Map<Symbol, Object> dynamicNodeProperties = new HashMap<Symbol, Object>(); + dynamicNodeProperties.put(DYNAMIC_NODE_LIFETIME_POLICY, DeleteOnClose.getInstance()); + source.setDynamicNodeProperties(dynamicNodeProperties); + + // Set the capability to indicate the node type being created + if (!topic) { + source.setCapabilities(TEMP_QUEUE_CAPABILITY); + } else { + source.setCapabilities(TEMP_TOPIC_CAPABILITY); + } + + return source; + } + protected Target createDynamicTarget(boolean topic) { Target target = new Target();
