Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 14F68200C54 for ; Wed, 29 Mar 2017 00:33:31 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 137A0160B9B; Tue, 28 Mar 2017 22:33:31 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id DB3C0160B89 for ; Wed, 29 Mar 2017 00:33:29 +0200 (CEST) Received: (qmail 87270 invoked by uid 500); 28 Mar 2017 22:33:29 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 87255 invoked by uid 99); 28 Mar 2017 22:33:29 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Mar 2017 22:33:29 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F3CEEDFE1E; Tue, 28 Mar 2017 22:33:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: clebertsuconic@apache.org To: commits@activemq.apache.org Date: Tue, 28 Mar 2017 22:33:28 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] activemq-artemis git commit: ARTEMIS-1064 AddressControl routingType fix archived-at: Tue, 28 Mar 2017 22:33:31 -0000 Repository: activemq-artemis Updated Branches: refs/heads/master e3a23cda7 -> facc9dbc9 ARTEMIS-1064 AddressControl routingType fix Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/b7e11f92 Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/b7e11f92 Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/b7e11f92 Branch: refs/heads/master Commit: b7e11f92b663334ec2e38337a1012e9cfbc13cb1 Parents: e3a23cd Author: Justin Bertram Authored: Tue Mar 28 14:28:31 2017 -0500 Committer: Justin Bertram Committed: Tue Mar 28 15:30:52 2017 -0500 ---------------------------------------------------------------------- .../activemq/artemis/api/core/JsonUtil.java | 11 +- .../api/core/management/AddressControl.java | 11 +- .../management/impl/AddressControlImpl.java | 18 +- .../management/AddressControlTest.java | 45 ++++ .../management/AddressControlUsingCoreTest.java | 233 +++++++------------ 5 files changed, 155 insertions(+), 163 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b7e11f92/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java ---------------------------------------------------------------------- diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java index 5fefbbc..150789e 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java @@ -28,6 +28,7 @@ import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeDataSupport; import java.io.ByteArrayInputStream; import java.io.StringReader; +import java.lang.reflect.Array; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -303,10 +304,16 @@ public final class JsonUtil { } } else if (jsonValue instanceof Object[]) { Object[] array = (Object[]) jsonValue; + Object[] result; + if (desiredType != null) { + result = (Object[]) Array.newInstance(desiredType, array.length); + } else { + result = array; + } for (int i = 0; i < array.length; i++) { - array[i] = convertJsonValue(array[i], desiredType); + result[i] = convertJsonValue(array[i], desiredType); } - return array; + return result; } else { return jsonValue; } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b7e11f92/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressControl.java ---------------------------------------------------------------------- diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressControl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressControl.java index 635eb72..0dadad1 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressControl.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressControl.java @@ -18,9 +18,6 @@ package org.apache.activemq.artemis.api.core.management; import javax.management.MBeanOperationInfo; import java.util.Map; -import java.util.Set; - -import org.apache.activemq.artemis.api.core.RoutingType; /** * An AddressControl is used to manage an address. @@ -36,14 +33,14 @@ public interface AddressControl { /* * Whether multicast routing is enabled for this address * */ - @Attribute(desc = "Get the delivery modes enabled on this address") - Set getDeliveryModes(); + @Attribute(desc = "Get the routing types enabled on this address") + String[] getRoutingTypes(); /* * Whether multicast routing is enabled for this address * */ - @Attribute(desc = "Get the delivery modes enabled on this address as JSON") - String getDeliveryModesAsJSON() throws Exception; + @Attribute(desc = "Get the routing types enabled on this address as JSON") + String getRoutingTypesAsJSON() throws Exception; /** * Returns the roles (name and permissions) associated with this address. http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b7e11f92/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java ---------------------------------------------------------------------- diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java index 37756dc..afdca45 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java @@ -98,19 +98,25 @@ public class AddressControlImpl extends AbstractControl implements AddressContro } @Override - public Set getDeliveryModes() { - return addressInfo.getRoutingTypes(); + public String[] getRoutingTypes() { + Set routingTypes = addressInfo.getRoutingTypes(); + String[] result = new String[routingTypes.size()]; + int i = 0; + for (RoutingType routingType : routingTypes) { + result[i++] = routingType.toString(); + } + return result; } @Override - public String getDeliveryModesAsJSON() throws Exception { + public String getRoutingTypesAsJSON() throws Exception { clearIO(); try { JsonArrayBuilder json = JsonLoader.createArrayBuilder(); - Set routingTypes = getDeliveryModes(); + String[] routingTypes = getRoutingTypes(); - for (RoutingType routingType : routingTypes) { - json.add(routingType.toString()); + for (String routingType : routingTypes) { + json.add(routingType); } return json.build().toString(); } finally { http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b7e11f92/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java ---------------------------------------------------------------------- diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java index 35e1aa2..e62ce12 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java @@ -16,10 +16,15 @@ */ package org.apache.activemq.artemis.tests.integration.management; +import javax.json.JsonArray; +import javax.json.JsonString; +import java.util.Arrays; import java.util.HashSet; import java.util.Set; import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration; +import org.apache.activemq.artemis.api.core.JsonUtil; +import org.apache.activemq.artemis.api.core.RoutingType; import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.client.ClientMessage; import org.apache.activemq.artemis.api.core.client.ClientProducer; @@ -48,6 +53,10 @@ public class AddressControlTest extends ManagementTestBase { private ServerLocator locator; private ClientSessionFactory sf; + public boolean usingCore() { + return false; + } + @Test public void testGetAddress() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); @@ -265,6 +274,42 @@ public class AddressControlTest extends ManagementTestBase { Assert.assertEquals(1024, addressControl.getNumberOfBytesPerPage()); } + @Test + public void testGetRoutingTypes() throws Exception { + SimpleString address = RandomUtil.randomSimpleString(); + session.createAddress(address, RoutingType.ANYCAST, false); + + AddressControl addressControl = createManagementControl(address); + String[] routingTypes = addressControl.getRoutingTypes(); + Assert.assertEquals(1, routingTypes.length); + Assert.assertEquals(RoutingType.ANYCAST.toString(), routingTypes[0]); + + address = RandomUtil.randomSimpleString(); + Set types = new HashSet<>(); + types.add(RoutingType.ANYCAST); + types.add(RoutingType.MULTICAST); + session.createAddress(address, types, false); + + addressControl = createManagementControl(address); + routingTypes = addressControl.getRoutingTypes(); + Set strings = new HashSet<>(Arrays.asList(routingTypes)); + Assert.assertEquals(2, strings.size()); + Assert.assertTrue(strings.contains(RoutingType.ANYCAST.toString())); + Assert.assertTrue(strings.contains(RoutingType.MULTICAST.toString())); + } + + @Test + public void testGetRoutingTypesAsJSON() throws Exception { + SimpleString address = RandomUtil.randomSimpleString(); + session.createAddress(address, RoutingType.ANYCAST, false); + + AddressControl addressControl = createManagementControl(address); + JsonArray jsonArray = JsonUtil.readJsonArray(addressControl.getRoutingTypesAsJSON()); + + assertEquals(1, jsonArray.size()); + assertEquals(RoutingType.ANYCAST.toString(), ((JsonString) jsonArray.get(0)).getString()); + } + // Package protected --------------------------------------------- // Protected ----------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b7e11f92/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlUsingCoreTest.java ---------------------------------------------------------------------- diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlUsingCoreTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlUsingCoreTest.java index 4b8e487..d9c9f2e 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlUsingCoreTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlUsingCoreTest.java @@ -16,173 +16,110 @@ */ package org.apache.activemq.artemis.tests.integration.management; -import java.util.HashSet; -import java.util.Set; +import java.util.Map; import org.apache.activemq.artemis.api.core.SimpleString; -import org.apache.activemq.artemis.api.core.client.ClientSession; -import org.apache.activemq.artemis.api.core.client.ClientSessionFactory; -import org.apache.activemq.artemis.api.core.client.ServerLocator; import org.apache.activemq.artemis.api.core.management.AddressControl; import org.apache.activemq.artemis.api.core.management.ResourceNames; -import org.apache.activemq.artemis.core.config.Configuration; -import org.apache.activemq.artemis.core.security.CheckType; -import org.apache.activemq.artemis.core.security.Role; -import org.apache.activemq.artemis.core.server.ActiveMQServer; -import org.apache.activemq.artemis.utils.RandomUtil; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import static org.apache.activemq.artemis.tests.util.RandomUtil.randomString; - -public class AddressControlUsingCoreTest extends ManagementTestBase { +public class AddressControlUsingCoreTest extends AddressControlTest { // Constants ----------------------------------------------------- // Attributes ---------------------------------------------------- - private ActiveMQServer server; - - private ServerLocator locator; - - private ClientSessionFactory sf; - - protected ClientSession session; - // Static -------------------------------------------------------- // Constructors -------------------------------------------------- - // Public -------------------------------------------------------- - - @Test - public void testGetAddress() throws Exception { - SimpleString address = RandomUtil.randomSimpleString(); - SimpleString queue = RandomUtil.randomSimpleString(); - - session.createQueue(address, queue, false); - - CoreMessagingProxy proxy = createProxy(address); - - Assert.assertEquals(address.toString(), proxy.retrieveAttributeValue("address")); - - session.deleteQueue(queue); - } - - @Test - public void testGetQueueNames() throws Exception { - SimpleString address = RandomUtil.randomSimpleString(); - SimpleString queue = RandomUtil.randomSimpleString(); - SimpleString anotherQueue = RandomUtil.randomSimpleString(); - - session.createQueue(address, queue, true); - - CoreMessagingProxy proxy = createProxy(address); - Object[] queueNames = (Object[]) proxy.retrieveAttributeValue("queueNames"); - Assert.assertEquals(1, queueNames.length); - Assert.assertEquals(queue.toString(), queueNames[0]); - - session.createQueue(address, anotherQueue, false); - queueNames = (Object[]) proxy.retrieveAttributeValue("queueNames"); - Assert.assertEquals(2, queueNames.length); - - session.deleteQueue(queue); - - queueNames = (Object[]) proxy.retrieveAttributeValue("queueNames"); - Assert.assertEquals(1, queueNames.length); - Assert.assertEquals(anotherQueue.toString(), queueNames[0]); - - session.deleteQueue(anotherQueue); - } - - @Test - public void testGetBindingNames() throws Exception { - SimpleString address = RandomUtil.randomSimpleString(); - SimpleString queue = RandomUtil.randomSimpleString(); - String divertName = RandomUtil.randomString(); - - session.createQueue(address, queue, false); - - CoreMessagingProxy proxy = createProxy(address); - Object[] bindingNames = (Object[]) proxy.retrieveAttributeValue("bindingNames"); - assertEquals(1, bindingNames.length); - assertEquals(queue.toString(), bindingNames[0]); - - server.getActiveMQServerControl().createDivert(divertName, randomString(), address.toString(), RandomUtil.randomString(), false, null, null); - - bindingNames = (Object[]) proxy.retrieveAttributeValue("bindingNames"); - assertEquals(2, bindingNames.length); - - session.deleteQueue(queue); - - bindingNames = (Object[]) proxy.retrieveAttributeValue("bindingNames"); - assertEquals(1, bindingNames.length); - assertEquals(divertName.toString(), bindingNames[0]); - } - - @Test - public void testGetRoles() throws Exception { - SimpleString address = RandomUtil.randomSimpleString(); - SimpleString queue = RandomUtil.randomSimpleString(); - Role role = new Role(RandomUtil.randomString(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean()); - - session.createQueue(address, queue, true); - - CoreMessagingProxy proxy = createProxy(address); - Object[] roles = (Object[]) proxy.retrieveAttributeValue("roles"); - for (Object role2 : roles) { - System.out.println(((Object[]) role2)[0]); - } - Assert.assertEquals(0, roles.length); - - Set newRoles = new HashSet<>(); - newRoles.add(role); - server.getSecurityRepository().addMatch(address.toString(), newRoles); - - roles = (Object[]) proxy.retrieveAttributeValue("roles", String.class); - Assert.assertEquals(1, roles.length); - Object[] r = (Object[]) roles[0]; - Assert.assertEquals(role.getName(), r[0]); - Assert.assertEquals(CheckType.SEND.hasRole(role), r[1]); - Assert.assertEquals(CheckType.CONSUME.hasRole(role), r[2]); - Assert.assertEquals(CheckType.CREATE_DURABLE_QUEUE.hasRole(role), r[3]); - Assert.assertEquals(CheckType.DELETE_DURABLE_QUEUE.hasRole(role), r[4]); - Assert.assertEquals(CheckType.CREATE_NON_DURABLE_QUEUE.hasRole(role), r[5]); - Assert.assertEquals(CheckType.DELETE_NON_DURABLE_QUEUE.hasRole(role), r[6]); - Assert.assertEquals(CheckType.MANAGE.hasRole(role), r[7]); - - session.deleteQueue(queue); - } - - // Package protected --------------------------------------------- - - // Protected ----------------------------------------------------- @Override - @Before - public void setUp() throws Exception { - super.setUp(); - - Configuration config = createDefaultInVMConfig().setJMXManagementEnabled(true); - server = createServer(false, config); - server.setMBeanServer(mbeanServer); - server.start(); - - locator = createInVMNonHALocator().setBlockOnNonDurableSend(true); - sf = createSessionFactory(locator); - session = sf.createSession(false, true, false); - session.start(); + protected AddressControl createManagementControl(final SimpleString name) throws Exception { + return new AddressControl() { + private final CoreMessagingProxy proxy = new CoreMessagingProxy(addServerLocator(createInVMNonHALocator()), ResourceNames.ADDRESS + name); + + @Override + public String getAddress() { + return (String) proxy.retrieveAttributeValue("address"); + } + + @Override + public String[] getRoutingTypes() { + return (String[]) proxy.retrieveAttributeValue("routingTypes", String.class); + } + + @Override + public String getRoutingTypesAsJSON() throws Exception { + return (String) proxy.retrieveAttributeValue("routingTypesAsJSON"); + } + + @Override + public Object[] getRoles() throws Exception { + return (Object[]) proxy.retrieveAttributeValue("roles"); + } + + @Override + public String getRolesAsJSON() throws Exception { + return (String) proxy.retrieveAttributeValue("rolesAsJSON"); + } + + @Override + public long getAddressSize() throws Exception { + return (long) proxy.retrieveAttributeValue("addressSize"); + } + + @Override + public long getNumberOfMessages() throws Exception { + return (long) proxy.retrieveAttributeValue("numberOfMessages"); + } + + @Override + public String[] getQueueNames() throws Exception { + return (String[]) proxy.retrieveAttributeValue("queueNames", String.class); + } + + @Override + public int getNumberOfPages() throws Exception { + return (int) proxy.retrieveAttributeValue("numberOfPages", Integer.class); + } + + @Override + public boolean isPaging() throws Exception { + return (boolean) proxy.retrieveAttributeValue("paging"); + } + + @Override + public long getNumberOfBytesPerPage() throws Exception { + return (long) proxy.retrieveAttributeValue("numberOfBytesPerPage"); + } + + @Override + public String[] getBindingNames() throws Exception { + return (String[]) proxy.retrieveAttributeValue("bindingNames", String.class); + } + + @Override + public long getMessageCount() { + return (long) proxy.retrieveAttributeValue("messageCount"); + } + + @Override + public String sendMessage(Map headers, + int type, + String body, + boolean durable, + String user, + String password) throws Exception { + return (String) proxy.invokeOperation("sendMessage", headers, type, body, durable, user, password); + } + }; } - protected CoreMessagingProxy createProxy(final SimpleString address) throws Exception { - CoreMessagingProxy proxy = new CoreMessagingProxy(addServerLocator(createInVMNonHALocator()), ResourceNames.ADDRESS + address); - - return proxy; - } + // Public -------------------------------------------------------- - protected AddressControl createManagementControl(final SimpleString address) throws Exception { - return ManagementControlHelper.createAddressControl(address, mbeanServer); + @Override + public boolean usingCore() { + return true; } // Private -------------------------------------------------------