示例#1
0
        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();
            }
        }
示例#2
0
        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();
            }
        }
示例#3
0
        private void GetUserHeaderSizeTestAssert(int uHeaderSize)
        {
            IPersistentCollectionSpaceManager pafs = InitPAFS("PCSMGetUserHeaderSizeTestAssert", 16, uHeaderSize);

            try
            {
                Assert.AreEqual(uHeaderSize, pafs.GetUserHeaderSize());
            }
            finally
            {
                pafs.Close();
            }
        }
示例#4
0
        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();
            }
        }
示例#5
0
        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();
            }
        }
示例#6
0
        public void GetHeaderTest()
        {
            IPersistentCollectionSpaceManager pafs = InitPAFS("GetPCSMHeader", 16, 20);

            try
            {
                byte[] userheader = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 100, 110, 120, 130, 140, 150, 210, 220, 230, 240, 255 };
                pafs.PutUserHeader(userheader);

                TestHelper.AssertByteArraysAreSame(userheader, pafs.GetUserHeader());


                try {
                    pafs.PutUserHeader(new byte[21]);
                    Assert.Fail("Should throw an exception");
                } catch (InvalidUserHeaderException) {}
            }
            finally
            {
                pafs.Close();
            }
        }
示例#7
0
        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();
            }
        }
示例#8
0
        public void GetUserHeaderTest()
        {
            int uHeaderSize = 8;
            IPersistentCollectionSpaceManager pafs = InitPAFS("GetPCSMUserHeader", 16, uHeaderSize);

            try
            {
                byte[] uHeader = pafs.GetUserHeader();

                Assert.AreEqual(uHeaderSize, uHeader.Length);

                TestHelper.AssertByteArraysAreSame(new byte[0], uHeader);

                byte[] newUserHeader = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
                pafs.PutUserHeader(newUserHeader);
                byte[] actual = pafs.GetUserHeader();

                TestHelper.AssertByteArraysAreSame(newUserHeader, actual);
            }
            finally
            {
                pafs.Close();
            }
        }
 public void Close()
 {
     _persistentSimpleCollection.Close();
 }