forked from opensearch-project/data-prepper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Krishna Kondaka <[email protected]>
- Loading branch information
Krishna Kondaka
committed
Dec 8, 2023
1 parent
95ce39b
commit 176045c
Showing
2 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
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
71 changes: 71 additions & 0 deletions
71
data-prepper-api/src/test/java/org/opensearch/dataprepper/model/codec/InputCodecTest.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,71 @@ | ||
package org.opensearch.dataprepper.model.codec; | ||
|
||
import org.apache.parquet.io.SeekableInputStream; | ||
import org.junit.jupiter.api.Test; | ||
import org.opensearch.dataprepper.model.event.Event; | ||
import org.opensearch.dataprepper.model.record.Record; | ||
import org.opensearch.dataprepper.model.io.InputFile; | ||
|
||
import java.util.function.Consumer; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.doAnswer; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class InputCodecTest { | ||
private SeekableInputStream inputStream; | ||
private InputFile inputFile; | ||
private DecompressionEngine decompressionEngine; | ||
private boolean closeCalled; | ||
|
||
@Test | ||
void testParse_success() throws Exception { | ||
InputCodec objectUnderTest = new InputCodec() { | ||
@Override | ||
public void parse(InputStream inputStream, Consumer<Record<Event>> eventConsumer) throws IOException { | ||
|
||
} | ||
}; | ||
|
||
inputFile = mock(InputFile.class); | ||
inputStream = mock(SeekableInputStream.class); | ||
decompressionEngine = mock(DecompressionEngine.class); | ||
when(inputFile.newStream()).thenReturn(inputStream); | ||
closeCalled = false; | ||
doAnswer(a -> { | ||
closeCalled = true; | ||
return null; | ||
}).when(inputStream).close(); | ||
when(decompressionEngine.createInputStream(any(InputStream.class))).thenReturn(inputStream); | ||
objectUnderTest.parse(inputFile, decompressionEngine, rec -> {}); | ||
assertTrue(closeCalled); | ||
} | ||
|
||
@Test | ||
void testParse_exception() throws Exception { | ||
InputCodec objectUnderTest = new InputCodec() { | ||
@Override | ||
public void parse(InputStream inputStream, Consumer<Record<Event>> eventConsumer) throws IOException { | ||
throw new RuntimeException("error"); | ||
} | ||
}; | ||
|
||
inputFile = mock(InputFile.class); | ||
inputStream = mock(SeekableInputStream.class); | ||
decompressionEngine = mock(DecompressionEngine.class); | ||
when(inputFile.newStream()).thenReturn(inputStream); | ||
closeCalled = false; | ||
doAnswer(a -> { | ||
closeCalled = true; | ||
return null; | ||
}).when(inputStream).close(); | ||
when(decompressionEngine.createInputStream(any(InputStream.class))).thenReturn(inputStream); | ||
assertThrows(RuntimeException.class, () -> objectUnderTest.parse(inputFile, decompressionEngine, rec -> {})); | ||
assertTrue(closeCalled); | ||
} | ||
} |