activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1351743 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java test/java/org/apache/activemq/jmx/OpenTypeSupportTest.java
Date Tue, 19 Jun 2012 15:32:33 GMT
Author: tabish
Date: Tue Jun 19 15:32:32 2012
New Revision: 1351743

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

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/jmx/OpenTypeSupportTest.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=1351743&r1=1351742&r2=1351743&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
Tue Jun 19 15:32:32 2012
@@ -23,6 +23,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+
 import javax.jms.DeliveryMode;
 import javax.jms.JMSException;
 import javax.management.openmbean.ArrayType;
@@ -284,6 +285,7 @@ public final class OpenTypeSupport {
             try {
                 byte preview[] = new byte[(int)Math.min(length, 255)];
                 m.readBytes(preview);
+                m.reset();
 
                 // This is whack! Java 1.5 JMX spec does not support primitive
                 // arrays!
@@ -389,7 +391,7 @@ public final class OpenTypeSupport {
             return rc;
         }
     }
-    
+
 
     static class JobOpenTypeFactory extends AbstractOpenTypeFactory {
 
@@ -490,7 +492,7 @@ public final class OpenTypeSupport {
 
     private OpenTypeSupport() {
     }
-    
+
     public static OpenTypeFactory getFactory(Class<?> clazz) throws OpenDataException
{
         return OPEN_TYPE_FACTORIES.get(clazz);
     }

Modified: 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=1351743&r1=1351742&r2=1351743&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/jmx/OpenTypeSupportTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/jmx/OpenTypeSupportTest.java
Tue Jun 19 15:32:32 2012
@@ -16,14 +16,81 @@
  */
 package org.apache.activemq.jmx;
 
+import static org.junit.Assert.assertEquals;
+
+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;
 
 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();
@@ -31,4 +98,22 @@ public class OpenTypeSupportTest {
         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 {
+        ObjectName queueViewMBeanName = new ObjectName(
+                "org.apache.activemq" + ":Type=Queue,Destination=" +
+                queue.getQueueName() + ",BrokerName=localhost");
+        QueueViewMBean proxy = (QueueViewMBean)
+            brokerService.getManagementContext().newProxyInstance(queueViewMBeanName, QueueViewMBean.class,
true);
+        return proxy;
+    }
 }



Mime
View raw message