-
Notifications
You must be signed in to change notification settings - Fork 31
[FLINK-37950][Connectors/MongoDB] Supporting ordered & bypassdocumentValidation behaviour for sink writer. #58
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -92,6 +92,34 @@ static void tearDown() { | |
| } | ||
| } | ||
|
|
||
| @Test | ||
| void unorderedWrite() throws Exception { | ||
| final String collection = "test-sink-with-unordered-write"; | ||
| final MongoSink<Document> sink = | ||
| createSink(collection, DeliveryGuarantee.AT_LEAST_ONCE, false, true); | ||
| final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); | ||
| env.enableCheckpointing(100L); | ||
| env.setRestartStrategy(RestartStrategies.noRestart()); | ||
|
|
||
| env.fromSequence(1, 5).map(new TestMapFunction()).sinkTo(sink); | ||
| env.execute(); | ||
| assertThatIdsAreWritten(collectionOf(collection), 1, 2, 3, 4, 5); | ||
|
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. The current tests don't fully validate the behavioral difference between ordered and unordered writes. |
||
| } | ||
|
|
||
| @Test | ||
| void bypassDocumentValidation() throws Exception { | ||
|
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. |
||
| final String collection = "test-sink-with-bypass-doc-validation"; | ||
| final MongoSink<Document> sink = | ||
| createSink(collection, DeliveryGuarantee.AT_LEAST_ONCE, true, false); | ||
|
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.
In this test, you are passing |
||
| final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); | ||
| env.enableCheckpointing(100L); | ||
| env.setRestartStrategy(RestartStrategies.noRestart()); | ||
|
|
||
| env.fromSequence(1, 5).map(new TestMapFunction()).sinkTo(sink); | ||
| env.execute(); | ||
| assertThatIdsAreWritten(collectionOf(collection), 1, 2, 3, 4, 5); | ||
|
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 think the current test passes regardless of the flag because the collection has no validation rules. |
||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @EnumSource( | ||
| value = DeliveryGuarantee.class, | ||
|
|
@@ -100,7 +128,7 @@ static void tearDown() { | |
| void testWriteToMongoWithDeliveryGuarantee(DeliveryGuarantee deliveryGuarantee) | ||
| throws Exception { | ||
| final String collection = "test-sink-with-delivery-" + deliveryGuarantee; | ||
| final MongoSink<Document> sink = createSink(collection, deliveryGuarantee); | ||
| final MongoSink<Document> sink = createSink(collection, deliveryGuarantee, true, false); | ||
| final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); | ||
| env.enableCheckpointing(100L); | ||
| env.setRestartStrategy(RestartStrategies.noRestart()); | ||
|
|
@@ -113,7 +141,8 @@ void testWriteToMongoWithDeliveryGuarantee(DeliveryGuarantee deliveryGuarantee) | |
| @Test | ||
| void testRecovery() throws Exception { | ||
| final String collection = "test-recovery-mongo-sink"; | ||
| final MongoSink<Document> sink = createSink(collection, DeliveryGuarantee.AT_LEAST_ONCE); | ||
| final MongoSink<Document> sink = | ||
| createSink(collection, DeliveryGuarantee.AT_LEAST_ONCE, true, false); | ||
|
|
||
| final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); | ||
| env.enableCheckpointing(100L); | ||
|
|
@@ -131,13 +160,18 @@ void testRecovery() throws Exception { | |
| } | ||
|
|
||
| private static MongoSink<Document> createSink( | ||
| String collection, DeliveryGuarantee deliveryGuarantee) { | ||
| String collection, | ||
| DeliveryGuarantee deliveryGuarantee, | ||
| boolean ordered, | ||
| boolean bypassDocumentValidation) { | ||
| return MongoSink.<Document>builder() | ||
| .setUri(MONGO_CONTAINER.getConnectionString()) | ||
| .setDatabase(TEST_DATABASE) | ||
| .setCollection(collection) | ||
| .setBatchSize(5) | ||
| .setDeliveryGuarantee(deliveryGuarantee) | ||
| .setOrderedWrites(ordered) | ||
| .setBypassDocumentValidation(bypassDocumentValidation) | ||
| .setSerializationSchema(new UpsertSerializationSchema()) | ||
| .build(); | ||
| } | ||
|
|
||
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.
nit: The naming style is slightly inconsistent (
unorderedWritevstestRecovery)Maybe it is cleaner to pick one style?