/** remove(key,value) removes only if pair present */
 public void testDescendingRemove2() {
   ConcurrentNavigableMap map = dmap5();
   assertTrue(map.containsKey(m5));
   assertEquals("E", map.get(m5));
   map.remove(m5, "E");
   assertEquals(4, map.size());
   assertFalse(map.containsKey(m5));
   map.remove(m4, "A");
   assertEquals(4, map.size());
   assertTrue(map.containsKey(m4));
 }
 /** remove(key,value) removes only if pair present */
 public void testRemove2() {
   ConcurrentNavigableMap map = map5();
   assertTrue(map.containsKey(five));
   assertEquals("E", map.get(five));
   map.remove(five, "E");
   assertEquals(4, map.size());
   assertFalse(map.containsKey(five));
   map.remove(four, "A");
   assertEquals(4, map.size());
   assertTrue(map.containsKey(four));
 }
 /** remove(null, x) throws NPE */
 public void testRemove2_NullPointerException() {
   try {
     ConcurrentNavigableMap c = map5();
     c.remove(null, "whatever");
     shouldThrow();
   } catch (NullPointerException success) {
   }
 }
 /** remove(null) throws NPE */
 public void testDescendingRemove1_NullPointerException() {
   try {
     ConcurrentNavigableMap c = dmap5();
     c.remove(null);
     shouldThrow();
   } catch (NullPointerException success) {
   }
 }
Exemplo n.º 5
0
  private void registerRemoval(String id, long lifeTime, TimeUnit unit) {
    ITaskManagerHook hook = taskManagerHooks.get(id);
    if (hook != null) {

      long removalTime = unit.toMillis(lifeTime) + System.currentTimeMillis();

      // Remove current scheduled removal
      Long currentRemovalTime = taskManagerRemovalBackRegister.get(hook);
      if (currentRemovalTime != null) {
        taskManagerRemovalRegister.remove(currentRemovalTime);
      }

      // Find an empty spot in the sorted map's key register
      removalTime--;
      do {
        removalTime++;
        taskManagerRemovalRegister.putIfAbsent(removalTime, hook);
      } while (taskManagerRemovalRegister.get(removalTime) != hook);

      // Back reference the removal
      taskManagerRemovalBackRegister.put(hook, removalTime);
    }
  }
 /** 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);
 }
 /** remove removes the correct key-value pair from the map */
 public void testDescendingRemove() {
   ConcurrentNavigableMap map = dmap5();
   map.remove(m5);
   assertEquals(4, map.size());
   assertFalse(map.containsKey(m5));
 }
 /** remove removes the correct key-value pair from the map */
 public void testRemove() {
   ConcurrentNavigableMap map = map5();
   map.remove(five);
   assertEquals(4, map.size());
   assertFalse(map.containsKey(five));
 }