Search in sources :

Example 6 with MysqlInsertMutation

use of com.airbnb.spinaltap.mysql.mutation.MysqlInsertMutation in project SpinalTap by airbnb.

the class AbstractMysqlSourceTest method testCommitCheckpoint.

@Test
public void testCommitCheckpoint() throws Exception {
    StateHistory stateHistory = new TestStateHistory();
    TestSource source = new TestSource(stateHistory);
    Row row = new Row(null, ImmutableMap.of());
    BinlogFilePos filePos = new BinlogFilePos("test.txt", 18, 156);
    Transaction lastTransaction = new Transaction(0L, 0L, filePos);
    MysqlMutationMetadata metadata = new MysqlMutationMetadata(null, filePos, null, 0L, 0L, 0L, null, lastTransaction, 0, 0);
    MysqlMutation mutation = new MysqlInsertMutation(metadata, row);
    SourceState savedState = new SourceState(SAVED_TIMESTAMP, SAVED_OFFSET, 0L, BINLOG_FILE_POS);
    when(stateRepository.read()).thenReturn(savedState);
    source.initialize();
    source.checkpoint(mutation);
    assertEquals(savedState, source.getLastSavedState().get());
    source.checkpoint(null);
    assertEquals(savedState, source.getLastSavedState().get());
    long newOffset = SAVED_OFFSET + 1;
    metadata = new MysqlMutationMetadata(null, filePos, null, 0L, newOffset, 23L, null, lastTransaction, 0, 0);
    mutation = new MysqlInsertMutation(metadata, row);
    source.checkpoint(mutation);
    assertEquals(new SourceState(23L, newOffset, 0L, filePos), source.getLastSavedState().get());
    assertEquals(stateHistory.removeLast(), source.getLastSavedState().get());
}
Also used : MysqlMutationMetadata(com.airbnb.spinaltap.mysql.mutation.MysqlMutationMetadata) MysqlMutation(com.airbnb.spinaltap.mysql.mutation.MysqlMutation) SourceState(com.airbnb.spinaltap.common.source.SourceState) MysqlInsertMutation(com.airbnb.spinaltap.mysql.mutation.MysqlInsertMutation) Row(com.airbnb.spinaltap.mysql.mutation.schema.Row) Test(org.junit.Test)

Example 7 with MysqlInsertMutation

use of com.airbnb.spinaltap.mysql.mutation.MysqlInsertMutation in project SpinalTap by airbnb.

the class AbstractMysqlSourceTest method testResetToLastValidState.

@Test
public void testResetToLastValidState() throws Exception {
    StateHistory stateHistory = new TestStateHistory();
    TestSource source = new TestSource(stateHistory);
    SourceState savedState = mock(SourceState.class);
    SourceState earliestState = new SourceState(0L, 0L, 0L, AbstractMysqlSource.EARLIEST_BINLOG_POS);
    when(stateRepository.read()).thenReturn(savedState);
    SourceState firstState = mock(SourceState.class);
    SourceState secondState = mock(SourceState.class);
    SourceState thirdState = mock(SourceState.class);
    SourceState fourthState = mock(SourceState.class);
    stateHistory.add(firstState);
    stateHistory.add(secondState);
    stateHistory.add(thirdState);
    source.initialize();
    source.resetToLastValidState();
    assertEquals(thirdState, source.getLastSavedState().get());
    source.resetToLastValidState();
    assertEquals(firstState, source.getLastSavedState().get());
    assertTrue(stateHistory.isEmpty());
    source.resetToLastValidState();
    assertEquals(earliestState, source.getLastSavedState().get());
    stateHistory.add(firstState);
    stateHistory.add(secondState);
    stateHistory.add(thirdState);
    stateHistory.add(fourthState);
    source.resetToLastValidState();
    assertEquals(firstState, source.getLastSavedState().get());
    stateHistory.add(firstState);
    stateHistory.add(secondState);
    source.resetToLastValidState();
    assertEquals(earliestState, source.getLastSavedState().get());
    assertTrue(stateHistory.isEmpty());
    BinlogFilePos filePos = new BinlogFilePos("test.txt", 18, 156);
    Transaction lastTransaction = new Transaction(0L, 0L, filePos);
    MysqlMutationMetadata metadata = new MysqlMutationMetadata(null, null, null, 0L, 1L, 23L, null, lastTransaction, 0L, 0);
    source.checkpoint(new MysqlInsertMutation(metadata, null));
    assertFalse(stateHistory.isEmpty());
    source.resetToLastValidState();
    assertEquals(new SourceState(23L, 1L, 0L, filePos), source.getLastSavedState().get());
}
Also used : SourceState(com.airbnb.spinaltap.common.source.SourceState) MysqlMutationMetadata(com.airbnb.spinaltap.mysql.mutation.MysqlMutationMetadata) MysqlInsertMutation(com.airbnb.spinaltap.mysql.mutation.MysqlInsertMutation) Test(org.junit.Test)

Aggregations

MysqlInsertMutation (com.airbnb.spinaltap.mysql.mutation.MysqlInsertMutation)7 Row (com.airbnb.spinaltap.mysql.mutation.schema.Row)6 MysqlMutationMetadata (com.airbnb.spinaltap.mysql.mutation.MysqlMutationMetadata)4 Test (org.junit.Test)4 MysqlDeleteMutation (com.airbnb.spinaltap.mysql.mutation.MysqlDeleteMutation)3 MysqlMutation (com.airbnb.spinaltap.mysql.mutation.MysqlMutation)3 ColumnMetadata (com.airbnb.spinaltap.mysql.mutation.schema.ColumnMetadata)3 Serializable (java.io.Serializable)3 SourceState (com.airbnb.spinaltap.common.source.SourceState)2 BinlogEvent (com.airbnb.spinaltap.mysql.event.BinlogEvent)2 MysqlUpdateMutation (com.airbnb.spinaltap.mysql.mutation.MysqlUpdateMutation)2 Mutation (com.airbnb.jitney.event.spinaltap.v1.Mutation)1 BinlogFilePos (com.airbnb.spinaltap.mysql.BinlogFilePos)1 DataSource (com.airbnb.spinaltap.mysql.DataSource)1 UpdateEvent (com.airbnb.spinaltap.mysql.event.UpdateEvent)1 WriteEvent (com.airbnb.spinaltap.mysql.event.WriteEvent)1 Column (com.airbnb.spinaltap.mysql.mutation.schema.Column)1 Table (com.airbnb.spinaltap.mysql.mutation.schema.Table)1 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1