static void TestBTreeInsert() { LeafTableCell result = null; // init record DBRecord record_0 = GetTestBRecord(100); DBRecord record_1 = GetTestBRecord(101); DBRecord record_2 = GetTestBRecord(102); DBRecord record_3 = GetTestBRecord(103); DBRecord record_4 = GetTestBRecord(104); DBRecord record_5 = GetTestBRecord(105); DBRecord record_6 = GetTestBRecord(106); DBRecord record_7 = GetTestBRecord(107); DBRecord keyRecord_0 = GetTestBRecord(1); DBRecord keyRecord_1 = GetTestBRecord(2); DBRecord keyRecord_2 = GetTestBRecord(3); DBRecord keyRecord_3 = GetTestBRecord(4); DBRecord keyRecord_4 = GetTestBRecord(5); DBRecord keyRecord_5 = GetTestBRecord(6); DBRecord keyRecord_6 = GetTestBRecord(7); // init key string dbPath = "./testdbfile.minidb"; File.Delete(dbPath); Pager pager = new Pager(dbPath); FreeList freeList = new FreeList(pager); BTreeController controller = new BTreeController(pager, freeList); BTreeNode root = null; root = controller.InsertCell(root, keyRecord_0, record_0); result = (LeafTableCell)controller.FindCell(keyRecord_0, root); Assert.NotNull(result); Assert.Equal(1, result.Key.GetValues()[0].IntegerValue); //1 root = controller.InsertCell(root, keyRecord_1, record_1); result = (LeafTableCell)controller.FindCell(keyRecord_1, root); Assert.NotNull(result); Assert.Equal(2, result.Key.GetValues()[0].IntegerValue); //2 root = controller.InsertCell(root, keyRecord_2, record_2); result = (LeafTableCell)controller.FindCell(keyRecord_2, root); Assert.NotNull(result); Assert.Equal(3, result.Key.GetValues()[0].IntegerValue); //3 root = controller.InsertCell(root, keyRecord_3, record_3); result = (LeafTableCell)controller.FindCell(keyRecord_3, root); Assert.NotNull(result); Assert.Equal(4, result.Key.GetValues()[0].IntegerValue); //4 root = controller.InsertCell(root, keyRecord_4, record_4); result = (LeafTableCell)controller.FindCell(keyRecord_4, root); Assert.NotNull(result); Assert.Equal(5, result.Key.GetValues()[0].IntegerValue); //5 root = controller.InsertCell(root, keyRecord_5, record_5); result = (LeafTableCell)controller.FindCell(keyRecord_5, root); Assert.NotNull(result); Assert.Equal(6, result.Key.GetValues()[0].IntegerValue); //6 root = controller.InsertCell(root, keyRecord_6, record_6); result = (LeafTableCell)controller.FindCell(keyRecord_6, root); Assert.NotNull(result); Assert.Equal(7, result.Key.GetValues()[0].IntegerValue); //Find result = (LeafTableCell)controller.FindCell(keyRecord_0, root); Assert.NotNull(result); Assert.Equal(1, result.Key.GetValues()[0].IntegerValue); result = (LeafTableCell)controller.FindCell(keyRecord_1, root); Assert.NotNull(result); Assert.Equal(2, result.Key.GetValues()[0].IntegerValue); result = (LeafTableCell)controller.FindCell(keyRecord_2, root); Assert.NotNull(result); Assert.Equal(3, result.Key.GetValues()[0].IntegerValue); result = (LeafTableCell)controller.FindCell(keyRecord_3, root); Assert.NotNull(result); Assert.Equal(4, result.Key.GetValues()[0].IntegerValue); result = (LeafTableCell)controller.FindCell(keyRecord_4, root); Assert.NotNull(result); Assert.Equal(5, result.Key.GetValues()[0].IntegerValue); result = (LeafTableCell)controller.FindCell(keyRecord_5, root); Assert.NotNull(result); Assert.Equal(6, result.Key.GetValues()[0].IntegerValue); result = (LeafTableCell)controller.FindCell(keyRecord_6, root); Assert.NotNull(result); Assert.Equal(7, result.Key.GetValues()[0].IntegerValue); pager.Close(); }
static void HardTestForBTree() { string dbPath = "./testdbfile.minidb"; File.Delete(dbPath); Pager pager = new Pager(dbPath); FreeList freeList = new FreeList(pager); BTreeController controller = new BTreeController(pager, freeList, 4); BTreeNode root = null; LeafTableCell result = null; //Construct BTree for (int i = 1; i < 20; i++) { DBRecord record = GetTestBRecord(i + 100); DBRecord keyRecord = GetTestBRecord(i); root = controller.InsertCell(root, keyRecord, record); result = (LeafTableCell)controller.FindCell(keyRecord, root); Assert.NotNull(result); Assert.Equal(i, result.Key.GetValues()[0].IntegerValue); } // test inserting records with repeated primary keys DBRecord record_D = GetTestBRecord(103); DBRecord keyRecord_D = GetTestBRecord(3); bool isError = false; try { root = controller.InsertCell(root, keyRecord_D, record_D); } catch (RepeatedKeyException) { isError = true; } Assert.True(isError); isError = false; record_D = GetTestBRecord(105); keyRecord_D = GetTestBRecord(5); try { root = controller.InsertCell(root, keyRecord_D, record_D); } catch (RepeatedKeyException) { isError = true; } BTreeNodeHelper.VisualizeIntegerTree(pager, root); //find all for (int i = 1; i < 20; i++) { DBRecord keyRecord = GetTestBRecord(i); result = (LeafTableCell)controller.FindCell(keyRecord, root); Assert.NotNull(result); Assert.Equal(i, result.Key.GetValues()[0].IntegerValue); } //delete for (int i = 10; i < 20; i++) { DBRecord keyRecord = GetTestBRecord(i); root = controller.Delete(keyRecord, root); result = (LeafTableCell)controller.FindCell(keyRecord, root); Assert.Null(result); for (int m = 1; m < 10; m++) { DBRecord keyRecord_check = GetTestBRecord(m); result = (LeafTableCell)controller.FindCell(keyRecord_check, root); Assert.NotNull(result); Assert.Equal(m, result.Key.GetValues()[0].IntegerValue); } } BTreeNodeHelper.VisualizeIntegerTree(pager, root); //find others for (int i = 1; i < 10; i++) { DBRecord keyRecord = GetTestBRecord(i); result = (LeafTableCell)controller.FindCell(keyRecord, root); Assert.NotNull(result); Assert.Equal(i, result.Key.GetValues()[0].IntegerValue); } //insert after delete for (int i = 10; i < 20; i++) { DBRecord record = GetTestBRecord(i + 100); DBRecord keyRecord = GetTestBRecord(i); root = controller.InsertCell(root, keyRecord, record); result = (LeafTableCell)controller.FindCell(keyRecord, root); Assert.NotNull(result); Assert.Equal(i, result.Key.GetValues()[0].IntegerValue); } //find all for (int i = 1; i < 20; i++) { DBRecord keyRecord = GetTestBRecord(i); result = (LeafTableCell)controller.FindCell(keyRecord, root); Assert.NotNull(result); Assert.Equal(i, result.Key.GetValues()[0].IntegerValue); } pager.Close(); }
static void Bugtest2() { string dbPath = "./testdbfile.minidb"; File.Delete(dbPath); Pager pager = new Pager(dbPath); FreeList freeList = new FreeList(pager); BTreeController controller = new BTreeController(pager, freeList); BTreeNode root = null; LeafTableCell result = null; DBRecord record = GetTestBRecord(660132168); DBRecord keyRecord = GetTestBRecord(660132168); root = controller.InsertCell(root, keyRecord, record); record = GetTestBRecord(2007593075); keyRecord = GetTestBRecord(2007593075); root = controller.InsertCell(root, keyRecord, record); record = GetTestBRecord(356456016); keyRecord = GetTestBRecord(356456016); root = controller.InsertCell(root, keyRecord, record); record = GetTestBRecord(32731844); keyRecord = GetTestBRecord(32731844); root = controller.InsertCell(root, keyRecord, record); BTreeNodeHelper.VisualizeIntegerTree(pager, root); record = GetTestBRecord(159431057); keyRecord = GetTestBRecord(159431057); root = controller.InsertCell(root, keyRecord, record); keyRecord = GetTestBRecord(660132168); result = (LeafTableCell)controller.FindCell(keyRecord, root); Assert.NotNull(result); Assert.Equal(660132168, result.Key.GetValues()[0].IntegerValue); BTreeNodeHelper.VisualizeIntegerTree(pager, root); record = GetTestBRecord(991596943); keyRecord = GetTestBRecord(991596943); root = controller.InsertCell(root, keyRecord, record); BTreeNodeHelper.VisualizeIntegerTree(pager, root); record = GetTestBRecord(794643883); keyRecord = GetTestBRecord(794643883); root = controller.InsertCell(root, keyRecord, record); BTreeNodeHelper.VisualizeIntegerTree(pager, root); record = GetTestBRecord(1158712065); keyRecord = GetTestBRecord(1158712065); root = controller.InsertCell(root, keyRecord, record); BTreeNodeHelper.VisualizeIntegerTree(pager, root); pager.Close(); }
static void BugTest3() { string dbPath = "./testdbfile.minidb"; File.Delete(dbPath); Pager pager = new Pager(dbPath); FreeList freeList = new FreeList(pager); BTreeController controller = new BTreeController(pager, freeList); BTreeNode root = null; LeafTableCell result = null; // 1 // DBRecord record = GetTestBRecord(74396264); // DBRecord keyRecord = GetTestBRecord(74396264); DBRecord record = GetTestBRecord(1); DBRecord keyRecord = GetTestBRecord(1); root = controller.InsertCell(root, keyRecord, record); // 2 // record = GetTestBRecord(1766307441); // keyRecord = GetTestBRecord(1766307441); record = GetTestBRecord(7); keyRecord = GetTestBRecord(7); root = controller.InsertCell(root, keyRecord, record); // 3 // record = GetTestBRecord(2025306881); // keyRecord = GetTestBRecord(2025306881); record = GetTestBRecord(8); keyRecord = GetTestBRecord(8); root = controller.InsertCell(root, keyRecord, record); // 4 // record = GetTestBRecord(147488698); // keyRecord = GetTestBRecord(147488698); record = GetTestBRecord(2); keyRecord = GetTestBRecord(2); root = controller.InsertCell(root, keyRecord, record); BTreeNodeHelper.VisualizeIntegerTree(pager, root); // 5 // record = GetTestBRecord(1109110087); // keyRecord = GetTestBRecord(1109110087); record = GetTestBRecord(4); keyRecord = GetTestBRecord(4); root = controller.InsertCell(root, keyRecord, record); BTreeNodeHelper.VisualizeIntegerTree(pager, root); // test 5 // keyRecord = GetTestBRecord(1109110087); keyRecord = GetTestBRecord(4); result = (LeafTableCell)controller.FindCell(keyRecord, root); Assert.NotNull(result); // Assert.Equal(==, result.Key.GetValues()[0].IntegerValue 1109110087); Assert.Equal(4, result.Key.GetValues()[0].IntegerValue); // 6 // record = GetTestBRecord(1163206015); // keyRecord = GetTestBRecord(1163206015); record = GetTestBRecord(5); keyRecord = GetTestBRecord(5); // ISSUE HERE root = controller.InsertCell(root, keyRecord, record); BTreeNodeHelper.VisualizeIntegerTree(pager, root); // 7 // record = GetTestBRecord(1485715653); // keyRecord = GetTestBRecord(1485715653); record = GetTestBRecord(6); keyRecord = GetTestBRecord(6); root = controller.InsertCell(root, keyRecord, record); BTreeNodeHelper.VisualizeIntegerTree(pager, root); // 8 // record = GetTestBRecord(1087082570); // keyRecord = GetTestBRecord(1087082570); record = GetTestBRecord(3); keyRecord = GetTestBRecord(3); root = controller.InsertCell(root, keyRecord, record); BTreeNodeHelper.VisualizeIntegerTree(pager, root); pager.Close(); }
static void BugTest1() { string dbPath = "./testdbfile.minidb"; File.Delete(dbPath); Pager pager = new Pager(dbPath); FreeList freeList = new FreeList(pager); BTreeController controller = new BTreeController(pager, freeList); BTreeNode root = null; LeafTableCell result = null; DBRecord record = GetTestBRecord(76767785); DBRecord keyRecord = GetTestBRecord(76767785); root = controller.InsertCell(root, keyRecord, record); record = GetTestBRecord(1922063022); keyRecord = GetTestBRecord(1922063022); root = controller.InsertCell(root, keyRecord, record); record = GetTestBRecord(514874720); keyRecord = GetTestBRecord(514874720); root = controller.InsertCell(root, keyRecord, record); record = GetTestBRecord(724803552); keyRecord = GetTestBRecord(724803552); root = controller.InsertCell(root, keyRecord, record); BTreeNodeHelper.VisualizeIntegerTree(pager, root); record = GetTestBRecord(1219882375); keyRecord = GetTestBRecord(1219882375); root = controller.InsertCell(root, keyRecord, record); keyRecord = GetTestBRecord(724803552); result = (LeafTableCell)controller.FindCell(keyRecord, root); Assert.NotNull(result); Assert.Equal(724803552, result.Key.GetValues()[0].IntegerValue); BTreeNodeHelper.VisualizeIntegerTree(pager, root); record = GetTestBRecord(681446986); keyRecord = GetTestBRecord(681446986); root = controller.InsertCell(root, keyRecord, record); BTreeNodeHelper.VisualizeIntegerTree(pager, root); record = GetTestBRecord(1427789753); keyRecord = GetTestBRecord(1427789753); root = controller.InsertCell(root, keyRecord, record); BTreeNodeHelper.VisualizeIntegerTree(pager, root); record = GetTestBRecord(1066176166); keyRecord = GetTestBRecord(1066176166); root = controller.InsertCell(root, keyRecord, record); BTreeNodeHelper.VisualizeIntegerTree(pager, root); pager.Close(); }