use of com.airbnb.spinaltap.common.source.SourceState in project SpinalTap by airbnb.
the class StateHistoryTest method testRemoveMultipleElementsFromHistory.
@Test
public void testRemoveMultipleElementsFromHistory() throws Exception {
SourceState firstState = mock(SourceState.class);
SourceState secondState = mock(SourceState.class);
SourceState thirdState = mock(SourceState.class);
TestRepository repository = new TestRepository(firstState, secondState, thirdState);
StateHistory history = new StateHistory(SOURCE_NAME, 3, repository, metrics);
assertEquals(secondState, history.removeLast(2));
assertEquals(Collections.singletonList(firstState), repository.get());
}
use of com.airbnb.spinaltap.common.source.SourceState in project SpinalTap by airbnb.
the class StateHistoryTest method testRemoveAllElementsFromHistory.
@Test
public void testRemoveAllElementsFromHistory() throws Exception {
SourceState firstState = mock(SourceState.class);
SourceState secondState = mock(SourceState.class);
TestRepository repository = new TestRepository(firstState, secondState);
StateHistory history = new StateHistory(SOURCE_NAME, 2, repository, metrics);
assertEquals(firstState, history.removeLast(2));
assertTrue(history.isEmpty());
}
use of com.airbnb.spinaltap.common.source.SourceState in project SpinalTap by airbnb.
the class StateRepositoryTest method testSave.
@Test
public void testSave() throws Exception {
SourceState state = mock(SourceState.class);
SourceState nextState = mock(SourceState.class);
AtomicReference<SourceState> updatedState = new AtomicReference<>();
when(state.getCurrentLeaderEpoch()).thenReturn(5l);
doAnswer(new Answer<SourceState>() {
@Override
public SourceState answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
SourceState newState = (SourceState) args[0];
Repository.DataUpdater<SourceState> updater = (Repository.DataUpdater<SourceState>) args[1];
updatedState.set(updater.apply(state, newState));
return null;
}
}).when(repository).update(any(SourceState.class), any(Repository.DataUpdater.class));
// Test new leader epoch leader less than current
when(nextState.getCurrentLeaderEpoch()).thenReturn(4l);
stateRepository.save(nextState);
assertEquals(state, updatedState.get());
// Test new leader epoch leader same as current
when(nextState.getCurrentLeaderEpoch()).thenReturn(5l);
stateRepository.save(nextState);
assertEquals(nextState, updatedState.get());
// Test new leader epoch leader greather current
when(nextState.getCurrentLeaderEpoch()).thenReturn(6l);
stateRepository.save(nextState);
assertEquals(nextState, updatedState.get());
}
use of com.airbnb.spinaltap.common.source.SourceState in project SpinalTap by airbnb.
the class JsonSerializationTest method testSerializeSourceState.
@Test
public void testSerializeSourceState() throws Exception {
SourceState state = JsonUtil.OBJECT_MAPPER.readValue(JsonUtil.OBJECT_MAPPER.writeValueAsString(SOURCE_STATE), new TypeReference<SourceState>() {
});
assertEquals(BINLOG_FILE_POS, state.getLastPosition());
assertEquals(SOURCE_STATE.getLastTimestamp(), state.getLastTimestamp());
assertEquals(SOURCE_STATE.getLastOffset(), state.getLastOffset());
}
use of com.airbnb.spinaltap.common.source.SourceState in project SpinalTap by airbnb.
the class JsonSerializationTest method testSerializeStateHistory.
@Test
public void testSerializeStateHistory() throws Exception {
SourceState firstState = new SourceState(15l, 20l, -1l, BINLOG_FILE_POS);
SourceState secondState = new SourceState(16l, 21l, -1l, BINLOG_FILE_POS);
SourceState thirdState = new SourceState(17l, 22l, -1l, BINLOG_FILE_POS);
Deque<SourceState> stateHistory = Queues.newArrayDeque();
stateHistory.addLast(firstState);
stateHistory.addLast(secondState);
stateHistory.addLast(thirdState);
Collection<SourceState> states = JsonUtil.OBJECT_MAPPER.readValue(JsonUtil.OBJECT_MAPPER.writeValueAsString(stateHistory), new TypeReference<Collection<SourceState>>() {
});
stateHistory = Queues.newArrayDeque(states);
assertEquals(3, states.size());
assertEquals(thirdState, stateHistory.removeLast());
assertEquals(secondState, stateHistory.removeLast());
assertEquals(firstState, stateHistory.removeLast());
}
Aggregations