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 ReopenTest() { const string arrayName = "ReopenPCSMWithSpaceManagerTest"; const int elementSize = 16; const int userHeaderSize = 8; IPersistentCollectionSpaceManager pafs = InitPAFS(arrayName, elementSize, userHeaderSize); try { byte[] userHeader = new byte[userHeaderSize] { 1, 2, 3, 4, 5, 6, 7, 8 }; pafs.PutUserHeader(userHeader); int index = 0; byte[] expectedBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; pafs.Put(index, expectedBytes); pafs.Close(); pafs = new PersistentCollectionSpaceManager(arrayName); Assert.AreEqual(elementSize, pafs.GetElementSize()); Assert.AreEqual(userHeaderSize, pafs.GetUserHeaderSize()); TestHelper.AssertByteArraysAreSame(userHeader, pafs.GetUserHeader()); TestHelper.AssertByteArraysAreSame(expectedBytes, pafs.Get(index)); } 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(); } }
public PersistentLinkedList(String listName, int elementSize, int userHeaderSize) { _persistentSimpleCollection = new PersistentCollectionSpaceManager(listName, elementSize + 2 * PersistenceConstants.IntSize, userHeaderSize+GetSizeSize()); _persistentSimpleCollection.Put(0, new byte[0]); // I don't want the first element to be returned for GetNextIndex() }
private void PutElement(LinkedListElement element) { byte[] elementBytes = element.Serialize(); _persistentSimpleCollection.Put(element.Index, elementBytes); }
public PersistentLinkedList(String listName, int elementSize, int userHeaderSize) { _persistentSimpleCollection = new PersistentCollectionSpaceManager(listName, elementSize + 2 * PersistenceConstants.IntSize, userHeaderSize + GetSizeSize()); _persistentSimpleCollection.Put(0, new byte[0]); // I don't want the first element to be returned for GetNextIndex() }