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