use of com.airbnb.spinaltap.mysql.event.StartEvent in project SpinalTap by airbnb.
the class MysqlMutationMapperTest method testStart.
@Test
public void testStart() throws Exception {
StartEvent event = new StartEvent(0l, 0l, BINLOG_FILE_POS);
List<? extends Mutation> mutations = eventMapper.map(event);
assertTrue(mutations.isEmpty());
verify(tableCache, times(1)).clear();
}
use of com.airbnb.spinaltap.mysql.event.StartEvent in project SpinalTap by airbnb.
the class MysqlSource method toBinlogEvent.
public static BinlogEvent toBinlogEvent(Event event, BinlogFilePos filePos) {
EventHeaderV4 header = event.getHeader();
EventType eventType = header.getEventType();
long serverId = header.getServerId();
long timestamp = header.getTimestamp();
if (EventType.isWrite(eventType)) {
WriteRowsEventData data = event.getData();
return new WriteEvent(data.getTableId(), serverId, timestamp, filePos, data.getRows());
} else if (EventType.isUpdate(eventType)) {
UpdateRowsEventData data = event.getData();
return new UpdateEvent(data.getTableId(), serverId, timestamp, filePos, data.getRows());
} else if (EventType.isDelete(eventType)) {
DeleteRowsEventData data = event.getData();
return new DeleteEvent(data.getTableId(), serverId, timestamp, filePos, data.getRows());
} else {
switch(eventType) {
case TABLE_MAP:
TableMapEventData tableMapData = event.getData();
return new TableMapEvent(tableMapData.getTableId(), serverId, timestamp, filePos, tableMapData.getDatabase(), tableMapData.getTable(), tableMapData.getColumnTypes());
case XID:
XidEventData xidData = event.getData();
return new XidEvent(serverId, timestamp, filePos, xidData.getXid());
case QUERY:
QueryEventData queryData = event.getData();
return new QueryEvent(serverId, timestamp, filePos, queryData.getDatabase(), queryData.getSql());
case FORMAT_DESCRIPTION:
return new StartEvent(serverId, timestamp, filePos);
default:
return null;
}
}
}
use of com.airbnb.spinaltap.mysql.event.StartEvent in project SpinalTap by airbnb.
the class MysqlEventFilterTest method testEventFilter.
@Test
public void testEventFilter() throws Exception {
TableCache tableCache = mock(TableCache.class);
BinlogEvent lastEvent = new XidEvent(0l, 0l, BINLOG_FILE_POS, 0l);
BinlogFilePos nextPosition = new BinlogFilePos("test.123", 15, 100);
SourceState state = new SourceState(0l, lastEvent.getOffset(), 0l, BINLOG_FILE_POS);
Filter<BinlogEvent> filter = MysqlEventFilter.create(tableCache, TABLE_NAMES, new AtomicReference(state));
when(tableCache.contains(TABLE_ID)).thenReturn(true);
assertTrue(filter.apply(new TableMapEvent(TABLE_ID, 0l, 0l, nextPosition, DATABASE_NAME, TABLE_NAME, new byte[1])));
assertTrue(filter.apply(new WriteEvent(TABLE_ID, 0l, 0l, nextPosition, Collections.emptyList())));
assertTrue(filter.apply(new DeleteEvent(TABLE_ID, 0l, 0l, nextPosition, Collections.emptyList())));
assertTrue(filter.apply(new UpdateEvent(TABLE_ID, 0l, 0l, nextPosition, Collections.emptyList())));
assertTrue(filter.apply(new XidEvent(0l, 0l, BINLOG_FILE_POS, 12l)));
assertTrue(filter.apply(new QueryEvent(0l, 0l, BINLOG_FILE_POS, DATABASE_NAME, "")));
assertTrue(filter.apply(new StartEvent(0l, 0l, BINLOG_FILE_POS)));
assertFalse(filter.apply(new TableMapEvent(TABLE_ID, 0l, 0l, BINLOG_FILE_POS, "", "", new byte[1])));
assertFalse(filter.apply(new WriteEvent(0l, 0l, 0l, BINLOG_FILE_POS, Collections.emptyList())));
assertFalse(filter.apply(new WriteEvent(TABLE_ID, 0l, 0l, BINLOG_FILE_POS, Collections.emptyList())));
assertFalse(filter.apply(mock(BinlogEvent.class)));
}
Aggregations