Search in sources :

Example 1 with TableCache

use of com.airbnb.spinaltap.mysql.TableCache 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)));
}
Also used : WriteEvent(com.airbnb.spinaltap.mysql.event.WriteEvent) SourceState(com.airbnb.spinaltap.common.source.SourceState) TableMapEvent(com.airbnb.spinaltap.mysql.event.TableMapEvent) TableCache(com.airbnb.spinaltap.mysql.TableCache) AtomicReference(java.util.concurrent.atomic.AtomicReference) BinlogEvent(com.airbnb.spinaltap.mysql.event.BinlogEvent) QueryEvent(com.airbnb.spinaltap.mysql.event.QueryEvent) DeleteEvent(com.airbnb.spinaltap.mysql.event.DeleteEvent) BinlogFilePos(com.airbnb.spinaltap.mysql.BinlogFilePos) StartEvent(com.airbnb.spinaltap.mysql.event.StartEvent) XidEvent(com.airbnb.spinaltap.mysql.event.XidEvent) UpdateEvent(com.airbnb.spinaltap.mysql.event.UpdateEvent) Test(org.junit.Test)

Aggregations

SourceState (com.airbnb.spinaltap.common.source.SourceState)1 BinlogFilePos (com.airbnb.spinaltap.mysql.BinlogFilePos)1 TableCache (com.airbnb.spinaltap.mysql.TableCache)1 BinlogEvent (com.airbnb.spinaltap.mysql.event.BinlogEvent)1 DeleteEvent (com.airbnb.spinaltap.mysql.event.DeleteEvent)1 QueryEvent (com.airbnb.spinaltap.mysql.event.QueryEvent)1 StartEvent (com.airbnb.spinaltap.mysql.event.StartEvent)1 TableMapEvent (com.airbnb.spinaltap.mysql.event.TableMapEvent)1 UpdateEvent (com.airbnb.spinaltap.mysql.event.UpdateEvent)1 WriteEvent (com.airbnb.spinaltap.mysql.event.WriteEvent)1 XidEvent (com.airbnb.spinaltap.mysql.event.XidEvent)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Test (org.junit.Test)1