use of com.alibaba.citrus.turbine.Context 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.alibaba.citrus.turbine.Context 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.alibaba.citrus.turbine.Context in project plugins by qlangtech.
the class TestDefaultK8SImage method testHostAliasesValidate.
public void testHostAliasesValidate() {
// https://blog.csdn.net/weixin_47729423/article/details/114288431
DefaultK8SImage k8SImage = new DefaultK8SImage();
DefaultK8SImage.DescriptorImpl descriptor = (DefaultK8SImage.DescriptorImpl) k8SImage.getDescriptor();
assertNotNull("descriptor can not be null", descriptor);
IFieldErrorHandler msgHandler = EasyMock.createMock("msgHandler", IFieldErrorHandler.class);
Context context = EasyMock.createMock("context", Context.class);
String fieldName = "hostAliases";
EasyMock.replay(msgHandler, context);
assertTrue(descriptor.validateHostAliases(msgHandler, context, fieldName, IOUtils.loadResourceFromClasspath(DefaultK8SImage.class, "DefaultK8SImage-hostaliases-content.yaml")));
EasyMock.verify(msgHandler, context);
}
use of com.alibaba.citrus.turbine.Context in project plugins by qlangtech.
the class DataXOssReader method verifyFormOSSRelative.
public static boolean verifyFormOSSRelative(IControlMsgHandler msgHandler, Context context, Descriptor.PostFormVals postFormVals) {
String endpoint = postFormVals.getField(FIELD_ENDPOINT);
String bucket = postFormVals.getField(FIELD_BUCKET);
HttpEndpoint end = ParamsConfig.getItem(endpoint, HttpEndpoint.KEY_DISPLAY_NAME);
try {
OSS ossClient = new OSSClientBuilder().build(end.getEndpoint(), end.getAccessKeyId(), end.getAccessKeySecret());
List<Bucket> buckets = ossClient.listBuckets();
if (buckets.size() < 1) {
msgHandler.addErrorMessage(context, "buckets不能为空");
return false;
}
Optional<Bucket> bucketFind = buckets.stream().filter((b) -> StringUtils.equals(bucket, b.getName())).findFirst();
if (!bucketFind.isPresent()) {
// msgHandler.addErrorMessage(context, );
msgHandler.addFieldError(context, FIELD_BUCKET, "还未创建bucket:" + bucket);
return false;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return true;
}
use of com.alibaba.citrus.turbine.Context in project plugins by qlangtech.
the class TestRockMqPluginValidate method testDigital_Alpha_CharacterValidate.
public void testDigital_Alpha_CharacterValidate() throws Exception {
final DefaultContext context = new DefaultContext();
final Map<String, Object> fieldErrors = context.getContextMap();
validatePluginPostForm("rockmq_plugin_from_invalid.json", context);
List<List<DefaultFieldErrorHandler.FieldError>> /**
* item
*/
itemsErrorList = (List<List<DefaultFieldErrorHandler.FieldError>>) fieldErrors.get(IFieldErrorHandler.ACTION_ERROR_FIELDS);
assertNotNull(itemsErrorList);
assertEquals(1, itemsErrorList.size());
List<DefaultFieldErrorHandler.FieldError> fieldErrors1 = itemsErrorList.get(0);
assertEquals(2, fieldErrors1.size());
Optional<DefaultFieldErrorHandler.FieldError> mqTopicErr = fieldErrors1.stream().filter((r) -> mqTopic.equals(r.getFieldName())).findFirst();
assertTrue(mqTopicErr.isPresent());
assertEquals(ValidatorCommons.MSG_IDENTITY_ERROR, mqTopicErr.get().getMsg());
assertNull(mqTopicErr.get().itemsErrorList);
assertEquals(mqTopic, mqTopicErr.get().getFieldName());
Optional<DefaultFieldErrorHandler.FieldError> deserializeErr = fieldErrors1.stream().filter((r) -> deserialize.equals(r.getFieldName())).findFirst();
assertTrue(deserializeErr.isPresent());
DefaultFieldErrorHandler.FieldError dErr = deserializeErr.get();
assertEquals(deserialize, dErr.getFieldName());
assertNull(dErr.getMsg());
assertNotNull(dErr.itemsErrorList);
assertEquals(1, dErr.itemsErrorList.size());
List<DefaultFieldErrorHandler.FieldError> /**
* item
*/
dValsItem = dErr.itemsErrorList.get(0);
assertEquals(1, dValsItem.size());
DefaultFieldErrorHandler.FieldError testName = dValsItem.get(0);
assertEquals(testProp, testName.getFieldName());
assertEquals("ddd", testName.getMsg());
assertNull(testName.itemsErrorList);
}
Aggregations