Exemple #1
0
  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);
    }
  }
 /** 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);
 }