Search in sources :

Example 6 with QueryEvent

use of com.airbnb.spinaltap.mysql.event.QueryEvent in project SpinalTap by airbnb.

the class MysqlSchemaTrackerTest method testDropDatabase.

@Test
public void testDropDatabase() throws Exception {
    Table<String, String, TreeMap<Integer, MysqlTableSchema>> allTableSchemaInStore = Tables.newCustomTable(Maps.newHashMap(), Maps::newHashMap);
    allTableSchemaInStore.put(DATABASE_NAME, "table1", new TreeMap<Integer, MysqlTableSchema>() {

        {
            put(1, TABLE1_SCHEMA);
        }
    });
    allTableSchemaInStore.put(DATABASE_NAME, "table2", new TreeMap<Integer, MysqlTableSchema>() {

        {
            put(1, TABLE2_SCHEMA);
        }
    });
    allTableSchemaInStore.put(DATABASE2_NAME, "table1", new TreeMap<Integer, MysqlTableSchema>() {

        {
            put(1, DATABASE2_TABLE1_SCHEMA);
        }
    });
    when(schemaDatabase.listDatabases()).thenReturn(Sets.newHashSet(DATABASE2_NAME));
    when(schemaStore.getAll()).thenReturn(allTableSchemaInStore);
    when(schemaDatabase.fetchTableSchema(DATABASE_NAME)).thenReturn(ImmutableMap.of());
    when(schemaDatabase.fetchTableSchema(DATABASE2_NAME)).thenReturn(ImmutableMap.of("table1", DATABASE2_TABLE1_SCHEMA));
    QueryEvent queryEvent = new QueryEvent(0, 0, binlogFilePos, DATABASE2_NAME, "DROP DATABASE `database1`");
    SchemaTracker schemaTracker = new MysqlSchemaTracker(schemaStore, schemaDatabase);
    schemaTracker.processDDLStatement(queryEvent);
    verify(schemaStore).put(DATABASE_NAME, "table1", queryEvent.getBinlogFilePos(), queryEvent.getTimestamp(), queryEvent.getSql(), Lists.newArrayList());
    verify(schemaStore).put(DATABASE_NAME, "table2", queryEvent.getBinlogFilePos(), queryEvent.getTimestamp(), queryEvent.getSql(), Lists.newArrayList());
}
Also used : Maps(com.google.common.collect.Maps) TreeMap(java.util.TreeMap) QueryEvent(com.airbnb.spinaltap.mysql.event.QueryEvent) Test(org.junit.Test)

Aggregations

QueryEvent (com.airbnb.spinaltap.mysql.event.QueryEvent)6 Test (org.junit.Test)4 Maps (com.google.common.collect.Maps)3 BinlogFilePos (com.airbnb.spinaltap.mysql.BinlogFilePos)2 DeleteEvent (com.airbnb.spinaltap.mysql.event.DeleteEvent)2 StartEvent (com.airbnb.spinaltap.mysql.event.StartEvent)2 TableMapEvent (com.airbnb.spinaltap.mysql.event.TableMapEvent)2 UpdateEvent (com.airbnb.spinaltap.mysql.event.UpdateEvent)2 WriteEvent (com.airbnb.spinaltap.mysql.event.WriteEvent)2 XidEvent (com.airbnb.spinaltap.mysql.event.XidEvent)2 TreeMap (java.util.TreeMap)2 SourceState (com.airbnb.spinaltap.common.source.SourceState)1 TableCache (com.airbnb.spinaltap.mysql.TableCache)1 BinlogEvent (com.airbnb.spinaltap.mysql.event.BinlogEvent)1 DeleteRowsEventData (com.github.shyiko.mysql.binlog.event.DeleteRowsEventData)1 EventHeaderV4 (com.github.shyiko.mysql.binlog.event.EventHeaderV4)1 EventType (com.github.shyiko.mysql.binlog.event.EventType)1 QueryEventData (com.github.shyiko.mysql.binlog.event.QueryEventData)1 TableMapEventData (com.github.shyiko.mysql.binlog.event.TableMapEventData)1 UpdateRowsEventData (com.github.shyiko.mysql.binlog.event.UpdateRowsEventData)1