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);
}
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);
}
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);
}
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);
}
Aggregations