### Question:
Counters implements Iterable<Counter> { public void snapshot() { for (Counter counter : counterMap.values()) { counter.snapshot(); } }  Counter create(String group, String name, int opt); Counter remove(String group, String name); @Override Iterator<Counter> iterator(); Counter get(String group, String name); void reset(); void snapshot(); void enable(String group, int opt); void disable(String group, int opt); void print(PrintStream out); int size(); @Override String toString(); static final int OPT_TOTAL_ONLY; static final int OPT_NO_PRINT; static final int OPT_NO_RESET; }### Answer:
@Test public void test() { Counters counters = new Counters(); CounterThread thread = new CounterThread(counters); thread.start(); List<Long> lasts = new ArrayList<>(); List<Long> snapshots = new ArrayList<>(); for (Counter counter : counters) { lasts.add(counter.getLast()); snapshots.add(counter.getSnapshot()); } for (int i = 0; i < 10; i++) { Assert.assertEquals(snapshots, lasts); snapshots.clear(); for (Counter counter : counters) { snapshots.add(counter.getSnapshot()); } counters.snapshot(); lasts.clear(); for (Counter counter : counters) { lasts.add(counter.getLast()); } try { Thread.sleep(100); } catch (InterruptedException e) { break; } } }