activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r425426 - in /incubator/activemq/branches/activemq-4.0/activemq-core/src: main/java/org/apache/activemq/util/MarshallingSupport.java test/java/org/apache/activemq/command/ActiveMQMapMessageTest.java
Date Tue, 25 Jul 2006 15:42:40 GMT
Author: chirino
Date: Tue Jul 25 08:42:38 2006
New Revision: 425426

URL: http://svn.apache.org/viewvc?rev=425426&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQ-788

Modified:
    incubator/activemq/branches/activemq-4.0/activemq-core/src/main/java/org/apache/activemq/util/MarshallingSupport.java
    incubator/activemq/branches/activemq-4.0/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQMapMessageTest.java

Modified: incubator/activemq/branches/activemq-4.0/activemq-core/src/main/java/org/apache/activemq/util/MarshallingSupport.java
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/activemq-core/src/main/java/org/apache/activemq/util/MarshallingSupport.java?rev=425426&r1=425425&r2=425426&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/activemq-core/src/main/java/org/apache/activemq/util/MarshallingSupport.java
(original)
+++ incubator/activemq/branches/activemq-4.0/activemq-core/src/main/java/org/apache/activemq/util/MarshallingSupport.java
Tue Jul 25 08:42:38 2006
@@ -46,6 +46,7 @@
     public static final byte FLOAT_TYPE              = 8;
     public static final byte STRING_TYPE             = 9;
     public static final byte BYTE_ARRAY_TYPE         = 10;
+    public static final byte BIG_STRING_TYPE         = 13;
 
     static  public void marshalPrimitiveMap(HashMap map, DataOutputStream out) throws IOException
{
         if( map == null ) {
@@ -121,8 +122,17 @@
             out.writeInt(((byte[])value).length);
             out.write(((byte[])value));
         } else if( value.getClass() == String.class ) {
-            out.writeByte(STRING_TYPE);
-            out.writeUTF((String)value);
+            String s = (String)value;
+            
+            // If it's too big, out.writeUTF may not able able to write it out.
+            if( s.length() < Short.MAX_VALUE/4 ) {
+                out.writeByte(STRING_TYPE);
+                out.writeUTF((String)value);
+            } else {
+                out.writeByte(BIG_STRING_TYPE);
+                writeUTF8(out, s);
+            }
+            
         } else {
             throw new IOException("Object is not a primitive: "+value);
         }
@@ -161,6 +171,15 @@
             break;
         case STRING_TYPE:
             value = in.readUTF();
+            break;
+        case BIG_STRING_TYPE:
+            value = readUTF8(in);
+            break;
+        case MAP_TYPE:
+            value = unmarshalPrimitiveMap(in);
+            break;
+        case LIST_TYPE:
+            value = unmarshalPrimitiveList(in);
             break;
         }
         return value;

Modified: incubator/activemq/branches/activemq-4.0/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQMapMessageTest.java
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQMapMessageTest.java?rev=425426&r1=425425&r2=425426&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQMapMessageTest.java
(original)
+++ incubator/activemq/branches/activemq-4.0/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQMapMessageTest.java
Tue Jul 25 08:42:38 2006
@@ -18,6 +18,7 @@
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Enumeration;
 
@@ -77,9 +78,17 @@
         msg.setShort("short", (short) 1);
         msg.setString("string", "string");
 
-        msg.onSend();
-        msg.setContent(msg.getContent());
-
+        // Test with a 1Meg String
+        StringBuffer bigSB = new StringBuffer(1024*1024);
+        for( int i=0; i < 1024*1024; i++ ) {
+            bigSB.append((char)'a'+i%26);
+        }
+        String bigString = bigSB.toString();
+        
+        msg.setString("bigString", bigString);
+        
+        msg = (ActiveMQMapMessage) msg.copy();
+        
         assertEquals(msg.getBoolean("boolean"), true);
         assertEquals(msg.getByte("byte"), (byte) 1);
         assertEquals(msg.getBytes("bytes").length, 1);
@@ -91,6 +100,7 @@
         assertEquals(msg.getObject("object"), "stringObj");
         assertEquals(msg.getShort("short"), (short) 1);
         assertEquals(msg.getString("string"), "string");
+        assertEquals(msg.getString("bigString"), bigString);
     }
 
     public void testGetBoolean() throws JMSException {
@@ -101,8 +111,7 @@
         msg.clearBody();
         msg.setString(name, "true");
         
-        msg.onSend();
-        msg.setContent(msg.getContent());
+        msg = (ActiveMQMapMessage) msg.copy();
         
         assertTrue(msg.getBoolean(name));
     }
@@ -110,7 +119,7 @@
     public void testGetByte() throws JMSException {
         ActiveMQMapMessage msg = new ActiveMQMapMessage();
         msg.setByte(this.name, (byte) 1);
-        msg.setReadOnlyBody(true);
+        msg = (ActiveMQMapMessage) msg.copy();
         assertTrue(msg.getByte(this.name) == (byte) 1);
     }
 
@@ -118,7 +127,7 @@
         ActiveMQMapMessage msg = new ActiveMQMapMessage();
         try {
             msg.setShort(this.name, (short) 1);
-            msg.setReadOnlyBody(true);
+            msg = (ActiveMQMapMessage) msg.copy();
             assertTrue(msg.getShort(this.name) == (short) 1);
         } catch (JMSException jmsEx) {
             jmsEx.printStackTrace();
@@ -130,7 +139,7 @@
         ActiveMQMapMessage msg = new ActiveMQMapMessage();
         try {
             msg.setChar(this.name, 'a');
-            msg.setReadOnlyBody(true);
+            msg = (ActiveMQMapMessage) msg.copy();
             assertTrue(msg.getChar(this.name) == 'a');
         } catch (JMSException jmsEx) {
             jmsEx.printStackTrace();
@@ -142,7 +151,7 @@
         ActiveMQMapMessage msg = new ActiveMQMapMessage();
         try {
             msg.setInt(this.name, 1);
-            msg.setReadOnlyBody(true);
+            msg = (ActiveMQMapMessage) msg.copy();
             assertTrue(msg.getInt(this.name) == 1);
         } catch (JMSException jmsEx) {
             jmsEx.printStackTrace();
@@ -154,7 +163,7 @@
         ActiveMQMapMessage msg = new ActiveMQMapMessage();
         try {
             msg.setLong(this.name, 1);
-            msg.setReadOnlyBody(true);
+            msg = (ActiveMQMapMessage) msg.copy();
             assertTrue(msg.getLong(this.name) == 1);
         } catch (JMSException jmsEx) {
             jmsEx.printStackTrace();
@@ -166,7 +175,7 @@
         ActiveMQMapMessage msg = new ActiveMQMapMessage();
         try {
             msg.setFloat(this.name, 1.5f);
-            msg.setReadOnlyBody(true);
+            msg = (ActiveMQMapMessage) msg.copy();
             assertTrue(msg.getFloat(this.name) == 1.5f);
         } catch (JMSException jmsEx) {
             jmsEx.printStackTrace();
@@ -178,7 +187,7 @@
         ActiveMQMapMessage msg = new ActiveMQMapMessage();
         try {
             msg.setDouble(this.name, 1.5);
-            msg.setReadOnlyBody(true);
+            msg = (ActiveMQMapMessage) msg.copy();
             assertTrue(msg.getDouble(this.name) == 1.5);
         } catch (JMSException jmsEx) {
             jmsEx.printStackTrace();
@@ -191,8 +200,8 @@
         try {
             String str = "test";
             msg.setString(this.name, str);
-            msg.setReadOnlyBody(true);
-            assertTrue(msg.getString(this.name) == str);
+            msg = (ActiveMQMapMessage) msg.copy();
+            assertEquals(msg.getString(this.name), str);
         } catch (JMSException jmsEx) {
             jmsEx.printStackTrace();
             assertTrue(false);
@@ -207,8 +216,8 @@
             System.arraycopy(bytes1, 0, bytes2, 0, 2);
             msg.setBytes(this.name, bytes1);
             msg.setBytes(this.name + "2", bytes1, 0, 2);
-            msg.setReadOnlyBody(true);
-            assertTrue(msg.getBytes(this.name) == bytes1);
+            msg = (ActiveMQMapMessage) msg.copy();
+            assertTrue( Arrays.equals(msg.getBytes(this.name), bytes1));
             assertEquals(msg.getBytes(this.name + "2").length, bytes2.length);
         } catch (JMSException jmsEx) {
             jmsEx.printStackTrace();
@@ -244,8 +253,7 @@
             fail("object formats should be correct");
         }
         
-        msg.onSend();
-        msg.setContent(msg.getContent());
+        msg = (ActiveMQMapMessage) msg.copy();
 
         assertTrue(msg.getObject("boolean") instanceof Boolean);
         assertEquals(msg.getObject("boolean"), booleanValue);
@@ -302,8 +310,7 @@
         msg.setShort("short", (short) 1);
         msg.setString("string", "string");
 
-        msg.onSend();
-        msg.setContent(msg.getContent());
+        msg = (ActiveMQMapMessage) msg.copy();
 
         Enumeration mapNamesEnum = msg.getMapNames();
         ArrayList mapNamesList = Collections.list(mapNamesEnum);
@@ -328,8 +335,7 @@
 
         mapMessage.setString("exists", "test");
         
-        mapMessage.onSend();
-        mapMessage.setContent(mapMessage.getContent());
+        mapMessage = (ActiveMQMapMessage) mapMessage.copy();
 
         assertTrue(mapMessage.itemExists("exists"));
         assertFalse(mapMessage.itemExists("doesntExist"));
@@ -348,8 +354,7 @@
         mapMessage.clearBody();
         mapMessage.setString("String", "String");
         
-        mapMessage.onSend();
-        mapMessage.setContent(mapMessage.getContent());
+        mapMessage = (ActiveMQMapMessage) mapMessage.copy();
 
         mapMessage.getString("String");            
     }



Mime
View raw message