forked from apache/seatunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88ae428
commit fbbedf2
Showing
5 changed files
with
183 additions
and
48 deletions.
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
...e/connector-tidb-e2e/src/test/java/org/apache/seatunnel/e2e/connector/tidb/TiDBCDCIT.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,113 @@ | ||
/* | ||
* 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.connector.tidb; | ||
|
||
import org.apache.seatunnel.e2e.common.TestResource; | ||
import org.apache.seatunnel.e2e.common.container.TestContainer; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.TestTemplate; | ||
import org.testcontainers.containers.Container; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.awaitility.Awaitility.await; | ||
|
||
@Slf4j | ||
public class TiDBCDCIT extends TiDBTestBase implements TestResource { | ||
private final String SQL_TEMPLATE = "select id,name,description,weight from %s.%s"; | ||
private final String DATABASE_NAME = "inventory"; | ||
private final String SOURCE_TABLE_NAME = "products"; | ||
private final String SINK_TABLE_NAME = "products_sink"; | ||
|
||
@BeforeAll | ||
@Override | ||
public void startUp() throws Exception { | ||
startContainers(); | ||
} | ||
|
||
@TestTemplate | ||
public void testAllEvents(TestContainer container) throws Exception { | ||
Container.ExecResult execResult = container.executeJob("/tidb/tidb_source_to_sink.conf"); | ||
Assertions.assertEquals(0, execResult.getExitCode()); | ||
|
||
try (Connection connection = getJdbcConnection("inventory"); | ||
Statement statement = connection.createStatement()) { | ||
|
||
statement.execute( | ||
"UPDATE products SET description='18oz carpenter hammer' WHERE id=106;"); | ||
statement.execute("UPDATE products SET weight='5.1' WHERE id=107;"); | ||
statement.execute( | ||
"INSERT INTO products VALUES (default,'jacket','water resistent white wind breaker',0.2);"); // 110 | ||
statement.execute( | ||
"INSERT INTO products VALUES (default,'scooter','Big 2-wheel scooter ',5.18);"); | ||
statement.execute( | ||
"UPDATE products SET description='new water resistent white wind breaker', weight='0.5' WHERE id=110;"); | ||
statement.execute("UPDATE products SET weight='5.17' WHERE id=111;"); | ||
statement.execute("DELETE FROM products WHERE id=111;"); | ||
} | ||
|
||
// stream stage | ||
await().atMost(60000, TimeUnit.MILLISECONDS) | ||
.untilAsserted( | ||
() -> { | ||
Assertions.assertIterableEquals( | ||
query(getQuerySQL(DATABASE_NAME, SOURCE_TABLE_NAME)), | ||
query(getQuerySQL(DATABASE_NAME, SINK_TABLE_NAME))); | ||
}); | ||
} | ||
|
||
private List<List<Object>> query(String sql) { | ||
try (Connection connection = getJdbcConnection("inventory")) { | ||
ResultSet resultSet = connection.createStatement().executeQuery(sql); | ||
List<List<Object>> result = new ArrayList<>(); | ||
int columnCount = resultSet.getMetaData().getColumnCount(); | ||
while (resultSet.next()) { | ||
ArrayList<Object> objects = new ArrayList<>(); | ||
for (int i = 1; i <= columnCount; i++) { | ||
objects.add(resultSet.getObject(i)); | ||
} | ||
log.debug(String.format("Print MySQL-CDC query, sql: %s, data: %s", sql, objects)); | ||
result.add(objects); | ||
} | ||
return result; | ||
} catch (SQLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private String getQuerySQL(String database, String tableName) { | ||
return String.format(SQL_TEMPLATE, database, tableName); | ||
} | ||
|
||
@AfterAll | ||
@Override | ||
public void tearDown() throws Exception { | ||
stopContainers(); | ||
} | ||
} |
41 changes: 0 additions & 41 deletions
41
...-e2e/connector-tidb-e2e/src/test/java/org/apache/seatunnel/e2e/connector/tidb/TiDBIT.java
This file was deleted.
Oops, something went wrong.
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
56 changes: 56 additions & 0 deletions
56
...nnel-connector-v2-e2e/connector-tidb-e2e/src/test/resources/tidb/tidb_source_to_sink.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,56 @@ | ||
# | ||
# 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 { | ||
parallelism = 2 | ||
job.mode = "BATCH" | ||
} | ||
|
||
source { | ||
# This is a example source plugin **only for test and demonstrate the feature source plugin** | ||
TDengine { | ||
url: "jdbc:TAOS-RS://flink_e2e_tdengine_src:6041/" | ||
username: "root" | ||
password: "taosdata" | ||
database: "power" | ||
stable: "meters" | ||
lower_bound: "2018-10-03 14:38:05.000" | ||
upper_bound: "2018-10-03 14:38:16.801" | ||
result_table_name = "tdengine_result" | ||
} | ||
# 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/category/source-v2 | ||
} | ||
|
||
transform { | ||
} | ||
|
||
sink { | ||
TDengine { | ||
url: "jdbc:TAOS-RS://flink_e2e_tdengine_sink:6041/" | ||
username: "root" | ||
password: "taosdata" | ||
database: "power2" | ||
stable: "meters2" | ||
timezone: "UTC" | ||
} | ||
# 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/category/sink-v2 | ||
} |