Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 17FEC1859E for ; Tue, 9 Jun 2015 16:36:38 +0000 (UTC) Received: (qmail 25639 invoked by uid 500); 9 Jun 2015 16:36:32 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 25526 invoked by uid 500); 9 Jun 2015 16:36:32 -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 25289 invoked by uid 99); 9 Jun 2015 16:36:32 -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, 09 Jun 2015 16:36:32 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 83F92DFC3D; Tue, 9 Jun 2015 16:36:32 +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, 09 Jun 2015 16:36:35 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [04/52] [abbrv] [partial] activemq-artemis git commit: ARTEMIS-127 Adding activemq unit test module to Artemis http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jmx/JmxCreateNCTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jmx/JmxCreateNCTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jmx/JmxCreateNCTest.java new file mode 100644 index 0000000..e96c596 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jmx/JmxCreateNCTest.java @@ -0,0 +1,67 @@ +/** + * 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.jmx; + +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.jmx.BrokerViewMBean; +import org.apache.activemq.broker.jmx.NetworkConnectorViewMBean; +import org.junit.Test; + +import javax.management.ObjectName; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + * This test shows that when we create a network connector via JMX, + * the NC/bridge shows up in the MBean Server + * + * @author Christian Posta + */ +public class JmxCreateNCTest { + + private static final String BROKER_NAME = "jmx-broker"; + + @Test + public void testBridgeRegistration() throws Exception { + BrokerService broker = new BrokerService(); + broker.setBrokerName(BROKER_NAME); + broker.setUseJmx(true); // explicitly set this so no funny issues + broker.start(); + broker.waitUntilStarted(); + + // now create network connector over JMX + ObjectName brokerObjectName = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + BROKER_NAME); + BrokerViewMBean proxy = (BrokerViewMBean) broker.getManagementContext().newProxyInstance(brokerObjectName, + BrokerViewMBean.class, true); + + assertNotNull("We could not retrieve the broker from JMX", proxy); + + // let's add the NC + String connectoName = proxy.addNetworkConnector("static:(tcp://localhost:61617)"); + assertEquals("NC", connectoName); + + // Make sure we can retrieve the NC through JMX + ObjectName networkConnectorObjectName = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + BROKER_NAME + + ",connector=networkConnectors,networkConnectorName=" + connectoName); + NetworkConnectorViewMBean nc = (NetworkConnectorViewMBean) broker.getManagementContext().newProxyInstance(networkConnectorObjectName, + NetworkConnectorViewMBean.class, true); + + assertNotNull(nc); + assertEquals("NC", nc.getName()); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jmx/OpenTypeSupportTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jmx/OpenTypeSupportTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jmx/OpenTypeSupportTest.java new file mode 100644 index 0000000..7306dfd --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jmx/OpenTypeSupportTest.java @@ -0,0 +1,115 @@ +/** + * 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.jmx; + +import javax.jms.BytesMessage; +import javax.jms.Connection; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.management.openmbean.CompositeData; +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.jmx.CompositeDataConstants; +import org.apache.activemq.broker.jmx.OpenTypeSupport; +import org.apache.activemq.broker.jmx.QueueViewMBean; +import org.apache.activemq.command.ActiveMQBytesMessage; +import org.apache.activemq.command.ActiveMQQueue; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import static org.junit.Assert.assertEquals; + +public class OpenTypeSupportTest { + private static final Logger LOG = LoggerFactory.getLogger(OpenTypeSupportTest.class); + + private static BrokerService brokerService; + private static String TESTQUEUE = "testQueue"; + private static ActiveMQConnectionFactory connectionFactory; + private static String BYTESMESSAGE_TEXT = "This is a short text"; + private static String BROKER_ADDRESS = "tcp://localhost:0"; + private static ActiveMQQueue queue = new ActiveMQQueue(TESTQUEUE); + + private String connectionUri; + + @Before + public void setUp() throws Exception { + brokerService = new BrokerService(); + brokerService.setPersistent(false); + brokerService.setUseJmx(true); + connectionUri = brokerService.addConnector(BROKER_ADDRESS).getPublishableConnectString(); + brokerService.start(); + connectionFactory = new ActiveMQConnectionFactory(connectionUri); + sendMessage(); + } + + @After + public void tearDown() throws Exception { + brokerService.stop(); + brokerService.waitUntilStopped(); + } + + private static void sendMessage() throws JMSException { + Connection conn = connectionFactory.createConnection(); + try { + conn.start(); + Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); + Destination queue = session.createQueue(TESTQUEUE); + BytesMessage toSend = session.createBytesMessage(); + toSend.writeBytes(BYTESMESSAGE_TEXT.getBytes()); + MessageProducer producer = session.createProducer(queue); + producer.send(queue, toSend); + } finally { + conn.close(); + } + } + + @Test + public void bytesMessagePreview() throws Exception { + QueueViewMBean queue = getProxyToQueueViewMBean(); + assertEquals(extractText(queue.browse()[0]), extractText(queue.browse()[0])); + } + + @Test + public void testBrowseByteMessageFails() throws Exception { + ActiveMQBytesMessage bm = new ActiveMQBytesMessage(); + bm.writeBytes("123456".getBytes()); + Object result = OpenTypeSupport.convert(bm); + LOG.info("result : " + result); + } + + private String extractText(CompositeData message) { + Byte content[] = (Byte[]) message.get(CompositeDataConstants.BODY_PREVIEW); + byte out[] = new byte[content.length]; + for (int i = 0; i < content.length; i++) { + out[i] = content[i]; + } + return new String(out); + } + + private QueueViewMBean getProxyToQueueViewMBean() throws MalformedObjectNameException, JMSException { + final ObjectName queueViewMBeanName = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=" + queue.getQueueName()); + QueueViewMBean proxy = (QueueViewMBean) + brokerService.getManagementContext().newProxyInstance(queueViewMBeanName, QueueViewMBean.class, true); + return proxy; + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/ActiveMQInitialContextFactoryTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/ActiveMQInitialContextFactoryTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/ActiveMQInitialContextFactoryTest.java new file mode 100644 index 0000000..86e5a43 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/ActiveMQInitialContextFactoryTest.java @@ -0,0 +1,75 @@ +/** + * 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.jndi; + +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import org.apache.activemq.command.ActiveMQQueue; +import org.apache.activemq.command.ActiveMQTopic; + +/** + * + */ +public class ActiveMQInitialContextFactoryTest extends JNDITestSupport { + + public void testConnectionFactoriesArePresent() throws NamingException { + String lookupName = getConnectionFactoryLookupName(); + assertConnectionFactoryPresent(lookupName); + } + + public void testDestinationsArePresent() throws NamingException { + + // Retrieving destinations context is not yet implemented on the broker. + // For this test, a jndi file properties will be used. + + InitialContext context = new InitialContext(); + + // make sure context is not null + assertTrue("Created context", context != null); + + Object topicDestination = context.lookup("MyTopic"); + + // check if MyTopic is an ActiveMQTopic + assertTrue("Should have found a topic but found: " + topicDestination, topicDestination instanceof ActiveMQTopic); + + Object queueDestination = context.lookup("MyQueue"); + + // check if MyQueue is an ActiveMQueue + assertTrue("Should have found a queue but found: " + queueDestination, queueDestination instanceof ActiveMQQueue); + + } + + public void testDynamicallyGrowing() throws Exception { + Object answer = context.lookup("dynamicQueues/FOO.BAR"); + assertTrue("Should have found a queue but found: " + answer, answer instanceof ActiveMQQueue); + + ActiveMQQueue queue = (ActiveMQQueue)answer; + assertEquals("queue name", "FOO.BAR", queue.getPhysicalName()); + + answer = context.lookup("dynamicTopics/A.B.C"); + assertTrue("Should have found a topic but found: " + answer, answer instanceof ActiveMQTopic); + + ActiveMQTopic topic = (ActiveMQTopic)answer; + assertEquals("topic name", "A.B.C", topic.getPhysicalName()); + + } + + protected String getConnectionFactoryLookupName() { + return "ConnectionFactory"; + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/ActiveMQWASInitialContextFactoryTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/ActiveMQWASInitialContextFactoryTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/ActiveMQWASInitialContextFactoryTest.java new file mode 100644 index 0000000..f9ce5b1 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/ActiveMQWASInitialContextFactoryTest.java @@ -0,0 +1,43 @@ +/** + * 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.jndi; + +import java.util.Hashtable; + +import javax.naming.Context; + +public class ActiveMQWASInitialContextFactoryTest extends JNDITestSupport { + + @SuppressWarnings("unchecked") + public void testTransformEnvironment() { + Hashtable originalEnvironment = new Hashtable(); + originalEnvironment.put("java.naming.connectionFactoryNames", "ConnectionFactory"); + originalEnvironment.put("java.naming.topic.jms.systemMessageTopic", "jms/systemMessageTopic"); + originalEnvironment.put(Context.PROVIDER_URL, "tcp://localhost:61616;tcp://localhost:61617"); + originalEnvironment.put("non-string", Integer.valueOf(43)); + originalEnvironment.put("java.naming.queue", "jms/systemMessageQueue"); + + Hashtable transformedEnvironment = new ActiveMQWASInitialContextFactory().transformEnvironment(originalEnvironment); + assertEquals("ConnectionFactory", "ConnectionFactory", transformedEnvironment.get("connectionFactoryNames")); + assertEquals("topic.jm", "jms/systemMessageTopic", transformedEnvironment.get("topic.jms/systemMessageTopic")); + assertEquals("java.naming.provider.url", "tcp://localhost:61616,tcp://localhost:61617", transformedEnvironment.get("java.naming.provider.url")); + assertNull("non-string", transformedEnvironment.get("non-string")); + + assertEquals("queue", "jms/systemMessageQueue", transformedEnvironment.get("java.naming.queue")); + } + +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/CustomConnectionFactoryNameTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/CustomConnectionFactoryNameTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/CustomConnectionFactoryNameTest.java new file mode 100644 index 0000000..517735b --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/CustomConnectionFactoryNameTest.java @@ -0,0 +1,56 @@ +/** + * 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.jndi; + +import javax.naming.NamingException; + +import org.apache.activemq.ActiveMQConnectionFactory; + +/** + * Test case for AMQ-141 + * + * + */ +public class CustomConnectionFactoryNameTest extends ActiveMQInitialContextFactoryTest { + + @Override + public void testConnectionFactoriesArePresent() throws NamingException { + super.testConnectionFactoriesArePresent(); + assertConnectionFactoryPresent("jms/Connection"); + assertConnectionFactoryPresent("jms/DURABLE_SUB_CONNECTION_FACTORY"); + } + + public void testConnectionFactoriesAreConfigured() throws NamingException { + super.testConnectionFactoriesArePresent(); + ActiveMQConnectionFactory factory1 = (ActiveMQConnectionFactory) context.lookup("jms/Connection"); + assertNull(factory1.getClientID()); + ActiveMQConnectionFactory factory2 = (ActiveMQConnectionFactory) context.lookup("jms/DURABLE_SUB_CONNECTION_FACTORY"); + assertEquals("testclient", factory2.getClientID()); + } + + @Override + protected String getConnectionFactoryLookupName() { + return "myConnectionFactory"; + } + + @Override + protected void configureEnvironment() { + super.configureEnvironment(); + environment.put("connectionFactoryNames", " myConnectionFactory, jms/Connection, jms/DURABLE_SUB_CONNECTION_FACTORY"); + environment.put("connection.jms/DURABLE_SUB_CONNECTION_FACTORY.clientID", "testclient"); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/DestinationNameWithSlashTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/DestinationNameWithSlashTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/DestinationNameWithSlashTest.java new file mode 100644 index 0000000..6e3e9da --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/DestinationNameWithSlashTest.java @@ -0,0 +1,36 @@ +/** + * 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.jndi; + + +/** + * Test case for AMQ-140 + * + * + */ +public class DestinationNameWithSlashTest extends JNDITestSupport { + public void testNameWithSlash() throws Exception { + assertDestinationExists("jms/Queue"); + + } + + @Override + protected void configureEnvironment() { + super.configureEnvironment(); + environment.put("queue.jms/Queue", "example.myqueue"); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/InitialContextTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/InitialContextTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/InitialContextTest.java new file mode 100644 index 0000000..2c983a5 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/InitialContextTest.java @@ -0,0 +1,97 @@ +/** + * 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.jndi; + +import java.util.Properties; + +import javax.naming.Context; +import javax.naming.InitialContext; + +import junit.framework.TestCase; +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.ActiveMQXAConnectionFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + */ +public class InitialContextTest extends TestCase { + + private static final Logger LOG = LoggerFactory.getLogger(InitialContextTest.class); + + public void testInitialContext() throws Exception { + InitialContext context = new InitialContext(); + assertTrue("Created context", context != null); + + ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory)context.lookup("ConnectionFactory"); + + assertTrue("Should have created a ConnectionFactory", connectionFactory != null); + + LOG.info("Created with brokerURL: " + connectionFactory.getBrokerURL()); + + } + + public void testInitialContextHasXA() throws Exception { + InitialContext context = new InitialContext(); + assertTrue("Created context", context != null); + + ActiveMQXAConnectionFactory connectionFactory = (ActiveMQXAConnectionFactory)context.lookup("XAConnectionFactory"); + + assertTrue("Should have created an XAConnectionFactory", connectionFactory != null); + + LOG.info("Created with brokerURL: " + connectionFactory.getBrokerURL()); + + } + + public void testUsingStandardJNDIKeys() throws Exception { + Properties properties = new Properties(); + properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); + String expected = "tcp://localhost:65432"; + properties.put(Context.PROVIDER_URL, expected); + + InitialContext context = new InitialContext(properties); + assertTrue("Created context", context != null); + + ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory)context.lookup("ConnectionFactory"); + + assertTrue("Should have created a ConnectionFactory", connectionFactory != null); + + assertEquals("the brokerURL should match", expected, connectionFactory.getBrokerURL()); + } + + public void testConnectionFactoryPolicyConfig() throws Exception { + + Properties properties = new Properties(); + properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); + properties.put(Context.PROVIDER_URL, "tcp://localhost:65432"); + properties.put("prefetchPolicy.queuePrefetch", "777"); + properties.put("redeliveryPolicy.maximumRedeliveries", "15"); + properties.put("redeliveryPolicy.backOffMultiplier", "32"); + + InitialContext context = new InitialContext(properties); + assertTrue("Created context", context != null); + + ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory)context.lookup("ConnectionFactory"); + + assertTrue("Should have created a ConnectionFactory", connectionFactory != null); + + assertEquals(777, connectionFactory.getPrefetchPolicy().getQueuePrefetch()); + assertEquals(15, connectionFactory.getRedeliveryPolicy().getMaximumRedeliveries()); + assertEquals(32d, connectionFactory.getRedeliveryPolicy().getBackOffMultiplier()); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/JNDITestSupport.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/JNDITestSupport.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/JNDITestSupport.java new file mode 100644 index 0000000..13adbc4 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/JNDITestSupport.java @@ -0,0 +1,103 @@ +/** + * 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.jndi; + +import java.util.Hashtable; + +import javax.jms.ConnectionFactory; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.naming.Binding; +import javax.naming.Context; +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.spi.InitialContextFactory; + +import junit.framework.TestCase; + +import org.apache.activemq.ActiveMQConnectionFactory; + +/** + * + */ +public abstract class JNDITestSupport extends TestCase { + + private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory + .getLog(JNDITestSupport.class); + + protected Hashtable environment = new Hashtable(); + protected Context context; + + protected void assertConnectionFactoryPresent(String lookupName) throws NamingException { + Object connectionFactory = context.lookup(lookupName); + + assertTrue("Should have created a ConnectionFactory for key: " + lookupName + + " but got: " + connectionFactory, connectionFactory instanceof ConnectionFactory); + } + + protected void assertBinding(Binding binding) throws NamingException { + Object object = binding.getObject(); + assertTrue("Should have got a child context but got: " + object, object instanceof Context); + + Context childContext = (Context) object; + NamingEnumeration iter = childContext.listBindings(""); + while (iter.hasMore()) { + Binding destinationBinding = iter.next(); + LOG.info("Found destination: " + destinationBinding.getName()); + Object destination = destinationBinding.getObject(); + assertTrue("Should have a Destination but got: " + destination, destination instanceof Destination); + } + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + configureEnvironment(); + + InitialContextFactory factory = new ActiveMQInitialContextFactory(); + context = factory.getInitialContext(environment); + assertTrue("No context created", context != null); + } + + /** + * Stops all existing ActiveMQConnectionFactory in Context. + * + * @throws javax.naming.NamingException + */ + @Override + protected void tearDown() throws NamingException, JMSException { + NamingEnumeration iter = context.listBindings(""); + while (iter.hasMore()) { + Binding binding = iter.next(); + Object connFactory = binding.getObject(); + if (connFactory instanceof ActiveMQConnectionFactory) { + // ((ActiveMQConnectionFactory) connFactory).stop(); + } + } + } + + protected void configureEnvironment() { + environment.put("brokerURL", "vm://localhost"); + } + + protected void assertDestinationExists(String name) throws NamingException { + Object object = context.lookup(name); + assertTrue("Should have received a Destination for name: " + name + " but instead found: " + object, + object instanceof Destination); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/ObjectFactoryTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/ObjectFactoryTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/ObjectFactoryTest.java new file mode 100644 index 0000000..c389144 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/ObjectFactoryTest.java @@ -0,0 +1,89 @@ +/** + * 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.jndi; + +import javax.naming.Reference; + +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.CombinationTestSupport; +import org.apache.activemq.command.ActiveMQDestination; +import org.apache.activemq.command.ActiveMQQueue; + +public class ObjectFactoryTest extends CombinationTestSupport { + public void testConnectionFactory() throws Exception { + // Create sample connection factory + ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(); + factory.setDispatchAsync(true); + factory.setBrokerURL("vm://test"); + factory.setClientID("test"); + factory.setCopyMessageOnSend(false); + factory.setDisableTimeStampsByDefault(true); + factory.setObjectMessageSerializationDefered(true); + factory.setOptimizedMessageDispatch(false); + factory.setPassword("pass"); + factory.setUseAsyncSend(true); + factory.setUseCompression(true); + factory.setUseRetroactiveConsumer(true); + factory.setUserName("user"); + factory.getPrefetchPolicy().setQueuePrefetch(777); + factory.getRedeliveryPolicy().setMaximumRedeliveries(15); + factory.getRedeliveryPolicy().setBackOffMultiplier((short) 32); + + + // 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 + assertEquals(factory.isDispatchAsync(), temp.isDispatchAsync()); + assertEquals(factory.getBrokerURL(), temp.getBrokerURL()); + assertEquals(factory.getClientID(), temp.getClientID()); + assertEquals(factory.isCopyMessageOnSend(), temp.isCopyMessageOnSend()); + assertEquals(factory.isDisableTimeStampsByDefault(), temp.isDisableTimeStampsByDefault()); + assertEquals(factory.isObjectMessageSerializationDefered(), temp.isObjectMessageSerializationDefered()); + assertEquals(factory.isOptimizedMessageDispatch(), temp.isOptimizedMessageDispatch()); + assertEquals(factory.getPassword(), temp.getPassword()); + assertEquals(factory.isUseAsyncSend(), temp.isUseAsyncSend()); + assertEquals(factory.isUseCompression(), temp.isUseCompression()); + assertEquals(factory.isUseRetroactiveConsumer(), temp.isUseRetroactiveConsumer()); + assertEquals(factory.getUserName(), temp.getUserName()); + assertEquals(factory.getPrefetchPolicy().getQueuePrefetch(), temp.getPrefetchPolicy().getQueuePrefetch()); + assertEquals(factory.getRedeliveryPolicy().getMaximumRedeliveries(), temp.getRedeliveryPolicy().getMaximumRedeliveries()); + assertEquals(factory.getRedeliveryPolicy().getBackOffMultiplier(), temp.getRedeliveryPolicy().getBackOffMultiplier()); + } + + public void testDestination() throws Exception { + // Create sample destination + ActiveMQDestination dest = new ActiveMQQueue(); + dest.setPhysicalName("TEST.FOO"); + + // 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.getPhysicalName(), temp.getPhysicalName()); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/XAConnectionFactoryTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/XAConnectionFactoryTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/XAConnectionFactoryTest.java new file mode 100644 index 0000000..cf7cca1 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/jndi/XAConnectionFactoryTest.java @@ -0,0 +1,32 @@ +/** + * 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.jndi; + +import javax.jms.XAConnectionFactory; +import javax.naming.NamingException; + +public class XAConnectionFactoryTest extends ActiveMQInitialContextFactoryTest { + + public void testConnectionFactoriesIsXA() throws NamingException { + assertTrue("connection factory implements XA", context.lookup(getConnectionFactoryLookupName()) instanceof XAConnectionFactory); + } + + protected void configureEnvironment() { + environment.put("xa", "true"); + super.configureEnvironment(); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/joramtests/ActiveMQAdmin.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/joramtests/ActiveMQAdmin.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/joramtests/ActiveMQAdmin.java new file mode 100644 index 0000000..b20b9ad --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/joramtests/ActiveMQAdmin.java @@ -0,0 +1,150 @@ +/** + * 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.joramtests; + +import java.io.File; +import java.net.URI; +import java.util.Hashtable; + +import javax.jms.ConnectionFactory; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.broker.BrokerFactory; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.command.ActiveMQQueue; +import org.apache.activemq.command.ActiveMQTopic; +import org.objectweb.jtests.jms.admin.Admin; + +/** + * + * @author Hiram Chirino + */ +public class ActiveMQAdmin implements Admin { + + Context context; + { + try { + // Use the jetty JNDI context since it's mutable. + final Hashtable env = new Hashtable(); + env.put("java.naming.factory.initial", "org.eclipse.jetty.jndi.InitialContextFactory"); + env.put("java.naming.factory.url.pkgs", "org.eclipse.jetty.jndi");; + context = new InitialContext(env); + } catch (NamingException e) { + throw new RuntimeException(e); + } + } + + protected BrokerService createBroker() throws Exception { + return BrokerFactory.createBroker(new URI("broker://()/localhost?persistent=false")); + } + + public String getName() { + return getClass().getName(); + } + + BrokerService broker; + public void startServer() throws Exception { + if (System.getProperty("basedir") == null) { + File file = new File("."); + System.setProperty("basedir", file.getAbsolutePath()); + } + broker = createBroker(); + broker.start(); + } + + public void stopServer() throws Exception { + broker.stop(); + } + + public void start() throws Exception { + } + + public void stop() throws Exception { + } + + public Context createContext() throws NamingException { + return context; + } + + public void createQueue(String name) { + try { + context.bind(name, new ActiveMQQueue(name)); + } catch (NamingException e) { + throw new RuntimeException(e); + } + } + + public void createTopic(String name) { + try { + context.bind(name, new ActiveMQTopic(name)); + } catch (NamingException e) { + throw new RuntimeException(e); + } + } + + public void deleteQueue(String name) { + // BrokerTestSupport.delete_queue((Broker)base.broker, name); + try { + context.unbind(name); + } catch (NamingException e) { + throw new RuntimeException(e); + } + } + + public void deleteTopic(String name) { + try { + context.unbind(name); + } catch (NamingException e) { + throw new RuntimeException(e); + } + } + + public void createConnectionFactory(String name) { + try { + final ConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost"); + ((ActiveMQConnectionFactory) factory).setNestedMapAndListEnabled(false); + context.bind(name, factory); + } catch (NamingException e) { + throw new RuntimeException(e); + } + } + + public void deleteConnectionFactory(String name) { + try { + context.unbind(name); + } catch (NamingException e) { + throw new RuntimeException(e); + } + } + + public void createQueueConnectionFactory(String name) { + createConnectionFactory(name); + } + public void createTopicConnectionFactory(String name) { + createConnectionFactory(name); + } + public void deleteQueueConnectionFactory(String name) { + deleteConnectionFactory(name); + } + public void deleteTopicConnectionFactory(String name) { + deleteConnectionFactory(name); + } + +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/joramtests/JoramJmsTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/joramtests/JoramJmsTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/joramtests/JoramJmsTest.java new file mode 100644 index 0000000..00c5423 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/joramtests/JoramJmsTest.java @@ -0,0 +1,74 @@ +/** + * 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.joramtests; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.objectweb.jtests.jms.conform.connection.ConnectionTest; +import org.objectweb.jtests.jms.conform.connection.TopicConnectionTest; +import org.objectweb.jtests.jms.conform.message.MessageBodyTest; +import org.objectweb.jtests.jms.conform.message.MessageDefaultTest; +import org.objectweb.jtests.jms.conform.message.MessageTypeTest; +import org.objectweb.jtests.jms.conform.message.headers.MessageHeaderTest; +import org.objectweb.jtests.jms.conform.message.properties.JMSXPropertyTest; +import org.objectweb.jtests.jms.conform.message.properties.MessagePropertyConversionTest; +import org.objectweb.jtests.jms.conform.message.properties.MessagePropertyTest; +import org.objectweb.jtests.jms.conform.queue.QueueBrowserTest; +import org.objectweb.jtests.jms.conform.queue.TemporaryQueueTest; +import org.objectweb.jtests.jms.conform.selector.SelectorSyntaxTest; +import org.objectweb.jtests.jms.conform.selector.SelectorTest; +import org.objectweb.jtests.jms.conform.session.QueueSessionTest; +import org.objectweb.jtests.jms.conform.session.SessionTest; +import org.objectweb.jtests.jms.conform.session.TopicSessionTest; +import org.objectweb.jtests.jms.conform.session.UnifiedSessionTest; +import org.objectweb.jtests.jms.conform.topic.TemporaryTopicTest; + +/** + * @author Hiram Chirino + */ +public class JoramJmsTest extends TestCase { + + public static Test suite() { + TestSuite suite = new TestSuite(); + suite.addTestSuite(SelectorTest.class); + suite.addTestSuite(ConnectionTest.class); + suite.addTestSuite(TopicConnectionTest.class); + suite.addTestSuite(MessageHeaderTest.class); + suite.addTestSuite(MessageBodyTest.class); + suite.addTestSuite(MessageDefaultTest.class); + suite.addTestSuite(MessageTypeTest.class); + suite.addTestSuite(JMSXPropertyTest.class); + suite.addTestSuite(MessagePropertyConversionTest.class); + suite.addTestSuite(TemporaryQueueTest.class); + suite.addTestSuite(SelectorSyntaxTest.class); + suite.addTestSuite(QueueSessionTest.class); + suite.addTestSuite(SessionTest.class); + suite.addTestSuite(TopicSessionTest.class); + suite.addTestSuite(TemporaryTopicTest.class); + suite.addTestSuite(UnifiedSessionTest.class); + suite.addTestSuite(QueueBrowserTest.class); + suite.addTestSuite(MessagePropertyTest.class); + return suite; + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/leveldb/LevelDBStoreBrokerTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/leveldb/LevelDBStoreBrokerTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/leveldb/LevelDBStoreBrokerTest.java new file mode 100644 index 0000000..6f58586 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/leveldb/LevelDBStoreBrokerTest.java @@ -0,0 +1,62 @@ +/** + * 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.leveldb; + +import junit.framework.Test; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.BrokerTest; +import org.apache.activemq.store.PersistenceAdapter; + +import java.io.File; +import java.io.IOException; + +/** + * @author Hiram Chirino + */ +public class LevelDBStoreBrokerTest extends BrokerTest { + + public static Test suite() { + return suite(LevelDBStoreBrokerTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + + @Override + protected BrokerService createBroker() throws Exception { + BrokerService broker = new BrokerService(); + broker.setPersistenceAdapter(createPersistenceAdapter(true)); + return broker; + } + + protected PersistenceAdapter createPersistenceAdapter(boolean delete) { + LevelDBStore store = new LevelDBStore(); + store.setDirectory(new File("target/activemq-data/leveldb")); + if (delete) { + store.deleteAllMessages(); + } + return store; + } + + protected BrokerService createRestartedBroker() throws IOException { + BrokerService broker = new BrokerService(); + broker.setPersistenceAdapter(createPersistenceAdapter(false)); + return broker; + } + +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/leveldb/LevelDBXARecoveryBrokerTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/leveldb/LevelDBXARecoveryBrokerTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/leveldb/LevelDBXARecoveryBrokerTest.java new file mode 100644 index 0000000..82cd7e4 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/leveldb/LevelDBXARecoveryBrokerTest.java @@ -0,0 +1,68 @@ +/** + * 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.leveldb; + +import java.io.File; +import java.io.IOException; + +import junit.framework.Test; + +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.XARecoveryBrokerTest; +import org.apache.commons.io.FileUtils; + +/** + * @author Hiram Chirino + */ +public class LevelDBXARecoveryBrokerTest extends XARecoveryBrokerTest { + public static final String LEVELDB_DIR_BASE = "target/activemq-data/xahaleveldb"; + public static String levelDbDirectoryName; + + @Override + protected void setUp() throws Exception { + levelDbDirectoryName = LEVELDB_DIR_BASE + "/" + System.currentTimeMillis(); + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + try { + File levelDbDir = new File(levelDbDirectoryName); + FileUtils.deleteDirectory(levelDbDir); + } catch (IOException e) { + } + } + + + public static Test suite() { + return suite(LevelDBXARecoveryBrokerTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + + @Override + protected void configureBroker(BrokerService broker) throws Exception { + super.configureBroker(broker); + LevelDBStore store = new LevelDBStore(); + store.setDirectory(new File(levelDbDirectoryName)); + broker.setPersistenceAdapter(store); + } + +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/load/LoadClient.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/load/LoadClient.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/load/LoadClient.java new file mode 100644 index 0000000..0f69567 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/load/LoadClient.java @@ -0,0 +1,233 @@ +/** + * 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.load; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.DeliveryMode; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.jms.TextMessage; + +import org.apache.activemq.ActiveMQMessageAudit; +import org.apache.activemq.perf.PerfRate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + */ +public class LoadClient implements Runnable{ + private static final Logger LOG = LoggerFactory.getLogger(LoadClient.class); + protected static int SLEEP_TIME = 2; + protected String name; + protected ConnectionFactory factory; + protected Connection connection; + protected Destination startDestination; + protected Destination nextDestination; + protected Session session; + protected MessageConsumer consumer; + protected MessageProducer producer; + protected PerfRate rate = new PerfRate(); + protected int deliveryMode = DeliveryMode.PERSISTENT; + protected ActiveMQMessageAudit audit = new ActiveMQMessageAudit(); + protected boolean connectionPerMessage = false; + protected boolean running; + protected int timeout = 10000; + + + public LoadClient(String name,ConnectionFactory factory) { + this.name=name; + this.factory = factory; + } + + + + public synchronized void start() throws JMSException { + if (!running) { + rate.reset(); + running = true; + if (!connectionPerMessage) { + connection = factory.createConnection(); + connection.start(); + session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + consumer = session.createConsumer(getConsumeDestination()); + producer = session.createProducer(getSendDestination()); + producer.setDeliveryMode(this.deliveryMode); + + } + + Thread t = new Thread(this); + t.setName(name); + t.start(); + } + } + + public void stop() throws JMSException, InterruptedException { + running = false; + if(connection != null) { + connection.stop(); + } + } + + + public void run() { + try { + while (running) { + String result = consume(); + if(result != null) { + send(result); + rate.increment(); + } + else if (running) { + LOG.error(name + " Failed to consume!"); + } + } + } catch (Throwable e) { + e.printStackTrace(); + } + } + + protected String consume() throws Exception { + Connection con = null; + MessageConsumer c = consumer; + if (connectionPerMessage){ + con = factory.createConnection(); + con.start(); + Session s = con.createSession(false, Session.AUTO_ACKNOWLEDGE); + c = s.createConsumer(getConsumeDestination()); + } + TextMessage result = (TextMessage) c.receive(timeout); + if (result != null) { + if (audit.isDuplicate(result.getJMSMessageID())) { + throw new JMSException("Received duplicate " + result.getText()); + } + if (!audit.isInOrder(result.getJMSMessageID())) { + throw new JMSException("Out of order " + result.getText()); + } + + if (connectionPerMessage) { + Thread.sleep(SLEEP_TIME);//give the broker a chance + con.close(); + } + } + return result != null ? result.getText() : null; + } + + protected void send(String text) throws Exception { + Connection con = connection; + MessageProducer p = producer; + Session s = session; + if (connectionPerMessage){ + con = factory.createConnection(); + con.start(); + s = con.createSession(false, Session.AUTO_ACKNOWLEDGE); + p = s.createProducer(getSendDestination()); + p.setDeliveryMode(deliveryMode); + } + TextMessage message = s.createTextMessage(text); + p.send(message); + if (connectionPerMessage) { + Thread.sleep(SLEEP_TIME);//give the broker a chance + con.close(); + } + } + + + + public String getName() { + return name; + } + + + + public void setName(String name) { + this.name = name; + } + + + + public Destination getStartDestination() { + return startDestination; + } + + + + public void setStartDestination(Destination startDestination) { + this.startDestination = startDestination; + } + + + + public Destination getNextDestination() { + return nextDestination; + } + + + + public void setNextDestination(Destination nextDestination) { + this.nextDestination = nextDestination; + } + + + + public int getDeliveryMode() { + return deliveryMode; + } + + + + public void setDeliveryMode(int deliveryMode) { + this.deliveryMode = deliveryMode; + } + + + + public boolean isConnectionPerMessage() { + return connectionPerMessage; + } + + + + public void setConnectionPerMessage(boolean connectionPerMessage) { + this.connectionPerMessage = connectionPerMessage; + } + + + + public int getTimeout() { + return timeout; + } + + + + public void setTimeout(int timeout) { + this.timeout = timeout; + } + + protected Destination getSendDestination() { + return nextDestination; + } + + protected Destination getConsumeDestination() { + return startDestination; + } + +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/load/LoadController.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/load/LoadController.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/load/LoadController.java new file mode 100644 index 0000000..22b9064 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/load/LoadController.java @@ -0,0 +1,103 @@ +/** + * 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.load; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import javax.jms.ConnectionFactory; +import javax.jms.Destination; +import javax.jms.JMSException; + +/** + * + */ +public class LoadController extends LoadClient{ + + private int numberOfBatches=1; + private int batchSize =1000; + private int count; + private final CountDownLatch stopped = new CountDownLatch(1); + + public LoadController(String name,ConnectionFactory factory) { + super(name,factory); + } + + + public int awaitTestComplete() throws InterruptedException { + stopped.await(60*5,TimeUnit.SECONDS); + return count; + } + + @Override + public void stop() throws JMSException, InterruptedException { + running = false; + stopped.countDown(); + if (connection != null) { + this.connection.stop(); + } + } + + @Override + public void run() { + try { + for (int i = 0; i < numberOfBatches; i++) { + for (int j = 0; j < batchSize; j++) { + String payLoad = "batch[" + i + "]no:" + j; + send(payLoad); + } + for (int j = 0; j < batchSize; j++) { + String result = consume(); + if (result != null) { + count++; + rate.increment(); + } + } + } + } catch (Throwable e) { + e.printStackTrace(); + } finally { + stopped.countDown(); + } + } + + public int getNumberOfBatches() { + return numberOfBatches; + } + + public void setNumberOfBatches(int numberOfBatches) { + this.numberOfBatches = numberOfBatches; + } + + public int getBatchSize() { + return batchSize; + } + + public void setBatchSize(int batchSize) { + this.batchSize = batchSize; + } + + @Override + protected Destination getSendDestination() { + return startDestination; + } + + @Override + protected Destination getConsumeDestination() { + return nextDestination; + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/load/LoadTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/load/LoadTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/load/LoadTest.java new file mode 100644 index 0000000..ee1037b --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/load/LoadTest.java @@ -0,0 +1,155 @@ +/** + * 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.load; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.DeliveryMode; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Session; +import junit.framework.TestCase; +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.broker.BrokerService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + */ +public class LoadTest extends TestCase { + + private static final Logger LOG = LoggerFactory.getLogger(LoadTest.class); + + protected BrokerService broker; + protected String bindAddress="tcp://localhost:61616"; + + protected LoadController controller; + protected LoadClient[] clients; + protected ConnectionFactory factory; + protected Destination destination; + protected int numberOfClients = 50; + protected int deliveryMode = DeliveryMode.PERSISTENT; + protected int batchSize = 1000; + protected int numberOfBatches = 10; + protected int timeout = Integer.MAX_VALUE; + protected boolean connectionPerMessage = false; + protected Connection managementConnection; + protected Session managementSession; + + /** + * Sets up a test where the producer and consumer have their own connection. + * + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + if (broker == null) { + broker = createBroker(bindAddress); + } + factory = createConnectionFactory(bindAddress); + managementConnection = factory.createConnection(); + managementSession = managementConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + Destination startDestination = createDestination(managementSession, getClass()+".start"); + Destination endDestination = createDestination(managementSession, getClass()+".end"); + LOG.info("Running with " + numberOfClients + " clients - sending " + + numberOfBatches + " batches of " + batchSize + " messages"); + controller = new LoadController("Controller",factory); + controller.setBatchSize(batchSize); + controller.setNumberOfBatches(numberOfBatches); + controller.setDeliveryMode(deliveryMode); + controller.setConnectionPerMessage(connectionPerMessage); + controller.setStartDestination(startDestination); + controller.setNextDestination(endDestination); + controller.setTimeout(timeout); + clients = new LoadClient[numberOfClients]; + for (int i = 0; i < numberOfClients; i++) { + Destination inDestination = null; + if (i==0) { + inDestination = startDestination; + }else { + inDestination = createDestination(managementSession, getClass() + ".client."+(i)); + } + Destination outDestination = null; + if (i==(numberOfClients-1)) { + outDestination = endDestination; + }else { + outDestination = createDestination(managementSession, getClass() + ".client."+(i+1)); + } + LoadClient client = new LoadClient("client("+i+")",factory); + client.setTimeout(timeout); + client.setDeliveryMode(deliveryMode); + client.setConnectionPerMessage(connectionPerMessage); + client.setStartDestination(inDestination); + client.setNextDestination(outDestination); + clients[i] = client; + } + + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + managementConnection.close(); + for (int i = 0; i < numberOfClients; i++) { + clients[i].stop(); + } + controller.stop(); + if (broker != null) { + broker.stop(); + broker = null; + } + } + + protected Destination createDestination(Session s, String destinationName) throws JMSException { + return s.createQueue(destinationName); + } + + /** + * Factory method to create a new broker + * + * @throws Exception + */ + protected BrokerService createBroker(String uri) throws Exception { + BrokerService answer = new BrokerService(); + configureBroker(answer,uri); + answer.start(); + return answer; + } + + + + protected void configureBroker(BrokerService answer,String uri) throws Exception { + answer.setDeleteAllMessagesOnStartup(true); + answer.addConnector(uri); + answer.setUseShutdownHook(false); + } + + protected ActiveMQConnectionFactory createConnectionFactory(String uri) throws Exception { + return new ActiveMQConnectionFactory(uri); + } + + public void testLoad() throws JMSException, InterruptedException { + for (int i = 0; i < numberOfClients; i++) { + clients[i].start(); + } + controller.start(); + assertEquals((batchSize* numberOfBatches),controller.awaitTestComplete()); + + } + +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/BoundaryStatisticTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/BoundaryStatisticTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/BoundaryStatisticTest.java new file mode 100644 index 0000000..194cbbc --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/BoundaryStatisticTest.java @@ -0,0 +1,38 @@ +/** + * 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.management; + + +public class BoundaryStatisticTest extends StatisticTestSupport { + + private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory + .getLog(BoundaryStatisticTest.class); + + /** + * Use case for BoundaryStatisticImpl class. + * @throws Exception + */ + public void testStatistic() throws Exception { + BoundaryStatisticImpl stat = new BoundaryStatisticImpl("myBoundaryStat", "seconds", "myBoundaryStatDesc", 1000, 2000); + assertStatistic(stat, "myBoundaryStat", "seconds", "myBoundaryStatDesc"); + + assertEquals(1000, stat.getLowerBound()); + assertEquals(2000, stat.getUpperBound()); + + LOG.info("Stat is: " + stat); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/BoundedRangeStatisticTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/BoundedRangeStatisticTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/BoundedRangeStatisticTest.java new file mode 100644 index 0000000..b920718 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/BoundedRangeStatisticTest.java @@ -0,0 +1,38 @@ +/** + * 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.management; + + + +/** + * + */ +public class BoundedRangeStatisticTest extends RangeStatisticTest { + + /** + * Use case for BoundedRangeStatisticImpl class. + * @throws Exception + */ + public void testStatistic() throws Exception { + BoundedRangeStatisticImpl stat = new BoundedRangeStatisticImpl("myRange", "millis", "myDescription", 10, 3000); + assertStatistic(stat, "myRange", "millis", "myDescription"); + assertEquals(10, stat.getLowerBound()); + assertEquals(3000, stat.getUpperBound()); + + assertRangeStatistic(stat); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/CountStatisticTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/CountStatisticTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/CountStatisticTest.java new file mode 100644 index 0000000..85f8be1 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/CountStatisticTest.java @@ -0,0 +1,57 @@ +/** + * 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.management; + + +public class CountStatisticTest extends StatisticTestSupport { + + private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory + .getLog(CountStatisticTest.class); + + /** + * Use case for CountStatisticImple class. + * @throws Exception + */ + public void testStatistic() throws Exception { + CountStatisticImpl stat = new CountStatisticImpl("myCounter", "seconds", "myDescription"); + stat.setEnabled(true); + assertStatistic(stat, "myCounter", "seconds", "myDescription"); + + assertEquals(0, stat.getCount()); + + stat.increment(); + assertEquals(1, stat.getCount()); + + stat.increment(); + assertEquals(2, stat.getCount()); + + stat.decrement(); + assertEquals(1, stat.getCount()); + + Thread.sleep(500); + + stat.increment(); + + assertLastTimeNotStartTime(stat); + + LOG.info("Counter is: " + stat); + + stat.reset(); + + assertEquals(0, stat.getCount()); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/RangeStatisticTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/RangeStatisticTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/RangeStatisticTest.java new file mode 100644 index 0000000..49caa98 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/RangeStatisticTest.java @@ -0,0 +1,78 @@ +/** + * 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.management; + + +public class RangeStatisticTest extends StatisticTestSupport { + + private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory + .getLog(RangeStatisticTest.class); + + /** + * Use case for RangeStatisticImpl class. + * @throws Exception + */ + public void testStatistic() throws Exception { + RangeStatisticImpl stat = new RangeStatisticImpl("myRange", "millis", "myDescription"); + assertStatistic(stat, "myRange", "millis", "myDescription"); + + assertRangeStatistic(stat); + } + + protected void assertRangeStatistic(RangeStatisticImpl stat) throws InterruptedException { + assertEquals(0, stat.getCurrent()); + assertEquals(0, stat.getLowWaterMark()); + assertEquals(0, stat.getHighWaterMark()); + + stat.setCurrent(100); + assertEquals(100, stat.getCurrent()); + assertEquals(100, stat.getLowWaterMark()); + assertEquals(100, stat.getHighWaterMark()); + + stat.setCurrent(50); + assertEquals(50, stat.getCurrent()); + assertEquals(50, stat.getLowWaterMark()); + assertEquals(100, stat.getHighWaterMark()); + + stat.setCurrent(200); + assertEquals(200, stat.getCurrent()); + assertEquals(50, stat.getLowWaterMark()); + assertEquals(200, stat.getHighWaterMark()); + + Thread.sleep(500); + + stat.setCurrent(10); + assertEquals(10, stat.getCurrent()); + assertEquals(10, stat.getLowWaterMark()); + assertEquals(200, stat.getHighWaterMark()); + + assertLastTimeNotStartTime(stat); + + LOG.info("Stat is: " + stat); + + stat.reset(); + + assertEquals(0, stat.getCurrent()); + assertEquals(0, stat.getLowWaterMark()); + assertEquals(0, stat.getHighWaterMark()); + + stat.setCurrent(100); + assertEquals(100, stat.getCurrent()); + assertEquals(100, stat.getLowWaterMark()); + assertEquals(100, stat.getHighWaterMark()); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/StatisticTestSupport.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/StatisticTestSupport.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/StatisticTestSupport.java new file mode 100644 index 0000000..9d68cb2 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/StatisticTestSupport.java @@ -0,0 +1,47 @@ +/** + * 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.management; + +import junit.framework.TestCase; + +public abstract class StatisticTestSupport extends TestCase { + + /** + * assert method used by the management related classes for its usecase. + * + * @param counter + * @param name + * @param unit + * @param description + */ + protected void assertStatistic(StatisticImpl counter, String name, String unit, String description) { + assertEquals(name, counter.getName()); + assertEquals(unit, counter.getUnit()); + assertEquals(description, counter.getDescription()); + } + + /** + * assert method to determine last time vs the start time. + * + * @param counter + */ + protected void assertLastTimeNotStartTime(StatisticImpl counter) { + assertTrue("Should not have start time the same as last sample time. Start time: " + + counter.getStartTime() + " lastTime: " + counter.getLastSampleTime(), counter + .getStartTime() != counter.getLastSampleTime()); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/TimeStatisticTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/TimeStatisticTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/TimeStatisticTest.java new file mode 100644 index 0000000..88ec2ea --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/management/TimeStatisticTest.java @@ -0,0 +1,75 @@ +/** + * 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.management; + + +public class TimeStatisticTest extends StatisticTestSupport { + + private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory + .getLog(TimeStatisticTest.class); + + /** + * Use case for TimeStatisticImpl class. + * @throws Exception + */ + public void testStatistic() throws Exception { + TimeStatisticImpl stat = new TimeStatisticImpl("myTimer", "millis", "myDescription"); + assertStatistic(stat, "myTimer", "millis", "myDescription"); + + assertEquals(0, stat.getCount()); + + stat.addTime(100); + assertEquals(1, stat.getCount()); + assertEquals(100, stat.getMinTime()); + assertEquals(100, stat.getMaxTime()); + + stat.addTime(403); + assertEquals(2, stat.getCount()); + assertEquals(100, stat.getMinTime()); + assertEquals(403, stat.getMaxTime()); + + stat.addTime(50); + assertEquals(3, stat.getCount()); + assertEquals(50, stat.getMinTime()); + assertEquals(403, stat.getMaxTime()); + + + assertEquals(553, stat.getTotalTime()); + + Thread.sleep(500); + + stat.addTime(10); + + assertLastTimeNotStartTime(stat); + + LOG.info("Stat is: " + stat); + + stat.reset(); + + assertEquals(0, stat.getCount()); + assertEquals(0, stat.getMinTime()); + assertEquals(0, stat.getMaxTime()); + assertEquals(0, stat.getTotalTime()); + + stat.addTime(100); + assertEquals(1, stat.getCount()); + assertEquals(100, stat.getMinTime()); + assertEquals(100, stat.getMaxTime()); + assertEquals(100, stat.getTotalTime()); + + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/memory/MemoryPropertyTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/memory/MemoryPropertyTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/memory/MemoryPropertyTest.java new file mode 100644 index 0000000..294916e --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/memory/MemoryPropertyTest.java @@ -0,0 +1,75 @@ +/** + * 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.memory; + +import junit.framework.TestCase; + +import org.apache.activemq.broker.BrokerFactory; +import org.apache.activemq.broker.BrokerService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MemoryPropertyTest extends TestCase { + + private static final transient Logger LOG = LoggerFactory.getLogger(MemoryPropertyTest.class); + BrokerService broker; + + + /** + * Sets up a test where the producer and consumer have their own connection. + * + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + // Create broker from resource + LOG.info("Creating broker... "); + broker = createBroker("xbean:org/apache/activemq/memory/activemq.xml"); + LOG.info("Success"); + super.setUp(); + } + + protected BrokerService createBroker(String resource) throws Exception { + return BrokerFactory.createBroker(resource); + } + + /* + * Stops the Broker + * + * @see junit.framework.TestCase#tearDown() + */ + @Override + protected void tearDown() throws Exception { + LOG.info("Closing Broker"); + if (broker != null) { + broker.stop(); + } + LOG.info("Broker closed..."); + } + + public void testBrokerInitialized() { + assertTrue("We should have a broker", broker != null); + + assertEquals("test-broker", broker.getBrokerName()); + assertEquals(1024, broker.getSystemUsage().getMemoryUsage().getLimit()); + assertEquals(34, broker.getSystemUsage().getMemoryUsage().getPercentUsageMinDelta()); + + assertNotNull(broker.getSystemUsage().getStoreUsage().getStore()); + // non persistent broker so no temp storage + assertNull(broker.getSystemUsage().getTempUsage().getStore()); + } +}