public void testSimple() throws Exception { File tmp = new File("tmp"); PersistentMap<String> pm = new PersistentMap<String>(new File(tmp, "simple"), String.class); try { assertNull(pm.put("abc", "def")); assertEquals("def", pm.get("abc")); pm.close(); PersistentMap<String> pm2 = new PersistentMap<String>(new File(tmp, "simple"), String.class); assertEquals("def", pm2.get("abc")); assertEquals(Arrays.asList("abc"), new ArrayList<String>(pm2.keySet())); for (Map.Entry<String, String> e : pm2.entrySet()) { e.setValue("XXX"); } assertEquals("XXX", pm2.get("abc")); pm2.close(); } finally { pm.close(); IO.delete(tmp); } }
/** higherEntry returns next entry. */ public void testDescendingHigherEntry() { ConcurrentNavigableMap map = dmap5(); Map.Entry e1 = map.higherEntry(m3); assertEquals(m4, e1.getKey()); Map.Entry e2 = map.higherEntry(zero); assertEquals(m1, e2.getKey()); Map.Entry e3 = map.higherEntry(m5); assertNull(e3); Map.Entry e4 = map.higherEntry(m6); assertNull(e4); }
/** higherEntry returns next entry. */ public void testHigherEntry() { ConcurrentNavigableMap map = map5(); Map.Entry e1 = map.higherEntry(three); assertEquals(four, e1.getKey()); Map.Entry e2 = map.higherEntry(zero); assertEquals(one, e2.getKey()); Map.Entry e3 = map.higherEntry(five); assertNull(e3); Map.Entry e4 = map.higherEntry(six); assertNull(e4); }
/** lowerEntry returns preceding entry. */ public void testLowerEntry() { ConcurrentNavigableMap map = map5(); Map.Entry e1 = map.lowerEntry(three); assertEquals(two, e1.getKey()); Map.Entry e2 = map.lowerEntry(six); assertEquals(five, e2.getKey()); Map.Entry e3 = map.lowerEntry(one); assertNull(e3); Map.Entry e4 = map.lowerEntry(zero); assertNull(e4); }
/** * Verifies that all operation sets have the type they are declarded to have. * * @throws java.lang.Exception if a class indicated in one of the keys could not be forName()ed. */ public void testOperationSetTypes() throws Exception { Map<String, OperationSet> supportedOperationSets = fixture.provider1.getSupportedOperationSets(); // make sure that keys (which are supposed to be class names) correspond // what the class of the values recorded against them. for (Map.Entry<String, OperationSet> entry : supportedOperationSets.entrySet()) { String setName = entry.getKey(); Object opSet = entry.getValue(); assertTrue( opSet + " was not an instance of " + setName + " as declared", Class.forName(setName).isInstance(opSet)); } }
/** headMap returns map with keys in requested range */ public void testTailMapContents() { ConcurrentNavigableMap map = map5(); SortedMap sm = map.tailMap(two); assertFalse(sm.containsKey(one)); assertTrue(sm.containsKey(two)); assertTrue(sm.containsKey(three)); assertTrue(sm.containsKey(four)); assertTrue(sm.containsKey(five)); Iterator i = sm.keySet().iterator(); Object k; k = (Integer) (i.next()); assertEquals(two, k); k = (Integer) (i.next()); assertEquals(three, k); k = (Integer) (i.next()); assertEquals(four, k); k = (Integer) (i.next()); assertEquals(five, k); assertFalse(i.hasNext()); Iterator ei = sm.entrySet().iterator(); Map.Entry e; e = (Map.Entry) (ei.next()); assertEquals(two, e.getKey()); assertEquals("B", e.getValue()); e = (Map.Entry) (ei.next()); assertEquals(three, e.getKey()); assertEquals("C", e.getValue()); e = (Map.Entry) (ei.next()); assertEquals(four, e.getKey()); assertEquals("D", e.getValue()); e = (Map.Entry) (ei.next()); assertEquals(five, e.getKey()); assertEquals("E", e.getValue()); assertFalse(i.hasNext()); SortedMap ssm = sm.tailMap(four); assertEquals(four, ssm.firstKey()); assertEquals(five, ssm.lastKey()); assertEquals("D", ssm.remove(four)); assertEquals(1, ssm.size()); assertEquals(3, sm.size()); assertEquals(4, map.size()); }
/** headMap returns map with keys in requested range */ public void testDescendingTailMapContents() { ConcurrentNavigableMap map = dmap5(); SortedMap sm = map.tailMap(m2); assertFalse(sm.containsKey(m1)); assertTrue(sm.containsKey(m2)); assertTrue(sm.containsKey(m3)); assertTrue(sm.containsKey(m4)); assertTrue(sm.containsKey(m5)); Iterator i = sm.keySet().iterator(); Object k; k = (Integer) (i.next()); assertEquals(m2, k); k = (Integer) (i.next()); assertEquals(m3, k); k = (Integer) (i.next()); assertEquals(m4, k); k = (Integer) (i.next()); assertEquals(m5, k); assertFalse(i.hasNext()); Iterator ei = sm.entrySet().iterator(); Map.Entry e; e = (Map.Entry) (ei.next()); assertEquals(m2, e.getKey()); assertEquals("B", e.getValue()); e = (Map.Entry) (ei.next()); assertEquals(m3, e.getKey()); assertEquals("C", e.getValue()); e = (Map.Entry) (ei.next()); assertEquals(m4, e.getKey()); assertEquals("D", e.getValue()); e = (Map.Entry) (ei.next()); assertEquals(m5, e.getKey()); assertEquals("E", e.getValue()); assertFalse(i.hasNext()); SortedMap ssm = sm.tailMap(m4); assertEquals(m4, ssm.firstKey()); assertEquals(m5, ssm.lastKey()); assertEquals("D", ssm.remove(m4)); assertEquals(1, ssm.size()); assertEquals(3, sm.size()); assertEquals(4, map.size()); }
/** entrySet contains all pairs */ public void testEntrySet() { ConcurrentNavigableMap map = map5(); Set s = map.entrySet(); assertEquals(5, s.size()); Iterator it = s.iterator(); while (it.hasNext()) { Map.Entry e = (Map.Entry) it.next(); assertTrue( (e.getKey().equals(one) && e.getValue().equals("A")) || (e.getKey().equals(two) && e.getValue().equals("B")) || (e.getKey().equals(three) && e.getValue().equals("C")) || (e.getKey().equals(four) && e.getValue().equals("D")) || (e.getKey().equals(five) && e.getValue().equals("E"))); } }
/** entrySet contains all pairs */ public void testDescendingEntrySet() { ConcurrentNavigableMap map = dmap5(); Set s = map.entrySet(); assertEquals(5, s.size()); Iterator it = s.iterator(); while (it.hasNext()) { Map.Entry e = (Map.Entry) it.next(); assertTrue( (e.getKey().equals(m1) && e.getValue().equals("A")) || (e.getKey().equals(m2) && e.getValue().equals("B")) || (e.getKey().equals(m3) && e.getValue().equals("C")) || (e.getKey().equals(m4) && e.getValue().equals("D")) || (e.getKey().equals(m5) && e.getValue().equals("E"))); } }
/** pollLastEntry returns entries in order */ public void testDescendingPollLastEntry() { ConcurrentNavigableMap map = dmap5(); Map.Entry e = map.pollLastEntry(); assertEquals(m5, e.getKey()); assertEquals("E", e.getValue()); e = map.pollLastEntry(); assertEquals(m4, e.getKey()); map.put(m5, "E"); e = map.pollLastEntry(); assertEquals(m5, e.getKey()); assertEquals("E", e.getValue()); e = map.pollLastEntry(); assertEquals(m3, e.getKey()); map.remove(m2); e = map.pollLastEntry(); assertEquals(m1, e.getKey()); try { e.setValue("E"); shouldThrow(); } catch (UnsupportedOperationException success) { } e = map.pollLastEntry(); assertNull(e); }
/** pollLastEntry returns entries in order */ public void testPollLastEntry() { ConcurrentNavigableMap map = map5(); Map.Entry e = map.pollLastEntry(); assertEquals(five, e.getKey()); assertEquals("E", e.getValue()); e = map.pollLastEntry(); assertEquals(four, e.getKey()); map.put(five, "E"); e = map.pollLastEntry(); assertEquals(five, e.getKey()); assertEquals("E", e.getValue()); e = map.pollLastEntry(); assertEquals(three, e.getKey()); map.remove(two); e = map.pollLastEntry(); assertEquals(one, e.getKey()); try { e.setValue("E"); shouldThrow(); } catch (UnsupportedOperationException success) { } e = map.pollLastEntry(); assertNull(e); }
/** floorEntry returns preceding entry. */ public void testDescendingFloorEntry() { ConcurrentNavigableMap map = dmap5(); Map.Entry e1 = map.floorEntry(m3); assertEquals(m3, e1.getKey()); Map.Entry e2 = map.floorEntry(m6); assertEquals(m5, e2.getKey()); Map.Entry e3 = map.floorEntry(m1); assertEquals(m1, e3.getKey()); Map.Entry e4 = map.floorEntry(zero); assertNull(e4); }
/** ceilingEntry returns next entry. */ public void testCeilingEntry() { ConcurrentNavigableMap map = map5(); Map.Entry e1 = map.ceilingEntry(three); assertEquals(three, e1.getKey()); Map.Entry e2 = map.ceilingEntry(zero); assertEquals(one, e2.getKey()); Map.Entry e3 = map.ceilingEntry(five); assertEquals(five, e3.getKey()); Map.Entry e4 = map.ceilingEntry(six); assertNull(e4); }