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());
}
Aggregations