use of com.alibaba.otter.shared.etl.model.EventData in project otter by alibaba.
the class DbLoadMergerTest method makeInsertEventData.
private EventData makeInsertEventData() {
EventData eventData = new EventData();
eventData.setEventType(EventType.INSERT);
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);
List<EventColumn> columns = new ArrayList<EventColumn>();
int i = 0;
for (String columnName : COLUMN_NAMES1) {
columns.add(makeEventColumn(columnName, columnName + i, false));
}
eventData.setColumns(columns);
return eventData;
}
use of com.alibaba.otter.shared.etl.model.EventData in project otter by alibaba.
the class DbLoadMergerTest method testMergeWithUpdateKeyOfUUD.
/**
* 测试在主键发生变化后的merge操作,Update/Update/delete
*/
@Test
public void testMergeWithUpdateKeyOfUUD() {
Map<RowKey, EventData> mergeMap = new MapMaker().makeMap();
DbLoadMerger.merge(makeUpdateEventData(KEY_VALUE_NEW1, KEY_VALUE_NEW2), mergeMap);
DbLoadMerger.merge(makeUpdateEventData(KEY_VALUE_NEW2, KEY_VALUE), 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_NEW1, 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);
}
}
use of com.alibaba.otter.shared.etl.model.EventData in project otter by alibaba.
the class DbLoadMergerTest method testMergeWithUpdateKeyOfUI.
/**
* 测试在主键发生变化后的merge操作,Update/Update/Insert
*/
@Test
public void testMergeWithUpdateKeyOfUI() {
Map<RowKey, EventData> mergeMap = new MapMaker().makeMap();
DbLoadMerger.merge(makeUpdateEventData(KEY_VALUE_NEW1, KEY_VALUE_NEW2), mergeMap);
DbLoadMerger.merge(makeUpdateEventData(KEY_VALUE_NEW2, KEY_VALUE), mergeMap);
DbLoadMerger.merge(makeInsertEventData(), 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.INSERT, eventData.getEventType());
List<EventColumn> oldKeys = eventData.getOldKeys();
List<EventColumn> keys = eventData.getKeys();
Assert.assertNotSame(oldKeys, keys);
}
}
use of com.alibaba.otter.shared.etl.model.EventData in project otter by alibaba.
the class DbLoadMergerTest method testMergeWithSameKeyOfIU.
/**
* 测试insert+update
*/
@Test
public void testMergeWithSameKeyOfIU() {
Map<RowKey, EventData> mergeMap = new MapMaker().makeMap();
DbLoadMerger.merge(makeInsertEventData(), mergeMap);
DbLoadMerger.merge(makeUpdateEventData(), 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.INSERT, eventData.getEventType());
// 不存在oldKeys
Assert.assertEquals(eventData.getOldKeys().size(), 0);
List<EventColumn> columns = eventData.getColumns();
Assert.assertEquals(3, columns.size());
}
}
use of com.alibaba.otter.shared.etl.model.EventData in project otter by alibaba.
the class DbLoadMergerTest method makeUpdateEventData.
private EventData makeUpdateEventData() {
EventData eventData = new EventData();
eventData.setEventType(EventType.UPDATE);
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);
List<EventColumn> columns = new ArrayList<EventColumn>();
int i = 0;
for (String columnName : COLUMN_NAMES2) {
columns.add(makeEventColumn(columnName, columnName + i, false));
i++;
}
eventData.setColumns(columns);
return eventData;
}
Aggregations