use of com.qlangtech.tis.util.IPluginContext in project plugins by qlangtech.
the class TestDataxMySQLReader method testGetSubTasks.
public void testGetSubTasks() {
MySQLDataSourceFactory mysqlDs = new MySQLDataSourceFactory() {
// @Override
// protected Connection getConnection(String jdbcUrl, String username, String password) throws SQLException {
// throw new UnsupportedOperationException();
// }
@Override
public List<ColumnMetaData> getTableMetadata(String table) {
switch(table) {
case TestSelectedTabs.tabNameOrderDetail:
return TestSelectedTabs.tabColsMetaOrderDetail;
case TestSelectedTabs.tabNameTotalpayinfo:
return TestSelectedTabs.tabColsMetaTotalpayinfo;
default:
throw new IllegalArgumentException("table:" + table);
}
}
};
mysqlDs.dbName = dbName;
mysqlDs.port = 3306;
mysqlDs.encode = "utf8";
mysqlDs.userName = userName;
mysqlDs.password = password;
mysqlDs.nodeDesc = "192.168.28.200[0-7]";
Descriptor.ParseDescribable<DataSourceFactory> desc = new Descriptor.ParseDescribable<>(mysqlDs);
Context context = EasyMock.createMock("context", Context.class);
EasyMock.expect(context.hasErrors()).andReturn(false);
IPluginContext pluginContext = EasyMock.createMock("pluginContext", IPluginContext.class);
pluginContext.addDb(desc, dbName, context, true);
EasyMock.replay(pluginContext, context);
DataSourceFactoryPluginStore dbStore = TIS.getDataBasePluginStore(new PostedDSProp(dbName));
assertTrue("save mysql db Config faild", dbStore.setPlugins(pluginContext, Optional.of(context), Collections.singletonList(desc)));
DataxMySQLReader mySQLReader = new DataxMySQLReader() {
@Override
public MySQLDataSourceFactory getDataSourceFactory() {
return mysqlDs;
}
};
mySQLReader.dataXName = this.dataXName;
List<SelectedTab> selectedTabs = TestSelectedTabs.createSelectedTabs();
mySQLReader.setSelectedTabs(selectedTabs);
List<SelectedTab> selectedTabs2 = mySQLReader.getSelectedTabs();
assertEquals(2, selectedTabs2.size());
for (SelectedTab tab : selectedTabs2) {
tab.getCols().forEach((c) -> {
assertNotNull("table:" + tab.getName() + "'s col " + c.getName() + " relevant type can not be null", c.getType());
});
}
List<String> tabs = Lists.newArrayList();
for (SelectedTab tab : selectedTabs) {
for (int i = 0; i < 8; i++) {
tabs.add(tab.name);
}
}
int readerContextCount = 0;
IDataxReaderContext readerContext = null;
IGroupChildTaskIterator subTasks = mySQLReader.getSubTasks();
while (subTasks.hasNext()) {
readerContext = subTasks.next();
assertEquals(tabs.get(readerContextCount), readerContext.getSourceEntityName());
assertEquals(tabs.get(readerContextCount) + "_" + readerContextCount, readerContext.getTaskName());
System.out.println(readerContext.getSourceEntityName() + " " + readerContext.getTaskName());
assertNotNull(readerContext);
readerContextCount++;
}
assertEquals(16, readerContextCount);
Map<String, List<String>> groupedInfo = subTasks.getGroupedInfo();
assertNotNull("groupedInfo can not be null", groupedInfo);
List<String> subTabs = groupedInfo.get(TestSelectedTabs.tabNameOrderDetail);
assertEquals(8, subTabs.size());
subTabs = groupedInfo.get(TestSelectedTabs.tabNameTotalpayinfo);
assertEquals(8, subTabs.size());
EasyMock.verify(pluginContext, context);
}
use of com.qlangtech.tis.util.IPluginContext 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.util.IPluginContext in project tis by qlangtech.
the class DataxReader method createDataXReaderKey.
private static TIS.DataXReaderAppKey createDataXReaderKey(IPluginContext pluginContext, boolean db, String appname) {
return new TIS.DataXReaderAppKey(pluginContext, db, appname, new PluginStore.IPluginProcessCallback<DataxReader>() {
@Override
public void afterDeserialize(final DataxReader reader) {
List<PluginFormProperties> subFieldFormPropertyTypes = reader.getDescriptor().getSubPluginFormPropertyTypes();
if (subFieldFormPropertyTypes.size() > 0) {
// 加载子字段
subFieldFormPropertyTypes.forEach((pt) -> {
pt.accept(new PluginFormProperties.IVisitor() {
@Override
public Void visit(final SuFormProperties props) {
SubFieldFormAppKey<DataxReader> subFieldKey = new SubFieldFormAppKey<>(pluginContext, db, appname, props, DataxReader.class);
KeyedPluginStore<DataxReader> subFieldStore = KeyedPluginStore.getPluginStore(subFieldKey);
// 子表单中的内容更新了之后,要同步父表单中的状态
subFieldStore.addPluginsUpdateListener(new PluginStore.PluginsUpdateListener<DataxReader>(subFieldKey.getSerializeFileName(), reader) {
@Override
public void accept(PluginStore<DataxReader> pluginStore) {
setReaderSubFormProp(props, pluginStore.getPlugin());
}
});
DataxReader subFieldReader = subFieldStore.getPlugin();
if (subFieldReader == null) {
return null;
}
setReaderSubFormProp(props, subFieldReader);
return null;
}
private void setReaderSubFormProp(SuFormProperties props, DataxReader subFieldReader) {
setReaderSubFormProp(props, reader, subFieldReader);
}
private void setReaderSubFormProp(SuFormProperties props, DataxReader reader, DataxReader subFieldReader) {
if (reader == null) {
return;
}
try {
props.subFormField.set(reader, props.subFormField.get(subFieldReader));
} catch (IllegalAccessException e) {
throw new RuntimeException("get subField:" + props.getSubFormFieldName(), e);
}
}
});
});
}
}
});
}
use of com.qlangtech.tis.util.IPluginContext in project tis by qlangtech.
the class DataSourceFactoryPluginStore method setPlugins.
@Override
public synchronized boolean setPlugins(IPluginContext pluginContext, Optional<Context> context, List<Descriptor.ParseDescribable<DataSourceFactory>> dlist, boolean update) {
if (dlist.size() != 1) {
throw new IllegalArgumentException("size of dlist must equal to 1");
}
if (!context.isPresent()) {
throw new IllegalArgumentException("Context shall exist");
}
Context ctx = context.get();
final String dbName = this.key.keyVal.getVal();
if (!super.setPlugins(pluginContext, context, dlist, update)) {
return false;
}
Descriptor.ParseDescribable<DataSourceFactory> dbDesc = dlist.get(0);
pluginContext.addDb(dbDesc, dbName, ctx, (shallUpdateDB && !update));
return !ctx.hasErrors();
}
use of com.qlangtech.tis.util.IPluginContext in project tis by qlangtech.
the class TISSinkFactory method getIncrSinKFactory.
public static TISSinkFactory getIncrSinKFactory(String dataXName) {
IPluginContext pluginContext = IPluginContext.namedContext(dataXName);
List<TISSinkFactory> sinkFactories = sinkFactory.getPlugins(pluginContext, null);
TISSinkFactory sinkFactory = null;
logger.info("sinkFactories size:" + sinkFactories.size());
for (TISSinkFactory factory : sinkFactories) {
sinkFactory = factory;
break;
}
Objects.requireNonNull(sinkFactory, "sinkFactories.size():" + sinkFactories.size());
return sinkFactory;
}
Aggregations