Search in sources :

Example 6 with BinlogEvent

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

the class MysqlMutationMapperTest method testUpdateMutationWithNullPK.

@Test
public void testUpdateMutationWithNullPK() throws Exception {
    Serializable[] old = new Serializable[4];
    old[0] = null;
    old[1] = "test_user";
    old[2] = 25;
    old[3] = 0;
    Serializable[] current = new Serializable[4];
    current[0] = null;
    current[1] = old[1];
    current[2] = 26;
    current[3] = old[3];
    Map.Entry<Serializable[], Serializable[]> change = new AbstractMap.SimpleEntry<>(old, current);
    BinlogEvent event = new UpdateEvent(TABLE_ID, SERVER_ID, TIMESTAMP, BINLOG_FILE_POS, ImmutableList.of(change));
    List<? extends Mutation> mutations = eventMapper.map(event);
    assertEquals(1, mutations.size());
    assertTrue(mutations.get(0) instanceof MysqlUpdateMutation);
    MysqlUpdateMutation mutation = (MysqlUpdateMutation) mutations.get(0);
    validateMetadata(mutation, 0);
    Row oldRow = mutation.getPreviousRow();
    Row newRow = mutation.getRow();
    assertEquals(null, oldRow.getColumns().get("id").getValue());
    assertEquals("test_user", oldRow.getColumns().get("name").getValue());
    assertEquals(25, oldRow.getColumns().get("age").getValue());
    assertEquals(0, oldRow.getColumns().get("sex").getValue());
    assertEquals(null, newRow.getColumns().get("id").getValue());
    assertEquals("test_user", newRow.getColumns().get("name").getValue());
    assertEquals(26, newRow.getColumns().get("age").getValue());
    assertEquals(0, newRow.getColumns().get("sex").getValue());
}
Also used : Serializable(java.io.Serializable) MysqlUpdateMutation(com.airbnb.spinaltap.mysql.mutation.MysqlUpdateMutation) BinlogEvent(com.airbnb.spinaltap.mysql.event.BinlogEvent) Row(com.airbnb.spinaltap.mysql.mutation.schema.Row) Map(java.util.Map) AbstractMap(java.util.AbstractMap) UpdateEvent(com.airbnb.spinaltap.mysql.event.UpdateEvent) Test(org.junit.Test)

Aggregations

BinlogEvent (com.airbnb.spinaltap.mysql.event.BinlogEvent)6 Test (org.junit.Test)6 Row (com.airbnb.spinaltap.mysql.mutation.schema.Row)5 Serializable (java.io.Serializable)5 UpdateEvent (com.airbnb.spinaltap.mysql.event.UpdateEvent)4 AbstractMap (java.util.AbstractMap)3 Map (java.util.Map)3 DeleteEvent (com.airbnb.spinaltap.mysql.event.DeleteEvent)2 WriteEvent (com.airbnb.spinaltap.mysql.event.WriteEvent)2 MysqlDeleteMutation (com.airbnb.spinaltap.mysql.mutation.MysqlDeleteMutation)2 MysqlInsertMutation (com.airbnb.spinaltap.mysql.mutation.MysqlInsertMutation)2 MysqlUpdateMutation (com.airbnb.spinaltap.mysql.mutation.MysqlUpdateMutation)2 SourceState (com.airbnb.spinaltap.common.source.SourceState)1 BinlogFilePos (com.airbnb.spinaltap.mysql.BinlogFilePos)1 TableCache (com.airbnb.spinaltap.mysql.TableCache)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 XidEvent (com.airbnb.spinaltap.mysql.event.XidEvent)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1