public void testAddLeafPage() throws HeapException {
// A 10 B
final NonTerminalPage nonTerminalPage = new NonTerminalPage(1, true);
nonTerminalPage.setPageRecord(PAGE_RECORD);
final MockLeafPage leafPageA = newMockLeafPage();
final long pageAPositionInFile = 1000;
leafPageA.setPositionInFile(pageAPositionInFile);
final MockLeafPage leafPageB = newMockLeafPage();
final long pageBPositionInFile = 2000;
leafPageB.setPositionInFile(pageBPositionInFile);
final DataRecordIdentifier key10 = new DataRecordIdentifier(10);
nonTerminalPage.setEntry(0, leafPageA.getPositionInFile(), key10);
nonTerminalPage.setEntry(1, leafPageB.getPositionInFile(), null);
nonTerminalPage.updateByteSize();
checkState(nonTerminalPage, new int[] { 10 }, new long[] {
pageAPositionInFile, pageBPositionInFile });
assertEquals("bad key 9 index", 0,// NOPMD
nonTerminalPage.getIndex(new DataRecordIdentifier(9)));
assertEquals("bad key 11 index", 1,// NOPMD
nonTerminalPage.getIndex(new DataRecordIdentifier(11)));
// A 10 B -> A 5 C 10 B
final MockLeafPage leafPageC = newMockLeafPage();
final long pageCPositionInFile = 3000;
leafPageC.setPositionInFile(pageCPositionInFile);
final DataRecordIdentifier key5 = new DataRecordIdentifier(5);
leafPageA.setLastKey(key5);
leafPageA.setInParentIndex(0);
nonTerminalPage.add(leafPageA, leafPageC);
checkState(nonTerminalPage, new int[] { 5, 10 }, new long[] {
pageAPositionInFile, pageCPositionInFile, pageBPositionInFile });
assertEquals("bad key 4 index", 0,// NOPMD
nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
assertEquals("bad key 9 index", 1,
nonTerminalPage.getIndex(new DataRecordIdentifier(9)));
assertEquals("bad key 11 index", 2,
nonTerminalPage.getIndex(new DataRecordIdentifier(11)));
// A 5 C 10 B -> A 5 C 10 B 15 D
final MockLeafPage leafPageD = newMockLeafPage();
final long pageDPositionInFile = 4000;
leafPageD.setPositionInFile(pageDPositionInFile);
final DataRecordIdentifier key15 = new DataRecordIdentifier(15);
leafPageB.setLastKey(key15);
leafPageB.setInParentIndex(2);
nonTerminalPage.add(leafPageB, leafPageD);
checkState(nonTerminalPage, new int[] { 5, 10, 15 }, new long[] {
pageAPositionInFile, pageCPositionInFile, pageBPositionInFile,
pageDPositionInFile });
assertEquals("bad key 4 index", 0,
nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
assertEquals("bad key 9 index", 1,
nonTerminalPage.getIndex(new DataRecordIdentifier(9)));
assertEquals("bad key 11 index", 2,
nonTerminalPage.getIndex(new DataRecordIdentifier(11)));
assertEquals("bad key 16 index", 3,// NOPMD
nonTerminalPage.getIndex(new DataRecordIdentifier(16)));
// A 5 C 10 B 15 D -> A 5 C 7 E 10 B 15 D
final MockLeafPage leafPageE = newMockLeafPage();
final long pageEPositionInFile = 5000;
leafPageE.setPositionInFile(pageEPositionInFile);
final DataRecordIdentifier key7 = new DataRecordIdentifier(7);
leafPageC.setLastKey(key7);
leafPageC.setInParentIndex(1);
nonTerminalPage.add(leafPageC, leafPageE);
checkState(nonTerminalPage, new int[] { 5, 7, 10, 15 }, new long[] {
pageAPositionInFile, pageCPositionInFile, pageEPositionInFile,
pageBPositionInFile, pageDPositionInFile });
assertEquals("bad key 4 index", 0,
nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
assertEquals("bad key 6 index", 1,// NOPMD
nonTerminalPage.getIndex(new DataRecordIdentifier(6)));
assertEquals("bad key 9 index", 2,
nonTerminalPage.getIndex(new DataRecordIdentifier(9)));
assertEquals("bad key 11 index", 3,
nonTerminalPage.getIndex(new DataRecordIdentifier(11)));
assertEquals("bad key 16 index", 4,
nonTerminalPage.getIndex(new DataRecordIdentifier(16)));
// A 5 C 7 E 10 B 15 D -> A 5 C 7 E 10 B 15 D 17 F
final MockLeafPage leafPageF = newMockLeafPage();
final long pageFPositionInFile = 6000;
leafPageF.setPositionInFile(pageFPositionInFile);
final DataRecordIdentifier key17 = new DataRecordIdentifier(17);
leafPageD.setLastKey(key17);
leafPageD.setInParentIndex(4);
nonTerminalPage.add(leafPageD, leafPageF);
checkState(nonTerminalPage, new int[] { 5, 7, 10, 15, 17 }, new long[] {