commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [4/7] commons-compress git commit: Slight test speed up by avoiding more writing to disk Signed-off-by: Simon Spero <sesuncedu@gmail.com>
Date Thu, 06 Jul 2017 07:07:33 GMT
Slight test speed up by avoiding more writing to disk Signed-off-by: Simon Spero <sesuncedu@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/64573bb2
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/64573bb2
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/64573bb2

Branch: refs/heads/master
Commit: 64573bb2e0bd2c7a7b1282b8a574a4796ae61609
Parents: 1261172
Author: Simon Spero <sesuncedu@gmail.com>
Authored: Sun Jun 25 16:57:23 2017 -0400
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Thu Jul 6 09:07:16 2017 +0200

----------------------------------------------------------------------
 .../compressors/snappy/SnappyRoundtripTest.java | 27 +++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/64573bb2/src/test/java/org/apache/commons/compress/compressors/snappy/SnappyRoundtripTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/compressors/snappy/SnappyRoundtripTest.java
b/src/test/java/org/apache/commons/compress/compressors/snappy/SnappyRoundtripTest.java
index 8b96309..350ef4e 100644
--- a/src/test/java/org/apache/commons/compress/compressors/snappy/SnappyRoundtripTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/snappy/SnappyRoundtripTest.java
@@ -18,6 +18,8 @@
  */
 package org.apache.commons.compress.compressors.snappy;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -57,6 +59,25 @@ public final class SnappyRoundtripTest extends AbstractTestCase {
         }
         System.err.println(outputSz.getName() + " read after " + (System.currentTimeMillis()
- start) + "ms");
     }
+    private void roundTripTest(final byte[] input, Parameters params) throws IOException
{
+        long start = System.currentTimeMillis();
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        try (
+             SnappyCompressorOutputStream sos = new SnappyCompressorOutputStream(os, input.length,
params)) {
+            sos.write(input);
+        }
+        System.err.println("byte array" + " written, uncompressed bytes: " + input.length
+            + ", compressed bytes: " + os.size() + " after " + (System.currentTimeMillis()
- start) + "ms");
+        start = System.currentTimeMillis();
+        try (
+             SnappyCompressorInputStream sis = new SnappyCompressorInputStream(new ByteArrayInputStream(os.toByteArray()),
+                 params.getWindowSize())) {
+            byte[] expected = input;
+            byte[] actual = IOUtils.toByteArray(sis);
+            Assert.assertArrayEquals(expected, actual);
+        }
+        System.err.println("byte array" + " read after " + (System.currentTimeMillis() -
start) + "ms");
+    }
 
     // should yield decent compression
     @Test
@@ -108,7 +129,7 @@ public final class SnappyRoundtripTest extends AbstractTestCase {
         // of random noise that doesn't contain any 0000 at all, then
         // add 0000.
         File f = new File(dir, "reallyBigOffsetTest");
-        try (FileOutputStream fs = new FileOutputStream(f)) {
+        ByteArrayOutputStream fs = new ByteArrayOutputStream((1<<16) + 1024);
             fs.write(0);
             fs.write(0);
             fs.write(0);
@@ -122,8 +143,8 @@ public final class SnappyRoundtripTest extends AbstractTestCase {
             fs.write(0);
             fs.write(0);
             fs.write(0);
-        }
-        roundTripTest(f, newParameters(1 << 17, 4, 64, 1 << 17 - 1, 1 <<
17 - 1));
+
+        roundTripTest(fs.toByteArray(), newParameters(1 << 17, 4, 64, 1 << 17
- 1, 1 << 17 - 1));
     }
 
     @Test


Mime
View raw message