use of com.airbnb.spinaltap.common.source.SourceState in project SpinalTap by airbnb.
the class StateRepository method read.
/**
* Reads the source state from the repository. Returns a new state if one does not exist
*/
public SourceState read() {
SourceState state = null;
try {
if (repository.exists()) {
state = repository.get();
} else {
log.info("State does not exist for source {}", sourceName);
}
} catch (Exception ex) {
log.error("Failed to read state for source " + sourceName, ex);
metrics.stateReadFailure(ex);
Throwables.throwIfUnchecked(ex);
throw new RuntimeException(ex);
}
log.debug("Read state for source {}. state={}", sourceName, state);
metrics.stateRead();
return state;
}
use of com.airbnb.spinaltap.common.source.SourceState in project SpinalTap by airbnb.
the class StateHistoryTest method test.
@Test
public void test() throws Exception {
SourceState firstState = mock(SourceState.class);
SourceState secondState = mock(SourceState.class);
SourceState thirdState = mock(SourceState.class);
SourceState fourthState = mock(SourceState.class);
TestRepository repository = new TestRepository(firstState);
StateHistory history = new StateHistory(SOURCE_NAME, 2, repository, metrics);
history.add(secondState);
assertEquals(Arrays.asList(firstState, secondState), repository.get());
history.add(thirdState);
history.add(fourthState);
assertEquals(Arrays.asList(thirdState, fourthState), repository.get());
}
use of com.airbnb.spinaltap.common.source.SourceState in project SpinalTap by airbnb.
the class StateHistoryTest method testRemoveMoreElementsThanInHistory.
@Test(expected = IllegalStateException.class)
public void testRemoveMoreElementsThanInHistory() 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);
history.removeLast(3);
}
use of com.airbnb.spinaltap.common.source.SourceState in project SpinalTap by airbnb.
the class StateHistoryTest method testEmptyHistory.
@Test
public void testEmptyHistory() throws Exception {
SourceState state = mock(SourceState.class);
TestRepository repository = new TestRepository();
StateHistory history = new StateHistory(SOURCE_NAME, 2, repository, metrics);
assertTrue(history.isEmpty());
repository = new TestRepository(state);
history = new StateHistory(SOURCE_NAME, 2, repository, metrics);
assertFalse(history.isEmpty());
}
use of com.airbnb.spinaltap.common.source.SourceState in project SpinalTap by airbnb.
the class StateHistoryTest method testRemoveLastFromHistory.
@Test
public void testRemoveLastFromHistory() 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(thirdState, history.removeLast());
assertEquals(secondState, history.removeLast());
assertEquals(firstState, history.removeLast());
assertTrue(history.isEmpty());
}
Aggregations