@Test public void testRead() throws Exception { MysqlSourceState state = mock(MysqlSourceState.class); when(repository.get()).thenReturn(state); when(repository.exists()).thenReturn(false); assertNull(stateRepository.read()); when(repository.exists()).thenReturn(true); Assert.assertEquals(state, stateRepository.read()); verify(metrics, times(2)).stateRead(); }
public S read() { S 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); throw new RuntimeException(ex); } log.debug("Read state for source {}. state={}", sourceName, state); metrics.stateRead(); return state; }
StateRepository { public S read() { S 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); throw new RuntimeException(ex); } log.debug("Read state for source {}. state={}", sourceName, state); metrics.stateRead(); return state; } }
StateRepository { public S read() { S 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); throw new RuntimeException(ex); } log.debug("Read state for source {}. state={}", sourceName, state); metrics.stateRead(); return state; }  }
StateRepository { public S read() { S 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); throw new RuntimeException(ex); } log.debug("Read state for source {}. state={}", sourceName, state); metrics.stateRead(); return state; }  void save(@NonNull final S state); S read(); }
StateRepository { public S read() { S 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); throw new RuntimeException(ex); } log.debug("Read state for source {}. state={}", sourceName, state); metrics.stateRead(); return state; }  void save(@NonNull final S state); S read();  }