TimeoutCache { public void remove(final T key) { timers.remove(key); tasks.remove(key); } TimeoutCache(final int seconds); void put(final T key, final Runnable task); void remove(final T key); int size();  }
@Test public void testRemove() throws Exception { final TimeoutCache<InstrumentID> cache = new TimeoutCache<InstrumentID>(2); final List<InstrumentID> ids = new ArrayList<InstrumentID>(); for(int i = 0; i <10000; i++) { ids.add(new InstrumentID(i)); } Thread.sleep(10000); for(final InstrumentID id : ids) { cache.put(id, new Runnable() { @Override public void run() { } }); } for(final InstrumentID id : ids) { cache.remove(id); } assertEquals(0, cache.size()); }