コード例 #1
0
        public void TestCreateAndUpdatePage()
        {
            using (var pageStore = CreateEmptyPageStore("TestCreateAndUpdatePage.dat"))
            {
                var newPage = pageStore.Create(1);
                newPage = pageStore.GetWriteablePage(1, newPage);
                newPage.SetData(_testBuffer1);
                pageStore.Commit(1, null);
                Assert.AreEqual(1ul, newPage.Id);
            }

            using (var fs = new FileStream("TestCreateAndUpdatePage.dat", FileMode.Open, FileAccess.Read))
            {
                Assert.AreEqual(8192L, fs.Length);
            }

            using (var pageStore = new BinaryFilePageStore(_pm, "TestCreateAndUpdatePage.dat", 4096, true, 1))
            {
                var page = pageStore.Retrieve(1ul, null);
                Assert.IsFalse(pageStore.IsWriteable(page));
                try
                {
                    page.SetData(_testBuffer2);
                    Assert.Fail("Expected an InvalidOperationException when attempting to write to a non-writeable page");
                }
                catch (InvalidOperationException)
                {
                    // Expected
                }

                page = pageStore.GetWriteablePage(2, page);
                Assert.IsTrue(pageStore.IsWriteable(page));
                Assert.AreEqual(0, _testBuffer1.Compare(page.Data));
                page.SetData(_testBuffer2);
                pageStore.Commit(2, null);
            }

            using (var pageStore = new BinaryFilePageStore(_pm, "TestCreateAndUpdatePage.dat", 4096, true, 2))
            {
                var page = pageStore.Retrieve(1ul, null);
                Assert.AreEqual(0, _testBuffer2.Compare(page.Data));
            }
        }
コード例 #2
0
        public void TestStoreModifiedExceptionThrown()
        {
            ulong pageId;
            IPage page;
            byte[] buffer1 = new byte[] {1, 1, 1, 1};
            byte[] buffer2 = new byte[] {2, 2, 2, 2};
            using (
                var pageStore = TestUtils.CreateEmptyPageStore("TestStoreModifiedExceptionThrown.data",
                                                               PersistenceType.Rewrite))
            {
                page = pageStore.Create(1);
                pageId = page.Id;
                page.SetData(buffer1, 0, 0, 4);
                pageStore.Commit(1, null);
            }

            using (
                var readStore = new BinaryFilePageStore(TestUtils.PersistenceManager,
                                                        "TestStoreModifiedExceptionThrown.data",
                                                        BPlusTreeStoreManager.PageSize, true, 1))
            {
                page = readStore.Retrieve(page.Id, null);
                Assert.AreEqual(1, page.Data[0]);

                using (
                    var writeStore = new BinaryFilePageStore(TestUtils.PersistenceManager,
                                                             "TestStoreModifiedExceptionThrown.data",
                                                             BPlusTreeStoreManager.PageSize, true, 1))
                {
                    var writePage = writeStore.Retrieve(pageId, null);
                    Assert.IsFalse(writeStore.IsWriteable(writePage));
                    writePage =  writeStore.GetWriteablePage(2, writePage);
                    writePage.SetData(buffer2, 0, 0, 4);
                    writeStore.Commit(2, null);
                }

                page = readStore.Retrieve(page.Id, null);
                Assert.AreEqual(1, page.Data[0]);

                using (
                    var writeStore = new BinaryFilePageStore(TestUtils.PersistenceManager,
                                                             "TestStoreModifiedExceptionThrown.data",
                                                             BPlusTreeStoreManager.PageSize, true, 2))
                {
                    var writePage = writeStore.Retrieve(pageId, null);
                    writePage = writeStore.GetWriteablePage(3, writePage);
                    writePage.SetData(buffer2, 0, 0, 4);
                    writeStore.Commit(3, null);
                }

                page = readStore.Retrieve(1, null);
                Assert.AreEqual(1, page.Data[0]);
                // We should not reach this assert because the ReadWriteStoreModifiedException should get thrown
            }
        }