Search in sources :

Example 6 with MysqlMutationMetadata

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

the class MysqlMutationMapperTest method validateMetadata.

private void validateMetadata(Mutation mutation, int rowPosition) {
    MysqlMutationMetadata metadata = (MysqlMutationMetadata) mutation.getMetadata();
    assertEquals(DATA_SOURCE, metadata.getDataSource());
    assertEquals(BINLOG_FILE_POS, metadata.getFilePos());
    assertEquals(TEST_TABLE, metadata.getTable());
    assertEquals(SERVER_ID, metadata.getServerId());
    assertEquals(TIMESTAMP, metadata.getTimestamp());
    assertEquals(beginTransaction.get(), metadata.getBeginTransaction());
    assertEquals(lastTransaction.get(), metadata.getLastTransaction());
    assertEquals(leaderEpoch.get(), metadata.getLeaderEpoch());
    assertEquals(rowPosition, metadata.getEventRowPosition());
}
Also used : MysqlMutationMetadata(com.airbnb.spinaltap.mysql.mutation.MysqlMutationMetadata)

Example 7 with MysqlMutationMetadata

use of com.airbnb.spinaltap.mysql.mutation.MysqlMutationMetadata 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 8 with MysqlMutationMetadata

use of com.airbnb.spinaltap.mysql.mutation.MysqlMutationMetadata 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

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