use of com.airbnb.spinaltap.mysql.mutation.schema.Row in project SpinalTap by airbnb.
the class MysqlMutationMapperTest method testInsertMutation.
@Test
public void testInsertMutation() throws Exception {
Serializable[] change = new Serializable[4];
change[0] = 12131L;
change[1] = "test_user";
change[2] = 25;
change[3] = 0;
Serializable[] change2 = new Serializable[4];
change2[0] = 12334L;
change2[1] = "test_user2";
change2[2] = 12;
change2[3] = 1;
BinlogEvent event = new WriteEvent(TABLE_ID, SERVER_ID, TIMESTAMP, BINLOG_FILE_POS, ImmutableList.of(change, change2));
List<? extends Mutation> mutations = eventMapper.map(event);
assertEquals(2, mutations.size());
assertTrue(mutations.get(0) instanceof MysqlInsertMutation);
MysqlInsertMutation mutation = (MysqlInsertMutation) mutations.get(0);
validateMetadata(mutation, 0);
Row row = mutation.getEntity();
assertEquals(12131L, row.getColumns().get("id").getValue());
assertEquals("test_user", row.getColumns().get("name").getValue());
assertEquals(25, row.getColumns().get("age").getValue());
assertEquals(0, row.getColumns().get("sex").getValue());
assertTrue(mutations.get(1) instanceof MysqlInsertMutation);
mutation = (MysqlInsertMutation) mutations.get(1);
validateMetadata(mutation, 1);
row = mutation.getEntity();
assertEquals(12334L, row.getColumns().get("id").getValue());
assertEquals("test_user2", row.getColumns().get("name").getValue());
assertEquals(12, row.getColumns().get("age").getValue());
assertEquals(1, row.getColumns().get("sex").getValue());
}
use of com.airbnb.spinaltap.mysql.mutation.schema.Row 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());
}
use of com.airbnb.spinaltap.mysql.mutation.schema.Row in project SpinalTap by airbnb.
the class MysqlKeyProviderTest method testGetNullKey.
@Test
public void testGetNullKey() throws Exception {
Row row = new Row(TABLE, ImmutableMap.of(ID_COLUMN, new Column(TABLE.getColumns().get(ID_COLUMN), null)));
MysqlMutation mutation = new MysqlInsertMutation(MUTATION_METADATA, row);
assertEquals("test:users:null", MysqlKeyProvider.INSTANCE.get(mutation));
}
use of com.airbnb.spinaltap.mysql.mutation.schema.Row 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.schema.Row in project SpinalTap by airbnb.
the class MutationSchemaValidatorTest method testIncorrectColumn.
@Test(expected = IllegalStateException.class)
public void testIncorrectColumn() throws Exception {
Row row = new Row(TABLE, ImmutableMap.of(ID_COLUMN, createColumn(ID_COLUMN, ColumnDataType.LONGLONG, true, 1L, 0), NAME_COLUMN, createColumn(NAME_COLUMN, ColumnDataType.VARCHAR, false, "bob", 1), AGE_COLUMN, createColumn(AGE_COLUMN, ColumnDataType.INT24, false, 25, 2), "bad_column", createColumn("bad_column", ColumnDataType.VARCHAR, false, "bad", 3)));
validator.validate(createMutation(row));
}
Aggregations