activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1362477 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/jmx/QueueView.java test/java/org/apache/activemq/bugs/AMQ3934Test.java
Date Tue, 17 Jul 2012 13:03:26 GMT
Author: tabish
Date: Tue Jul 17 13:03:26 2012
New Revision: 1362477

URL: http://svn.apache.org/viewvc?rev=1362477&view=rev
Log:
apply fix for: https://issues.apache.org/jira/browse/AMQ-3934

Added:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3934Test.java 
 (with props)
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/QueueView.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/QueueView.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/QueueView.java?rev=1362477&r1=1362476&r2=1362477&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/QueueView.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/QueueView.java
Tue Jul 17 13:03:26 2012
@@ -36,12 +36,18 @@ public class QueueView extends Destinati
     }
 
     public CompositeData getMessage(String messageId) throws OpenDataException {
-        QueueMessageReference ref = ((Queue)destination).getMessage(messageId);
-        Message rc = ref.getMessage();
-        if (rc == null) {
-            return null;
+    	CompositeData result = null;
+    	QueueMessageReference ref = ((Queue)destination).getMessage(messageId);
+
+        if (ref != null) {
+	        Message rc = ref.getMessage();
+	        if (rc == null) {
+	            return null;
+	        }
+	        result = OpenTypeSupport.convert(rc);
         }
-        return OpenTypeSupport.convert(rc);
+
+        return result;
     }
 
     public void purge() throws Exception {
@@ -117,7 +123,7 @@ public class QueueView extends Destinati
             throw new JMSException("Could not find message: "+ messageId);
         }
     }
-    
+
     public int cursorSize() {
         Queue queue = (Queue) destination;
         if (queue.getMessages() != null){
@@ -126,7 +132,7 @@ public class QueueView extends Destinati
         return 0;
     }
 
-   
+
     public boolean doesCursorHaveMessagesBuffered() {
        Queue queue = (Queue) destination;
        if (queue.getMessages() != null){
@@ -136,7 +142,7 @@ public class QueueView extends Destinati
 
     }
 
-    
+
     public boolean doesCursorHaveSpace() {
         Queue queue = (Queue) destination;
         if (queue.getMessages() != null){
@@ -145,7 +151,7 @@ public class QueueView extends Destinati
         return false;
     }
 
-    
+
     public long getCursorMemoryUsage() {
         Queue queue = (Queue) destination;
         if (queue.getMessages() != null &&  queue.getMessages().getSystemUsage()
!= null){

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3934Test.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3934Test.java?rev=1362477&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3934Test.java (added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3934Test.java Tue
Jul 17 13:03:26 2012
@@ -0,0 +1,108 @@
+/**
+ * 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.bugs;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+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.QueueViewMBean;
+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;
+
+public class AMQ3934Test {
+
+    private static final transient Logger LOG = LoggerFactory.getLogger(AMQ3934Test.class);
+    private static BrokerService brokerService;
+    private static String TEST_QUEUE = "testQueue";
+    private static ActiveMQQueue queue = new ActiveMQQueue(TEST_QUEUE);
+    private static String BROKER_ADDRESS = "tcp://localhost:0";
+
+    private ActiveMQConnectionFactory connectionFactory;
+    private String connectionUri;
+    private String messageID;
+
+    @Before
+    public void setUp() throws Exception {
+        brokerService = new BrokerService();
+        brokerService.setPersistent(false);
+        brokerService.setUseJmx(true);
+        connectionUri = brokerService.addConnector(BROKER_ADDRESS).getPublishableConnectString();
+        brokerService.start();
+        brokerService.waitUntilStarted();
+
+        connectionFactory = new ActiveMQConnectionFactory(connectionUri);
+        sendMessage();
+    }
+
+    public void sendMessage() throws Exception {
+        final Connection conn = connectionFactory.createConnection();
+        try {
+            conn.start();
+            final Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            final Destination queue = session.createQueue(TEST_QUEUE);
+            final Message toSend = session.createMessage();
+            final MessageProducer producer = session.createProducer(queue);
+            producer.send(queue, toSend);
+        } finally {
+            conn.close();
+        }
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        brokerService.stop();
+        brokerService.waitUntilStopped();
+    }
+
+    @Test
+    public void getMessage() throws Exception {
+        final QueueViewMBean queueView = getProxyToQueueViewMBean();
+        final CompositeData messages[] = queueView.browse();
+        messageID = (String) messages[0].get("JMSMessageID");
+        assertNotNull(messageID);
+        assertNotNull(queueView.getMessage(messageID));
+        LOG.debug("Attempting to remove message ID: " + messageID);
+        queueView.removeMessage(messageID);
+        assertNull(queueView.getMessage(messageID));
+    }
+
+    private QueueViewMBean getProxyToQueueViewMBean() throws MalformedObjectNameException,
NullPointerException,
+            JMSException {
+        final ObjectName queueViewMBeanName = new ObjectName("org.apache.activemq:Type=Queue,Destination="
+                + queue.getQueueName() + ",BrokerName=localhost");
+        final QueueViewMBean proxy = (QueueViewMBean) brokerService.getManagementContext().newProxyInstance(
+                queueViewMBeanName, QueueViewMBean.class, true);
+        return proxy;
+    }
+}

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3934Test.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message