eskabetxe commented on code in PR #241: URL: https://github.com/apache/flink-connector-jdbc/pull/241#discussion_r4127496880
########## flink-connector-jdbc-core/src/test/java/org/apache/flink/connector/jdbc/internal/JdbcTableOutputFormatTest.java: ########## @@ -1,301 +0,0 @@ -/* - * 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.jdbc.internal; - -import org.apache.flink.api.common.typeinfo.TypeInformation; -import org.apache.flink.connector.jdbc.JdbcDataTestBase; -import org.apache.flink.connector.jdbc.JdbcExecutionOptions; -import org.apache.flink.connector.jdbc.datasource.connections.SimpleJdbcConnectionProvider; -import org.apache.flink.connector.jdbc.internal.executor.JdbcBatchStatementExecutor; -import org.apache.flink.connector.jdbc.internal.options.InternalJdbcConnectionOptions; -import org.apache.flink.connector.jdbc.internal.options.JdbcDmlOptions; -import org.apache.flink.streaming.api.lineage.LineageVertex; -import org.apache.flink.types.Row; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static org.apache.flink.connector.jdbc.JdbcTestFixture.OUTPUT_TABLE; -import static org.apache.flink.connector.jdbc.JdbcTestFixture.TEST_DATA; -import static org.apache.flink.connector.jdbc.JdbcTestFixture.TestEntry; -import static org.assertj.core.api.Assertions.assertThat; - -/** Tests for the {@link JdbcOutputFormat}. */ -public class JdbcTableOutputFormatTest extends JdbcDataTestBase { - - private TableJdbcUpsertOutputFormat format; - private String[] fieldNames; - private String[] keyFields; - - @BeforeEach - void setup() { - fieldNames = new String[] {"id", "title", "author", "price", "qty"}; - keyFields = new String[] {"id"}; - } - - @Test - void testUpsertFormatCloseBeforeOpen() throws Exception { - InternalJdbcConnectionOptions options = - InternalJdbcConnectionOptions.builder() - .setDBUrl(getMetadata().getJdbcUrl()) - .setTableName(OUTPUT_TABLE) - .build(); - JdbcDmlOptions dmlOptions = - JdbcDmlOptions.builder() - .withTableName(options.getTableName()) - .withDialect(options.getDialect()) - .withFieldNames(fieldNames) - .withKeyFields(keyFields) - .build(); - format = - new TableJdbcUpsertOutputFormat( - new SimpleJdbcConnectionProvider(options), - dmlOptions, - JdbcExecutionOptions.defaults()); - // FLINK-17544: There should be no NPE thrown from this method - format.close(); - } - - /** - * Test that the delete executor in {@link TableJdbcUpsertOutputFormat} is updated when {@link - * JdbcOutputFormat#attemptFlush()} fails. - */ - @Test - void testDeleteExecutorUpdatedOnReconnect() throws Exception { Review Comment: This test guards against a regression that is easy to reintroduce, the delete statement not being re-prepared after a reconnect, and the functional successor on the live path, `TableBufferReducedStatementExecutor` (built by `JdbcOutputFormatBuilder.createBufferReduceExecutor`), currently has no direct test for it, even though its `prepareStatements()` does re-prepare the delete executor (TableBufferReducedStatementExecutor.java:54-57). Would you consider porting this test against `TableBufferReducedStatementExecutor` combined with `JdbcOutputFormat.updateExecutor(true)`? That way the regression guard follows the logic onto the live code path rather than disappearing along with the old format class. Not a blocker from my side. this is just a suggestion to preserve the safety net. -- 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]
