public void testAddNonTerminalPage() throws HeapException {
// A 10 B
final NonTerminalPage nonTerminalPage = new NonTerminalPage(1, true);
nonTerminalPage.setPageRecord(PAGE_RECORD);
final MockNonTerminalPage pageA = newMockNonTerminalPage();
final long pageAPositionInFile = 1000;
pageA.setPositionInFile(pageAPositionInFile);
final MockNonTerminalPage pageB = newMockNonTerminalPage();
final long pageBPositionInFile = 2000;
pageB.setPositionInFile(pageBPositionInFile);
final DataRecordIdentifier key10 = new DataRecordIdentifier(10);
nonTerminalPage.setEntry(0, pageA.getPositionInFile(), key10);
nonTerminalPage.setEntry(1, pageB.getPositionInFile(), null);
nonTerminalPage.updateByteSize();
checkState(nonTerminalPage, new int[] { 10 }, new long[] {
pageAPositionInFile, pageBPositionInFile });
assertEquals("bad key 9 index", 0,
nonTerminalPage.getIndex(new DataRecordIdentifier(9)));
assertEquals("bad key 11 index", 1,
nonTerminalPage.getIndex(new DataRecordIdentifier(11)));
// A 10 B -> A 5 C 10 B
final MockNonTerminalPage pageC = newMockNonTerminalPage();
final long pageCPositionInFile = 3000;
pageC.setPositionInFile(pageCPositionInFile);
final DataRecordIdentifier key5 = new DataRecordIdentifier(5);
pageA.setInParentIndex(0);
nonTerminalPage.add(pageA, key5, pageC);
checkState(nonTerminalPage, new int[] { 5, 10 }, new long[] {
pageAPositionInFile, pageCPositionInFile, pageBPositionInFile });
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)));
// ------------
// A 5 C 10 B -> A 5 C 10 B 15 D
final MockNonTerminalPage pageD = newMockNonTerminalPage();
final long pageDPositionInFile = 4000;
pageD.setPositionInFile(pageDPositionInFile);
final DataRecordIdentifier key15 = new DataRecordIdentifier(15);
pageB.setInParentIndex(2);
nonTerminalPage.add(pageB, key15, pageD);
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,
nonTerminalPage.getIndex(new DataRecordIdentifier(16)));
// A 5 C 10 B 15 D -> A 5 C 7 E 10 B 15 D
final MockNonTerminalPage pageE = newMockNonTerminalPage();
final long pageEPositionInFile = 5000;
pageE.setPositionInFile(pageEPositionInFile);
final DataRecordIdentifier key7 = new DataRecordIdentifier(7);
pageC.setInParentIndex(1);
nonTerminalPage.add(pageC, key7, pageE);
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,
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 MockNonTerminalPage pageF = newMockNonTerminalPage();
final long pageFPositionInFile = 6000;
pageF.setPositionInFile(pageFPositionInFile);
final DataRecordIdentifier key17 = new DataRecordIdentifier(17);
pageD.setInParentIndex(4);
nonTerminalPage.add(pageD, key17, pageF);
checkState(nonTerminalPage, new int[] { 5, 7, 10, 15, 17 }, new long[] {
pageAPositionInFile, pageCPositionInFile, pageEPositionInFile,