-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for [BUG] Data Prepper is losing connections from S3 pool (#3836)
* Fix for [BUG] Data Prepper is losing connections from S3 pool Signed-off-by: Krishna Kondaka <[email protected]> * Addressed review comments Signed-off-by: Krishna Kondaka <[email protected]> * Fixed CheckStyle errors Signed-off-by: Krishna Kondaka <[email protected]> --------- Signed-off-by: Krishna Kondaka <[email protected]> Co-authored-by: Krishna Kondaka <[email protected]>
- Loading branch information
Showing
6 changed files
with
81 additions
and
46 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); | ||
} | ||
} |
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
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