You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ce...@apache.org on 2013/05/02 06:33:10 UTC
svn commit: r1478266 -
/activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/BrowseDLQTest.java
Author: ceposta
Date: Thu May 2 04:33:10 2013
New Revision: 1478266
URL: http://svn.apache.org/r1478266
Log:
test to help debug hawtio not being able to browse DLQ...
Added:
activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/BrowseDLQTest.java
Added: activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/BrowseDLQTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/BrowseDLQTest.java?rev=1478266&view=auto
==============================================================================
--- activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/BrowseDLQTest.java (added)
+++ activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/BrowseDLQTest.java Thu May 2 04:33:10 2013
@@ -0,0 +1,109 @@
+/**
+ * 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.usecases;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.jmx.QueueViewMBean;
+import org.apache.activemq.broker.region.policy.PolicyEntry;
+import org.apache.activemq.broker.region.policy.PolicyMap;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.junit.After;
+import org.junit.Test;
+
+import javax.jms.*;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.OpenDataException;
+import javax.management.openmbean.TabularData;
+
+import java.util.concurrent.TimeUnit;
+
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.TestCase.assertTrue;
+
+/**
+ * @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
+ */
+public class BrowseDLQTest {
+
+ private static final int NUM_MESSAGES = 100;
+ private BrokerService brokerService;
+ private ActiveMQQueue testQueue = new ActiveMQQueue("TEST.FOO");
+ private ActiveMQQueue dlq = new ActiveMQQueue("ActiveMQ.DLQ");
+
+ @Test
+ public void testCannotBrowseDLQAsTable() throws Exception {
+ startBroker();
+ // send 100 messages to queue with TTL of 1 second
+ sendMessagesToBeExpired();
+
+ // let's let the messages expire
+ TimeUnit.SECONDS.sleep(2);
+
+ assertCanBrowse();
+ }
+
+ private void assertCanBrowse() throws MalformedObjectNameException, OpenDataException {
+ ObjectName queueViewMBeanName = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=ActiveMQ.DLQ");
+ QueueViewMBean queue = (QueueViewMBean)
+ brokerService.getManagementContext().newProxyInstance(queueViewMBeanName, QueueViewMBean.class, true);
+ // make sure we have messages here
+ assertTrue(queue.getQueueSize() > 0);
+
+ CompositeData[] regularBrowse = queue.browse();
+ assertNotNull(regularBrowse);
+
+ TabularData tableData = queue.browseAsTable();
+ assertNotNull(tableData);
+
+ }
+
+
+
+ @After
+ public void tearDown() throws Exception {
+ brokerService.stop();
+ brokerService.waitUntilStopped();
+ }
+
+ private void startBroker() throws Exception {
+ brokerService = BrokerFactory.createBroker("broker:()/localhost?deleteAllMessagesOnStartup=true");
+
+ PolicyMap policyMap = new PolicyMap();
+ PolicyEntry policyEntry = new PolicyEntry();
+ policyEntry.setExpireMessagesPeriod(1000);
+ policyMap.setDefaultEntry(policyEntry);
+ brokerService.setDestinationPolicy(policyMap);
+ brokerService.start();
+ brokerService.waitUntilStarted();
+ }
+
+ private void sendMessagesToBeExpired() throws JMSException, InterruptedException {
+ ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
+ Connection connection = factory.createConnection();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = session.createProducer(testQueue);
+ for (int i = 0; i < NUM_MESSAGES; i++) {
+ producer.send(testQueue,session.createTextMessage("Hello world #" + i), DeliveryMode.PERSISTENT,
+ 4, 500);
+ }
+ connection.close();
+ }
+}