commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject svn commit: r307292 - in /jakarta/commons/proper/collections/trunk: ./ data/test/ src/java/org/apache/commons/collections/buffer/ src/test/org/apache/commons/collections/buffer/
Date Sat, 08 Oct 2005 12:50:01 GMT
Author: scolebourne
Date: Sat Oct  8 05:49:53 2005
New Revision: 307292

URL: http://svn.apache.org/viewcvs?rev=307292&view=rev
Log:
Make PriorityBuffer Serializable
bug 36163, from Steve Phelps

Added:
    jakarta/commons/proper/collections/trunk/data/test/PriorityBuffer.emptyCollection.version3.2.obj
  (with props)
    jakarta/commons/proper/collections/trunk/data/test/PriorityBuffer.fullCollection.version3.2.obj
  (with props)
Modified:
    jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html
    jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/PriorityBuffer.java
    jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestPriorityBuffer.java

Modified: jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html?rev=307292&r1=307291&r2=307292&view=diff
==============================================================================
--- jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html (original)
+++ jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html Sat Oct  8 05:49:53 2005
@@ -71,6 +71,7 @@
 <li>BlockingBuffer - now includes stack trace if InterupttedException occurs [33700]</li>
 <li>BlockingBuffer - new methods that allow get and remove with a timeout [27691]</li>
 <li>Transformed*Map - new factory decorateTransform() that transforms any existing
entries in the map [30959]</li>
+<li>PriorityBuffer - now Serializable [36163]</li>
 </ul>
 
 <center><h3>BUG FIXES</h3></center>

Added: jakarta/commons/proper/collections/trunk/data/test/PriorityBuffer.emptyCollection.version3.2.obj
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/data/test/PriorityBuffer.emptyCollection.version3.2.obj?rev=307292&view=auto
==============================================================================
Binary file - no diff available.

Propchange: jakarta/commons/proper/collections/trunk/data/test/PriorityBuffer.emptyCollection.version3.2.obj
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: jakarta/commons/proper/collections/trunk/data/test/PriorityBuffer.fullCollection.version3.2.obj
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/data/test/PriorityBuffer.fullCollection.version3.2.obj?rev=307292&view=auto
==============================================================================
Binary file - no diff available.

Propchange: jakarta/commons/proper/collections/trunk/data/test/PriorityBuffer.fullCollection.version3.2.obj
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/PriorityBuffer.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/PriorityBuffer.java?rev=307292&r1=307291&r2=307292&view=diff
==============================================================================
--- jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/PriorityBuffer.java
(original)
+++ jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/PriorityBuffer.java
Sat Oct  8 05:49:53 2005
@@ -15,6 +15,7 @@
  */
 package org.apache.commons.collections.buffer;
 
+import java.io.Serializable;
 import java.util.AbstractCollection;
 import java.util.Comparator;
 import java.util.Iterator;
@@ -57,8 +58,13 @@
  * @author Michael A. Smith
  * @author Paul Jack
  * @author Stephen Colebourne
+ * @author Steve Phelps
  */
-public class PriorityBuffer extends AbstractCollection implements Buffer {
+public class PriorityBuffer extends AbstractCollection
+        implements Buffer, Serializable {
+
+    /** Serialization lock. */
+    private static final long serialVersionUID = 6891186490470027896L;
 
     /**
      * The default capacity for the buffer.

Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestPriorityBuffer.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestPriorityBuffer.java?rev=307292&r1=307291&r2=307292&view=diff
==============================================================================
--- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestPriorityBuffer.java
(original)
+++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestPriorityBuffer.java
Sat Oct  8 05:49:53 2005
@@ -15,10 +15,12 @@
  */
 package org.apache.commons.collections.buffer;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Comparator;
+import java.util.Iterator;
 import java.util.Random;
 
 import junit.framework.Test;
@@ -37,6 +39,7 @@
  * @version $Revision$ $Date$
  * 
  * @author Michael A. Smith
+ * @author Steve Phelps
  */
 public class TestPriorityBuffer extends AbstractTestCollection {
 
@@ -306,7 +309,6 @@
     protected void checkOrder(PriorityBuffer h) {
         Integer lastNum = null;
         Integer num = null;
-        boolean fail = false;
         while (!h.isEmpty()) {
             num = (Integer) h.remove();
             if (h.ascendingOrder) {
@@ -336,5 +338,70 @@
         }
         return buffer.toString();
     }
-    
+
+    /**
+     * Generates 500 randomly initialized heaps of size 100
+     * and tests that after serializing and restoring them to a byte array
+     * that the following conditions hold:
+     * 
+     *  - the size of the restored heap is the same 
+     *      as the size of the orignal heap
+     *  
+     *  - all elements in the original heap are present in the restored heap
+     *  
+     *  - the heap order of the restored heap is intact as 
+     *      verified by checkOrder()
+     */
+    public void testSerialization() {
+        int iterations = 500;
+        int heapSize = 100;
+        PriorityBuffer h;
+        Random randGenerator = new Random();
+        for (int i = 0; i < iterations; i++) {
+            if (i < iterations / 2) {
+                h = new PriorityBuffer(true);
+            } else {
+                h = new PriorityBuffer(false);
+            }
+            for (int r = 0; r < heapSize; r++) {
+                h.add(new Integer(randGenerator.nextInt(heapSize)));
+            }
+            assertTrue(h.size() == heapSize);
+            PriorityBuffer h1 = serializeAndRestore(h);
+            assertTrue(h1.size() == heapSize);
+            Iterator hit = h.iterator();
+            while (hit.hasNext()) {
+                Integer n = (Integer) hit.next();
+                assertTrue(h1.contains(n));
+            }
+            checkOrder(h1);
+        }
+    }
+
+    public PriorityBuffer serializeAndRestore(PriorityBuffer h) {
+        PriorityBuffer h1 = null;
+        try {
+            byte[] objekt = writeExternalFormToBytes(h);
+            h1 = (PriorityBuffer) readExternalFormFromBytes(objekt);
+        } catch (IOException e) {
+            e.printStackTrace();
+            fail(e.toString());
+        } catch (ClassNotFoundException e) {
+            e.printStackTrace();
+            fail(e.toString());
+        }
+        return h1;
+    }
+
+    public String getCompatibilityVersion() {
+        return "3.2";
+    }
+
+//    public void testCreate() throws Exception {
+//        resetEmpty();
+//        writeExternalFormToDisk((java.io.Serializable) collection, "C:/commons/collections/data/test/PriorityBuffer.emptyCollection.version3.2.obj");
+//        resetFull();
+//        writeExternalFormToDisk((java.io.Serializable) collection, "C:/commons/collections/data/test/PriorityBuffer.fullCollection.version3.2.obj");
+//    }
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message