MemoryMetricObserver extends BaseMetricObserver { public List<List<Metric>> getObservations() { List<List<Metric>> builder = new ArrayList<>(); int pos = next; for (List<Metric> ignored : observations) { if (observations[pos] != null) { builder.add(observations[pos]); } pos = (pos + 1) % observations.length; } return Collections.unmodifiableList(builder); } MemoryMetricObserver(); @SuppressWarnings("unchecked")  MemoryMetricObserver(String name, int num); void updateImpl(List<Metric> metrics); List<List<Metric>> getObservations();  }
@Test public void testUpdate() throws Exception { MemoryMetricObserver mmo = new MemoryMetricObserver("test", 2); mmo.update(mkList(1)); assertEquals(mmo.getObservations(), UnmodifiableList.of(mkList(1))); }
@Test public void testExceedN() throws Exception { MemoryMetricObserver mmo = new MemoryMetricObserver("test", 2); mmo.update(mkList(1)); mmo.update(mkList(2)); mmo.update(mkList(3)); assertEquals(mmo.getObservations(), UnmodifiableList.of(mkList(2), mkList(3))); }