@Test
	public void testWorksAfterRebuild() throws Exception {
		Storage storage = DirectoryStorage.newStorage(TEST_DIR_NAME);

		int testCount = 10;

		long[] IDs = new long[testCount];
		byte[][] objects = new byte[testCount][];
		for (int i = 0; i < testCount; i++) {
			objects[i] = new byte[rnd.nextInt(100) + 1];
			rnd.nextBytes(objects[i]);
			IDs[i] = storage.write(objects[i]);
		}

		for (int i = 0; i < testCount / 2; i++) {
			storage.remove(IDs[i]);
		}

		for (int i = 0; i < testCount / 2; i++) {
			assertNull(storage.get(IDs[i]));
		}
		for (int i = testCount / 2; i < testCount; i++) {
			assertArrayEquals(objects[i], storage.get(IDs[i]));
		}

		storage = DirectoryStorage.getStorage(TEST_DIR_NAME);

		for (int i = 0; i < testCount / 2; i++) {
			assertNull(storage.get(IDs[i]));
		}
		for (int i = testCount / 2; i < testCount; i++) {
			assertArrayEquals(objects[i], storage.get(IDs[i]));
		}

		storage.rebuild();

		for (int i = 0; i < testCount / 2; i++) {
			assertNull(storage.get(IDs[i]));
		}
		for (int i = testCount / 2; i < testCount; i++) {
			assertArrayEquals(objects[i], storage.get(IDs[i]));
		}
	}