Search in sources :

Example 11 with EventData

use of com.alibaba.otter.shared.etl.model.EventData in project otter by alibaba.

the class DbLoadMergerTest method makeDeleteEventData.

private EventData makeDeleteEventData() {
    EventData eventData = new EventData();
    eventData.setEventType(EventType.DELETE);
    eventData.setSchemaName(SCHEMA_NAME);
    eventData.setTableName(TABLE_NAME);
    eventData.setTableId(TABLE_ID);
    List<EventColumn> keys = new ArrayList<EventColumn>();
    keys.add(makeEventColumn(KEY_NAME, KEY_VALUE, true));
    eventData.setKeys(keys);
    return eventData;
}
Also used : EventColumn(com.alibaba.otter.shared.etl.model.EventColumn) ArrayList(java.util.ArrayList) EventData(com.alibaba.otter.shared.etl.model.EventData)

Example 12 with EventData

use of com.alibaba.otter.shared.etl.model.EventData in project otter by alibaba.

the class DbLoadMergerTest method testMergeWithSameKeyOfIUD.

/**
     * 测试insert+update+delete
     */
@Test
public void testMergeWithSameKeyOfIUD() {
    Map<RowKey, EventData> mergeMap = new MapMaker().makeMap();
    DbLoadMerger.merge(makeInsertEventData(), mergeMap);
    DbLoadMerger.merge(makeUpdateEventData(), mergeMap);
    DbLoadMerger.merge(makeDeleteEventData(), mergeMap);
    for (Entry<RowKey, EventData> entry : mergeMap.entrySet()) {
        RowKey key = entry.getKey();
        EventColumn keyColumn = key.getKeys().get(0);
        Assert.assertEquals(KEY_VALUE, keyColumn.getColumnValue());
        Assert.assertEquals(KEY_NAME, keyColumn.getColumnName());
        EventData eventData = entry.getValue();
        Assert.assertEquals(SCHEMA_NAME, eventData.getSchemaName());
        Assert.assertEquals(TABLE_NAME, eventData.getTableName());
        Assert.assertEquals(TABLE_ID, eventData.getTableId());
        Assert.assertEquals(EventType.DELETE, eventData.getEventType());
        // 不存在oldKeys
        Assert.assertEquals(eventData.getOldKeys().size(), 0);
        List<EventColumn> columns = eventData.getColumns();
        Assert.assertEquals(0, columns.size());
    }
}
Also used : RowKey(com.alibaba.otter.node.etl.load.loader.db.DbLoadMerger.RowKey) EventColumn(com.alibaba.otter.shared.etl.model.EventColumn) MapMaker(com.google.common.collect.MapMaker) EventData(com.alibaba.otter.shared.etl.model.EventData) Test(org.testng.annotations.Test) BaseDbTest(com.alibaba.otter.node.etl.BaseDbTest)

Example 13 with EventData

use of com.alibaba.otter.shared.etl.model.EventData in project otter by alibaba.

the class DbLoadMergerTest method makeUpdateEventData.

private EventData makeUpdateEventData(String oldKeyValue, String newKeyValue) {
    EventData eventData = new EventData();
    eventData.setEventType(EventType.UPDATE);
    eventData.setSchemaName(SCHEMA_NAME);
    eventData.setTableName(TABLE_NAME);
    eventData.setTableId(TABLE_ID);
    List<EventColumn> oldKeys = new ArrayList<EventColumn>();
    oldKeys.add(makeEventColumn(KEY_NAME, oldKeyValue, true));
    List<EventColumn> newKeys = new ArrayList<EventColumn>();
    newKeys.add(makeEventColumn(KEY_NAME, newKeyValue, true));
    eventData.setKeys(newKeys);
    eventData.setOldKeys(oldKeys);
    return eventData;
}
Also used : EventColumn(com.alibaba.otter.shared.etl.model.EventColumn) ArrayList(java.util.ArrayList) EventData(com.alibaba.otter.shared.etl.model.EventData)

Example 14 with EventData

use of com.alibaba.otter.shared.etl.model.EventData in project otter by alibaba.

the class FreedomExtractorTest method test_mysql.

@Test
public void test_mysql() {
    final Pipeline pipeline = new Pipeline();
    pipeline.setId(100L);
    int start = RandomUtils.nextInt();
    int count = 10;
    List<DataMediaPair> pairs = getDataMediaPairForMysql(start, count);
    pipeline.setPairs(pairs);
    new NonStrictExpectations() {

        {
            configClientService.findPipeline(100L);
            returns(pipeline);
        }
    };
    // 构造数据
    RowBatch rowBatch = new RowBatch();
    rowBatch.setIdentity(identity);
    for (int tableId = start; tableId < start + count; tableId++) {
        for (int i = start; i < start + count; i++) {
            EventData eventData = getEventData(tableId, i);
            eventData.setSchemaName("retl");
            eventData.setTableName("retl_buffer");
            rowBatch.merge(eventData);
        }
    }
    DbBatch dbBatch = new DbBatch(rowBatch);
    freedomExtractor.extract(dbBatch);
    want.collection(dbBatch.getRowBatch().getDatas()).sizeEq(count * count);
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) RowBatch(com.alibaba.otter.shared.etl.model.RowBatch) EventData(com.alibaba.otter.shared.etl.model.EventData) DbBatch(com.alibaba.otter.shared.etl.model.DbBatch) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) Test(org.testng.annotations.Test) BaseDbTest(com.alibaba.otter.node.etl.BaseDbTest)

Example 15 with EventData

use of com.alibaba.otter.shared.etl.model.EventData in project otter by alibaba.

the class FreedomExtractorTest method getEventData.

private EventData getEventData(long tableId, int value) {
    EventData eventData = new EventData();
    eventData.setTableId(tableId);
    eventData.setEventType(EventType.INSERT);
    eventData.setExecuteTime(new Date().getTime());
    eventData.setKeys(getPrimary(value));
    eventData.setColumns(getColumn(value));
    return eventData;
}
Also used : EventData(com.alibaba.otter.shared.etl.model.EventData) Date(java.util.Date)

Aggregations

EventData (com.alibaba.otter.shared.etl.model.EventData)48 ArrayList (java.util.ArrayList)20 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)19 EventColumn (com.alibaba.otter.shared.etl.model.EventColumn)18 DataMediaPair (com.alibaba.otter.shared.common.model.config.data.DataMediaPair)16 Test (org.testng.annotations.Test)16 BaseDbTest (com.alibaba.otter.node.etl.BaseDbTest)15 RowBatch (com.alibaba.otter.shared.etl.model.RowBatch)14 Identity (com.alibaba.otter.shared.etl.model.Identity)9 MapMaker (com.google.common.collect.MapMaker)9 RowKey (com.alibaba.otter.node.etl.load.loader.db.DbLoadMerger.RowKey)8 DataMedia (com.alibaba.otter.shared.common.model.config.data.DataMedia)8 DbBatch (com.alibaba.otter.shared.etl.model.DbBatch)7 DbDialect (com.alibaba.otter.node.etl.common.db.dialect.DbDialect)5 ExtractException (com.alibaba.otter.node.etl.extract.exceptions.ExtractException)5 LoadException (com.alibaba.otter.node.etl.load.exception.LoadException)4 FileData (com.alibaba.otter.shared.etl.model.FileData)4 SelectException (com.alibaba.otter.node.etl.select.exceptions.SelectException)3 Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)3 EventType (com.alibaba.otter.shared.etl.model.EventType)3