activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r1070442 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/jmx/ test/java/org/apache/activemq/broker/jmx/ test/java/org/apache/activemq/jmx/
Date Mon, 14 Feb 2011 11:11:01 GMT
Author: gtully
Date: Mon Feb 14 11:11:01 2011
New Revision: 1070442

URL: http://svn.apache.org/viewvc?rev=1070442&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3180 - JMX Browse of BytesMessage fails with javax.management.openmbean.OpenDataException:
Argument's element itemValues[8]=[B@de15a0 is not a valid value for this item. readonly flag
needs to be flipped by browser such that content can be read.

Added:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/jmx/
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/jmx/OpenTypeSupportTest.java
  (with props)
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java?rev=1070442&r1=1070441&r2=1070442&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java
Mon Feb 14 11:11:01 2011
@@ -283,6 +283,7 @@ public final class OpenTypeSupport {
         @Override
         public Map<String, Object> getFields(Object o) throws OpenDataException {
             ActiveMQBytesMessage m = (ActiveMQBytesMessage)o;
+            m.setReadOnlyBody(true);
             Map<String, Object> rc = super.getFields(o);
             long length = 0;
             try {

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java?rev=1070442&r1=1070441&r2=1070442&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java
Mon Feb 14 11:11:01 2011
@@ -23,6 +23,7 @@ import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.jms.BytesMessage;
 import javax.jms.Connection;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
@@ -601,7 +602,26 @@ public class MBeanTest extends EmbeddedB
         }
         Thread.sleep(1000);
     }
-    
+
+    protected void useConnectionWithByteMessage(Connection connection) throws Exception {
+        connection.setClientID(clientID);
+        connection.start();
+        ActiveMQSession session = (ActiveMQSession) connection.createSession(transacted,
authMode);
+        destination = createDestination();
+        MessageProducer producer = session.createProducer(destination);
+        for (int i = 0; i < MESSAGE_COUNT; i++) {
+            BytesMessage message = session.createBytesMessage();
+            message.writeBytes(("Message: " + i).getBytes());
+            message.setIntProperty("counter", i);
+            message.setJMSCorrelationID("MyCorrelationID");
+            message.setJMSReplyTo(new ActiveMQQueue("MyReplyTo"));
+            message.setJMSType("MyType");
+            message.setJMSPriority(5);
+            producer.send(message);
+        }
+        Thread.sleep(1000);
+    }
+
     protected void echo(String text) {
         LOG.info(text);
     }
@@ -667,4 +687,48 @@ public class MBeanTest extends EmbeddedB
 
         assertTrue("dest has some memory usage", queue.getMemoryPercentUsage() > 0);
     }
+
+    public void testBrowseBytesMessages() throws Exception {
+        connection = connectionFactory.createConnection();
+        useConnectionWithByteMessage(connection);
+
+        ObjectName queueViewMBeanName = assertRegisteredObjectName(domain + ":Type=Queue,Destination="
+ getDestinationString() + ",BrokerName=localhost");
+
+        QueueViewMBean queue = (QueueViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer,
queueViewMBeanName, QueueViewMBean.class, true);
+
+        CompositeData[] compdatalist = queue.browse();
+        int initialQueueSize = compdatalist.length;
+        if (initialQueueSize == 0) {
+            fail("There is no message in the queue:");
+        }
+        else {
+            echo("Current queue size: " + initialQueueSize);
+        }
+        int messageCount = initialQueueSize;
+        String[] messageIDs = new String[messageCount];
+        for (int i = 0; i < messageCount; i++) {
+            CompositeData cdata = compdatalist[i];
+            String messageID = (String) cdata.get("JMSMessageID");
+            assertNotNull("Should have a message ID for message " + i, messageID);
+            messageIDs[i] = messageID;
+
+            Byte[] preview = (Byte[]) cdata.get(CompositeDataConstants.BODY_PREVIEW);
+            assertNotNull("should be a preview", preview);
+            assertTrue("not empty", preview.length > 0);
+        }
+
+        assertTrue("dest has some memory usage", queue.getMemoryPercentUsage() > 0);
+
+        // consume all the messages
+        echo("Attempting to consume all bytes messages from: " + destination);
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        MessageConsumer consumer = session.createConsumer(destination);
+        for (int i=0; i<MESSAGE_COUNT; i++) {
+            Message message = consumer.receive(5000);
+            assertNotNull(message);
+            assertTrue(message instanceof BytesMessage);
+        }
+        consumer.close();
+        session.close();
+    }
 }

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/jmx/OpenTypeSupportTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/jmx/OpenTypeSupportTest.java?rev=1070442&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/jmx/OpenTypeSupportTest.java
(added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/jmx/OpenTypeSupportTest.java
Mon Feb 14 11:11:01 2011
@@ -0,0 +1,34 @@
+/**
+ * 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.jmx.OpenTypeSupport;
+import org.apache.activemq.command.ActiveMQBytesMessage;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class OpenTypeSupportTest {
+    private static final Logger LOG = LoggerFactory.getLogger(OpenTypeSupportTest.class);
+    @Test
+    public void testBrowseByteMessageFails() throws Exception {
+        ActiveMQBytesMessage bm = new ActiveMQBytesMessage();
+        bm.writeBytes("123456".getBytes());
+        Object result = OpenTypeSupport.convert(bm);
+        LOG.info("result : " + result);
+    }
+}

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

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/jmx/OpenTypeSupportTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message