@Test
  public void test_phys_record_reused() {
    final long recid = engine.put(1L, Serializer.LONG_SERIALIZER);
    final long physRecid = engine.index.getLong(recid * 8 + StorageDirect.INDEX_OFFSET_START * 8);
    engine.delete(recid, Serializer.LONG_SERIALIZER);
    final long recid2 = engine.put(1L, Serializer.LONG_SERIALIZER);

    assertEquals(recid, recid2);
    assertEquals(physRecid, engine.index.getLong(recid * 8 + StorageDirect.INDEX_OFFSET_START * 8));
  }
 @Test
 public void test_index_record_delete_and_reusef() {
   long recid = engine.put(1000L, Serializer.LONG_SERIALIZER);
   engine.commit();
   assertEquals(1, countIndexRecords());
   assertEquals(Engine.LAST_RESERVED_RECID + 1, recid);
   engine.delete(recid, Serializer.LONG_SERIALIZER);
   engine.commit();
   assertEquals(0, countIndexRecords());
   long recid2 = engine.put(1000L, Serializer.LONG_SERIALIZER);
   engine.commit();
   // test that previously deleted index slot was reused
   assertEquals(recid, recid2);
   assertEquals(1, countIndexRecords());
   assertNotEquals(0, engine.index.getLong(recid * 8 + StorageDirect.INDEX_OFFSET_START * 8));
 }
 @Test
 public void test_index_record_delete() {
   long recid = engine.put(1000L, Serializer.LONG_SERIALIZER);
   engine.commit();
   assertEquals(1, countIndexRecords());
   engine.delete(recid, Serializer.LONG_SERIALIZER);
   engine.commit();
   assertEquals(0, countIndexRecords());
 }
 @Test
 public void in_memory_test() {
   StorageDirect engine = new StorageDirect(Volume.memoryFactory(false));
   Map<Long, Integer> recids = new HashMap<Long, Integer>();
   for (int i = 0; i < 1000; i++) {
     long recid = engine.put(i, Serializer.BASIC_SERIALIZER);
     recids.put(recid, i);
   }
   for (Long recid : recids.keySet()) {
     assertEquals(recids.get(recid), engine.get(recid, Serializer.BASIC_SERIALIZER));
   }
 }
  @Test
  public void test_index_record_delete_and_reuse_large() {
    final long MAX = 10;

    List<Long> recids = new ArrayList<Long>();
    for (int i = 0; i < MAX; i++) {
      recids.add(engine.put(0L, Serializer.LONG_SERIALIZER));
    }

    for (long recid : recids) {
      engine.delete(recid, Serializer.LONG_SERIALIZER);
    }

    // now allocate again second recid list
    List<Long> recids2 = new ArrayList<Long>();
    for (int i = 0; i < MAX; i++) {
      recids2.add(engine.put(0L, Serializer.LONG_SERIALIZER));
    }

    // second list should be reverse of first, as Linked Offset List is LIFO
    Collections.reverse(recids);
    assertEquals(recids, recids2);
  }
  @Test
  public void test_index_stores_record_size() throws IOException {

    final long recid = engine.put(1, Serializer.INTEGER_SERIALIZER);
    engine.commit();
    assertEquals(
        4, engine.index.getUnsignedShort(recid * 8 + StorageDirect.INDEX_OFFSET_START * 8));
    assertEquals(Integer.valueOf(1), engine.get(recid, Serializer.INTEGER_SERIALIZER));

    engine.update(recid, 1L, Serializer.LONG_SERIALIZER);
    engine.commit();
    assertEquals(
        8, engine.index.getUnsignedShort(recid * 8 + StorageDirect.INDEX_OFFSET_START * 8));
    assertEquals(Long.valueOf(1), engine.get(recid, Serializer.LONG_SERIALIZER));
  }
  @Test
  public void compact() {
    Map<Long, Long> recids = new HashMap<Long, Long>();
    for (Long l = 0L; l < 1000; l++) {
      recids.put(l, engine.put(l, Serializer.LONG_SERIALIZER));
    }

    engine.commit();
    engine.compact();

    for (Map.Entry<Long, Long> e : recids.entrySet()) {
      Long recid = e.getValue();
      Long value = e.getKey();
      assertEquals(value, engine.get(recid, Serializer.LONG_SERIALIZER));
    }
  }