From 285323e044c54abf0e7c2cdee6f4eeef13563c37 Mon Sep 17 00:00:00 2001 From: Sushant Mane Date: Wed, 18 Dec 2024 19:42:50 -0800 Subject: [PATCH] Add avro test --- .../vson/VeniceVsonFileIteratorTest.java | 14 +++++++++++++- .../spark/input/hdfs/TestSparkInputFromHdfs.java | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clients/venice-push-job/src/test/java/com/linkedin/venice/hadoop/input/recordreader/vson/VeniceVsonFileIteratorTest.java b/clients/venice-push-job/src/test/java/com/linkedin/venice/hadoop/input/recordreader/vson/VeniceVsonFileIteratorTest.java index b76478fb50..63664d33f5 100644 --- a/clients/venice-push-job/src/test/java/com/linkedin/venice/hadoop/input/recordreader/vson/VeniceVsonFileIteratorTest.java +++ b/clients/venice-push-job/src/test/java/com/linkedin/venice/hadoop/input/recordreader/vson/VeniceVsonFileIteratorTest.java @@ -10,6 +10,7 @@ import com.linkedin.venice.exceptions.VeniceException; import com.linkedin.venice.spark.input.hdfs.TestSparkInputFromHdfs; +import com.linkedin.venice.utils.ExceptionUtils; import com.linkedin.venice.utils.Utils; import java.io.File; import java.io.IOException; @@ -56,9 +57,20 @@ public void testConstructorInitializationAndExceptions() throws IOException { assertTrue(exception3.getMessage().contains("RecordReader cannot be null")); // Case 4: Invalid SequenceFile - expectThrows( + Exception exception4 = expectThrows( VeniceException.class, () -> new VeniceVsonFileIterator(fileSystem, tempNonSeqFilePath, mockRecordReader)); + assertTrue(ExceptionUtils.recursiveMessageContains(exception4, "not a SequenceFile")); + + // Create avro file + File tempAvroFile = File.createTempFile("test-file", ".avro", tempDir); + Path tempAvroFilePath = new Path(tempAvroFile.getAbsolutePath()); + TestSparkInputFromHdfs.writeAvroFile(tempDir, tempAvroFilePath.getName(), 1, 2); + + Exception exception5 = expectThrows( + VeniceException.class, + () -> new VeniceVsonFileIterator(fileSystem, tempAvroFilePath, mockRecordReader)); + assertTrue(ExceptionUtils.recursiveMessageContains(exception5, "not a SequenceFile")); } @Test diff --git a/clients/venice-push-job/src/test/java/com/linkedin/venice/spark/input/hdfs/TestSparkInputFromHdfs.java b/clients/venice-push-job/src/test/java/com/linkedin/venice/spark/input/hdfs/TestSparkInputFromHdfs.java index 11a2c63ae9..4fe17daf9c 100644 --- a/clients/venice-push-job/src/test/java/com/linkedin/venice/spark/input/hdfs/TestSparkInputFromHdfs.java +++ b/clients/venice-push-job/src/test/java/com/linkedin/venice/spark/input/hdfs/TestSparkInputFromHdfs.java @@ -257,7 +257,7 @@ private Map getDefaultConfigs(File inputDir) { return config; } - private void writeAvroFile(File inputDir, String fileName, int start, int end) throws IOException { + public static void writeAvroFile(File inputDir, String fileName, int start, int end) throws IOException { File file = new File(inputDir, fileName); DatumWriter datumWriter = new GenericDatumWriter<>(AVRO_FILE_SCHEMA);