Repository: cassandra
Updated Branches:
  refs/heads/trunk c87b6a30f -> 2e22bc9aa


cleanup test:close OffHeapBitSets, use junit


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/2e22bc9a
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/2e22bc9a
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/2e22bc9a

Branch: refs/heads/trunk
Commit: 2e22bc9aa6d5c0e6ca90acfa8e7923390e69b033
Parents: c87b6a3
Author: Dave Brosius <dbros...@mebigfatguy.com>
Authored: Sun Jan 25 22:57:27 2015 -0500
Committer: Dave Brosius <dbros...@mebigfatguy.com>
Committed: Sun Jan 25 22:57:27 2015 -0500

----------------------------------------------------------------------
 .../cassandra/utils/SerializationsTest.java     | 46 ++++++++++++--------
 1 file changed, 27 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/2e22bc9a/test/unit/org/apache/cassandra/utils/SerializationsTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/utils/SerializationsTest.java 
b/test/unit/org/apache/cassandra/utils/SerializationsTest.java
index 46fa017..d5b45d1 100644
--- a/test/unit/org/apache/cassandra/utils/SerializationsTest.java
+++ b/test/unit/org/apache/cassandra/utils/SerializationsTest.java
@@ -22,6 +22,7 @@ import org.apache.cassandra.AbstractSerializationsTester;
 import org.apache.cassandra.io.util.DataOutputStreamAndChannel;
 import org.apache.cassandra.service.StorageService;
 
+import org.junit.Assert;
 import org.junit.Test;
 
 import java.io.DataInputStream;
@@ -32,12 +33,15 @@ public class SerializationsTest extends 
AbstractSerializationsTester
 
     private void testBloomFilterWrite(boolean offheap) throws IOException
     {
-        IFilter bf = FilterFactory.getFilter(1000000, 0.0001, offheap);
-        for (int i = 0; i < 100; i++)
-            
bf.add(StorageService.getPartitioner().getTokenFactory().toByteArray(StorageService.getPartitioner().getRandomToken()));
-        DataOutputStreamAndChannel out = getOutput("utils.BloomFilter.bin");
-        FilterFactory.serialize(bf, out);
-        out.close();
+        try (IFilter bf = FilterFactory.getFilter(1000000, 0.0001, offheap))
+        {
+            for (int i = 0; i < 100; i++)
+                
bf.add(StorageService.getPartitioner().getTokenFactory().toByteArray(StorageService.getPartitioner().getRandomToken()));
+            try (DataOutputStreamAndChannel out = 
getOutput("utils.BloomFilter.bin")) 
+            {
+                FilterFactory.serialize(bf, out);
+            }
+        }
     }
 
     @Test
@@ -46,9 +50,11 @@ public class SerializationsTest extends 
AbstractSerializationsTester
         if (EXECUTE_WRITES)
             testBloomFilterWrite(true);
 
-        DataInputStream in = getInput("utils.BloomFilter.bin");
-        assert FilterFactory.deserialize(in, true) != null;
-        in.close();
+        try (DataInputStream in = getInput("utils.BloomFilter.bin");
+             IFilter filter = FilterFactory.deserialize(in, true))
+        {
+            Assert.assertNotNull(filter);
+        }
     }
 
     private void testEstimatedHistogramWrite() throws IOException
@@ -65,11 +71,12 @@ public class SerializationsTest extends 
AbstractSerializationsTester
         data[offsets.length] = 100000;
         EstimatedHistogram hist2 = new EstimatedHistogram(offsets, data);
 
-        DataOutputStreamAndChannel out = 
getOutput("utils.EstimatedHistogram.bin");
-        EstimatedHistogram.serializer.serialize(hist0, out);
-        EstimatedHistogram.serializer.serialize(hist1, out);
-        EstimatedHistogram.serializer.serialize(hist2, out);
-        out.close();
+        try (DataOutputStreamAndChannel out = 
getOutput("utils.EstimatedHistogram.bin"))
+        {
+            EstimatedHistogram.serializer.serialize(hist0, out);
+            EstimatedHistogram.serializer.serialize(hist1, out);
+            EstimatedHistogram.serializer.serialize(hist2, out);
+        }
     }
 
     @Test
@@ -78,10 +85,11 @@ public class SerializationsTest extends 
AbstractSerializationsTester
         if (EXECUTE_WRITES)
             testEstimatedHistogramWrite();
 
-        DataInputStream in = getInput("utils.EstimatedHistogram.bin");
-        assert EstimatedHistogram.serializer.deserialize(in) != null;
-        assert EstimatedHistogram.serializer.deserialize(in) != null;
-        assert EstimatedHistogram.serializer.deserialize(in) != null;
-        in.close();
+        try (DataInputStream in = getInput("utils.EstimatedHistogram.bin"))
+        {
+            
Assert.assertNotNull(EstimatedHistogram.serializer.deserialize(in));
+            
Assert.assertNotNull(EstimatedHistogram.serializer.deserialize(in));
+            
Assert.assertNotNull(EstimatedHistogram.serializer.deserialize(in));
+        }
     }
 }

Reply via email to