Exemple #1
0
  @Test // (timeout = 10000)
  public void testIteration() {
    HTreeMap m =
        new HTreeMap<Integer, Integer>(recman, true) {
          @Override
          protected int hash(Object key) {
            return (Integer) key;
          }
        };

    final int max = 140;
    final int inc = 111111;

    for (Integer i = 0; i < max; i++) {
      m.put(i, i + inc);
    }

    Iterator<Integer> keys = m.keySet().iterator();
    for (Integer i = 0; i < max; i++) {
      assertTrue(keys.hasNext());
      assertEquals(i, keys.next());
    }
    assertTrue(!keys.hasNext());

    Iterator<Integer> vals = m.values().iterator();
    for (Integer i = inc; i < max + inc; i++) {
      assertTrue(vals.hasNext());
      assertEquals(i, vals.next());
    }
    assertTrue(!vals.hasNext());

    // great it worked, test stuff spread across segments
    m.clear();
    assertTrue(m.isEmpty());

    for (int i = 0; i < max; i++) {
      m.put((1 << 30) + i, i + inc);
      m.put((2 << 30) + i, i + inc);
      m.put((3 << 30) + i, i + inc);
    }

    assertEquals(max * 3, m.size());

    int countSegments = 0;
    for (long segmentRecid : m.segmentRecids) {
      if (recman.recordGet(segmentRecid, HTreeMap.DIR_SERIALIZER) != null) countSegments++;
    }

    assertEquals(3, countSegments);

    keys = m.keySet().iterator();
    for (int i = 1; i <= 3; i++) {
      for (int j = 0; j < max; j++) {
        assertTrue(keys.hasNext());
        assertEquals(Integer.valueOf((i << 30) + j), keys.next());
      }
    }
    assertTrue(!keys.hasNext());
  }
Exemple #2
0
 @Test
 public void clear() {
   HTreeMap m = new HTreeMap(recman, true);
   for (Integer i = 0; i < 100; i++) {
     m.put(i, i);
   }
   m.clear();
   assertTrue(m.isEmpty());
   assertEquals(0, m.size());
 }