avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fo...@apache.org
Subject [avro] branch master updated: AVRO-2262 Unit test to test codec behavior on sliced buffers (#376)
Date Mon, 12 Nov 2018 20:05:43 GMT
This is an automated email from the ASF dual-hosted git repository.

fokko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new 40a5e6a  AVRO-2262 Unit test to test codec behavior on sliced buffers (#376)
40a5e6a is described below

commit 40a5e6ae4cc4cd2d8065880c2641d640d1ca2f8f
Author: jacobtolar <accounts@sheckel.net>
AuthorDate: Mon Nov 12 14:05:38 2018 -0600

    AVRO-2262 Unit test to test codec behavior on sliced buffers (#376)
    
    See #352 for further reference.
---
 .../java/org/apache/avro/file/TestAllCodecs.java   | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/lang/java/avro/src/test/java/org/apache/avro/file/TestAllCodecs.java b/lang/java/avro/src/test/java/org/apache/avro/file/TestAllCodecs.java
index 0e531b7..c21c568 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/file/TestAllCodecs.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/file/TestAllCodecs.java
@@ -84,6 +84,39 @@ public class TestAllCodecs {
     Assert.assertEquals(decompressedBuffer, inputByteBuffer);
   }
 
+  @Test
+  public void testCodecSlice() throws IOException {
+    int inputSize = 500_000;
+    byte[] input = generateTestData(inputSize);
+
+    Codec codecInstance = CodecFactory.fromString(codec).createInstance();
+
+    ByteBuffer partialBuffer = ByteBuffer.wrap(input);
+    partialBuffer.position(17);
+
+    ByteBuffer inputByteBuffer = partialBuffer.slice();
+    ByteBuffer compressedBuffer = codecInstance.compress(inputByteBuffer);
+
+    int compressedSize = compressedBuffer.remaining();
+
+    // Make sure something returned
+    assertTrue(compressedSize > 0);
+
+    // Create a slice from the compressed buffer
+    ByteBuffer sliceBuffer = ByteBuffer.allocate(compressedSize + 100);
+    sliceBuffer.position(50);
+    sliceBuffer.put(compressedBuffer);
+    sliceBuffer.limit(compressedSize + 50);
+    sliceBuffer.position(50);
+
+    // Decompress the data
+    ByteBuffer decompressedBuffer = codecInstance.decompress(sliceBuffer.slice());
+
+    // Validate the the input and output are equal.
+    inputByteBuffer.rewind();
+    Assert.assertEquals(decompressedBuffer, inputByteBuffer);
+  }
+
   // Generate some test data that will compress easily
   public static byte[] generateTestData(int inputSize) {
     byte[] arr = new byte[inputSize];


Mime
View raw message