activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r472258 - in /incubator/activemq/trunk/activemq-core/src: main/java/org/apache/activemq/util/DataByteArrayOutputStream.java test/java/org/apache/activemq/util/DataByteArrayOutputStreamTest.java
Date Tue, 07 Nov 2006 21:00:47 GMT
Author: aco
Date: Tue Nov  7 13:00:46 2006
New Revision: 472258

URL: http://svn.apache.org/viewvc?view=rev&rev=472258
Log:
Added test case to test resizing of internal buffer of DataByteArrayOutputStream.
Fix bug during resizing of internal buffer of DataByteArrayOutputStream.

Added:
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/DataByteArrayOutputStreamTest.java
  (with props)
Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/DataByteArrayOutputStream.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/DataByteArrayOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/DataByteArrayOutputStream.java?view=diff&rev=472258&r1=472257&r2=472258
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/DataByteArrayOutputStream.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/DataByteArrayOutputStream.java
Tue Nov  7 13:00:46 2006
@@ -138,29 +138,29 @@
     
 
     public void writeBoolean(boolean v){
-        ensureEnoughBuffer(1);
+        ensureEnoughBuffer(pos + 1);
         buf[pos++]=(byte) (v?1:0);
     }
 
     public void writeByte(int v){
-        ensureEnoughBuffer(1);
+        ensureEnoughBuffer(pos + 1);
         buf[pos++]=(byte) (v>>>0);
     }
 
     public void writeShort(int v){
-        ensureEnoughBuffer(2);
+        ensureEnoughBuffer(pos + 2);
         buf[pos++]=(byte) (v>>>8);
         buf[pos++]=(byte) (v>>>0);
     }
 
     public void writeChar(int v){
-        ensureEnoughBuffer(2);
+        ensureEnoughBuffer(pos + 2);
         buf[pos++]=(byte) (v>>>8);
         buf[pos++]=(byte) (v>>>0);
     }
 
     public void writeInt(int v){
-        ensureEnoughBuffer(4);
+        ensureEnoughBuffer(pos + 4);
         buf[pos++]=(byte) (v>>>24);
         buf[pos++]=(byte) (v>>>16);
         buf[pos++]=(byte) (v>>>8);
@@ -168,7 +168,7 @@
     }
 
     public void writeLong(long v){
-        ensureEnoughBuffer(8);
+        ensureEnoughBuffer(pos + 8);
         buf[pos++]=(byte) (v>>>56);
         buf[pos++]=(byte) (v>>>48);
         buf[pos++]=(byte) (v>>>40);
@@ -219,7 +219,7 @@
         }
         if(encodedsize>65535)
             throw new UTFDataFormatException("encoded string too long: "+encodedsize+" bytes");
-        ensureEnoughBuffer(encodedsize+2);
+        ensureEnoughBuffer(pos + encodedsize+2);
         writeShort(encodedsize);
         int i=0;
         for(i=0;i<strlen;i++){

Added: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/DataByteArrayOutputStreamTest.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/DataByteArrayOutputStreamTest.java?view=auto&rev=472258
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/DataByteArrayOutputStreamTest.java
(added)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/DataByteArrayOutputStreamTest.java
Tue Nov  7 13:00:46 2006
@@ -0,0 +1,101 @@
+/**
+ *
+ * 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.util;
+
+import junit.framework.TestCase;
+
+import java.io.IOException;
+
+public class DataByteArrayOutputStreamTest extends TestCase {
+
+    /**
+     * This test case assumes that an ArrayIndexOutOfBoundsException will be thrown when
the buffer fails to resize
+     * @throws IOException
+     */
+    public void testResize() throws IOException {
+        int initSize = 64;
+        DataByteArrayOutputStream out = new DataByteArrayOutputStream();
+
+        fillOut(out, initSize);
+        // Should resized here
+        out.writeBoolean(true);
+
+        fillOut(out, initSize);
+        // Should resized here
+        out.writeByte(1);
+
+        fillOut(out, initSize);
+        // Should resized here
+        out.writeBytes("test");
+
+        fillOut(out, initSize);
+        // Should resized here
+        out.writeChar('C');
+
+        fillOut(out, initSize);
+        // Should resized here
+        out.writeChars("test");
+
+        fillOut(out, initSize);
+        // Should resized here
+        out.writeDouble(3.1416);
+
+        fillOut(out, initSize);
+        // Should resized here
+        out.writeFloat((float)3.1416);
+
+        fillOut(out, initSize);
+        // Should resized here
+        out.writeInt(12345);
+
+        fillOut(out, initSize);
+        // Should resized here
+        out.writeLong(12345);
+
+        fillOut(out, initSize);
+        // Should resized here
+        out.writeShort(1234);
+
+        fillOut(out, initSize);
+        // Should resized here
+        out.writeUTF("test");
+
+        fillOut(out, initSize);
+        // Should resized here
+        out.write(1234);
+
+        fillOut(out, initSize);
+        // Should resized here
+        out.write(new byte[10], 5, 5);
+
+        fillOut(out, initSize);
+        // Should resized here
+        out.write(new byte[10]);
+    }
+
+    /**
+     * This method restarts the stream to the init size, and fills it up with data
+     * @param out
+     * @param size
+     * @throws IOException
+     */
+    public void fillOut(DataByteArrayOutputStream out, int size) throws IOException {
+        out.restart(size);
+        out.write(new byte[size]);
+    }
+}

Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/DataByteArrayOutputStreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/DataByteArrayOutputStreamTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/DataByteArrayOutputStreamTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message