KarmaGYZ commented on a change in pull request #12619:
URL: https://github.com/apache/flink/pull/12619#discussion_r439167530
##########
File path:
flink-connectors/flink-connector-elasticsearch-base/src/main/java/org/apache/flink/streaming/connectors/elasticsearch/ElasticsearchSinkFunction.java
##########
@@ -65,6 +65,11 @@
*/
default void open() {}
+ /**
+ * Tear-down method for the function. It is called when the sink closes.
+ */
+ default void close () throws Exception {}
Review comment:
It's a bit weird that the `open` function does not allow to throw an
exception. I admit it is out of the scope of this PR though.
##########
File path:
flink-connectors/flink-connector-elasticsearch-base/src/test/java/org/apache/flink/streaming/connectors/elasticsearch/ElasticsearchSinkBaseTest.java
##########
@@ -412,6 +414,21 @@ public void
testDoesNotWaitForPendingRequestsIfFlushingDisabled() throws Excepti
testHarness.close();
}
+ @Test
+ public void testOpenAndCloseInSinkFunction() throws Exception {
+ @SuppressWarnings("unchecked")
+ ElasticsearchSinkFunction<String> sinkFunction =
(ElasticsearchSinkFunction<String>) mock(ElasticsearchSinkFunction.class);
+ final DummyElasticsearchSink<String> sink = new
DummyElasticsearchSink<>(
+ new HashMap<>(), sinkFunction, new
DummyRetryFailureHandler());
+
+ sink.open(mock(Configuration.class));
+ sink.close();
+
+ verify(sinkFunction, times(1)).open();
+ verify(sinkFunction, times(1)).close();
+ verifyNoMoreInteractions(sinkFunction);
Review comment:
The community tends to avoid `mock` if possible. In this case, I think
we could add `Testing ElasticsearchSinkFunction` or just an anonymous class.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]