Example #1
0
 public void PageIndex_AddEntryToPageIndexWithEntries()
 {
     using (target = new PageIndex(stream))
     {
         PageSummary summary1 = new PageSummary()
         {
             Allocated = true, DataFileOffset = 4096, Size = 1024, AddressSpaceId = id1, Used = 300
         };
         target.AddOrUpdateEntry(summary1);
         Assert.AreEqual(3, target[id1].Count());
         Assert.AreEqual(4096, target[id1][2].DataFileOffset);
         Assert.AreEqual(1024, target[id1][2].Size);
         Assert.IsTrue(target[id1][2].Allocated);
         Assert.AreEqual(132, target[id1][2].PageFileIndex);
         Assert.AreEqual(5120, target.EndOfPageIndex);
     }
 }
Example #2
0
 public void PageIndex_AddEntryToEmptyPageIndex()
 {
     stream = new MemoryStream();
     using (target = new PageIndex(stream))
     {
         PageSummary summary1 = new PageSummary()
         {
             AddressSpaceId = id1, Allocated = true, DataFileOffset = 0, Size = 1024, Used = 1024
         };
         target.AddOrUpdateEntry(summary1);
         Assert.AreEqual(0, target[id1][0].DataFileOffset);
         Assert.AreEqual(1024, target[id1][0].Size);
         Assert.AreEqual(1024, target[id1][0].Used);
         Assert.IsTrue(target[id1][0].Allocated);
         Assert.AreEqual(0, target[id1][0].PageFileIndex);
         Assert.AreEqual(id1, target[id1][0].AddressSpaceId);
         Assert.AreEqual(1024, target.EndOfPageIndex);
     }
 }
Example #3
0
        public void PageIndex_MoveSummaryFromEmptyToUsed()
        {
            target = new PageIndex(stream);
            Assert.AreEqual(2, target[id1].Count);
            Assert.AreEqual(1, target.EmptyPages.Count);
            PageSummary summary = target.EmptyPages[0];

            Assert.AreEqual(99, summary.PageFileIndex);
            summary.AddressSpaceId = id1;
            target.AddOrUpdateEntry(summary);

            stream.Position = 0;

            var newIndex = new PageIndex(stream);

            Assert.AreEqual(3, target[id1].Count);
            Assert.AreEqual(0, target.EmptyPages.Count);
            PageSummary retrieved = target[id1][2];

            Assert.AreEqual(99, retrieved.PageFileIndex);
        }
Example #4
0
        public void PageIndex_UpdateEntryInPageIndex()
        {
            using (target = new PageIndex(stream))
            {
                Assert.IsNotNull(target);
                var summary = target[id1][1];
                summary.Used = 400;
                target.AddOrUpdateEntry(summary);

                Assert.AreEqual(2, target[id1].Count);
                Assert.AreEqual(0, target[id1][0].DataFileOffset);
                Assert.AreEqual(1024, target[id1][0].Size);
                Assert.AreEqual(1024, target[id1][0].Used);
                Assert.IsTrue(target[id1][0].Allocated);
                Assert.AreEqual(0, target[id1][0].PageFileIndex);

                Assert.AreEqual(1, target[id2].Count);
                Assert.AreEqual(1024, target[id2][0].DataFileOffset);
                Assert.AreEqual(1024, target[id2][0].Size);
                Assert.AreEqual(100, target[id2][0].Used);
                Assert.IsTrue(target[id2][0].Allocated);
                Assert.AreEqual(33, target[id2][0].PageFileIndex);

                Assert.AreEqual(2048, target[id1][1].DataFileOffset);
                Assert.AreEqual(1024, target[id1][1].Size);
                Assert.AreEqual(400, target[id1][1].Used);
                Assert.IsTrue(target[id1][1].Allocated);
                Assert.AreEqual(66, target[id1][1].PageFileIndex);

                Assert.AreEqual(3072, target[Guid.Empty][0].DataFileOffset);
                Assert.AreEqual(1024, target[Guid.Empty][0].Size);
                Assert.AreEqual(0, target[Guid.Empty][0].Used);
                Assert.IsFalse(target[Guid.Empty][0].Allocated);
                Assert.AreEqual(99, target[Guid.Empty][0].PageFileIndex);

                Assert.AreEqual(4096, target.EndOfPageIndex);
            }
        }