@Test public void testDelayedExport() throws InterruptedException { RecordingStat<Integer> earlyExport = mockedStat(); for (int i = 1; i <= 4; i++) { expect(statRegistry.getStats()) .andReturn(ImmutableList.<RecordingStat<? extends Number>>of(earlyExport)); expect(earlyExport.getName()).andReturn("early"); expect(earlyExport.sample()).andReturn(i * 2); } RecordingStat<Integer> delayedExport = mockedStat(); expect(statRegistry.getStats()) .andReturn(ImmutableList.<RecordingStat<? extends Number>>of(earlyExport, delayedExport)); expect(earlyExport.getName()).andReturn("early"); expect(earlyExport.sample()).andReturn(10); expect(delayedExport.getName()).andReturn("delayed"); expect(delayedExport.sample()).andReturn(100); control.replay(); clock.setNowMillis(1000); for (int i = 0; i < 4; i++) { repo.runSampler(clock); clock.waitFor(1000); } expectTimestamps(1000L, 2000L, 3000L, 4000L); expectSeriesData("early", 2, 4, 6, 8); repo.runSampler(clock); expectTimestamps(1000L, 2000L, 3000L, 4000L, 5000L); expectSeriesData("early", 2, 4, 6, 8, 10); expectSeriesData("delayed", 0L, 0L, 0L, 0L, 100); }
@VisibleForTesting synchronized void runSampler(Clock clock) { timestamps.add(clock.nowMillis()); long startNanos = clock.nowNanos(); for (RecordingStat<? extends Number> var : statRegistry.getStats()) { timeSeries.getUnchecked(var.getName()).addSample(var.sample()); } scrapeDuration.accumulate( Amount.of(clock.nowNanos() - startNanos, Time.NANOSECONDS).as(Time.MICROSECONDS)); }
TimeSeriesRepositoryImpl extends AbstractScheduledService implements TimeSeriesRepository { @VisibleForTesting synchronized void runSampler(Clock clock) { timestamps.add(clock.nowMillis()); long startNanos = clock.nowNanos(); for (RecordingStat<? extends Number> var : statRegistry.getStats()) { timeSeries.getUnchecked(var.getName()).addSample(var.sample()); } scrapeDuration.accumulate( Amount.of(clock.nowNanos() - startNanos, Time.NANOSECONDS).as(Time.MICROSECONDS)); } }
TimeSeriesRepositoryImpl extends AbstractScheduledService implements TimeSeriesRepository { @VisibleForTesting synchronized void runSampler(Clock clock) { timestamps.add(clock.nowMillis()); long startNanos = clock.nowNanos(); for (RecordingStat<? extends Number> var : statRegistry.getStats()) { timeSeries.getUnchecked(var.getName()).addSample(var.sample()); } scrapeDuration.accumulate( Amount.of(clock.nowNanos() - startNanos, Time.NANOSECONDS).as(Time.MICROSECONDS)); } @Inject  TimeSeriesRepositoryImpl(
      StatRegistry statRegistry,
      @Named(SAMPLE_PERIOD) Amount<Long, Time> samplePeriod,
      @Named(SAMPLE_RETENTION_PERIOD) final Amount<Long, Time> retentionPeriod,
      BuildInfo buildInfo); }
TimeSeriesRepositoryImpl extends AbstractScheduledService implements TimeSeriesRepository { @VisibleForTesting synchronized void runSampler(Clock clock) { timestamps.add(clock.nowMillis()); long startNanos = clock.nowNanos(); for (RecordingStat<? extends Number> var : statRegistry.getStats()) { timeSeries.getUnchecked(var.getName()).addSample(var.sample()); } scrapeDuration.accumulate( Amount.of(clock.nowNanos() - startNanos, Time.NANOSECONDS).as(Time.MICROSECONDS)); } @Inject  TimeSeriesRepositoryImpl(
      StatRegistry statRegistry,
      @Named(SAMPLE_PERIOD) Amount<Long, Time> samplePeriod,
      @Named(SAMPLE_RETENTION_PERIOD) final Amount<Long, Time> retentionPeriod,
      BuildInfo buildInfo); @Override synchronized Set<String> getAvailableSeries(); @Override synchronized TimeSeries get(String name); @Override synchronized Iterable<Number> getTimestamps(); }
TimeSeriesRepositoryImpl extends AbstractScheduledService implements TimeSeriesRepository { @VisibleForTesting synchronized void runSampler(Clock clock) { timestamps.add(clock.nowMillis()); long startNanos = clock.nowNanos(); for (RecordingStat<? extends Number> var : statRegistry.getStats()) { timeSeries.getUnchecked(var.getName()).addSample(var.sample()); } scrapeDuration.accumulate( Amount.of(clock.nowNanos() - startNanos, Time.NANOSECONDS).as(Time.MICROSECONDS)); } @Inject  TimeSeriesRepositoryImpl(
      StatRegistry statRegistry,
      @Named(SAMPLE_PERIOD) Amount<Long, Time> samplePeriod,
      @Named(SAMPLE_RETENTION_PERIOD) final Amount<Long, Time> retentionPeriod,
      BuildInfo buildInfo); @Override synchronized Set<String> getAvailableSeries(); @Override synchronized TimeSeries get(String name); @Override synchronized Iterable<Number> getTimestamps(); static final String SAMPLE_PERIOD; static final String SAMPLE_RETENTION_PERIOD; }