-
Notifications
You must be signed in to change notification settings - Fork 89
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
[vpj] Improve error handling in VeniceVsonFileIterator and add tests #1406
Open
sushantmane
wants to merge
3
commits into
linkedin:main
Choose a base branch
from
sushantmane:fix-npe-in-VeniceVsonFileIterator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 3 additions & 2 deletions
5
clients/da-vinci-client/src/test/java/com/linkedin/davinci/stats/DIVStatsReporterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
...-client/src/test/java/com/linkedin/davinci/store/memory/InMemoryStoragePartitionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
clients/da-vinci-client/src/test/java/com/linkedin/davinci/utils/MapTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 12 additions & 2 deletions
14
...lient/src/test/java/com/linkedin/venice/fastclient/transport/GrpcTransportClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...job/src/test/java/com/linkedin/venice/hadoop/input/kafka/TestKafkaInputKeyComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...job/src/test/java/com/linkedin/venice/hadoop/input/kafka/TestKafkaInputMRPartitioner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...st/java/com/linkedin/venice/hadoop/input/kafka/TestKafkaInputValueGroupingComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...t/java/com/linkedin/venice/hadoop/input/recordreader/vson/VeniceVsonFileIteratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.linkedin.venice.hadoop.input.recordreader.vson; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertFalse; | ||
import static org.testng.Assert.assertNotNull; | ||
import static org.testng.Assert.assertTrue; | ||
import static org.testng.Assert.expectThrows; | ||
|
||
import com.linkedin.venice.exceptions.VeniceException; | ||
import com.linkedin.venice.spark.input.hdfs.TestSparkInputFromHdfs; | ||
import com.linkedin.venice.utils.Utils; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FileSystem; | ||
import org.apache.hadoop.fs.Path; | ||
import org.mockito.Mockito; | ||
import org.testng.annotations.Test; | ||
|
||
|
||
public class VeniceVsonFileIteratorTest { | ||
@Test | ||
public void testConstructorInitializationAndExceptions() throws IOException { | ||
// Setup: Temporary directory and files | ||
File tempDir = Utils.getTempDataDirectory("test-dir"); | ||
File tempSeqFile = File.createTempFile("test-file", ".seq", tempDir); | ||
Path tempSeqFilePath = new Path(tempSeqFile.getAbsolutePath()); | ||
File tempNonSeqFile = File.createTempFile("test-file", ".txt", tempDir); | ||
Path tempNonSeqFilePath = new Path(tempNonSeqFile.getAbsolutePath()); | ||
|
||
FileSystem fileSystem = FileSystem.getLocal(new Configuration()); | ||
VeniceVsonRecordReader mockRecordReader = Mockito.mock(VeniceVsonRecordReader.class); | ||
|
||
// Write valid data to the sequence file | ||
TestSparkInputFromHdfs.writeVsonFile(tempSeqFilePath, 1, 2); | ||
|
||
// Case 1: Valid FileSystem and Path | ||
VeniceVsonFileIterator iterator = new VeniceVsonFileIterator(fileSystem, tempSeqFilePath, mockRecordReader); | ||
assertNotNull(iterator); | ||
|
||
// Case 2: Null FileSystem | ||
Exception exception = | ||
expectThrows(VeniceException.class, () -> new VeniceVsonFileIterator(null, tempSeqFilePath, mockRecordReader)); | ||
assertTrue(exception.getMessage().contains("FileSystem cannot be null")); | ||
|
||
// Case 3: Null Path | ||
Exception exception2 = | ||
expectThrows(VeniceException.class, () -> new VeniceVsonFileIterator(fileSystem, null, mockRecordReader)); | ||
assertTrue(exception2.getMessage().contains("Path cannot be null")); | ||
|
||
// Case 4: Null RecordReader | ||
Exception exception3 = | ||
expectThrows(VeniceException.class, () -> new VeniceVsonFileIterator(fileSystem, tempSeqFilePath, null)); | ||
assertTrue(exception3.getMessage().contains("RecordReader cannot be null")); | ||
|
||
// Case 4: Invalid SequenceFile | ||
expectThrows( | ||
VeniceException.class, | ||
() -> new VeniceVsonFileIterator(fileSystem, tempNonSeqFilePath, mockRecordReader)); | ||
} | ||
|
||
@Test | ||
public void testNextAndGetCurrentKeyValue() throws IOException { | ||
// Setup: Temporary sequence file | ||
File tempDir = Utils.getTempDataDirectory("test-dir"); | ||
File tempSeqFile = File.createTempFile("test-file", ".seq", tempDir); | ||
Path tempSeqFilePath = new Path(tempSeqFile.getAbsolutePath()); | ||
FileSystem fileSystem = FileSystem.getLocal(new Configuration()); | ||
VeniceVsonRecordReader mockRecordReader = Mockito.mock(VeniceVsonRecordReader.class); | ||
|
||
int totalRecords = 5; | ||
// Write valid data to the sequence file | ||
TestSparkInputFromHdfs.writeVsonFile(tempSeqFilePath, 1, totalRecords); | ||
|
||
VeniceVsonFileIterator vsonFileIterator = new VeniceVsonFileIterator(fileSystem, tempSeqFilePath, mockRecordReader); | ||
|
||
// Mock behavior for record reader | ||
when(mockRecordReader.getKeyBytes(any(), any())).thenReturn("mockKey".getBytes()); | ||
when(mockRecordReader.getValueBytes(any(), any())).thenReturn("mockValue".getBytes()); | ||
|
||
byte[] lastKey = null; | ||
byte[] lastValue = null; | ||
|
||
int expectedRecords = totalRecords; | ||
while (vsonFileIterator.next()) { | ||
lastKey = vsonFileIterator.getCurrentKey(); | ||
lastValue = vsonFileIterator.getCurrentValue(); | ||
assertNotNull(lastKey); | ||
assertNotNull(lastValue); | ||
expectedRecords -= 1; | ||
} | ||
assertEquals(expectedRecords, 0); | ||
|
||
// Case 2: No more records (simulate by mocking behavior) | ||
assertFalse(vsonFileIterator.next()); | ||
assertNotNull(lastKey); | ||
assertNotNull(lastValue); | ||
assertEquals(lastKey, vsonFileIterator.getCurrentKey()); | ||
assertEquals(lastValue, vsonFileIterator.getCurrentValue()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...nice-pulsar/src/test/java/com/linkedin/venice/pulsar/sink/VenicePulsarSinkConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
...src/test/java/com/linkedin/venice/pushmonitor/RouterBasedHybridStoreQuotaMonitorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
...rnal/venice-client-common/src/test/java/com/linkedin/venice/compute/ComputeUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
internal/venice-common/src/test/java/com/linkedin/venice/meta/TestStoreJsonSerde.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../test/java/com/linkedin/venice/pubsub/adapter/kafka/admin/ApacheKafkaAdminConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
internal/venice-common/src/test/java/com/linkedin/venice/utils/KafkaSSLUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
...ionTest/java/com/linkedin/venice/fastclient/meta/RequestBasedMetadataIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is the right thing to do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me check how Avro input works. I'm very surprised this didn't fail for the avro inputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does fail for avro input (non sequence file)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? If we can't create
fileReader
what's the point in continuing with the execution? We can add retries (for non-seq file exception) if we want to have additional layer of protection