-
Notifications
You must be signed in to change notification settings - Fork 210
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
Filesource compression support #5255
base: main
Are you sure you want to change the base?
Changes from all commits
adce15c
18d92c6
44c7a5f
85e11f2
a551151
710dd13
4684124
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,13 +18,16 @@ | |
import org.opensearch.dataprepper.event.TestEventFactory; | ||
import org.opensearch.dataprepper.metrics.PluginMetrics; | ||
import org.opensearch.dataprepper.model.buffer.Buffer; | ||
import org.opensearch.dataprepper.model.codec.DecompressionEngine; | ||
import org.opensearch.dataprepper.model.codec.InputCodec; | ||
import org.opensearch.dataprepper.model.configuration.PluginModel; | ||
import org.opensearch.dataprepper.model.configuration.PluginSetting; | ||
import org.opensearch.dataprepper.model.event.Event; | ||
import org.opensearch.dataprepper.model.event.EventBuilder; | ||
import org.opensearch.dataprepper.model.plugin.PluginFactory; | ||
import org.opensearch.dataprepper.model.record.Record; | ||
import org.opensearch.dataprepper.plugins.buffer.blockingbuffer.BlockingBuffer; | ||
import org.opensearch.dataprepper.plugins.codec.CompressionOption; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
@@ -85,6 +88,31 @@ private FileSource createObjectUnderTest() { | |
return new FileSource(fileSourceConfig, pluginMetrics, pluginFactory, TestEventFactory.getTestEventFactory()); | ||
} | ||
|
||
/** | ||
* Variant of creatgeObjectUnderTest that uses mocks for the configuration instead of object mapper, so we can | ||
* pass concrete mocks to the FileSource through the FileSourceConfig. | ||
* @param codec the codec to use in the configuration | ||
* @param engine the {@link DecompressionEngine} to use in the configuration | ||
* @return | ||
*/ | ||
private FileSource createObjectUnderTest(PluginModel codec, DecompressionEngine engine) { | ||
FileSourceConfig fileSourceConfig = mock(FileSourceConfig.class); | ||
|
||
when(fileSourceConfig.getFilePathToRead()).thenReturn(TEST_FILE_PATH_PLAIN); | ||
|
||
if (codec != null) { | ||
when(fileSourceConfig.getCodec()).thenReturn(codec); | ||
} | ||
|
||
if (engine != null) { | ||
CompressionOption compressionOption = mock(CompressionOption.class); | ||
when(compressionOption.getDecompressionEngine()).thenReturn(engine); | ||
when(fileSourceConfig.getCompression()).thenReturn(compressionOption); | ||
} | ||
|
||
return new FileSource(fileSourceConfig, pluginMetrics, pluginFactory, TestEventFactory.getTestEventFactory()); | ||
} | ||
|
||
@Nested | ||
class WithRecord { | ||
private static final String TEST_PIPELINE_NAME = "pipeline"; | ||
|
@@ -278,6 +306,9 @@ class WithCodec { | |
@Mock | ||
private Buffer buffer; | ||
|
||
@Mock | ||
private DecompressionEngine decompressionEngine; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
Map<String, String> codecConfiguration = Map.of(UUID.randomUUID().toString(), UUID.randomUUID().toString()); | ||
|
@@ -290,21 +321,18 @@ void setUp() { | |
|
||
@Test | ||
void start_will_parse_codec_with_correct_inputStream() throws IOException { | ||
createObjectUnderTest().start(buffer); | ||
final FileInputStream decompressedStream = new FileInputStream(TEST_FILE_PATH_PLAIN); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rewrote the test: previous implementation worked by testing equality between the bytes produced by the source and the bytes produced by reading the file directly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than changing the whole test, could you just mock the Perhaps an alternative is to keep both tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I cannot keep the test as it is: the test relies on the previous implementation's behavior: it tries to read from the input stream created in |
||
DecompressionEngine mockEngine = mock(DecompressionEngine.class); | ||
when(mockEngine.createInputStream(any(InputStream.class))).thenReturn(decompressedStream); | ||
|
||
final ArgumentCaptor<InputStream> inputStreamArgumentCaptor = ArgumentCaptor.forClass(InputStream.class); | ||
PluginModel fakeCodec = mock(PluginModel.class); | ||
when(fakeCodec.getPluginName()).thenReturn("fake_codec"); | ||
when(fakeCodec.getPluginSettings()).thenReturn(Map.of()); | ||
|
||
await().atMost(2, TimeUnit.SECONDS) | ||
.untilAsserted(() -> verify(inputCodec).parse(any(InputStream.class), any(Consumer.class))); | ||
verify(inputCodec).parse(inputStreamArgumentCaptor.capture(), any(Consumer.class)); | ||
|
||
final InputStream actualInputStream = inputStreamArgumentCaptor.getValue(); | ||
createObjectUnderTest(fakeCodec, mockEngine).start(buffer); | ||
|
||
final byte[] actualBytes = actualInputStream.readAllBytes(); | ||
final FileInputStream fileInputStream = new FileInputStream(TEST_FILE_PATH_PLAIN); | ||
final byte[] expectedBytes = fileInputStream.readAllBytes(); | ||
|
||
assertThat(actualBytes, equalTo(expectedBytes)); | ||
await().atMost(2, TimeUnit.SECONDS) | ||
.untilAsserted(() -> verify(inputCodec).parse(eq(decompressedStream), any(Consumer.class))); | ||
} | ||
|
||
@Test | ||
|
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.
Is this a requirement from your company? We don't require contributors to add to this.
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.
Please see if your company requires this. If not, it would be best to remove this change.
In the meantime, I'm also checking with the OpenSearch project to determine if this is an acceptable change or not.
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.
Yes, they asked me to make this change. According to our OSS team, it's how the company can retain the copyright for my contributions as an employee.
I am not sure whether the notice file is the appropriate place to capture this, the information I found after some search tends to say it is not.
I think it is better to get some guidance.