From 4109b790595339e92306f00056746034e5541417 Mon Sep 17 00:00:00 2001 From: gtully Date: Mon, 4 Nov 2013 13:55:21 +0000 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-4843 - implement and test for composite virtual destinations - forwardTo --- .../plugin/RuntimeConfigurationBroker.java | 27 ++++++------- .../src/main/resources/binding.xjb | 16 ++++++++ .../org/apache/activemq/VirtualDestTest.java | 38 ++++++++++++++++++- .../virtualDestTest-add-composite-vd.xml | 36 ++++++++++++++++++ 4 files changed, 100 insertions(+), 17 deletions(-) create mode 100644 activemq-runtime-config/src/test/resources/org/apache/activemq/virtualDestTest-add-composite-vd.xml diff --git a/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java b/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java index b5415421cb..0d08fafd59 100644 --- a/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java +++ b/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java @@ -576,24 +576,19 @@ public class RuntimeConfigurationBroker extends BrokerFilter { // deal with nested elements for (Object nested : filter(dto, Object.class)) { String elementName = nested.getClass().getSimpleName(); - if (elementName.endsWith("s")) { - Method setter = findSetter(instance, elementName); - if (setter != null) { - - List argument = new LinkedList(); - for (Object elementContent : filter(nested, Object.class)) { - argument.add(fromDto(elementContent, inferTargetObject(elementContent))); - } - try { - setter.invoke(instance, matchType(argument, setter.getParameterTypes()[0])); - } catch (Exception e) { - info("failed to invoke " + setter + " on " + instance, e); - } - } else { - info("failed to find setter for " + elementName + " on :" + instance); + Method setter = findSetter(instance, elementName); + if (setter != null) { + List argument = new LinkedList(); + for (Object elementContent : filter(nested, Object.class)) { + argument.add(fromDto(elementContent, inferTargetObject(elementContent))); + } + try { + setter.invoke(instance, matchType(argument, setter.getParameterTypes()[0])); + } catch (Exception e) { + info("failed to invoke " + setter + " on " + instance, e); } } else { - info("unsupported mapping of element for non plural:" + elementName); + info("failed to find setter for " + elementName + " on :" + instance); } } return instance; diff --git a/activemq-runtime-config/src/main/resources/binding.xjb b/activemq-runtime-config/src/main/resources/binding.xjb index b5a5334793..6e786a576b 100644 --- a/activemq-runtime-config/src/main/resources/binding.xjb +++ b/activemq-runtime-config/src/main/resources/binding.xjb @@ -96,6 +96,22 @@ + + + + + + + + + + + + + + + + diff --git a/activemq-runtime-config/src/test/java/org/apache/activemq/VirtualDestTest.java b/activemq-runtime-config/src/test/java/org/apache/activemq/VirtualDestTest.java index e408afdee0..5c007a70a8 100644 --- a/activemq-runtime-config/src/test/java/org/apache/activemq/VirtualDestTest.java +++ b/activemq-runtime-config/src/test/java/org/apache/activemq/VirtualDestTest.java @@ -68,6 +68,17 @@ public class VirtualDestTest extends RuntimeConfigTestSupport { assertSame("same instance", newValue, brokerService.getDestinationInterceptors()[0]); } + @Test + public void testNewComposite() throws Exception { + final String brokerConfig = configurationSeed + "-new-composite-vd-broker"; + applyNewConfig(brokerConfig, RuntimeConfigTestSupport.EMPTY_UPDATABLE_CONFIG); + startBroker(brokerConfig); + assertTrue("broker alive", brokerService.isStarted()); + + applyNewConfig(brokerConfig, configurationSeed + "-add-composite-vd", SLEEP); + + exerciseCompositeQueue("VirtualDestination.CompositeQueue", "VirtualDestination.QueueConsumer"); + } @Test public void testNewNoDefaultVirtualTopicSupport() throws Exception { @@ -218,11 +229,15 @@ public class VirtualDestTest extends RuntimeConfigTestSupport { } private void exerciseVirtualTopic(String topic) throws Exception { + exerciseVirtualTopic("Consumer.A.", topic); + } + + private void exerciseVirtualTopic(String prefix, String topic) throws Exception { ActiveMQConnection connection = new ActiveMQConnectionFactory("vm://localhost").createActiveMQConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer) session.createConsumer(session.createQueue("Consumer.A." + topic)); + ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer) session.createConsumer(session.createQueue(prefix + topic)); LOG.info("new consumer for: " + consumer.getDestination()); MessageProducer producer = session.createProducer(session.createTopic(topic)); final String body = "To vt:" + topic; @@ -238,4 +253,25 @@ public class VirtualDestTest extends RuntimeConfigTestSupport { connection.close(); } + private void exerciseCompositeQueue(String dest, String consumerQ) throws Exception { + ActiveMQConnection connection = new ActiveMQConnectionFactory("vm://localhost").createActiveMQConnection(); + connection.start(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer) session.createConsumer(session.createQueue(consumerQ)); + LOG.info("new consumer for: " + consumer.getDestination()); + MessageProducer producer = session.createProducer(session.createQueue(dest)); + final String body = "To cq:" + dest; + producer.send(session.createTextMessage(body)); + LOG.info("sent to: " + producer.getDestination()); + + Message message = null; + for (int i=0; i<10 && message == null; i++) { + message = consumer.receive(1000); + } + assertNotNull("got message", message); + assertEquals("got expected message", body, ((TextMessage) message).getText()); + connection.close(); + } + } diff --git a/activemq-runtime-config/src/test/resources/org/apache/activemq/virtualDestTest-add-composite-vd.xml b/activemq-runtime-config/src/test/resources/org/apache/activemq/virtualDestTest-add-composite-vd.xml new file mode 100644 index 0000000000..9783e2a47d --- /dev/null +++ b/activemq-runtime-config/src/test/resources/org/apache/activemq/virtualDestTest-add-composite-vd.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + +