Skip to content
Merged
Show file tree
Hide file tree
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 @@ -26,7 +26,6 @@
import java.util.List;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -50,19 +49,19 @@ public void setUp() {
@Test
public void qualifiedPathTest() throws IOException {
Path path = this.command.qualifiedPath(FILE_PATH);
Assert.assertEquals("test.parquet", path.getName());
assertThat(path.getName()).isEqualTo("test.parquet");
}

@Test
public void qualifiedURITest() throws IOException {
URI uri = this.command.qualifiedURI(FILE_PATH);
Assert.assertEquals("/var/tmp/test.parquet", uri.getPath());
assertThat(uri.getPath()).isEqualTo("/var/tmp/test.parquet");
}

@Test
public void qualifiedURIResourceURITest() throws IOException {
URI uri = this.command.qualifiedURI("resource:/a");
Assert.assertEquals("/a", uri.getPath());
assertThat(uri.getPath()).isEqualTo("/a");
}

@Test
Expand Down Expand Up @@ -93,14 +92,14 @@ public void hexToBytesRejectsInvalidHexString() {
public void qualifiedPathTestForWindows() throws IOException {
Assume.assumeTrue(System.getProperty("os.name").toLowerCase().startsWith("win"));
Path path = this.command.qualifiedPath(WIN_FILE_PATH);
Assert.assertEquals("test.parquet", path.getName());
assertThat(path.getName()).isEqualTo("test.parquet");
}

@Test
public void qualifiedURITestForWindows() throws IOException {
Assume.assumeTrue(System.getProperty("os.name").toLowerCase().startsWith("win"));
URI uri = this.command.qualifiedURI(WIN_FILE_PATH);
Assert.assertEquals("/C:/Test/Downloads/test.parquet", uri.getPath());
assertThat(uri.getPath()).isEqualTo("/C:/Test/Downloads/test.parquet");
}

class TestCommand extends BaseCommand {
Expand Down
34 changes: 18 additions & 16 deletions parquet-cli/src/test/java/org/apache/parquet/cli/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@
*/
package org.apache.parquet.cli;

import static org.assertj.core.api.Assertions.assertThatCode;

import java.io.File;
import java.io.FileWriter;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.util.ToolRunner;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.LoggerFactory;

public class MainTest {

@Test
public void mainTest() throws Exception {
ToolRunner.run(new Configuration(), new Main(LoggerFactory.getLogger(MainTest.class)), new String[] {});
Assert.assertTrue("we simply verify there are no errors here", true);
assertThatCode(() -> ToolRunner.run(
new Configuration(), new Main(LoggerFactory.getLogger(MainTest.class)), new String[] {}))
.doesNotThrowAnyException();
}

@Test
Expand All @@ -43,28 +45,28 @@ public void testConfigFileLoading() throws Exception {
writer.write("test.key=test.value\n");
}

try {
new Main(LoggerFactory.getLogger(MainTest.class))
.run(new String[] {"--config-file", configFile.getAbsolutePath(), "help"});
Assert.assertTrue("Config file loading should not throw exception", true);
} catch (IllegalArgumentException e) {
Assert.fail("Config file loading failed: " + e.getMessage());
}
assertThatCode(() -> new Main(LoggerFactory.getLogger(MainTest.class))
.run(new String[] {"--config-file", configFile.getAbsolutePath(), "help"}))
.doesNotThrowAnyException();
}

@Test
public void testLocalPropertiesFile() throws Exception {
String configFile = getClass().getResource("/test-config.properties").getPath();
ToolRunner.run(new Configuration(), new Main(LoggerFactory.getLogger(MainTest.class)), new String[] {
"--config-file", configFile, "version"
});
assertThatCode(() -> ToolRunner.run(
new Configuration(),
new Main(LoggerFactory.getLogger(MainTest.class)),
new String[] {"--config-file", configFile, "version"}))
.doesNotThrowAnyException();
}

@Test
public void testLocalXmlFile() throws Exception {
String configFile = getClass().getResource("/test-config.xml").getPath();
ToolRunner.run(new Configuration(), new Main(LoggerFactory.getLogger(MainTest.class)), new String[] {
"--config-file", configFile, "version"
});
assertThatCode(() -> ToolRunner.run(
new Configuration(),
new Main(LoggerFactory.getLogger(MainTest.class)),
new String[] {"--config-file", configFile, "version"}))
.doesNotThrowAnyException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.parquet.cli.commands;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -47,7 +49,7 @@ protected File toAvro(File inputFile, File outputFile, boolean overwrite, String
command.overwrite = overwrite;
command.setConf(new Configuration());
int exitCode = command.run();
assert (exitCode == 0);
assertThat(exitCode).isZero();
return outputFile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
*/
package org.apache.parquet.cli.commands;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import org.apache.hadoop.conf.Configuration;
import org.junit.Assert;
import org.junit.Test;

public class CSVSchemaCommandTest extends CSVFileTest {
Expand All @@ -33,6 +34,6 @@ public void testCSVSchemaCommand() throws IOException {
command.samplePaths = Arrays.asList(file.getAbsolutePath());
command.recordName = "Test";
command.setConf(new Configuration());
Assert.assertEquals(0, command.run());
assertThat(command.run()).isZero();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.parquet.cli.commands;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.google.protobuf.Message;
Expand All @@ -35,7 +36,6 @@
import org.apache.parquet.schema.MessageType;
import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName;
import org.apache.parquet.schema.Types;
import org.junit.Assert;
import org.junit.Test;

public class CatCommandTest extends ParquetFileTest {
Expand All @@ -45,7 +45,7 @@ public void testCatCommand() throws IOException {
CatCommand command = new CatCommand(createLogger(), 0);
command.sourceFiles = Arrays.asList(file.getAbsolutePath());
command.setConf(new Configuration());
Assert.assertEquals(0, command.run());
assertThat(command.run()).isZero();
}

@Test
Expand All @@ -54,7 +54,7 @@ public void testCatCommandWithMultipleInput() throws IOException {
CatCommand command = new CatCommand(createLogger(), 0);
command.sourceFiles = Arrays.asList(file.getAbsolutePath(), file.getAbsolutePath());
command.setConf(new Configuration());
Assert.assertEquals(0, command.run());
assertThat(command.run()).isZero();
}

@Test
Expand All @@ -64,7 +64,7 @@ public void testCatCommandWithSpecificColumns() throws IOException {
command.sourceFiles = Arrays.asList(file.getAbsolutePath());
command.columns = Arrays.asList(INT32_FIELD, INT64_FIELD);
command.setConf(new Configuration());
Assert.assertEquals(0, command.run());
assertThat(command.run()).isZero();
}

@Test
Expand All @@ -89,7 +89,7 @@ public void testCatCommandProtoParquetAutoDetected() throws Exception {
cmd.setConf(new Configuration());

int result = cmd.run();
Assert.assertEquals(0, result);
assertThat(result).isZero();
}

@Test
Expand All @@ -104,7 +104,7 @@ public void testCatCommandWithSimpleReaderConfig() throws Exception {
cmd.setConf(conf);

int result = cmd.run();
Assert.assertEquals(0, result);
assertThat(result).isZero();
}

@Test
Expand All @@ -117,7 +117,7 @@ public void testCatCommandWithHyphenatedFieldNames() throws Exception {
cmd.setConf(new Configuration());

int result = cmd.run();
Assert.assertEquals(0, result);
assertThat(result).isZero();
}

private static void writeParquetWithHyphenatedFields(File file) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
*/
package org.apache.parquet.cli.commands;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import org.apache.hadoop.conf.Configuration;
import org.junit.Assert;
import org.junit.Test;

public class CheckParquet251CommandTest extends ParquetFileTest {
Expand All @@ -32,6 +33,6 @@ public void testCheckParquet251Command() throws IOException {
CheckParquet251Command command = new CheckParquet251Command(createLogger());
command.files = Arrays.asList(file.getAbsolutePath());
command.setConf(new Configuration());
Assert.assertEquals(0, command.run());
assertThat(command.run()).isZero();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT32;
import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT64;
import static org.apache.parquet.schema.Type.Repetition.REQUIRED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;
Expand All @@ -36,7 +35,6 @@
import org.apache.parquet.hadoop.example.GroupWriteSupport;
import org.apache.parquet.schema.MessageType;
import org.apache.parquet.schema.PrimitiveType;
import org.junit.Assert;
import org.junit.Test;

public class ColumnSizeCommandTest extends ParquetFileTest {
Expand All @@ -51,17 +49,17 @@ public void testColumnSizeCommand() throws IOException {
ColumnSizeCommand command = new ColumnSizeCommand(createLogger());
command.target = file.getAbsolutePath();
command.setConf(new Configuration());
Assert.assertEquals(0, command.run());
assertThat(command.run()).isZero();
}

@Test
public void testColumnSize() throws Exception {
String inputFile = createParquetFile();
Map<String, Long> columnSizeInBytes = command.getColumnSizeInBytes(new Path(inputFile));
assertEquals(columnSizeInBytes.size(), 2);
assertTrue(columnSizeInBytes.get("DocId") > columnSizeInBytes.get("Num"));
assertThat(columnSizeInBytes).hasSize(2);
assertThat(columnSizeInBytes.get("DocId")).isGreaterThan(columnSizeInBytes.get("Num"));
Map<String, Float> columnRatio = command.getColumnRatio(columnSizeInBytes);
assertTrue(columnRatio.get("DocId") > columnRatio.get("Num"));
assertThat(columnRatio.get("DocId")).isGreaterThan(columnRatio.get("Num"));
}

private String createParquetFile() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
*/
package org.apache.parquet.cli.commands;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import org.apache.hadoop.conf.Configuration;
import org.junit.Assert;
import org.junit.Test;

public class ConvertCSVCommandTest extends CSVFileTest {
Expand All @@ -36,8 +36,8 @@ public void testConvertCSVCommand() throws IOException {
File output = new File(getTempFolder(), getClass().getSimpleName() + ".parquet");
command.outputPath = output.getAbsolutePath();
command.setConf(new Configuration());
Assert.assertEquals(0, command.run());
Assert.assertTrue(output.exists());
assertThat(command.run()).isZero();
assertThat(output).exists();
}

@Test
Expand All @@ -48,8 +48,8 @@ public void testConvertCSVCommandWithMultipleInput() throws IOException {
File output = new File(getTempFolder(), getClass().getSimpleName() + ".parquet");
command.outputPath = output.getAbsolutePath();
command.setConf(new Configuration());
Assert.assertEquals(0, command.run());
Assert.assertTrue(output.exists());
assertThat(command.run()).isZero();
assertThat(output).exists();
}

@Test
Expand Down Expand Up @@ -77,7 +77,7 @@ public void testConvertCSVCommandWithGenericConf() throws IOException {
conf.set("parquet.avro.write-parquet-uuid", "true");
conf.set("parquet.avro.write-old-list-structure", "false");
command.setConf(conf);
Assert.assertEquals(0, command.run());
Assert.assertTrue(output.exists());
assertThat(command.run()).isZero();
assertThat(output).exists();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
*/
package org.apache.parquet.cli.commands;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import org.apache.hadoop.conf.Configuration;
import org.junit.Assert;
import org.junit.Test;

public class ConvertCommandTest extends AvroFileTest {
Expand All @@ -34,8 +35,8 @@ public void testConvertCommand() throws IOException {
File output = new File(getTempFolder(), "converted.avro");
command.outputPath = output.getAbsolutePath();
command.setConf(new Configuration());
Assert.assertEquals(0, command.run());
Assert.assertTrue(output.exists());
assertThat(command.run()).isZero();
assertThat(output).exists();
}

@Test
Expand All @@ -51,8 +52,8 @@ public void testConvertCommandWithGenericConf() throws IOException {
conf.set("test.property", "test.value");
command.setConf(conf);

Assert.assertEquals(0, command.run());
Assert.assertTrue(output.exists());
assertThat(command.run()).isZero();
assertThat(output).exists();
}

@Test
Expand All @@ -68,8 +69,8 @@ public void testConvertCommandConfigurationValidation() throws IOException {
conf.set("parquet.avro.write-old-list-structure", "false");
command.setConf(conf);

Assert.assertEquals(0, command.run());
Assert.assertTrue(output.exists());
assertThat(command.run()).isZero();
assertThat(output).exists();

File output2 = new File(getTempFolder(), "converted_with_config_validation2.parquet");
command.outputPath = output2.getAbsolutePath();
Expand All @@ -78,7 +79,7 @@ public void testConvertCommandConfigurationValidation() throws IOException {
conf2.set("parquet.avro.write-old-list-structure", "true");
command.setConf(conf2);

Assert.assertEquals(0, command.run());
Assert.assertTrue(output2.exists());
assertThat(command.run()).isZero();
assertThat(output2).exists();
}
}
Loading
Loading