コード例 #1
0
 private synchronized void load() {
   //noinspection unchecked
   map = (Hashtable<Object, Object>) storage.load();
 }
コード例 #2
0
ファイル: StorageTest.java プロジェクト: riengcs/utils
  /**
   * Tests {@link Storage} by creating a new Storage, {@link Storage#add(Storable) adding data},
   * adding more data, {@link Storage#remove(long) removing data}, and {@link Storage#compact()
   * compacting the directory}, checking the {@link Storage#size() number of stored objects} and the
   * {@link Storage#getDirectorySize() number of directory entries} after every action.
   *
   * @throws StorageException
   */
  @SuppressWarnings("synthetic-access")
  public void testSimpleStorage() throws StorageException {
    Storage<Data> storage;
    Data data;

    storage = new Storage<Data>(new DataFactory(), directory, "data");
    data = new Data(0x12345678);
    try {
      storage.add(data);
      fail("exception expected");
    } catch (IllegalStateException ise1) {
      /* okay. */
    }

    storage.open();
    assertEquals(0, storage.size());
    assertEquals(0, storage.getDirectorySize());
    storage.add(data);
    assertEquals(1, storage.size());
    assertEquals(1, storage.getDirectorySize());
    storage.close();

    storage.open();
    assertEquals(1, storage.size());
    assertEquals(1, storage.getDirectorySize());
    data = storage.load(0x12345678);
    assertNotNull(data);
    storage.close();

    data = new Data(0x23456789);
    storage.open();
    assertEquals(1, storage.size());
    assertEquals(1, storage.getDirectorySize());
    storage.add(data);
    assertEquals(2, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.close();

    storage.open();
    assertEquals(2, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.remove(0x12345678);
    assertEquals(1, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.close();

    storage.open();
    assertEquals(1, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.remove(0x01234567);
    assertEquals(1, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.close();

    storage.open();
    assertEquals(1, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.remove(0x23456789);
    assertEquals(0, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.close();

    storage.open();
    assertEquals(0, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.close();

    storage.compact();
    storage.open();
    assertEquals(0, storage.size());
    assertEquals(0, storage.getDirectorySize());
    storage.close();
  }