use of com.qlangtech.plugins.incr.flink.cdc.CUDCDCTestSuit in project plugins by qlangtech.
the class TestFlinkCDCMySQLSourceFactory method testBinlogConsumeWithDataStreamRegisterTable.
@Test
public void testBinlogConsumeWithDataStreamRegisterTable() throws Exception {
FlinkCDCMySQLSourceFactory mysqlCDCFactory = new FlinkCDCMySQLSourceFactory();
mysqlCDCFactory.startupOptions = "latest";
final String tabName = "base";
CUDCDCTestSuit cdcTestSuit = new CUDCDCTestSuit() {
@Override
protected BasicDataSourceFactory createDataSourceFactory(TargetResName dataxName) {
return createMySqlDataSourceFactory(dataxName);
}
@Override
protected String getColEscape() {
return "`";
}
@Override
protected IResultRows createConsumerHandle(String tabName) {
return new TestTableRegisterFlinkSourceHandle(tabName, cols);
}
};
cdcTestSuit.startTest(mysqlCDCFactory, tabName);
}
use of com.qlangtech.plugins.incr.flink.cdc.CUDCDCTestSuit in project plugins by qlangtech.
the class TestFlinkCDCMySQLSourceFactory method testBinlogConsume.
@Test
public void testBinlogConsume() throws Exception {
FlinkCDCMySQLSourceFactory mysqlCDCFactory = new FlinkCDCMySQLSourceFactory();
mysqlCDCFactory.startupOptions = "latest";
final String tabName = "base";
CUDCDCTestSuit cdcTestSuit = new CUDCDCTestSuit() {
@Override
protected BasicDataSourceFactory createDataSourceFactory(TargetResName dataxName) {
return createMySqlDataSourceFactory(dataxName);
}
@Override
protected String getColEscape() {
return "`";
}
};
cdcTestSuit.startTest(mysqlCDCFactory, tabName);
}
use of com.qlangtech.plugins.incr.flink.cdc.CUDCDCTestSuit in project plugins by qlangtech.
the class TestTISFlinkCDCOracleSourceFunction method testBinlogConsume.
@Test
public void testBinlogConsume() throws Exception {
FlinkCDCOracleSourceFactory mysqlCDCFactory = new FlinkCDCOracleSourceFactory();
mysqlCDCFactory.startupOptions = "latest";
// debezium
final String tabName = "DEBEZIUM.BASE";
CUDCDCTestSuit cdcTestSuit = new CUDCDCTestSuit() {
@Override
protected BasicDataSourceFactory createDataSourceFactory(TargetResName dataxName) {
return createMySqlDataSourceFactory(dataxName);
}
@Override
protected void startProcessConn(Connection conn) throws SQLException {
conn.setAutoCommit(false);
}
@Override
protected int executePreparedStatement(Connection connection, PreparedStatement statement) throws SQLException {
int count = super.executePreparedStatement(connection, statement);
connection.commit();
return count;
}
@Override
protected int executeStatement(Connection connection, Statement statement, String sql) throws SQLException {
int count = super.executeStatement(connection, statement, sql);
connection.commit();
return count;
}
};
cdcTestSuit.startTest(mysqlCDCFactory, tabName);
}
use of com.qlangtech.plugins.incr.flink.cdc.CUDCDCTestSuit in project plugins by qlangtech.
the class TestFlinkCDCPostgreSQLSourceFunction method testBinlogConsume.
@Test
public void testBinlogConsume() throws Exception {
FlinkCDCPostreSQLSourceFactory pgCDCFactory = new FlinkCDCPostreSQLSourceFactory();
final String tabName = "base";
CUDCDCTestSuit cdcTestSuit = new CUDCDCTestSuit() {
@Override
protected BasicDataSourceFactory createDataSourceFactory(TargetResName dataxName) {
return createPGDataSourceFactory(dataxName);
}
@Override
protected int executePreparedStatement(Connection connection, PreparedStatement statement) throws SQLException {
int updateCount = super.executePreparedStatement(connection, statement);
connection.commit();
return updateCount;
}
@Override
protected String createTableName(String tabName) {
return schemaName + "." + tabName;
}
@Override
protected int executeStatement(Connection connection, java.sql.Statement statement, String sql) throws SQLException {
int updateCount = super.executeStatement(connection, statement, sql);
connection.commit();
return updateCount;
}
@Override
protected void startProcessConn(Connection conn) throws SQLException {
super.startProcessConn(conn);
conn.setAutoCommit(false);
}
};
cdcTestSuit.startTest(pgCDCFactory, tabName);
}
use of com.qlangtech.plugins.incr.flink.cdc.CUDCDCTestSuit in project plugins by qlangtech.
the class TestFlinkCDCMySQLSourceFactory method testBinlogConsumeWithDataStreamRegisterInstaneDetailTable.
/**
* 测试 instancedetail
*
* @throws Exception
*/
@Test
public void testBinlogConsumeWithDataStreamRegisterInstaneDetailTable() throws Exception {
FlinkCDCMySQLSourceFactory mysqlCDCFactory = new FlinkCDCMySQLSourceFactory();
mysqlCDCFactory.startupOptions = "latest";
final String tabName = "instancedetail";
CUDCDCTestSuit cdcTestSuit = new CUDCDCTestSuit() {
@Override
protected BasicDataSourceFactory createDataSourceFactory(TargetResName dataxName) {
return createMySqlDataSourceFactory(dataxName);
}
@Override
protected String getColEscape() {
return "`";
}
@Override
protected IResultRows createConsumerHandle(String tabName) {
return new TestTableRegisterFlinkSourceHandle(tabName, cols);
}
@Override
protected void verfiyTableCrudProcess(String tabName, BasicDataXRdbmsReader dataxReader, ISelectedTab tab, IResultRows consumerHandle, IMQListener<JobExecutionResult> imqListener) throws MQConsumeException, InterruptedException {
// super.verfiyTableCrudProcess(tabName, dataxReader, tab, consumerHandle, imqListener);
List<ISelectedTab> tabs = Collections.singletonList(tab);
List<TestRow> exampleRows = Lists.newArrayList();
exampleRows.add(this.parseTestRow(RowKind.INSERT, TestFlinkCDCMySQLSourceFactory.class, tabName + "/insert1.txt"));
Assert.assertEquals(1, exampleRows.size());
imqListener.start(dataxName, dataxReader, tabs, null);
Thread.sleep(1000);
CloseableIterator<Row> snapshot = consumerHandle.getRowSnapshot(tabName);
BasicDataSourceFactory dataSourceFactory = (BasicDataSourceFactory) dataxReader.getDataSourceFactory();
Assert.assertNotNull("dataSourceFactory can not be null", dataSourceFactory);
dataSourceFactory.visitFirstConnection((conn) -> {
startProcessConn(conn);
for (TestRow t : exampleRows) {
RowVals<Object> vals = t.vals;
final String insertBase = "insert into " + createTableName(tabName) + "(" + cols.stream().filter((c) -> vals.notNull(c.getName())).map((col) -> getColEscape() + col.getName() + getColEscape()).collect(Collectors.joining(" , ")) + ") " + "values(" + cols.stream().filter((c) -> vals.notNull(c.getName())).map((col) -> "?").collect(Collectors.joining(" , ")) + ")";
PreparedStatement statement = conn.prepareStatement(insertBase);
AtomicInteger ci = new AtomicInteger();
cols.stream().filter((c) -> vals.notNull(c.getName())).forEach((col) -> {
col.type.accept(new DataType.TypeVisitor<Void>() {
@Override
public Void longType(DataType type) {
try {
statement.setLong(ci.incrementAndGet(), Long.parseLong(vals.getString(col.getName())));
} catch (SQLException e) {
throw new RuntimeException(e);
}
return null;
}
@Override
public Void doubleType(DataType type) {
try {
statement.setDouble(ci.incrementAndGet(), Double.parseDouble(vals.getString(col.getName())));
} catch (SQLException e) {
throw new RuntimeException(e);
}
return null;
}
@Override
public Void dateType(DataType type) {
try {
statement.setDate(ci.incrementAndGet(), java.sql.Date.valueOf(vals.getString(col.getName())));
} catch (Exception e) {
throw new RuntimeException(e);
}
return null;
}
@Override
public Void timestampType(DataType type) {
try {
statement.setTimestamp(ci.incrementAndGet(), java.sql.Timestamp.valueOf(vals.getString(col.getName())));
} catch (Exception e) {
throw new RuntimeException(e);
}
return null;
}
@Override
public Void bitType(DataType type) {
try {
statement.setByte(ci.incrementAndGet(), Byte.parseByte(vals.getString(col.getName())));
} catch (Exception e) {
throw new RuntimeException(e);
}
return null;
}
@Override
public Void blobType(DataType type) {
try {
try (InputStream input = new ByteArrayInputStream(vals.getString(col.getName()).getBytes(TisUTF8.get()))) {
statement.setBlob(ci.incrementAndGet(), input);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return null;
}
@Override
public Void varcharType(DataType type) {
try {
statement.setString(ci.incrementAndGet(), (vals.getString(col.getName())));
} catch (Exception e) {
throw new RuntimeException(e);
}
return null;
}
@Override
public Void intType(DataType type) {
try {
statement.setInt(ci.incrementAndGet(), Integer.parseInt(vals.getString(col.getName())));
} catch (Exception e) {
throw new RuntimeException(e);
}
return null;
}
@Override
public Void floatType(DataType type) {
try {
statement.setFloat(ci.incrementAndGet(), Float.parseFloat(vals.getString(col.getName())));
} catch (Exception e) {
throw new RuntimeException(e);
}
return null;
}
@Override
public Void decimalType(DataType type) {
try {
statement.setBigDecimal(ci.incrementAndGet(), BigDecimal.valueOf(Double.parseDouble(vals.getString(col.getName()))));
} catch (Exception e) {
throw new RuntimeException(e);
}
return null;
}
@Override
public Void timeType(DataType type) {
try {
statement.setTime(ci.incrementAndGet(), java.sql.Time.valueOf(vals.getString(col.getName())));
} catch (Exception e) {
throw new RuntimeException(e);
}
return null;
}
@Override
public Void tinyIntType(DataType dataType) {
try {
statement.setShort(ci.incrementAndGet(), Short.parseShort(vals.getString(col.getName())));
} catch (Exception e) {
throw new RuntimeException(e);
}
return null;
}
@Override
public Void smallIntType(DataType dataType) {
tinyIntType(dataType);
return null;
}
});
});
Assert.assertEquals(1, executePreparedStatement(conn, statement));
statement.close();
sleepForAWhile();
System.out.println("wait to show insert rows");
waitForSnapshotStarted(snapshot);
List<TestRow> rows = fetchRows(snapshot, 1, false);
for (TestRow rr : rows) {
System.out.println("------------" + rr.get("instance_id"));
assertTestRow(tabName, RowKind.INSERT, consumerHandle, t, rr);
}
}
});
}
};
cdcTestSuit.startTest(mysqlCDCFactory, tabName);
}
Aggregations