ModelInspector { @Scheduled(initialDelayString = "${model.inspection.interval:60000}", fixedRateString = "${model.inspection.interval:60000}") public void inspect() { Map<String, M> store = new HashMap<>(this.store); store.forEach((key, model) -> { try { List<PatchOperation> operations = agent.inspectModel(key, model); if (!operations.isEmpty()) { emitter.emit(new PatchSet(key, operations)); } } catch (Exception e) { log.warn("Problem inspecting model \"{}\"", key, e); } }); }  @Scheduled(initialDelayString = "${model.inspection.interval:60000}", fixedRateString = "${model.inspection.interval:60000}") void inspect();  }
@Test public void operations_are_passed_to_emitter() throws Exception { given(agent.inspectModel("one", 1)).willReturn(singletonList(add("/value", 1))); given(agent.inspectModel("two", 2)).willReturn(singletonList(add("/value", 2))); inspector.inspect(); then(emitter).should().emit(new PatchSet("one", singletonList(add("/value", 1)))); then(emitter).should().emit(new PatchSet("two", singletonList(add("/value", 2)))); }
@Test public void no_operations_means_no_PatchSet() throws Exception { given(agent.inspectModel("one", 1)).willReturn(emptyList()); given(agent.inspectModel("two", 2)).willReturn(emptyList()); inspector.inspect(); then(emitter).shouldHaveZeroInteractions(); }
@Test public void inspectModel_throwing_doesnot_stop_execution() throws Exception { given(agent.inspectModel(anyString(), any(Integer.class))).willThrow(RuntimeException.class); inspector.inspect(); then(agent).should(times(2)).inspectModel(anyString(), any(Integer.class)); }