-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add jdbc connector e2e test #2321
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
3c01da4
add jdbc e2e test
zhangyuge1 96f7667
add jdbc(postgresql) e2e test
zhangyuge1 8f279e2
Merge branch 'apache:dev' into dev
zhangyuge1 27467bd
add pdjdbc license
zhangyuge1 848d829
Merge branch 'apache:dev' into dev
zhangyuge1 9412fab
Merge branch 'dev' of https://github.com/zhangyuge1/incubator-seatunn…
zhangyuge1 c9e6d3b
add pgjdbc license
zhangyuge1 ee90a05
fix vcs.xml
zhangyuge1 de8607a
add checker-qual-3.5.0 license
zhangyuge1 0cb616e
fix dependency issue
zhangyuge1 b5b918b
solve conflicts
zhangyuge1 b436684
add jdbc e2e test
zhangyuge1 cdffad0
add jdbc(postgresql) e2e test
zhangyuge1 f4475f6
add pdjdbc license
zhangyuge1 d1dd054
add pgjdbc license
zhangyuge1 3f00329
fix vcs.xml
zhangyuge1 c8de56c
add checker-qual-3.5.0 license
zhangyuge1 f825524
fix dependency issue
zhangyuge1 65529b2
Merge branch 'dev' of https://github.com/zhangyuge1/incubator-seatunn…
zhangyuge1 d79b640
solve conflict
zhangyuge1 37bbd97
Merge branch 'dev' of https://github.com/zhangyuge1/incubator-seatunn…
zhangyuge1 96a9f7a
upgrade UT to junit to 5.+
zhangyuge1 b0ec5f1
solve conflict
zhangyuge1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Copyright (c) 1997, PostgreSQL Global Development Group | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...ector-v2-e2e/src/test/java/org/apache/seatunnel/e2e/flink/v2/jdbc/FakeSourceToJdbcIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* 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.seatunnel.e2e.flink.v2.jdbc; | ||
|
||
import org.apache.seatunnel.e2e.flink.FlinkContainer; | ||
|
||
import com.google.common.collect.Lists; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.Container; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
import org.testcontainers.lifecycle.Startables; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import java.io.IOException; | ||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
public class FakeSourceToJdbcIT extends FlinkContainer { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(FakeSourceToJdbcIT.class); | ||
private PostgreSQLContainer<?> psl; | ||
|
||
@SuppressWarnings("checkstyle:MagicNumber") | ||
@BeforeEach | ||
public void startPostgreSqlContainer() throws InterruptedException, ClassNotFoundException, SQLException { | ||
psl = new PostgreSQLContainer<>(DockerImageName.parse("postgres:alpine3.16")) | ||
.withNetwork(NETWORK) | ||
.withNetworkAliases("postgresql") | ||
.withLogConsumer(new Slf4jLogConsumer(LOGGER)); | ||
Startables.deepStart(Stream.of(psl)).join(); | ||
LOGGER.info("PostgreSql container started"); | ||
Thread.sleep(5000L); | ||
Class.forName(psl.getDriverClassName()); | ||
initializeJdbcTable(); | ||
} | ||
|
||
private void initializeJdbcTable() { | ||
try (Connection connection = DriverManager.getConnection(psl.getJdbcUrl(), psl.getUsername(), psl.getPassword())) { | ||
Statement statement = connection.createStatement(); | ||
String sql = "CREATE TABLE test (\n" + | ||
" name varchar(255) NOT NULL\n" + | ||
")"; | ||
statement.execute(sql); | ||
} catch (SQLException e) { | ||
throw new RuntimeException("Initializing PostgreSql table failed!", e); | ||
} | ||
} | ||
|
||
@Test | ||
public void testFakeSourceToJdbcSink() throws SQLException, IOException, InterruptedException { | ||
Container.ExecResult execResult = executeSeaTunnelFlinkJob("/jdbc/fakesource_to_jdbc.conf"); | ||
Assertions.assertEquals(0, execResult.getExitCode()); | ||
// query result | ||
String sql = "select * from test"; | ||
try (Connection connection = DriverManager.getConnection(psl.getJdbcUrl(), psl.getUsername(), psl.getPassword())) { | ||
Statement statement = connection.createStatement(); | ||
ResultSet resultSet = statement.executeQuery(sql); | ||
List<String> result = Lists.newArrayList(); | ||
while (resultSet.next()) { | ||
result.add(resultSet.getString("name")); | ||
} | ||
Assertions.assertFalse(result.isEmpty()); | ||
} | ||
} | ||
|
||
@AfterEach | ||
public void closeClickHouseContainer() { | ||
if (psl != null) { | ||
psl.stop(); | ||
} | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
...or-v2-e2e/src/test/java/org/apache/seatunnel/e2e/flink/v2/jdbc/JdbcSourceToConsoleIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* 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.seatunnel.e2e.flink.v2.jdbc; | ||
|
||
import org.apache.seatunnel.e2e.flink.FlinkContainer; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.Container; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
import org.testcontainers.lifecycle.Startables; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import java.io.IOException; | ||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.util.stream.Stream; | ||
|
||
public class JdbcSourceToConsoleIT extends FlinkContainer { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(JdbcSourceToConsoleIT.class); | ||
private PostgreSQLContainer<?> psl; | ||
|
||
@SuppressWarnings("checkstyle:MagicNumber") | ||
@BeforeEach | ||
public void startPostgreSqlContainer() throws InterruptedException, ClassNotFoundException, SQLException { | ||
psl = new PostgreSQLContainer<>(DockerImageName.parse("postgres:alpine3.16")) | ||
.withNetwork(NETWORK) | ||
.withNetworkAliases("postgresql") | ||
.withLogConsumer(new Slf4jLogConsumer(LOGGER)); | ||
Startables.deepStart(Stream.of(psl)).join(); | ||
LOGGER.info("PostgreSql container started"); | ||
Thread.sleep(5000L); | ||
Class.forName(psl.getDriverClassName()); | ||
initializeJdbcTable(); | ||
batchInsertData(); | ||
} | ||
|
||
private void initializeJdbcTable() { | ||
try (Connection connection = DriverManager.getConnection(psl.getJdbcUrl(), psl.getUsername(), psl.getPassword())) { | ||
Statement statement = connection.createStatement(); | ||
String sql = "CREATE TABLE test (\n" + | ||
" name varchar(255) NOT NULL\n" + | ||
")"; | ||
statement.execute(sql); | ||
} catch (SQLException e) { | ||
throw new RuntimeException("Initializing PostgreSql table failed!", e); | ||
} | ||
} | ||
|
||
@SuppressWarnings("checkstyle:MagicNumber") | ||
private void batchInsertData() throws SQLException { | ||
try (Connection connection = DriverManager.getConnection(psl.getJdbcUrl(), psl.getUsername(), psl.getPassword())) { | ||
String sql = "insert into test(name) values(?)"; | ||
connection.setAutoCommit(false); | ||
PreparedStatement preparedStatement = connection.prepareStatement(sql); | ||
for (int i = 0; i < 10; i++) { | ||
preparedStatement.setString(1, "Mike"); | ||
preparedStatement.addBatch(); | ||
} | ||
preparedStatement.executeBatch(); | ||
connection.commit(); | ||
} catch (SQLException e) { | ||
throw new RuntimeException("Batch insert data failed!", e); | ||
} | ||
} | ||
|
||
@Test | ||
public void testFakeSourceToJdbcSink() throws SQLException, IOException, InterruptedException { | ||
Container.ExecResult execResult = executeSeaTunnelFlinkJob("/jdbc/jdbcsource_to_console.conf"); | ||
Assertions.assertEquals(0, execResult.getExitCode()); | ||
} | ||
|
||
@AfterEach | ||
public void closePostgreSqlContainer() { | ||
if (psl != null) { | ||
psl.stop(); | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...nnel-e2e/seatunnel-flink-connector-v2-e2e/src/test/resources/jdbc/fakesource_to_jdbc.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# | ||
# 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. | ||
# | ||
###### | ||
###### This config file is a demonstration of streaming processing in seatunnel config | ||
###### | ||
|
||
env { | ||
# You can set flink configuration here | ||
execution.parallelism = 1 | ||
job.mode = "BATCH" | ||
#execution.checkpoint.interval = 10000 | ||
#execution.checkpoint.data-uri = "hdfs://localhost:9000/checkpoint" | ||
} | ||
|
||
source { | ||
# This is a example source plugin **only for test and demonstrate the feature source plugin** | ||
FakeSource { | ||
result_table_name = "fake" | ||
field_name = "name" | ||
} | ||
|
||
# If you would like to get more information about how to configure seatunnel and see full list of source plugins, | ||
# please go to https://seatunnel.apache.org/docs/flink/configuration/source-plugins/Fake | ||
} | ||
|
||
transform { | ||
sql { | ||
sql = "select name from fake" | ||
} | ||
|
||
# If you would like to get more information about how to configure seatunnel and see full list of transform plugins, | ||
# please go to https://seatunnel.apache.org/docs/flink/configuration/transform-plugins/Sql | ||
} | ||
|
||
sink { | ||
Jdbc { | ||
source_table_name = fake | ||
driver = org.postgresql.Driver | ||
url = "jdbc:postgresql://postgresql:5432/test?loggerLevel=OFF" | ||
user = test | ||
password = test | ||
query = "insert into test(name) values(?)" | ||
} | ||
|
||
# If you would like to get more information about how to configure seatunnel and see full list of sink plugins, | ||
# please go to https://seatunnel.apache.org/docs/flink/configuration/sink-plugins/Console | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Only check is not isEmpty that is not accurate.
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.
Yes, we need to do data quality check.