Search in sources :

Example 1 with DbDataMedia

use of com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia in project otter by alibaba.

the class LocalFileLoaderActionTest method generatorDataMediaPair.

private List<DataMediaPair> generatorDataMediaPair(int count) {
    List<DataMediaPair> pairs = new ArrayList<DataMediaPair>();
    for (int i = 0; i < count; i++) {
        DataMediaPair pair = new DataMediaPair();
        pair.setId(Long.valueOf(i));
        pair.setPullWeight(Long.valueOf(i));
        pair.setPushWeight(Long.valueOf(i));
        DbDataMedia mysqlMedia = getMysqlMedia();
        mysqlMedia.setId(Long.valueOf(count + 1));
        pair.setSource(mysqlMedia);
        DbDataMedia oracleMedia = getOracleMedia();
        oracleMedia.setId(Long.valueOf(i));
        pair.setTarget(oracleMedia);
        pairs.add(pair);
    }
    return pairs;
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) ArrayList(java.util.ArrayList) DbDataMedia(com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia)

Example 2 with DbDataMedia

use of com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia in project otter by alibaba.

the class OtterTransformerTest method test_rowData_mysql_oracle.

@Test
public void test_rowData_mysql_oracle() {
    final Pipeline pipeline = new Pipeline();
    pipeline.setId(100L);
    List<DataMediaPair> pairs = new ArrayList<DataMediaPair>();
    DataMediaPair pair1 = new DataMediaPair();
    pair1.setId(1L);
    pair1.setPipelineId(pipeline.getId());
    pair1.setPullWeight(1L);
    pair1.setPushWeight(1L);
    DbDataMedia mysqlMedia = getMysqlMedia();
    mysqlMedia.setId(1L);
    pair1.setSource(mysqlMedia);
    DbDataMedia oracleMedia = getOracleMedia();
    pair1.setTarget(oracleMedia);
    pairs.add(pair1);
    pipeline.setPairs(pairs);
    PipelineParameter param = new PipelineParameter();
    param.setSyncMode(SyncMode.ROW);
    pipeline.setParameters(param);
    new NonStrictExpectations() {

        {
            configClientService.findPipeline(anyLong);
            returns(pipeline);
        }
    };
    Identity identity = new Identity();
    identity.setChannelId(100L);
    identity.setPipelineId(100L);
    identity.setProcessId(100L);
    RowBatch rowBatch = new RowBatch();
    rowBatch.setIdentity(identity);
    EventData eventData = new EventData();
    eventData.setTableId(1L);
    eventData.setSchemaName("srf");
    eventData.setTableName("columns");
    eventData.setEventType(EventType.UPDATE);
    eventData.setExecuteTime(100L);
    eventData.getKeys().add(buildColumn("id", Types.INTEGER, "1", true, false));
    eventData.getKeys().add(buildColumn("name", Types.VARCHAR, "ljh", true, false));
    eventData.getColumns().add(buildColumn("alias_name", Types.CHAR, "hello", false, false));
    eventData.getColumns().add(buildColumn("amount", Types.DECIMAL, "100.01", false, false));
    eventData.getColumns().add(buildColumn("text_b", Types.BLOB, "[116,101,120,116,95,98]", false, false));
    eventData.getColumns().add(buildColumn("text_c", Types.CLOB, "text_c", false, false));
    eventData.getColumns().add(buildColumn("curr_date", Types.DATE, "2011-01-01", false, false));
    eventData.getColumns().add(buildColumn("gmt_create", Types.TIMESTAMP, "2011-01-01 11:11:11", false, false));
    eventData.getColumns().add(buildColumn("gmt_modify", Types.TIMESTAMP, "2011-01-01 11:11:11", false, false));
    rowBatch.merge(eventData);
    Map<Class, BatchObject> batchs = otterTransformFactory.transform(rowBatch);
    RowBatch result = (RowBatch) batchs.get(EventData.class);
    want.number(result.getDatas().size()).isEqualTo(1);
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) ArrayList(java.util.ArrayList) EventData(com.alibaba.otter.shared.etl.model.EventData) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) RowBatch(com.alibaba.otter.shared.etl.model.RowBatch) BatchObject(com.alibaba.otter.shared.etl.model.BatchObject) PipelineParameter(com.alibaba.otter.shared.common.model.config.pipeline.PipelineParameter) Identity(com.alibaba.otter.shared.etl.model.Identity) DbDataMedia(com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia) Test(org.testng.annotations.Test) BaseDbTest(com.alibaba.otter.node.etl.BaseDbTest)

Example 3 with DbDataMedia

use of com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia in project otter by alibaba.

the class OtterTransformerTest method test_fileData.

@Test
public void test_fileData() {
    final Pipeline pipeline = new Pipeline();
    pipeline.setId(100L);
    List<DataMediaPair> pairs = new ArrayList<DataMediaPair>();
    DataMediaPair pair1 = new DataMediaPair();
    pair1.setId(1L);
    pair1.setPipelineId(pipeline.getId());
    pair1.setPullWeight(1L);
    pair1.setPushWeight(1L);
    DbDataMedia oracleMedia = getOracleMedia();
    oracleMedia.setId(1L);
    pair1.setSource(oracleMedia);
    DbDataMedia mysqlMedia = getMysqlMedia();
    pair1.setTarget(mysqlMedia);
    pairs.add(pair1);
    pipeline.setPairs(pairs);
    new NonStrictExpectations() {

        {
            configClientService.findPipeline(anyLong);
            returns(pipeline);
        }
    };
    Identity identity = new Identity();
    identity.setChannelId(100L);
    identity.setPipelineId(100L);
    identity.setProcessId(100L);
    FileBatch fileBatch = new FileBatch();
    fileBatch.setIdentity(identity);
    File localFile = new File("/tmp", "httpPipeTest.jpg");
    FileData localFileData = new FileData();
    localFileData.setTableId(1L);
    localFileData.setPairId(1L);
    localFileData.setPath(localFile.getPath());
    fileBatch.getFiles().add(localFileData);
    Map<Class, BatchObject> batchs = otterTransformFactory.transform(fileBatch);
    FileBatch result = (FileBatch) batchs.get(FileData.class);
    want.number(result.getFiles().size()).isEqualTo(1);
}
Also used : FileBatch(com.alibaba.otter.shared.etl.model.FileBatch) DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) ArrayList(java.util.ArrayList) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) BatchObject(com.alibaba.otter.shared.etl.model.BatchObject) Identity(com.alibaba.otter.shared.etl.model.Identity) DbDataMedia(com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia) File(java.io.File) FileData(com.alibaba.otter.shared.etl.model.FileData) Test(org.testng.annotations.Test) BaseDbTest(com.alibaba.otter.node.etl.BaseDbTest)

Example 4 with DbDataMedia

use of com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia in project otter by alibaba.

the class DatabaseExtractorTest method getDataMediaPairForOracle.

private List<DataMediaPair> getDataMediaPairForOracle(long tableId, int count) {
    List<DataMediaPair> pairs = new ArrayList<DataMediaPair>();
    for (int i = 0; i < count; i++) {
        DataMediaPair pair = new DataMediaPair();
        pair.setId(Long.valueOf(i));
        pair.setPullWeight(1L);
        pair.setPushWeight(1L);
        DbDataMedia oracleMedia = getOracleMedia();
        oracleMedia.setId(tableId + i);
        pair.setSource(oracleMedia);
        DbDataMedia mysqlMedia = getMysqlMedia();
        mysqlMedia.setId(tableId + i + count);
        pair.setTarget(mysqlMedia);
        pairs.add(pair);
    }
    return pairs;
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) ArrayList(java.util.ArrayList) DbDataMedia(com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia)

Example 5 with DbDataMedia

use of com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia in project otter by alibaba.

the class FreedomExtractorTest method getDataMediaPairForMysql.

private List<DataMediaPair> getDataMediaPairForMysql(long tableId, int count) {
    List<DataMediaPair> pairs = new ArrayList<DataMediaPair>();
    for (int i = 0; i < count; i++) {
        DataMediaPair pair = new DataMediaPair();
        pair.setId(Long.valueOf(i));
        pair.setPullWeight(1L);
        pair.setPushWeight(1L);
        DbDataMedia mysqlMedia = getMysqlMedia();
        mysqlMedia.setId(tableId + i);
        pair.setSource(mysqlMedia);
        DbDataMedia oracleMedia = getOracleMedia();
        oracleMedia.setId(tableId + i + count);
        pair.setTarget(oracleMedia);
        pairs.add(pair);
    }
    return pairs;
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) ArrayList(java.util.ArrayList) DbDataMedia(com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia)

Aggregations

DbDataMedia (com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia)17 DataMediaPair (com.alibaba.otter.shared.common.model.config.data.DataMediaPair)10 ArrayList (java.util.ArrayList)10 BaseDbTest (com.alibaba.otter.node.etl.BaseDbTest)8 Test (org.testng.annotations.Test)8 DbDialect (com.alibaba.otter.node.etl.common.db.dialect.DbDialect)5 DbMediaSource (com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource)3 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)3 BatchObject (com.alibaba.otter.shared.etl.model.BatchObject)3 Identity (com.alibaba.otter.shared.etl.model.Identity)3 PreparedStatement (java.sql.PreparedStatement)3 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)3 TransactionStatus (org.springframework.transaction.TransactionStatus)3 TransactionCallback (org.springframework.transaction.support.TransactionCallback)3 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)3 SqlTemplate (com.alibaba.otter.node.etl.common.db.dialect.SqlTemplate)2 PipelineParameter (com.alibaba.otter.shared.common.model.config.pipeline.PipelineParameter)2 EventData (com.alibaba.otter.shared.etl.model.EventData)2 RowBatch (com.alibaba.otter.shared.etl.model.RowBatch)2 Column (org.apache.ddlutils.model.Column)2