Search in sources :

Example 1 with PluginExtraProps

use of com.qlangtech.tis.extension.util.PluginExtraProps in project plugins by qlangtech.

the class TestDataxMySQLWriter method testTempateGenerate.

public void testTempateGenerate() throws Exception {
    Optional<PluginExtraProps> extraProps = PluginExtraProps.load(DataxMySQLWriter.class);
    assertTrue("DataxMySQLWriter extraProps shall exist", extraProps.isPresent());
    IPluginContext pluginContext = EasyMock.createMock("pluginContext", IPluginContext.class);
    Context context = EasyMock.createMock("context", Context.class);
    EasyMock.expect(context.hasErrors()).andReturn(false);
    MySQLDataSourceFactory mysqlDs = new MySQLDataSourceFactory() {

        @Override
        public Connection getConnection(String jdbcUrl) throws SQLException {
            return null;
        }
    };
    mysqlDs.dbName = dbWriterName;
    mysqlDs.port = 3306;
    mysqlDs.encode = "utf8";
    mysqlDs.userName = "root";
    mysqlDs.password = "123456";
    mysqlDs.nodeDesc = "192.168.28.200";
    Descriptor.ParseDescribable<DataSourceFactory> desc = new Descriptor.ParseDescribable<>(mysqlDs);
    pluginContext.addDb(desc, dbWriterName, context, true);
    EasyMock.replay(pluginContext, context);
    DataSourceFactoryPluginStore dbStore = TIS.getDataBasePluginStore(new PostedDSProp(dbWriterName));
    assertTrue("save mysql db Config faild", dbStore.setPlugins(pluginContext, Optional.of(context), Collections.singletonList(desc)));
    DataxMySQLWriter mySQLWriter = new DataxMySQLWriter();
    mySQLWriter.dataXName = dataXName;
    mySQLWriter.writeMode = "replace";
    mySQLWriter.dbName = dbWriterName;
    mySQLWriter.template = DataxMySQLWriter.getDftTemplate();
    mySQLWriter.batchSize = 1001;
    mySQLWriter.preSql = "delete from test";
    mySQLWriter.postSql = "delete from test1";
    mySQLWriter.session = "set session sql_mode='ANSI'";
    validateConfigGenerate("mysql-datax-writer-assert.json", mySQLWriter);
    // System.out.println(mySQLWriter.getTemplate());
    // 将非必须输入的值去掉再测试一遍
    mySQLWriter.batchSize = null;
    mySQLWriter.preSql = null;
    mySQLWriter.postSql = null;
    mySQLWriter.session = null;
    validateConfigGenerate("mysql-datax-writer-assert-without-option-val.json", mySQLWriter);
    mySQLWriter.preSql = " ";
    mySQLWriter.postSql = " ";
    mySQLWriter.session = " ";
    validateConfigGenerate("mysql-datax-writer-assert-without-option-val.json", mySQLWriter);
}
Also used : IDataxContext(com.qlangtech.tis.datax.IDataxContext) Context(com.alibaba.citrus.turbine.Context) IPluginContext(com.qlangtech.tis.util.IPluginContext) DataSourceFactory(com.qlangtech.tis.plugin.ds.DataSourceFactory) MySQLDataSourceFactory(com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory) IPluginContext(com.qlangtech.tis.util.IPluginContext) PostedDSProp(com.qlangtech.tis.plugin.ds.PostedDSProp) DataSourceFactoryPluginStore(com.qlangtech.tis.plugin.ds.DataSourceFactoryPluginStore) Descriptor(com.qlangtech.tis.extension.Descriptor) PluginExtraProps(com.qlangtech.tis.extension.util.PluginExtraProps) MySQLDataSourceFactory(com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory)

Example 2 with PluginExtraProps

use of com.qlangtech.tis.extension.util.PluginExtraProps in project plugins by qlangtech.

the class TestDataXDorisWriter method testPluginExtraPropsLoad.

public void testPluginExtraPropsLoad() throws Exception {
    Optional<PluginExtraProps> extraProps = PluginExtraProps.load(DataXDorisWriter.class);
    assertTrue(extraProps.isPresent());
    PluginExtraProps props = extraProps.get();
    PluginExtraProps.Props dbNameProp = props.getProp("dbName");
    assertNotNull(dbNameProp);
    JSONObject creator = dbNameProp.getProps().getJSONObject("creator");
    assertNotNull(creator);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) PluginExtraProps(com.qlangtech.tis.extension.util.PluginExtraProps)

Example 3 with PluginExtraProps

use of com.qlangtech.tis.extension.util.PluginExtraProps in project plugins by qlangtech.

the class TestDataXStarRocksWriter method testPluginExtraPropsLoad.

public void testPluginExtraPropsLoad() throws Exception {
    Optional<PluginExtraProps> extraProps = PluginExtraProps.load(DataXStarRocksWriter.class);
    assertTrue(extraProps.isPresent());
    PluginExtraProps props = extraProps.get();
    PluginExtraProps.Props dbNameProp = props.getProp("dbName");
    assertNotNull(dbNameProp);
    JSONObject creator = dbNameProp.getProps().getJSONObject("creator");
    assertNotNull(creator);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) PluginExtraProps(com.qlangtech.tis.extension.util.PluginExtraProps)

Example 4 with PluginExtraProps

use of com.qlangtech.tis.extension.util.PluginExtraProps in project plugins by qlangtech.

the class TestDataxMySQLReader method testTempateGenerate.

public void testTempateGenerate() throws Exception {
    Optional<PluginExtraProps> extraProps = PluginExtraProps.load(DataxMySQLReader.class);
    assertTrue("DataxMySQLReader extraProps shall exist", extraProps.isPresent());
    // IPluginContext pluginContext = null;
    // IDataxProcessor processor = EasyMock.mock("dataxProcessor", IDataxProcessor.class);
    // IDataxWriter dataxWriter = EasyMock.mock("dataxWriter", IDataxWriter.class);
    // EasyMock.expect(dataxWriter.getSubTask(Optional.empty())).andReturn(null).anyTimes();
    // IDataxGlobalCfg dataxGlobalCfg = EasyMock.mock("dataxGlobalCfg", IDataxGlobalCfg.class);
    // IDataxReaderContext dataxReaderContext = EasyMock.mock("dataxReaderContext", IDataxReaderContext.class);
    // MySQLDataXReaderContext dataxReaderContext = new MySQLDataXReaderContext(tabName + "_0", tabName);
    // dataxReaderContext.jdbcUrl = TestDataxMySQLWriter.mysqlJdbcUrl;
    // dataxReaderContext.tabName = tabName;
    // dataxReaderContext.username = userName;
    // dataxReaderContext.password = password;
    // dataxReaderContext.cols = Lists.newArrayList("col1", "col2", "col3");//tableMetadata.stream().map((t) -> t.getValue()).collect(Collectors.toList());
    // EasyMock.expect(processor.getWriter()).andReturn(dataxWriter).anyTimes();
    // EasyMock.expect(processor.getDataXGlobalCfg()).andReturn(dataxGlobalCfg).anyTimes();
    MySQLDataSourceFactory mysqlDataSource = EasyMock.createMock("mysqlDataSourceFactory", MySQLDataSourceFactory.class);
    EasyMock.expect(mysqlDataSource.getPassword()).andReturn(password).anyTimes();
    EasyMock.expect(mysqlDataSource.getUserName()).andReturn(userName).anyTimes();
    IDataSourceDumper dataDumper = EasyMock.createMock(TestSelectedTabs.tabNameOrderDetail + "TableDumper", IDataSourceDumper.class);
    EasyMock.expect(dataDumper.getDbHost()).andReturn(TestDataxMySQLWriter.mysqlJdbcUrl).times(2);
    // int index, String key, int type, boolean pk
    TISTable targetTable = new TISTable();
    targetTable.setTableName(TestSelectedTabs.tabNameOrderDetail);
    EasyMock.expect(mysqlDataSource.getTableMetadata(TestSelectedTabs.tabNameOrderDetail)).andReturn(TestSelectedTabs.tabColsMetaOrderDetail).anyTimes();
    EasyMock.expect(mysqlDataSource.getDataDumpers(targetTable)).andDelegateTo(new MySQLDataSourceFactory() {

        // @Override
        // protected Connection getConnection(String jdbcUrl, String username, String password) throws SQLException {
        // throw new UnsupportedOperationException();
        // }
        @Override
        public DataDumpers getDataDumpers(TISTable table) {
            return new DataDumpers(1, Collections.singletonList(dataDumper).iterator());
        }
    }).times(// .andReturn(new DataDumpers(1, Collections.singletonList(dataDumper).iterator()));
    2);
    EasyMock.replay(mysqlDataSource, dataDumper);
    DataxMySQLReader mySQLReader = new DataxMySQLReader() {

        @Override
        public MySQLDataSourceFactory getDataSourceFactory() {
            return mysqlDataSource;
        }

        @Override
        public Class<?> getOwnerClass() {
            return DataxMySQLReader.class;
        }
    };
    mySQLReader.dataXName = dataXName;
    mySQLReader.template = DataxMySQLReader.getDftTemplate();
    SelectedTab selectedTab = new SelectedTab();
    selectedTab.setCols(Lists.newArrayList("col2", "col1", "col3"));
    selectedTab.setWhere("delete = 0");
    selectedTab.name = TestSelectedTabs.tabNameOrderDetail;
    mySQLReader.setSelectedTabs(Collections.singletonList(selectedTab));
    // 校验证列和 where条件都设置的情况
    // valiateReaderCfgGenerate("mysql-datax-reader-assert.json", processor, mySQLReader);
    ReaderTemplate.validateDataXReader("mysql-datax-reader-assert.json", dataXName, mySQLReader);
    // selectedTab = new SelectedTab();
    // selectedTab.setCols(Collections.emptyList());
    // selectedTab.name = TestSelectedTabs.tabNameOrderDetail;
    mySQLReader.setSelectedTabs(TestSelectedTabs.createSelectedTabs(1));
    // valiateReaderCfgGenerate("mysql-datax-reader-asser-without-option-val.json"
    // , processor, mySQLReader);
    ReaderTemplate.validateDataXReader("mysql-datax-reader-asser-without-option-val.json", dataXName, mySQLReader);
    EasyMock.verify(mysqlDataSource, dataDumper);
}
Also used : PluginExtraProps(com.qlangtech.tis.extension.util.PluginExtraProps) MySQLDataSourceFactory(com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory)

Aggregations

PluginExtraProps (com.qlangtech.tis.extension.util.PluginExtraProps)4 JSONObject (com.alibaba.fastjson.JSONObject)2 MySQLDataSourceFactory (com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory)2 Context (com.alibaba.citrus.turbine.Context)1 IDataxContext (com.qlangtech.tis.datax.IDataxContext)1 Descriptor (com.qlangtech.tis.extension.Descriptor)1 DataSourceFactory (com.qlangtech.tis.plugin.ds.DataSourceFactory)1 DataSourceFactoryPluginStore (com.qlangtech.tis.plugin.ds.DataSourceFactoryPluginStore)1 PostedDSProp (com.qlangtech.tis.plugin.ds.PostedDSProp)1 IPluginContext (com.qlangtech.tis.util.IPluginContext)1