PollableInfoWrapper extends InfoWrapper { @Override public Indicator measure() { long start = clock.wallTime(); try { return super.measure(); } finally { long duration = clock.wallTime() - start; if (duration > 1000) { logger.warn("Info metric id:{} value method invoke too long(duration:{})!", duration); } } } PollableInfoWrapper(Id id, Info info, Clock clock); boolean isAutoPolledAllowed(long stepMills); @Override Indicator measure();  }
@Test public void test_measure() { ManualClock clock = new ManualClock(); DefaultRegistry r = new DefaultRegistry(clock); PollableInfoWrapper w = new PollableInfoWrapper(r.createId("info"), new AutoPollFriendlyInfo() { @Override public AutoPollSuggestion autoPollSuggest() { return AutoPollSuggestion.POLL_WHEN_UPDATED; } @Override public long lastModifiedTime() { return 10; } @Override public Object value() { return "i_am_info"; } }, clock); clock.setWallTime(20L); Indicator indicator = w.measure(); assertThat(indicator).isNotNull(); assertThat(indicator.getTimestamp()).isEqualTo(20L); assertThat(indicator.measurements()).hasSize(1); assertThat(((Measurement<?>) indicator.measurements().iterator().next()).value()) .isEqualTo("i_am_info"); }
@Test public void test_measure_timeout() { Clock clock = Clock.SYSTEM; DefaultRegistry r = new DefaultRegistry(clock); PollableInfoWrapper w = new PollableInfoWrapper(r.createId("info"), new AutoPollFriendlyInfo() { @Override public AutoPollSuggestion autoPollSuggest() { return AutoPollSuggestion.POLL_WHEN_UPDATED; } @Override public long lastModifiedTime() { return 10; } @Override public Object value() { try { Thread.sleep(1100L); } catch (InterruptedException e) { e.printStackTrace(); } return "i_am_info"; } }, clock); Indicator indicator = w.measure(); assertThat(indicator).isNotNull(); assertThat(indicator.measurements()).hasSize(1); assertThat(((Measurement<?>) indicator.measurements().iterator().next()).value()) .isEqualTo("i_am_info"); }