public void testIterable() throws Exception {
    _store.clear();

    // Generate keys
    HashSet<String> keySet = new HashSet<String>(199);
    while (keySet.size() < 100) {
      keySet.add(UUID.randomUUID().toString());
    }
    assertEquals(100, keySet.size());

    // Populate store
    for (String key : keySet) {
      byte[] value = RandomBytes.getBytes();
      _store.put(key.getBytes(), value);
    }

    HashSet<String> keySet2 = new HashSet<String>(199);
    for (Entry<byte[], byte[]> e : _store) {
      keySet2.add(new String(e.getKey()));
    }

    assertEquals(keySet.size(), keySet2.size());

    keySet2.removeAll(keySet);
    assertEquals(0, keySet2.size());
  }
  public void testKeyIndexedIterator() throws Exception {
    IndexedIterator<byte[]> keyIter;

    _store.clear();
    keyIter = _store.keyIterator();
    assertFalse(keyIter.hasNext());

    // Generate keys
    HashSet<String> keySet = new HashSet<String>(199);
    while (keySet.size() < 100) {
      keySet.add(UUID.randomUUID().toString());
    }
    assertEquals(100, keySet.size());

    // Populate store
    for (String key : keySet) {
      byte[] value = RandomBytes.getBytes();
      _store.put(key.getBytes(), value);
    }

    // Check keys
    keyIter = _store.keyIterator();
    byte[] key1a = keyIter.next();

    keyIter.reset(0);
    byte[] key1b = keyIter.next();

    for (int i = 0; i < 10; i++) {
      keyIter.next();
    }
    keyIter.reset(keyIter.index());
    byte[] key1c = keyIter.next();

    assertTrue(Arrays.equals(key1a, key1b));

    // Re-open store
    _store.close();
    _store.open();

    // check keys
    keyIter = _store.keyIterator();
    byte[] key2a = keyIter.next();

    keyIter.reset(0);
    byte[] key2b = keyIter.next();

    for (int i = 0; i < 10; i++) {
      keyIter.next();
    }
    keyIter.reset(keyIter.index());
    byte[] key2c = keyIter.next();

    assertTrue(Arrays.equals(key1a, key2a));
    assertTrue(Arrays.equals(key1b, key2b));
    assertTrue(Arrays.equals(key1c, key2c));
  }
Beispiel #3
0
 @Override
 public final void put(DataStore<byte[], byte[]> store, byte[] key, byte[] value)
     throws Exception {
   store.put(key, value);
 }