test case;

This commit is contained in:
zhouhongfa 2019-07-31 20:05:55 +08:00
parent 2fb2d6f343
commit f13daa3c90
2 changed files with 46 additions and 24 deletions

View File

@ -2,9 +2,11 @@ package com.wugui.tool.datax;
import com.google.common.collect.ImmutableList;
import com.wugui.dataxweb.entity.JobJdbcDatasource;
import com.wugui.tool.datax.writer.StreamWriter;
import com.wugui.tool.util.JSONUtils;
import org.junit.Test;
import java.util.List;
import java.util.Map;
public class DataxJsonHelperTest {
@ -32,8 +34,16 @@ public class DataxJsonHelperTest {
@Test
public void buildJob() {
DataxJsonHelper dataxJsonHelper = new DataxJsonHelper();
dataxJsonHelper.initReader(getReaderDatasource(), ImmutableList.of("datax_plugin"), ImmutableList.of("id"));
dataxJsonHelper.initWriter(getWriterDatasource(), ImmutableList.of("datax_plugin"), ImmutableList.of("id"));
//表名
List<String> readerTables = ImmutableList.of("datax_plugin");
List<String> writerTables = ImmutableList.of("datax_plugin");
//抽取的字段
List<String> columns = ImmutableList.of("id");
dataxJsonHelper.initReader(getReaderDatasource(), readerTables, columns);
dataxJsonHelper.initWriter(getWriterDatasource(), writerTables, columns);
Map<String, Object> map = dataxJsonHelper.buildJob();
System.out.println(JSONUtils.formatJson(map));
}
@ -69,4 +79,20 @@ public class DataxJsonHelperTest {
Map<String, Object> writer = dataxJsonHelper.buildWriter();
System.out.println(JSONUtils.formatJson(writer));
}
@Test
public void buildJobWithStreamWriter() {
DataxJsonHelper dataxJsonHelper = new DataxJsonHelper();
dataxJsonHelper.setWriterPlugin(new StreamWriter());
//表名
List<String> readerTables = ImmutableList.of("datax_plugin");
//抽取的字段
List<String> columns = ImmutableList.of("id");
dataxJsonHelper.initReader(getReaderDatasource(), readerTables, columns);
Map<String, Object> map = dataxJsonHelper.buildJob();
System.out.println(JSONUtils.formatJson(map));
}
}

View File

@ -12,37 +12,27 @@ import java.util.Map;
@Slf4j
public class MySQLQueryToolTest {
private BaseQueryTool readQueryTool;
private BaseQueryTool writerQueryTool;
private JobJdbcDatasource readerDatasource;
private JobJdbcDatasource writerDatasource;
private BaseQueryTool queryTool;
private JobJdbcDatasource jdbcDatasource;
@Before
public void before() {
genMysqlDemo();
readQueryTool = QueryToolFactory.getByDbType(readerDatasource);
writerQueryTool = QueryToolFactory.getByDbType(writerDatasource);
queryTool = QueryToolFactory.getByDbType(jdbcDatasource);
}
private void genMysqlDemo() {
readerDatasource = new JobJdbcDatasource();
readerDatasource.setDatasourceName("z01_mysql_3306");
readerDatasource.setJdbcUsername("root");
readerDatasource.setJdbcPassword("root");
readerDatasource.setJdbcUrl("jdbc:mysql://z01:3306/datax_web?serverTimezone=Asia/Shanghai&useLegacyDatetimeCode=false&useSSL=false&nullNamePatternMatchesAll=true&useUnicode=true&characterEncoding=UTF-8");
readerDatasource.setJdbcDriverClass("com.mysql.jdbc.Driver");
writerDatasource = new JobJdbcDatasource();
writerDatasource.setDatasourceName("z01_mysql_3306");
writerDatasource.setJdbcUsername("root");
writerDatasource.setJdbcPassword("root");
writerDatasource.setJdbcUrl("jdbc:mysql://z01:3306/datax_web_demo?serverTimezone=Asia/Shanghai&useLegacyDatetimeCode=false&useSSL=false&nullNamePatternMatchesAll=true&useUnicode=true&characterEncoding=UTF-8");
writerDatasource.setJdbcDriverClass("com.mysql.jdbc.Driver");
jdbcDatasource = new JobJdbcDatasource();
jdbcDatasource.setDatasourceName("z01_mysql_3306");
jdbcDatasource.setJdbcUsername("root");
jdbcDatasource.setJdbcPassword("root");
jdbcDatasource.setJdbcUrl("jdbc:mysql://z01:3306/datax_web?serverTimezone=Asia/Shanghai&useLegacyDatetimeCode=false&useSSL=false&nullNamePatternMatchesAll=true&useUnicode=true&characterEncoding=UTF-8");
jdbcDatasource.setJdbcDriverClass("com.mysql.jdbc.Driver");
}
@Test
public void getTableInfo() {
List<Map<String, Object>> tableInfo = readQueryTool.getTableInfo("datax_plugin");
List<Map<String, Object>> tableInfo = queryTool.getTableInfo("datax_plugin");
tableInfo.forEach(e -> {
log.info(e.toString());
});
@ -50,13 +40,19 @@ public class MySQLQueryToolTest {
@Test
public void buildTableInfo() {
TableInfo tableInfo = readQueryTool.buildTableInfo("datax_plugin");
TableInfo tableInfo = queryTool.buildTableInfo("datax_plugin");
log.info(tableInfo.toString());
}
@Test
public void getTables() {
List<Map<String, Object>> tables = readQueryTool.getTables();
List<Map<String, Object>> tables = queryTool.getTables();
tables.forEach(e -> log.info(e.toString()));
}
@Test
public void getColumns() {
List<String> columns = queryTool.getColumnNames("datax_plugin");
log.info(columns.toString());
}
}