Search in sources :

Example 11 with TargetResName

use of com.qlangtech.tis.coredefine.module.action.TargetResName in project plugins by qlangtech.

the class TestFlinkCDCMongoDBSourceFunction method testStart.

public void testStart() throws Exception {
    FlinkCDCMongoDBSourceFactory mongoDBSourceFactory = this.mock("mongoDBSourceFactory", FlinkCDCMongoDBSourceFactory.class);
    FlinkCDCMongoDBSourceFunction mongoDBSourceFunction = new FlinkCDCMongoDBSourceFunction(mongoDBSourceFactory);
    DataXMongodbReader mongodbReader = new DataXMongodbReader();
    List<ISelectedTab> tabs = Lists.newArrayList();
    IDataxProcessor dataXProcessor = this.mock("dataxProcess", IDataxProcessor.class);
    this.replay();
    TargetResName dataXName = new TargetResName("test");
    mongoDBSourceFunction.start(dataXName, mongodbReader, tabs, dataXProcessor);
    this.verifyAll();
}
Also used : TargetResName(com.qlangtech.tis.coredefine.module.action.TargetResName) DataXMongodbReader(com.qlangtech.tis.plugin.datax.DataXMongodbReader) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor)

Example 12 with TargetResName

use of com.qlangtech.tis.coredefine.module.action.TargetResName in project plugins by qlangtech.

the class TestDefaultIncrK8sConfig method testlistPodsAndWatchLog.

// public void testDefaultIncrK8sConfig() throws Exception {
// DefaultIncrK8sConfig incrK8sCfg = new DefaultIncrK8sConfig();
// incrK8sCfg.namespace = "tis";
// incrK8sCfg.k8sName = "minikube";
// incrK8sCfg.imagePath = "registry.cn-hangzhou.aliyuncs.com/tis/tis-incr:latest";
// 
// incrK8sCfg.getIncrSync().removeInstance("search4totalpay");
// }
public void testlistPodsAndWatchLog() throws Exception {
    IRCController incrSync = getIncrSync();
    String podName = "podname";
    assertNotNull(incrSync);
    final AtomicInteger msgReceiveCount = new AtomicInteger();
    incrSync.listPodAndWatchLog(new TargetResName(totalpay), podName, new ILogListener() {

        @Override
        public void sendMsg2Client(Object biz) throws IOException {
            System.out.println("flushCount:" + msgReceiveCount.incrementAndGet());
        }

        @Override
        public void read(Object event) {
        }

        @Override
        public boolean isClosed() {
            return false;
        }
    });
    Thread.sleep(5000);
    assertTrue(msgReceiveCount.get() > 0);
}
Also used : TargetResName(com.qlangtech.tis.coredefine.module.action.TargetResName) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IRCController(com.qlangtech.tis.coredefine.module.action.IRCController) ILogListener(com.qlangtech.tis.trigger.jst.ILogListener) IOException(java.io.IOException)

Example 13 with TargetResName

use of com.qlangtech.tis.coredefine.module.action.TargetResName in project plugins by qlangtech.

the class TestK8sIncrSync method testLaunchIncrProcess.

public void testLaunchIncrProcess() throws Exception {
    IRCController incrSync = TestDefaultIncrK8sConfig.getIncrSync();
    incrSync.relaunch(new TargetResName(Config.S4TOTALPAY));
}
Also used : TargetResName(com.qlangtech.tis.coredefine.module.action.TargetResName) IRCController(com.qlangtech.tis.coredefine.module.action.IRCController)

Example 14 with TargetResName

use of com.qlangtech.tis.coredefine.module.action.TargetResName in project plugins by qlangtech.

the class TestK8sIncrSync method testDeleteDeployment.

public void testDeleteDeployment() throws Exception {
    IRCController incrSync = TestDefaultIncrK8sConfig.getIncrSync();
    incrSync.removeInstance(new TargetResName(Config.S4TOTALPAY));
}
Also used : TargetResName(com.qlangtech.tis.coredefine.module.action.TargetResName) IRCController(com.qlangtech.tis.coredefine.module.action.IRCController)

Example 15 with TargetResName

use of com.qlangtech.tis.coredefine.module.action.TargetResName 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);
}
Also used : TargetResName(com.qlangtech.tis.coredefine.module.action.TargetResName) CUDCDCTestSuit(com.qlangtech.plugins.incr.flink.cdc.CUDCDCTestSuit) IResultRows(com.qlangtech.plugins.incr.flink.cdc.IResultRows) TIS(com.qlangtech.tis.TIS) RowVals(com.qlangtech.plugins.incr.flink.cdc.RowVals) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) BasicDataSourceFactory(com.qlangtech.tis.plugin.ds.BasicDataSourceFactory) BigDecimal(java.math.BigDecimal) SQLException(java.sql.SQLException) Lists(com.google.common.collect.Lists) CenterResource(com.qlangtech.tis.manage.common.CenterResource) ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TisUTF8(com.qlangtech.tis.manage.common.TisUTF8) TestTableRegisterFlinkSourceHandle(com.qlangtech.plugins.incr.flink.cdc.source.TestTableRegisterFlinkSourceHandle) TestRow(com.qlangtech.plugins.incr.flink.cdc.TestRow) Before(org.junit.Before) MQConsumeException(com.qlangtech.tis.async.message.client.consumer.MQConsumeException) BasicDataXRdbmsReader(com.qlangtech.tis.plugin.datax.common.BasicDataXRdbmsReader) Descriptor(com.qlangtech.tis.extension.Descriptor) Test(org.junit.Test) PreparedStatement(java.sql.PreparedStatement) Collectors(java.util.stream.Collectors) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) TISEasyMock(com.qlangtech.tis.test.TISEasyMock) CloseableIterator(org.apache.flink.util.CloseableIterator) List(java.util.List) RowKind(org.apache.flink.types.RowKind) DataType(com.qlangtech.tis.plugin.ds.DataType) Row(org.apache.flink.types.Row) Assert(org.junit.Assert) IMQListener(com.qlangtech.tis.async.message.client.consumer.IMQListener) Collections(java.util.Collections) InputStream(java.io.InputStream) BasicDataSourceFactory(com.qlangtech.tis.plugin.ds.BasicDataSourceFactory) SQLException(java.sql.SQLException) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) CUDCDCTestSuit(com.qlangtech.plugins.incr.flink.cdc.CUDCDCTestSuit) IResultRows(com.qlangtech.plugins.incr.flink.cdc.IResultRows) IMQListener(com.qlangtech.tis.async.message.client.consumer.IMQListener) TargetResName(com.qlangtech.tis.coredefine.module.action.TargetResName) DataType(com.qlangtech.tis.plugin.ds.DataType) BasicDataXRdbmsReader(com.qlangtech.tis.plugin.datax.common.BasicDataXRdbmsReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TestRow(com.qlangtech.plugins.incr.flink.cdc.TestRow) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) MQConsumeException(com.qlangtech.tis.async.message.client.consumer.MQConsumeException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteArrayInputStream(java.io.ByteArrayInputStream) TestTableRegisterFlinkSourceHandle(com.qlangtech.plugins.incr.flink.cdc.source.TestTableRegisterFlinkSourceHandle) TestRow(com.qlangtech.plugins.incr.flink.cdc.TestRow) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Aggregations

TargetResName (com.qlangtech.tis.coredefine.module.action.TargetResName)19 CUDCDCTestSuit (com.qlangtech.plugins.incr.flink.cdc.CUDCDCTestSuit)5 IRCController (com.qlangtech.tis.coredefine.module.action.IRCController)5 ISelectedTab (com.qlangtech.tis.plugin.ds.ISelectedTab)5 Collectors (java.util.stream.Collectors)5 IMQListener (com.qlangtech.tis.async.message.client.consumer.IMQListener)4 MQConsumeException (com.qlangtech.tis.async.message.client.consumer.MQConsumeException)4 IDataxProcessor (com.qlangtech.tis.datax.IDataxProcessor)4 BasicDataXRdbmsReader (com.qlangtech.tis.plugin.datax.common.BasicDataXRdbmsReader)4 BasicDataSourceFactory (com.qlangtech.tis.plugin.ds.BasicDataSourceFactory)4 List (java.util.List)4 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)4 SourceChannel (com.qlangtech.plugins.incr.flink.cdc.SourceChannel)3 TISDeserializationSchema (com.qlangtech.plugins.incr.flink.cdc.TISDeserializationSchema)3 IAsyncMsgDeserialize (com.qlangtech.tis.async.message.client.consumer.IAsyncMsgDeserialize)3 IConsumerHandle (com.qlangtech.tis.async.message.client.consumer.IConsumerHandle)3 IDataxReader (com.qlangtech.tis.datax.IDataxReader)3 ReaderSource (com.qlangtech.tis.realtime.ReaderSource)3 DTO (com.qlangtech.tis.realtime.transfer.DTO)3 Test (org.junit.Test)3