public void SPT_TestReadWriteTable() { int entryCount = 40; int physicalPageDistance = 5; string dataFile = "SPT_TestData1.tpdb"; if (File.Exists(dataFile)) { File.Delete(dataFile); } List <int> freedPages = null; StoragePageManager spaceMgr = new StoragePageManager(); StoragePageTable pageTable2 = new StoragePageTable(); StoragePageTable pageTable = new StoragePageTable(); for (int idx = 0; idx < entryCount; idx++) { pageTable.SetLogicalPage(idx + physicalPageDistance); } using (FileStreamWrapper dataFileStream = FileStreamWrapper.CreateObject(dataFile)) { int root = pageTable.WritePageTableData(dataFileStream, spaceMgr, out freedPages); dataFileStream.Seek(0, SeekOrigin.Begin); pageTable2.ReadPageTableData(dataFileStream, root); } for (int idx = 0; idx < entryCount; idx++) { int physicalAddress = pageTable2.GetPhysicalPage(idx); Assert.AreEqual(idx + physicalPageDistance, physicalAddress); } }
/// <summary> /// Remarks: /// No locking needed beause this method cannot be invoked on the object. /// It is only called during initialization before the object is returned /// from the object factory method. /// </summary> /// <param name="filePath"></param> private void Init(string filePath) { // open the file this.dataFile = FileStreamWrapper.CreateObject(filePath); DBHdr dbRoot = this.ReadDBRoot(); if (null == dbRoot) { // setup the data file this.InitializeDataFile(); // flush the file this.dataFile.Flush(true); } else { // read the prepared transaction data this.preparedContextMap.ReadTransactionTableData( this.dataFile, dbRoot.PrepedTransactions); // read the data manager this.pageManager.ReadPageManagerData( this.dataFile, dbRoot.PageManager); } }
public void SP_TestReadWritePage() { string dataFile = "SP_TestData1.tpdb"; if (File.Exists(dataFile)) { File.Delete(dataFile); } TestData[] pageData = { new TestData { data = "Record_0", recordIdx = 0 }, new TestData { data = "Record_1", recordIdx = 1 }, new TestData { data = "Record_2", recordIdx = 2 } }; int pageIndex = int.MinValue; // write the page using (FileStreamWrapper dataFileStream = FileStreamWrapper.CreateObject(dataFile)) { // populate the page with some data StoragePage page = new StoragePage(); AddRecords(page, pageData); // write the file to disk pageIndex = page.WritePageData(dataFileStream, -1); } // read the page using (FileStreamWrapper dataFileStream = FileStreamWrapper.CreateObject(dataFile)) { // read page from file StoragePage page = new StoragePage(); page.ReadPageData(dataFileStream, pageIndex); // validate the page data ReadRecords(page, pageData); } }