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.
Adds a new integration test to the S3 sink which can test different s…
…cenarios. This currently is testing against ndjson since this codec generally works. (opensearch-project#3179) Signed-off-by: David Venable <dlv@amazon.com>
- Loading branch information
Showing
9 changed files
with
433 additions
and
2 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
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
19 changes: 19 additions & 0 deletions
19
.../integrationTest/java/org/opensearch/dataprepper/plugins/sink/s3/CompressionScenario.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,19 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.sink.s3; | ||
|
||
import org.opensearch.dataprepper.plugins.sink.s3.compression.CompressionOption; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* A scenario for whole-file compression. | ||
*/ | ||
public interface CompressionScenario { | ||
CompressionOption getCompressionOption(); | ||
InputStream decompressingInputStream(final InputStream inputStream) throws IOException; | ||
} |
24 changes: 24 additions & 0 deletions
24
...egrationTest/java/org/opensearch/dataprepper/plugins/sink/s3/GZipCompressionScenario.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,24 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.sink.s3; | ||
|
||
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; | ||
import org.opensearch.dataprepper.plugins.sink.s3.compression.CompressionOption; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class GZipCompressionScenario implements CompressionScenario { | ||
@Override | ||
public CompressionOption getCompressionOption() { | ||
return CompressionOption.GZIP; | ||
} | ||
|
||
@Override | ||
public InputStream decompressingInputStream(final InputStream inputStream) throws IOException { | ||
return new GzipCompressorInputStream(inputStream); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...integrationTest/java/org/opensearch/dataprepper/plugins/sink/s3/NdjsonOutputScenario.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,52 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.sink.s3; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.opensearch.dataprepper.model.codec.OutputCodec; | ||
import org.opensearch.dataprepper.plugins.codec.json.NdjsonOutputCodec; | ||
import org.opensearch.dataprepper.plugins.codec.json.NdjsonOutputConfig; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Scanner; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class NdjsonOutputScenario implements OutputScenario { | ||
|
||
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); | ||
|
||
@Override | ||
public OutputCodec getCodec() { | ||
return new NdjsonOutputCodec(new NdjsonOutputConfig()); | ||
} | ||
|
||
@Override | ||
public void validate(final List<Map<String, Object>> allEventData, final File actualContentFile) throws IOException { | ||
final FileInputStream fileInputStream = new FileInputStream(actualContentFile); | ||
|
||
final Scanner scanner = new Scanner(fileInputStream); | ||
|
||
int i = 0; | ||
while (scanner.hasNext()) { | ||
final Map<String, Object> expectedData = allEventData.get(i); | ||
|
||
final String actualJsonString = scanner.next(); | ||
|
||
final Map<String, Object> actualData = OBJECT_MAPPER.readValue(actualJsonString, Map.class); | ||
|
||
assertThat(actualData, equalTo(expectedData)); | ||
i++; | ||
} | ||
|
||
assertThat(i, equalTo(allEventData.size())); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...egrationTest/java/org/opensearch/dataprepper/plugins/sink/s3/NoneCompressionScenario.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,23 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.sink.s3; | ||
|
||
import org.opensearch.dataprepper.plugins.sink.s3.compression.CompressionOption; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class NoneCompressionScenario implements CompressionScenario { | ||
@Override | ||
public CompressionOption getCompressionOption() { | ||
return CompressionOption.NONE; | ||
} | ||
|
||
@Override | ||
public InputStream decompressingInputStream(final InputStream inputStream) throws IOException { | ||
return inputStream; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...k/src/integrationTest/java/org/opensearch/dataprepper/plugins/sink/s3/OutputScenario.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,34 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.sink.s3; | ||
|
||
import org.opensearch.dataprepper.model.codec.OutputCodec; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Represents a scenario for the output format. | ||
*/ | ||
public interface OutputScenario { | ||
/** | ||
* Gets the codec this scenario uses. | ||
* | ||
* @return The {@link OutputCodec} | ||
*/ | ||
OutputCodec getCodec(); | ||
|
||
/** | ||
* Validates the data against all the events provided. | ||
* | ||
* @param allEventData The collection of all the expected event maps. | ||
* @param actualContentFile The actual file which has been downloaded and decompressed as part of the test | ||
* @throws IOException Some IOException | ||
*/ | ||
void validate(List<Map<String, Object>> allEventData, File actualContentFile) throws IOException; | ||
} |
Oops, something went wrong.