You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2017/12/19 14:34:26 UTC
[2/3] activemq-artemis git commit: ARTEMIS-1516 - Ensure JNDI via
Tomcat Resource works
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3ef98044/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/jndi/ObjectFactoryTest.java
----------------------------------------------------------------------
diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/jndi/ObjectFactoryTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/jndi/ObjectFactoryTest.java
new file mode 100644
index 0000000..9ceebfd
--- /dev/null
+++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/jndi/ObjectFactoryTest.java
@@ -0,0 +1,138 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.tests.unit.jms.jndi;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.naming.Reference;
+
+import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
+import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
+import org.apache.activemq.artemis.jms.client.ActiveMQDestination;
+import org.apache.activemq.artemis.jndi.JNDIReferenceFactory;
+import org.apache.activemq.artemis.utils.RandomUtil;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ObjectFactoryTest {
+
+ @Test(timeout = 1000)
+ public void testConnectionFactory() throws Exception {
+ // Create sample connection factory
+ ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://0");
+
+ String clientID = RandomUtil.randomString();
+ String user = RandomUtil.randomString();
+ String password = RandomUtil.randomString();
+ long clientFailureCheckPeriod = RandomUtil.randomPositiveLong();
+ long connectionTTL = RandomUtil.randomPositiveLong();
+ long callTimeout = RandomUtil.randomPositiveLong();
+ int minLargeMessageSize = RandomUtil.randomPositiveInt();
+ int consumerWindowSize = RandomUtil.randomPositiveInt();
+ int consumerMaxRate = RandomUtil.randomPositiveInt();
+ int confirmationWindowSize = RandomUtil.randomPositiveInt();
+ int producerMaxRate = RandomUtil.randomPositiveInt();
+ boolean blockOnAcknowledge = RandomUtil.randomBoolean();
+ boolean blockOnDurableSend = RandomUtil.randomBoolean();
+ boolean blockOnNonDurableSend = RandomUtil.randomBoolean();
+ boolean autoGroup = RandomUtil.randomBoolean();
+ boolean preAcknowledge = RandomUtil.randomBoolean();
+ String loadBalancingPolicyClassName = RandomUtil.randomString();
+ boolean useGlobalPools = RandomUtil.randomBoolean();
+ int scheduledThreadPoolMaxSize = RandomUtil.randomPositiveInt();
+ int threadPoolMaxSize = RandomUtil.randomPositiveInt();
+ long retryInterval = RandomUtil.randomPositiveLong();
+ double retryIntervalMultiplier = RandomUtil.randomDouble();
+ int reconnectAttempts = RandomUtil.randomPositiveInt();
+ factory.setClientID(clientID);
+ factory.setUser(user);
+ factory.setPassword(password);
+ factory.setClientFailureCheckPeriod(clientFailureCheckPeriod);
+ factory.setConnectionTTL(connectionTTL);
+ factory.setCallTimeout(callTimeout);
+ factory.setMinLargeMessageSize(minLargeMessageSize);
+ factory.setConsumerWindowSize(consumerWindowSize);
+ factory.setConsumerMaxRate(consumerMaxRate);
+ factory.setConfirmationWindowSize(confirmationWindowSize);
+ factory.setProducerMaxRate(producerMaxRate);
+ factory.setBlockOnAcknowledge(blockOnAcknowledge);
+ factory.setBlockOnDurableSend(blockOnDurableSend);
+ factory.setBlockOnNonDurableSend(blockOnNonDurableSend);
+ factory.setAutoGroup(autoGroup);
+ factory.setPreAcknowledge(preAcknowledge);
+ factory.setConnectionLoadBalancingPolicyClassName(loadBalancingPolicyClassName);
+ factory.setUseGlobalPools(useGlobalPools);
+ factory.setScheduledThreadPoolMaxSize(scheduledThreadPoolMaxSize);
+ factory.setThreadPoolMaxSize(threadPoolMaxSize);
+ factory.setRetryInterval(retryInterval);
+ factory.setRetryIntervalMultiplier(retryIntervalMultiplier);
+ factory.setReconnectAttempts(reconnectAttempts);
+
+
+ // Create reference
+ Reference ref = JNDIReferenceFactory.createReference(factory.getClass().getName(), factory);
+
+ // Get object created based on reference
+ ActiveMQConnectionFactory temp;
+ JNDIReferenceFactory refFactory = new JNDIReferenceFactory();
+ temp = (ActiveMQConnectionFactory)refFactory.getObjectInstance(ref, null, null, null);
+
+ // Check settings
+ Assert.assertEquals(clientID, temp.getClientID());
+ Assert.assertEquals(user, temp.getUser());
+ Assert.assertEquals(password, temp.getPassword());
+ Assert.assertEquals(clientFailureCheckPeriod, temp.getClientFailureCheckPeriod());
+ Assert.assertEquals(connectionTTL, temp.getConnectionTTL());
+ Assert.assertEquals(callTimeout, temp.getCallTimeout());
+ Assert.assertEquals(minLargeMessageSize, temp.getMinLargeMessageSize());
+ Assert.assertEquals(consumerWindowSize, temp.getConsumerWindowSize());
+ Assert.assertEquals(consumerMaxRate, temp.getConsumerMaxRate());
+ Assert.assertEquals(confirmationWindowSize, temp.getConfirmationWindowSize());
+ Assert.assertEquals(producerMaxRate, temp.getProducerMaxRate());
+ Assert.assertEquals(blockOnAcknowledge, temp.isBlockOnAcknowledge());
+ Assert.assertEquals(blockOnDurableSend, temp.isBlockOnDurableSend());
+ Assert.assertEquals(blockOnNonDurableSend, temp.isBlockOnNonDurableSend());
+ Assert.assertEquals(autoGroup, temp.isAutoGroup());
+ Assert.assertEquals(preAcknowledge, temp.isPreAcknowledge());
+ Assert.assertEquals(loadBalancingPolicyClassName, temp.getConnectionLoadBalancingPolicyClassName());
+ Assert.assertEquals(useGlobalPools, temp.isUseGlobalPools());
+ Assert.assertEquals(scheduledThreadPoolMaxSize, temp.getScheduledThreadPoolMaxSize());
+ Assert.assertEquals(threadPoolMaxSize, temp.getThreadPoolMaxSize());
+ Assert.assertEquals(retryInterval, temp.getRetryInterval());
+ Assert.assertEquals(retryIntervalMultiplier, temp.getRetryIntervalMultiplier(), 0.0001);
+ Assert.assertEquals(reconnectAttempts, temp.getReconnectAttempts());
+
+ }
+
+ @Test(timeout = 1000)
+ public void testDestination() throws Exception {
+ // Create sample destination
+ ActiveMQDestination dest = (ActiveMQDestination) ActiveMQJMSClient.createQueue(RandomUtil.randomString());
+
+ // Create reference
+ Reference ref = JNDIReferenceFactory.createReference(dest.getClass().getName(), dest);
+
+ // Get object created based on reference
+ ActiveMQDestination temp;
+ JNDIReferenceFactory refFactory = new JNDIReferenceFactory();
+ temp = (ActiveMQDestination)refFactory.getObjectInstance(ref, null, null, null);
+
+ // Check settings
+ assertEquals(dest.getAddress(), temp.getAddress());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3ef98044/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/jndi/StringRefAddrReferenceTest.java
----------------------------------------------------------------------
diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/jndi/StringRefAddrReferenceTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/jndi/StringRefAddrReferenceTest.java
new file mode 100644
index 0000000..bbfbaf9
--- /dev/null
+++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/jndi/StringRefAddrReferenceTest.java
@@ -0,0 +1,119 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.tests.unit.jms.jndi;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+import javax.naming.spi.ObjectFactory;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
+import org.apache.activemq.artemis.jms.client.ActiveMQQueue;
+import org.apache.activemq.artemis.jms.client.ActiveMQTopic;
+import org.apache.activemq.artemis.jndi.JNDIReferenceFactory;
+import org.junit.Test;
+
+/**
+ * Test to simulate JNDI references created using String properties in containers such as Apache Tomcat.
+ */
+public class StringRefAddrReferenceTest {
+
+ private static final String FACTORY = "factory";
+ private static final String TYPE = "type";
+
+ @Test(timeout = 10000)
+ public void testActiveMQQueueFromPropertiesJNDI() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty(TYPE, ActiveMQQueue.class.getName());
+ properties.setProperty(FACTORY, JNDIReferenceFactory.class.getName());
+
+ String address = "foo.bar.queue";
+
+ properties.setProperty("address", address);
+
+ Reference reference = from(properties);
+ ActiveMQQueue object = getObject(reference, ActiveMQQueue.class);
+
+ assertEquals(address, object.getAddress());
+
+ }
+
+ @Test(timeout = 10000)
+ public void testActiveMQTopicFromPropertiesJNDI() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty(TYPE, ActiveMQTopic.class.getName());
+ properties.setProperty(FACTORY, JNDIReferenceFactory.class.getName());
+
+ String address = "foo.bar.topic";
+
+ properties.setProperty("address", address);
+
+ Reference reference = from(properties);
+ ActiveMQTopic object = getObject(reference, ActiveMQTopic.class);
+
+ assertEquals(address, object.getAddress());
+
+ }
+
+ @Test(timeout = 10000)
+ public void testActiveMQConnectionFactoryFromPropertiesJNDI() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty(TYPE, ActiveMQConnectionFactory.class.getName());
+ properties.setProperty(FACTORY, JNDIReferenceFactory.class.getName());
+
+ String brokerURL = "vm://0";
+ String connectionTTL = "1000";
+ String preAcknowledge = "true";
+
+ properties.setProperty("brokerURL", brokerURL);
+ properties.setProperty("connectionTTL", connectionTTL);
+ properties.setProperty("preAcknowledge", preAcknowledge);
+
+ Reference reference = from(properties);
+ ActiveMQConnectionFactory object = getObject(reference, ActiveMQConnectionFactory.class);
+
+ assertEquals(Long.parseLong(connectionTTL), object.getConnectionTTL());
+ assertEquals(Boolean.parseBoolean(preAcknowledge), object.isPreAcknowledge());
+
+ }
+
+ private <T> T getObject(Reference reference, Class<T> tClass) throws Exception {
+ String factoryName = reference.getFactoryClassName();
+ Class<?> factoryClass = Class.forName(factoryName);
+ ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
+ Object o = factory.getObjectInstance(reference, null, null, null);
+ if (tClass.isAssignableFrom(tClass)) {
+ return tClass.cast(o);
+ } else {
+ throw new IllegalStateException("Expected class, " + tClass.getName());
+ }
+ }
+
+ public Reference from(Properties properties) {
+ String type = (String) properties.remove("type");
+ String factory = (String) properties.remove("factory");
+ Reference result = new Reference(type, factory, null);
+ for (Enumeration iter = properties.propertyNames(); iter.hasMoreElements();) {
+ String key = (String)iter.nextElement();
+ result.add(new StringRefAddr(key, properties.getProperty(key)));
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3ef98044/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/referenceable/DestinationObjectFactoryTest.java
----------------------------------------------------------------------
diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/referenceable/DestinationObjectFactoryTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/referenceable/DestinationObjectFactoryTest.java
deleted file mode 100644
index 7bbbf31..0000000
--- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/referenceable/DestinationObjectFactoryTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.activemq.artemis.tests.unit.jms.referenceable;
-
-import javax.naming.Reference;
-
-import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
-import org.apache.activemq.artemis.jms.client.ActiveMQDestination;
-import org.apache.activemq.artemis.jms.referenceable.DestinationObjectFactory;
-import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
-import org.apache.activemq.artemis.utils.RandomUtil;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class DestinationObjectFactoryTest extends ActiveMQTestBase {
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- @Test
- public void testReference() throws Exception {
- ActiveMQDestination queue = (ActiveMQDestination) ActiveMQJMSClient.createQueue(RandomUtil.randomString());
- Reference reference = queue.getReference();
-
- DestinationObjectFactory factory = new DestinationObjectFactory();
- Object object = factory.getObjectInstance(reference, null, null, null);
- Assert.assertNotNull(object);
- Assert.assertTrue(object instanceof ActiveMQDestination);
- Assert.assertEquals(queue, object);
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3ef98044/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/ConnectionFactoryPropertiesTest.java
----------------------------------------------------------------------
diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/ConnectionFactoryPropertiesTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/ConnectionFactoryPropertiesTest.java
index b3ed958..3901e1b 100644
--- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/ConnectionFactoryPropertiesTest.java
+++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/ConnectionFactoryPropertiesTest.java
@@ -43,6 +43,9 @@ public class ConnectionFactoryPropertiesTest extends ActiveMQTestBase {
UNSUPPORTED_CF_PROPERTIES.add("discoveryGroupName");
UNSUPPORTED_CF_PROPERTIES.add("incomingInterceptorList");
UNSUPPORTED_CF_PROPERTIES.add("outgoingInterceptorList");
+ UNSUPPORTED_CF_PROPERTIES.add("user");
+ UNSUPPORTED_CF_PROPERTIES.add("userName");
+ UNSUPPORTED_CF_PROPERTIES.add("password");
UNSUPPORTED_RA_PROPERTIES = new TreeSet<>();
UNSUPPORTED_RA_PROPERTIES.add("HA");
@@ -62,6 +65,7 @@ public class ConnectionFactoryPropertiesTest extends ActiveMQTestBase {
UNSUPPORTED_RA_PROPERTIES.add("useMaskedPassword");
UNSUPPORTED_RA_PROPERTIES.add("useAutoRecovery");
UNSUPPORTED_RA_PROPERTIES.add("useLocalTx");
+ UNSUPPORTED_RA_PROPERTIES.add("user");
UNSUPPORTED_RA_PROPERTIES.add("userName");
UNSUPPORTED_RA_PROPERTIES.add("jgroupsChannelLocatorClass");
UNSUPPORTED_RA_PROPERTIES.add("jgroupsChannelRefName");
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3ef98044/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/referenceable/DestinationObjectFactoryTest.java
----------------------------------------------------------------------
diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/referenceable/DestinationObjectFactoryTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/referenceable/DestinationObjectFactoryTest.java
new file mode 100644
index 0000000..fedcfd9
--- /dev/null
+++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/referenceable/DestinationObjectFactoryTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.tests.unit.ra.referenceable;
+
+import javax.naming.Reference;
+import javax.naming.spi.ObjectFactory;
+
+import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
+import org.apache.activemq.artemis.jms.client.ActiveMQDestination;
+import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
+import org.apache.activemq.artemis.utils.RandomUtil;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DestinationObjectFactoryTest extends ActiveMQTestBase {
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ @Test
+ public void testReference() throws Exception {
+ ActiveMQDestination queue = (ActiveMQDestination) ActiveMQJMSClient.createQueue(RandomUtil.randomString());
+ Reference reference = queue.getReference();
+ String factoryName = reference.getFactoryClassName();
+ Class<?> factoryClass = Class.forName(factoryName);
+ ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
+ Object object = factory.getObjectInstance(reference, null, null, null);
+ Assert.assertNotNull(object);
+ Assert.assertTrue(object instanceof ActiveMQDestination);
+ Assert.assertEquals(queue, object);
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}