### Question:
AsmMetric { public void flush() { long time = TimeUtils.current_time_secs(); List<Integer> windows = getValidWindows(); if (windows.size() == 0) { return; } doFlush(); List<Integer> rollWindows = rollWindows(time, windows); for (int win : windows) { if (rollWindows.contains(win)) { updateSnapshot(win); Map<Integer, T> metricMap = getWindowMetricMap(); if (metricMap != null) { metricMap.put(win, mkInstance()); } } else if (!rollingDirtyMap.get(win)) { updateSnapshot(win); } } this.lastFlushTime = TimeUtils.current_time_secs(); } AsmMetric(); static void setSampleRate(double sampleRate); abstract void update(Number obj); abstract void updateTime(long obj); void updateDirectly(Number obj); abstract AsmMetric clone(); AsmMetric setOp(int op); int getOp(); static void setWindowSeconds(List<Integer> windows); static int getMinWindow(List<Integer> windows); void addAssocMetrics(AsmMetric... metrics); long getMetricId(); void setMetricId(long metricId); String getMetricName(); void setMetricName(String metricName); String getShortName(); void flush(); @VisibleForTesting void forceFlush(); List<Integer> rollWindows(long time, List<Integer> windows); abstract Map<Integer, T> getWindowMetricMap(); abstract T mkInstance(); @VisibleForTesting abstract Object getValue(Integer window); Map<Integer, AsmSnapshot> getSnapshots(); List<Integer> getValidWindows(); @VisibleForTesting List<Integer> getWindows(); boolean isAggregate(); void setAggregate(boolean aggregate); Set<AsmMetric> getAssocMetrics(); AsmMetric setEnabled(boolean enabled); boolean isAttached(); void setAttached(boolean attached); static String mkName(Object... parts);  }### Answer:
@Test public void testFlush() throws Exception { AsmCounter counter = new AsmCounter(); counter.setMetricName("mock@metric@name"); Random random = new Random(); for (int i = 0; i < 100; i++) { int c = random.nextInt(10); counter.update(c); } counter.flush(); assertEquals(4, counter.getSnapshots().size()); }