Search in sources :

Example 1 with DataXCfgGenerator

use of com.qlangtech.tis.datax.impl.DataXCfgGenerator in project plugins by qlangtech.

the class TestDataxMySQLWriter method validateConfigGenerate.

private void validateConfigGenerate(String assertFileName, DataxMySQLWriter mySQLWriter) throws IOException {
    // IDataxProcessor.TableMap tm = new IDataxProcessor.TableMap();
    // tm.setFrom("orderinfo");
    // tm.setTo("orderinfo_new");
    // tm.setSourceCols(Lists.newArrayList("col1", "col2", "col3").stream().map((c) -> {
    // ISelectedTab.ColMeta meta = new ISelectedTab.ColMeta();
    // meta.setName(c);
    // return meta;
    // }).collect(Collectors.toList()));
    Optional<IDataxProcessor.TableMap> tableMap = TestSelectedTabs.createTableMapper();
    IDataxContext subTaskCtx = mySQLWriter.getSubTask(tableMap);
    assertNotNull(subTaskCtx);
    RdbmsDataxContext mySQLDataxContext = (RdbmsDataxContext) subTaskCtx;
    assertEquals("\"`col1`\",\"`col2`\",\"`col3`\"", mySQLDataxContext.getColsQuotes());
    assertEquals(mysqlJdbcUrl, mySQLDataxContext.getJdbcUrl());
    assertEquals("123456", mySQLDataxContext.getPassword());
    assertEquals("orderinfo_new", mySQLDataxContext.tabName);
    assertEquals("root", mySQLDataxContext.getUsername());
    IDataxProcessor processor = EasyMock.mock("dataxProcessor", IDataxProcessor.class);
    IDataxGlobalCfg dataxGlobalCfg = EasyMock.mock("dataxGlobalCfg", IDataxGlobalCfg.class);
    IDataxReader dataxReader = EasyMock.mock("dataxReader", IDataxReader.class);
    EasyMock.expect(processor.getReader(null)).andReturn(dataxReader);
    EasyMock.expect(processor.getWriter(null)).andReturn(mySQLWriter);
    EasyMock.expect(processor.getDataXGlobalCfg()).andReturn(dataxGlobalCfg);
    EasyMock.replay(processor, dataxGlobalCfg, dataxReader);
    DataXCfgGenerator dataProcessor = new DataXCfgGenerator(null, "testDataXName", processor) {

        @Override
        public String getTemplateContent() {
            return mySQLWriter.getTemplate();
        }
    };
    String cfgResult = dataProcessor.generateDataxConfig(null, mySQLWriter, dataxReader, tableMap);
    JsonUtil.assertJSONEqual(this.getClass(), assertFileName, cfgResult, (m, e, a) -> {
        assertEquals(m, e, a);
    });
    EasyMock.verify(processor, dataxGlobalCfg, dataxReader);
}
Also used : DataXCfgGenerator(com.qlangtech.tis.datax.impl.DataXCfgGenerator) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) IDataxGlobalCfg(com.qlangtech.tis.datax.IDataxGlobalCfg) IDataxContext(com.qlangtech.tis.datax.IDataxContext) IDataxReader(com.qlangtech.tis.datax.IDataxReader)

Example 2 with DataXCfgGenerator

use of com.qlangtech.tis.datax.impl.DataXCfgGenerator in project plugins by qlangtech.

the class ReaderTemplate method valiateReaderCfgGenerate.

private static void valiateReaderCfgGenerate(String assertFileName, IDataxProcessor processor, DataxReader dataXReader, IDataxWriter dataxWriter, String dataXName) throws IOException {
    IDataxReaderContext dataxReaderContext = null;
    Iterator<IDataxReaderContext> subTasks = dataXReader.getSubTasks();
    int dataxReaderContextCount = 0;
    while (subTasks.hasNext()) {
        dataxReaderContext = subTasks.next();
        dataxReaderContextCount++;
    }
    TestCase.assertEquals(1, dataxReaderContextCount);
    TestCase.assertNotNull(dataxReaderContext);
    DataXCfgGenerator dataProcessor = new DataXCfgGenerator(null, dataXName, processor) {

        @Override
        public String getTemplateContent() {
            return dataXReader.getTemplate();
        }
    };
    String readerCfg = dataProcessor.generateDataxConfig(dataxReaderContext, dataxWriter, dataXReader, Optional.empty());
    TestCase.assertNotNull(readerCfg);
    System.out.println(readerCfg);
    com.qlangtech.tis.trigger.util.JsonUtil.assertJSONEqual(dataXReader.getClass(), assertFileName, readerCfg, (msg, expect, actual) -> {
        Assert.assertEquals(msg, expect, actual);
    });
    JSONObject reader = JSON.parseObject(readerCfg);
    Assert.assertEquals(dataXReader.getDataxMeta().getName(), reader.getString("name"));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) DataXCfgGenerator(com.qlangtech.tis.datax.impl.DataXCfgGenerator)

Example 3 with DataXCfgGenerator

use of com.qlangtech.tis.datax.impl.DataXCfgGenerator in project plugins by qlangtech.

the class WriterTemplate method valiateCfgGenerate.

// public static final Field jarLoaderCenterField;
// 
// static {
// try {
// jarLoaderCenterField = LoadUtil.class.getDeclaredField("jarLoaderCenter");
// jarLoaderCenterField.setAccessible(true);
// } catch (NoSuchFieldException e) {
// throw new RuntimeException("can not get field 'jarLoaderCenter' of LoadUtil", e);
// }
// }
public static void valiateCfgGenerate(String assertFileName, DataxWriter dataXWriter, IDataxProcessor.TableMap tableMap) throws Exception {
    IDataxProcessor processor = EasyMock.mock("dataxProcessor", IDataxProcessor.class);
    IDataxGlobalCfg dataxGlobalCfg = EasyMock.mock("dataxGlobalCfg", IDataxGlobalCfg.class);
    EasyMock.expect(processor.getDataXGlobalCfg()).andReturn(dataxGlobalCfg).anyTimes();
    // EasyMock.expect(processor.getWriter(null)).andReturn(dataXWriter);
    IDataxReader dataXReader = EasyMock.createMock("dataXReader", IDataxReader.class);
    // EasyMock.expect(processor.getReader(null)).andReturn(dataXReader);
    MockDataxReaderContext mockReaderContext = new MockDataxReaderContext();
    EasyMock.replay(processor, dataxGlobalCfg, dataXReader);
    DataXCfgGenerator dataProcessor = new DataXCfgGenerator(null, BasicTest.testDataXName, processor) {

        @Override
        public String getTemplateContent() {
            return dataXWriter.getTemplate();
        }
    };
    String writerCfg = dataProcessor.generateDataxConfig(mockReaderContext, dataXWriter, dataXReader, Optional.ofNullable(tableMap));
    Assert.assertNotNull(writerCfg);
    System.out.println(writerCfg);
    JsonUtil.assertJSONEqual(dataXWriter.getClass(), assertFileName, writerCfg, (message, expected, actual) -> {
        Assert.assertEquals(message, expected, actual);
    });
    JSONObject writer = JSON.parseObject(writerCfg);
    Assert.assertEquals(dataXWriter.getDataxMeta().getName(), writer.getString("name"));
    EasyMock.verify(processor, dataxGlobalCfg, dataXReader);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) DataXCfgGenerator(com.qlangtech.tis.datax.impl.DataXCfgGenerator) MockDataxReaderContext(com.qlangtech.tis.plugin.datax.MockDataxReaderContext)

Example 4 with DataXCfgGenerator

use of com.qlangtech.tis.datax.impl.DataXCfgGenerator in project plugins by qlangtech.

the class TestDataXOssWriter method valiateWriterCfgGenerate.

private void valiateWriterCfgGenerate(String assertFileName, IDataxProcessor processor, DataXOssWriter ossWriter) throws Exception {
    MockDataxReaderContext mockReaderContext = new MockDataxReaderContext();
    DataXCfgGenerator dataProcessor = new DataXCfgGenerator(null, testDataXName, processor) {

        @Override
        public String getTemplateContent() {
            return ossWriter.getTemplate();
        }
    };
    DataXOssReader ossReader = new DataXOssReader();
    String readerCfg = dataProcessor.generateDataxConfig(mockReaderContext, ossWriter, ossReader, Optional.empty());
    assertNotNull(readerCfg);
    System.out.println(readerCfg);
    JsonUtil.assertJSONEqual(this.getClass(), assertFileName, readerCfg, (msg, expect, actual) -> {
        Assert.assertEquals(msg, expect, actual);
    });
}
Also used : DataXCfgGenerator(com.qlangtech.tis.datax.impl.DataXCfgGenerator)

Aggregations

DataXCfgGenerator (com.qlangtech.tis.datax.impl.DataXCfgGenerator)4 JSONObject (com.alibaba.fastjson.JSONObject)2 IDataxContext (com.qlangtech.tis.datax.IDataxContext)1 IDataxGlobalCfg (com.qlangtech.tis.datax.IDataxGlobalCfg)1 IDataxProcessor (com.qlangtech.tis.datax.IDataxProcessor)1 IDataxReader (com.qlangtech.tis.datax.IDataxReader)1 MockDataxReaderContext (com.qlangtech.tis.plugin.datax.MockDataxReaderContext)1