schulzp commented on code in PR #83: URL: https://github.com/apache/flink-connector-elasticsearch/pull/83#discussion_r1418486556
########## flink-connector-elasticsearch-base/src/test/java/org/apache/flink/connector/elasticsearch/sink/DefaultBulkResponseInspectorTest.java: ########## @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.connector.elasticsearch.sink; + +import org.apache.flink.connector.elasticsearch.sink.ElasticsearchWriter.DefaultBulkResponseInspector; +import org.apache.flink.util.FlinkRuntimeException; + +import org.assertj.core.api.Assertions; +import org.elasticsearch.action.DocWriteRequest.OpType; +import org.elasticsearch.action.DocWriteResponse; +import org.elasticsearch.action.bulk.BulkItemResponse; +import org.elasticsearch.action.bulk.BulkItemResponse.Failure; +import org.elasticsearch.action.bulk.BulkRequest; +import org.elasticsearch.action.bulk.BulkResponse; +import org.elasticsearch.action.delete.DeleteRequest; +import org.elasticsearch.action.index.IndexRequest; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +public class DefaultBulkResponseInspectorTest { + + @Test + void testPassWithoutFailures() { + final DefaultBulkResponseInspector inspector = new DefaultBulkResponseInspector(); + inspector.inspect(new BulkRequest(), new BulkResponse(new BulkItemResponse[] {}, 0)); + } + + @Test + void testThrowsChainedFailure() { + final DefaultBulkResponseInspector inspector = new DefaultBulkResponseInspector(); + Assertions.assertThatExceptionOfType(FlinkRuntimeException.class) + .isThrownBy( + () -> { + final BulkRequest request = new BulkRequest(); + request.add( + new IndexRequest(), new DeleteRequest(), new DeleteRequest()); + + inspector.inspect( + request, + new BulkResponse( + new BulkItemResponse[] { + new BulkItemResponse( + 0, OpType.CREATE, (DocWriteResponse) null), + new BulkItemResponse( + 1, + OpType.DELETE, + new Failure( + "index", + "type", + "id", + new IOException("A"))), + new BulkItemResponse( + 2, + OpType.DELETE, + new Failure( + "index", + "type", + "id", + new IOException("B"))) + }, + 0)); + }); + } + + @Test + void testPassesDespiteChainedFailure() { + final DefaultBulkResponseInspector inspector = + new DefaultBulkResponseInspector((failure) -> {}); + Assertions.assertThatCode( + () -> { + final BulkRequest request = new BulkRequest(); + request.add( + new IndexRequest(), new DeleteRequest(), new DeleteRequest()); + + inspector.inspect( + request, + new BulkResponse( + new BulkItemResponse[] { + new BulkItemResponse( + 0, OpType.CREATE, (DocWriteResponse) null), + new BulkItemResponse( + 1, + OpType.DELETE, + new Failure( + "index", + "type", + "id", + new IOException("A"))), + new BulkItemResponse( + 2, + OpType.DELETE, + new Failure( + "index", + "type", + "id", + new IOException("B"))) + }, + 0)); + }) + .doesNotThrowAnyException(); + } +} Review Comment: This one is tricky. Since this `setFailureHandler` is part of the `ElasticsearchSinkBuilderBase` the test would have to make sure, that an overridden `failureHandler` is picked up by the default `bulkResponseInspector`. Otherwise, the only way to test that the `failureHandler` is passed on from builder to sink and finally writer would go beyond the scope of `ElasticsearchSinkBuilderBaseTest`. -- 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. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org