Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-42042: [Java] Update Unit Tests for Compressions Module #42044

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

package org.apache.arrow.compression;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.channels.Channels;
Expand Down Expand Up @@ -46,9 +51,7 @@
import org.apache.arrow.vector.types.pojo.FieldType;
import org.apache.arrow.vector.types.pojo.Schema;
import org.apache.arrow.vector.util.ByteArrayReadableSeekableByteChannel;
import org.junit.After;
import org.junit.Assert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -67,7 +70,7 @@ public void setup() {
root = null;
}

@After
@AfterEach
public void tearDown() {
if (root != null) {
root.close();
Expand Down Expand Up @@ -134,19 +137,19 @@ public void testArrowFileZstdRoundTrip() throws Exception {
try (ArrowFileReader reader =
new ArrowFileReader(new ByteArrayReadableSeekableByteChannel(out.toByteArray()), allocator,
CommonsCompressionFactory.INSTANCE)) {
Assertions.assertEquals(1, reader.getRecordBlocks().size());
Assertions.assertTrue(reader.loadNextBatch());
Assertions.assertTrue(root.equals(reader.getVectorSchemaRoot()));
Assertions.assertFalse(reader.loadNextBatch());
assertEquals(1, reader.getRecordBlocks().size());
assertTrue(reader.loadNextBatch());
assertTrue(root.equals(reader.getVectorSchemaRoot()));
assertFalse(reader.loadNextBatch());
}
// without compression
try (ArrowFileReader reader =
new ArrowFileReader(new ByteArrayReadableSeekableByteChannel(out.toByteArray()), allocator,
NoCompressionCodec.Factory.INSTANCE)) {
Assertions.assertEquals(1, reader.getRecordBlocks().size());
Exception exception = Assert.assertThrows(IllegalArgumentException.class,
assertEquals(1, reader.getRecordBlocks().size());
Exception exception = assertThrows(IllegalArgumentException.class,
reader::loadNextBatch);
Assertions.assertEquals("Please add arrow-compression module to use CommonsCompressionFactory for ZSTD",
assertEquals("Please add arrow-compression module to use CommonsCompressionFactory for ZSTD",
exception.getMessage());
}
}
Expand All @@ -158,17 +161,17 @@ public void testArrowStreamZstdRoundTrip() throws Exception {
try (ArrowStreamReader reader =
new ArrowStreamReader(new ByteArrayReadableSeekableByteChannel(out.toByteArray()), allocator,
CommonsCompressionFactory.INSTANCE)) {
Assert.assertTrue(reader.loadNextBatch());
Assert.assertTrue(root.equals(reader.getVectorSchemaRoot()));
Assert.assertFalse(reader.loadNextBatch());
assertTrue(reader.loadNextBatch());
assertTrue(root.equals(reader.getVectorSchemaRoot()));
assertFalse(reader.loadNextBatch());
}
// without compression
try (ArrowStreamReader reader =
new ArrowStreamReader(new ByteArrayReadableSeekableByteChannel(out.toByteArray()), allocator,
NoCompressionCodec.Factory.INSTANCE)) {
Exception exception = Assert.assertThrows(IllegalArgumentException.class,
Exception exception = assertThrows(IllegalArgumentException.class,
reader::loadNextBatch);
Assert.assertEquals(
assertEquals(
"Please add arrow-compression module to use CommonsCompressionFactory for ZSTD",
exception.getMessage()
);
Expand All @@ -189,19 +192,19 @@ public void testArrowFileZstdRoundTripWithDictionary() throws Exception {
try (ArrowFileReader reader =
new ArrowFileReader(new ByteArrayReadableSeekableByteChannel(out.toByteArray()), allocator,
CommonsCompressionFactory.INSTANCE)) {
Assertions.assertEquals(1, reader.getRecordBlocks().size());
Assertions.assertTrue(reader.loadNextBatch());
Assertions.assertTrue(root.equals(reader.getVectorSchemaRoot()));
Assertions.assertFalse(reader.loadNextBatch());
assertEquals(1, reader.getRecordBlocks().size());
assertTrue(reader.loadNextBatch());
assertTrue(root.equals(reader.getVectorSchemaRoot()));
assertFalse(reader.loadNextBatch());
}
// without compression
try (ArrowFileReader reader =
new ArrowFileReader(new ByteArrayReadableSeekableByteChannel(out.toByteArray()), allocator,
NoCompressionCodec.Factory.INSTANCE)) {
Assertions.assertEquals(1, reader.getRecordBlocks().size());
Exception exception = Assert.assertThrows(IllegalArgumentException.class,
assertEquals(1, reader.getRecordBlocks().size());
Exception exception = assertThrows(IllegalArgumentException.class,
reader::loadNextBatch);
Assertions.assertEquals("Please add arrow-compression module to use CommonsCompressionFactory for ZSTD",
assertEquals("Please add arrow-compression module to use CommonsCompressionFactory for ZSTD",
exception.getMessage());
}
dictionaryVector.close();
Expand All @@ -221,17 +224,17 @@ public void testArrowStreamZstdRoundTripWithDictionary() throws Exception {
try (ArrowStreamReader reader =
new ArrowStreamReader(new ByteArrayReadableSeekableByteChannel(out.toByteArray()), allocator,
CommonsCompressionFactory.INSTANCE)) {
Assertions.assertTrue(reader.loadNextBatch());
Assertions.assertTrue(root.equals(reader.getVectorSchemaRoot()));
Assertions.assertFalse(reader.loadNextBatch());
assertTrue(reader.loadNextBatch());
assertTrue(root.equals(reader.getVectorSchemaRoot()));
assertFalse(reader.loadNextBatch());
}
// without compression
try (ArrowStreamReader reader =
new ArrowStreamReader(new ByteArrayReadableSeekableByteChannel(out.toByteArray()), allocator,
NoCompressionCodec.Factory.INSTANCE)) {
Exception exception = Assert.assertThrows(IllegalArgumentException.class,
Exception exception = assertThrows(IllegalArgumentException.class,
reader::loadNextBatch);
Assertions.assertEquals("Please add arrow-compression module to use CommonsCompressionFactory for ZSTD",
assertEquals("Please add arrow-compression module to use CommonsCompressionFactory for ZSTD",
exception.getMessage());
}
dictionaryVector.close();
Expand Down
Loading