public void OnEmptyStorageShouldReturnMinusOneForRequestedFreePageIndex() { var manager = new FileSystemPageManager(4096); using (var storage = new Storage(manager)) { storage.CreateNew(StoragePath); var fsm = new FreeSpaceMap(manager); foreach (var fsmValue in EnumHelper.FixedSizeItemsFsmValues()) { Assert.AreEqual(-1, fsm.GetFreePageIndex(fsmValue)); } } }
public void MultiPageOperations() { var manager = new FileSystemPageManager(4096); using (var storage = new Storage(manager)) { storage.CreateNew(StoragePath); var fsm = new FreeSpaceMap(manager); int entryPerPage = PageFormatter.GetFsmEntryCount(manager.FetchPage(1)); int entryCount = entryPerPage * 3; // check writing to the last page var value = FsmValue.Class0; var index = entryCount - 1; fsm.Set(index, value); Assert.AreEqual(value, fsm.Get(index)); // middle page value = FsmValue.Class1; index = entryPerPage + 1; fsm.Set(index, value); Assert.AreEqual(value, fsm.Get(index)); // the first page value = FsmValue.Class2; index = entryPerPage - 1; fsm.Set(index, value); Assert.AreEqual(value, fsm.Get(index)); for (int i = 0; i < entryCount; i++) { fsm.Set(i, FsmValue.Class3); } for (int i = 0; i < entryCount; i++) { long pageIndex = fsm.GetFreePageIndex(FsmValue.Class3); Assert.AreNotEqual(-1, pageIndex); fsm.Set(i, FsmValue.Full); } } }