fapaul commented on a change in pull request #17363: URL: https://github.com/apache/flink/pull/17363#discussion_r718429830
########## File path: flink-connectors/flink-connector-elasticsearch7/src/test/java/org/apache/flink/connector/elasticsearch/sink/ElasticsearchSinkBuilderTest.java ########## @@ -0,0 +1,120 @@ +/* + * 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.base.DeliveryGuarantee; +import org.apache.flink.streaming.connectors.elasticsearch.ElasticsearchSinkBase; +import org.apache.flink.util.TestLogger; + +import org.apache.flink.shaded.guava30.com.google.common.collect.Lists; + +import org.apache.http.HttpHost; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.List; +import java.util.function.Consumer; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** Tests for {@link ElasticsearchSinkBuilder}. */ +class ElasticsearchSinkBuilderTest extends TestLogger { + + @ParameterizedTest + @MethodSource("validBuilders") + void testBuildElasticsearchSink(ElasticsearchSinkBuilder<?> builder) { + builder.build(); + } + + @Test + void testThrowIfExactlyOnceConfigured() { + assertThrows( + IllegalStateException.class, + () -> + new ElasticsearchSinkBuilder<>() + .setDeliveryGuarantee(DeliveryGuarantee.EXACTLY_ONCE)); + } + + @Test + void testThrowIfHostsNotSet() { + assertThrows( + NullPointerException.class, + () -> + new ElasticsearchSinkBuilder<>() + .setProcessor((element, indexer, context) -> {}) + .build()); + } + + @Test + void testThrowIfProcessorNotSet() { + assertThrows( + NullPointerException.class, + () -> + new ElasticsearchSinkBuilder<>() + .setHosts(new HttpHost("localhost:3000")) + .build()); + } + + @ParameterizedTest + @MethodSource("backoffConfigurations") + void testThrowIfBackoffNotEnabledButConfigured( + Consumer<ElasticsearchSinkBuilder<?>> configure) { + final ElasticsearchSinkBuilder<?> builder = + new ElasticsearchSinkBuilder<>() + .setHosts(new HttpHost("localhost:3000")) + .setProcessor((element, indexer, context) -> {}); + configure.accept(builder); + assertThrows(IllegalStateException.class, builder::build); + } + + @ParameterizedTest + @MethodSource("backoffConfigurations") Review comment: Some of the tests became unnecessary and only one simple method source is still used. I would say it is not worth the extra effort to remove it. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
