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(2); pageId = page.Id; page.SetData(buffer1, 0, 0, 4); pageStore.MarkDirty(2, pageId); pageStore.Commit(2, null); } using ( var readStore = new BinaryFilePageStore(TestUtils.PersistenceManager, "TestStoreModifiedExceptionThrown.data", BPlusTreeStoreManager.PageSize, true, 2, 3)) { using ( var writeStore = new BinaryFilePageStore(TestUtils.PersistenceManager, "TestStoreModifiedExceptionThrown.data", BPlusTreeStoreManager.PageSize, false, 2, 3)) { var writePage = writeStore.Retrieve(pageId, null); Assert.IsFalse(writeStore.IsWriteable(writePage)); writePage = writeStore.GetWriteablePage(3, writePage); writePage.SetData(buffer2, 0, 0, 4); writeStore.MarkDirty(3, pageId); writeStore.Commit(3, null); } using ( var writeStore = new BinaryFilePageStore(TestUtils.PersistenceManager, "TestStoreModifiedExceptionThrown.data", BPlusTreeStoreManager.PageSize, false, 3, 4)) { var writePage = writeStore.Retrieve(pageId, null); writePage = writeStore.GetWriteablePage(4, writePage); writePage.SetData(buffer2, 0, 0, 4); writeStore.MarkDirty(4, pageId); writeStore.Commit(4, null); } page = readStore.Retrieve(1, null); Assert.AreEqual(1, page.Data[0]); // We should not reach this assert because the ReadWriteStoreModifiedException should get thrown } }
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 fs = new FileStream("TestCreateAndUpdatePage.dat", FileMode.Open, FileAccess.Read)) { Assert.AreEqual(8192L, fs.Length); } using (var pageStore = new BinaryFilePageStore(_pm, "TestCreateAndUpdatePage.dat", 4096, false, 1, 2, false)) { 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.MarkDirty(2, 1ul); pageStore.Commit(2, null); } using (var pageStore = new BinaryFilePageStore(_pm, "TestCreateAndUpdatePage.dat", 4096, true, 2, 3, false)) { var page = pageStore.Retrieve(1ul, null); Assert.AreEqual(0, _testBuffer2.Compare(page.Data)); } }
public void TestReopenAfterReadWriteStoreModifiedException() { ulong pageId; var buffer1 = new byte[] { 1, 1, 1, 1 }; var buffer2 = new byte[] { 2, 2, 2, 2 }; var buffer3 = new byte[] { 3, 3, 3, 3 }; using ( var pageStore = TestUtils.CreateEmptyPageStore("TestStoreModifiedExceptionThrown.data", PersistenceType.Rewrite)) { var page = pageStore.Create(1); pageId = page.Id; page.SetData(buffer1, 0, 0, 4); pageStore.MarkDirty(2, pageId); pageStore.Commit(2, null); } var readStore = new BinaryFilePageStore(TestUtils.PersistenceManager, "TestStoreModifiedExceptionThrown.data", BPlusTreeStoreManager.PageSize, true, 2, 3); try { using ( var writeStore = new BinaryFilePageStore(TestUtils.PersistenceManager, "TestStoreModifiedExceptionThrown.data", BPlusTreeStoreManager.PageSize, false, 2, 3)) { var writePage = writeStore.Retrieve(pageId, null); writePage = writeStore.GetWriteablePage(3, writePage); writePage.SetData(buffer2, 0, 0, 4); writeStore.MarkDirty(3, pageId); writeStore.Commit(3, null); } //var page = readStore.Retrieve(pageId, null); //Assert.AreEqual(1, page.Data[0]); using ( var writeStore = new BinaryFilePageStore(TestUtils.PersistenceManager, "TestStoreModifiedExceptionThrown.data", BPlusTreeStoreManager.PageSize, false, 3, 4)) { var writePage = writeStore.Retrieve(pageId, null); writePage = writeStore.GetWriteablePage(4, writePage); writePage.SetData(buffer3, 0, 0, 4); writeStore.MarkDirty(4, pageId); writeStore.Commit(4, null); } try { readStore.Retrieve(pageId, null); Assert.Fail("Expected ReadWriteStoreModifiedException to be thrown"); } catch (ReadWriteStoreModifiedException) { readStore.Close(); readStore.Dispose(); readStore = null; readStore = new BinaryFilePageStore(TestUtils.PersistenceManager, "TestStoreModifiedExceptionThrown.data", BPlusTreeStoreManager.PageSize, true, 4, 5); var page = readStore.Retrieve(pageId, null); Assert.AreEqual(3, page.Data[0]); } } finally { if (readStore != null) { readStore.Dispose(); } } }