@Test public void testGetPromotion() { LRUMap<String, String> map = new LRUMap<String, String>(3); map.put("1","1"); map.put("2","2"); map.put("3","3"); // LRU is now 1 (then 2 then 3) // promote 1 to top // eviction order is now 2,3,1 map.get("1"); // add another value, forcing a remove // 2 should be evicted (then 3,1,4) map.put("4","4"); Iterator<String> keyIterator = map.keySet().iterator(); Object[] keys = new Object[3]; for (int i = 0; keyIterator.hasNext() ; ++i) { keys[i] = keyIterator.next(); } assertTrue("first evicted should be 3, was " + keys[0], keys[0].equals("3")); assertTrue("second evicted should be 1, was " + keys[1], keys[1].equals("1")); assertTrue("third evicted should be 4, was " + keys[2], keys[2].equals("4")); }
public void testGetPromotion() { LRUMap<String, String> map = new LRUMap<String, String>(3); map.put("1","1"); map.put("2","2"); map.put("3","3"); // LRU is now 1 (then 2 then 3) // promote 1 to top // eviction order is now 2,3,1 map.get("1"); // add another value, forcing a remove // 2 should be evicted (then 3,1,4) map.put("4","4"); Iterator<String> keyIterator = map.keySet().iterator(); Object[] keys = new Object[3]; for (int i = 0; keyIterator.hasNext() ; ++i) { keys[i] = keyIterator.next(); } assertTrue("first evicted should be 3, was " + keys[0], keys[0].equals("3")); assertTrue("second evicted should be 1, was " + keys[1], keys[1].equals("1")); assertTrue("third evicted should be 4, was " + keys[2], keys[2].equals("4")); }
public void testGetPromotion() { LRUMap map = new LRUMap(3); map.put("1","1"); map.put("2","2"); map.put("3","3"); // LRU is now 1 (then 2 then 3) // promote 1 to top // eviction order is now 2,3,1 map.get("1"); // add another value, forcing a remove // 2 should be evicted (then 3,1,4) map.put("4","4"); Iterator keyIterator = map.keySet().iterator(); Object[] keys = new Object[3]; for (int i = 0; keyIterator.hasNext() ; ++i) { keys[i] = keyIterator.next(); } assertTrue("first evicted should be 3, was " + keys[0], keys[0].equals("3")); assertTrue("second evicted should be 1, was " + keys[1], keys[1].equals("1")); assertTrue("third evicted should be 4, was " + keys[2], keys[2].equals("4")); }
@Test public void testGetPromotion() { LRUMap<String, String> map = new LRUMap<String, String>(3); map.put("1","1"); map.put("2","2"); map.put("3","3"); // LRU is now 1 (then 2 then 3) // promote 1 to top // eviction order is now 2,3,1 map.get("1"); // add another value, forcing a remove // 2 should be evicted (then 3,1,4) map.put("4","4"); Iterator<String> keyIterator = map.keySet().iterator(); Object[] keys = new Object[3]; for (int i = 0; keyIterator.hasNext() ; ++i) { keys[i] = keyIterator.next(); } assertTrue("first evicted should be 3, was " + keys[0], keys[0].equals("3")); assertTrue("second evicted should be 1, was " + keys[1], keys[1].equals("1")); assertTrue("third evicted should be 4, was " + keys[2], keys[2].equals("4")); }