public void AllocateBlockTest() { IPersistentCollectionSpaceManager pafs = InitPAFS("PCSMAllocateBlock", 16, 8); try { int token = pafs.AllocateBlock(); Assert.AreEqual(0, token); int token2 = pafs.AllocateBlock(); Assert.AreEqual(0, token2); pafs.Put(token2, new byte[0]); int token3 = pafs.AllocateBlock(); Assert.AreEqual(1, token3); pafs.Put(token3, new byte[0]); int token4 = pafs.AllocateBlock(); Assert.AreEqual(2, token4); } finally { pafs.Close(); } }
public void FreeBlockTest() { IPersistentCollectionSpaceManager pafs = InitPAFS("PCSMFreeBlock", 16, 8); try { int token1 = pafs.AllocateBlock(); int token2 = pafs.AllocateBlock(); int token3 = pafs.AllocateBlock(); int token4 = pafs.AllocateBlock(); pafs.FreeBlock(token4); pafs.FreeBlock(token3); pafs.FreeBlock(token2); pafs.FreeBlock(token1); } finally { pafs.Close(); } }
public void GetNextIndexTest() { IPersistentCollectionSpaceManager pafs = InitPAFS("PCSMGetNextIndex", 16, 8); try { //should just wrap AllocateBlock() int block = pafs.AllocateBlock(); int nextSpace = pafs.GetNextIndex(); Assert.AreEqual(block, nextSpace); pafs.Put(block, new byte[pafs.GetElementSize()]); int block2 = pafs.AllocateBlock(); int nextSpace2 = pafs.GetNextIndex(); Assert.AreEqual(block2, nextSpace2); } finally { pafs.Close(); } }
public void WipeIndexTest() { const int elementSize = 10; IPersistentCollectionSpaceManager pafs = InitPAFS("PCSMWipeIndex", elementSize, 8); try { int block = pafs.AllocateBlock(); byte[] putData = new byte[elementSize] { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }; pafs.Put(block, putData); //make sure the data was written TestHelper.AssertByteArraysAreSame(putData, pafs.Get(block)); pafs.WipeElement(block); TestHelper.AssertByteArraysAreSame(new byte[elementSize], pafs.Get(block)); } finally { pafs.Close(); } }
private LinkedListElement GetNewElement(byte[] buffer) { return(new LinkedListElement(buffer, -1, -1, _persistentSimpleCollection.AllocateBlock())); }