StorageDirect implements Engine { final int freePhysRecSize2FreeSlot(final int size){ if(size>MAX_RECORD_SIZE) throw new IllegalArgumentException("too big record"); if(size<0) throw new IllegalArgumentException("negative size"); if(size<1535) return size-1; else if(size == MAX_RECORD_SIZE) return NUMBER_OF_PHYS_FREE_SLOT-1; else return 1535 -1 + (size-1535)/64; } StorageDirect(Volume.Factory volFac, boolean appendOnly,
                   boolean deleteFilesOnExit, boolean failOnWrongHeader, boolean readOnly);  StorageDirect(Volume.Factory volFac); @Override long put(A value, Serializer<A> serializer); @Override A get(long recid, Serializer<A> serializer); @Override void update(long recid, A value, Serializer<A> serializer); @Override void delete(long recid, Serializer<A> serializer); @Override void commit(); @Override void rollback(); @Override void close(); @Override boolean isClosed(); @Override boolean compareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer); @Override boolean isReadOnly(); @Override void compact(); static final String DATA_FILE_EXT; }
@Test public void test_freePhysRecSize2FreeSlot_asserts(){ try{ engine.freePhysRecSize2FreeSlot(StorageDirect.MAX_RECORD_SIZE + 1); fail(); }catch(IllegalArgumentException e){ } try{ engine.freePhysRecSize2FreeSlot(-1); fail(); }catch(IllegalArgumentException e){ } }
@Test public void test_freePhysRecSize2FreeSlot_incremental(){ int oldSlot = -1; for(int size = 1;size<= StorageDirect.MAX_RECORD_SIZE;size++){ int slot = engine.freePhysRecSize2FreeSlot(size); assertTrue(slot >= 0); assertTrue(oldSlot <= slot); assertTrue(slot - oldSlot <= 1); oldSlot= slot; } assertEquals(StorageDirect.NUMBER_OF_PHYS_FREE_SLOT - 1, oldSlot); }
@Test public void test_freePhysRecSize2FreeSlot_max_size_has_unique_slot(){ int slotMax = engine.freePhysRecSize2FreeSlot(StorageDirect.MAX_RECORD_SIZE); int slotMaxMinus1 = engine.freePhysRecSize2FreeSlot(StorageDirect.MAX_RECORD_SIZE - 1); assertEquals(slotMax, slotMaxMinus1 + 1); }