Beispiel #1
0
  @Test
  public void testExportToBase64ShouldNotThrow() throws Exception {
    int numKeys = 1000;
    int numValuesPerKeys = 1000;
    createAndFillMap(DIRECTORY, numKeys, numValuesPerKeys).close();
    Map.exportToBase64(DIRECTORY, DATAFILE);

    // Clear the map.
    Map map = new Map(DIRECTORY);
    // TODO Check return value, which is a pair now.
    Utils.Pair<Integer, Long> result =
        map.removeAllMatches(
            new Predicate() {
              @Override
              public boolean call(ByteBuffer bytes) {
                return true;
              }
            });
    Assert.assertEquals(numKeys, result.a().intValue());
    Assert.assertEquals(numKeys * numValuesPerKeys, result.b().longValue());
    map.close();

    // Import and check content.
    Map.importFromBase64(DIRECTORY, DATAFILE);
    map = new Map(DIRECTORY);
    for (int i = 0; i < numKeys; ++i) {
      Iterator iter = map.get(makeKey(i));
      for (int j = 0; j < numValuesPerKeys; ++j) {
        Assert.assertTrue(iter.hasNext());
        Assert.assertEquals(j, getSuffix(iter.next()));
      }
      iter.close();
    }
    map.close();
  }
Beispiel #2
0
  @Test
  public void testRemoveAllKeys() throws Exception {
    int numKeys = 1000;
    int numValuesPerKeys = 1000;
    Map map = createAndFillMap(DIRECTORY, numKeys, numValuesPerKeys);

    Utils.Pair<Integer, Long> result = map.removeAllMatches(IS_EVEN);
    Assert.assertEquals(numKeys / 2, result.a().intValue());
    Assert.assertEquals(numKeys / 2 * numValuesPerKeys, result.b().longValue());
    for (int i = 0; i < numKeys; ++i) {
      if (i % 2 == 0) {
        Assert.assertFalse(map.contains(makeKey(i)));
      } else {
        Assert.assertTrue(map.contains(makeKey(i)));
      }
    }
    map.close();
  }