Package net.sf.joafip.btreeplus.entity.mock

Examples of net.sf.joafip.btreeplus.entity.mock.MockNonTerminalPage


  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,
View Full Code Here


  public void testAddNonTerminalPageNeedSplit() 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);
    int currentIdentifierValue = 10;
    nonTerminalPage.setEntry(0, pageA.getPositionInFile(),
        new DataRecordIdentifier(currentIdentifierValue));
    currentIdentifierValue += 10;
    nonTerminalPage.setEntry(1, pageB.getPositionInFile(), null);
    nonTerminalPage.updateByteSize();

    MockNonTerminalPage leftPage = pageB;
    final int maxNumberOfEntries = maxNumberOfEntries();
    while (nonTerminalPage.getNumberOfKeyEntries() < maxNumberOfEntries) {
      final MockNonTerminalPage rightPage = newMockNonTerminalPage();
      leftPage.setInParentIndex(nonTerminalPage.getNumberOfKeyEntries());
      assertTrue("must not need split",
          nonTerminalPage.add(leftPage, new DataRecordIdentifier(// NOPMD
              currentIdentifierValue), rightPage));
      currentIdentifierValue += 10;
      leftPage = rightPage;
    }
    final MockNonTerminalPage rightPage = newMockNonTerminalPage();
    leftPage.setInParentIndex(nonTerminalPage.getNumberOfKeyEntries());
    assertFalse("must need split", nonTerminalPage.add(leftPage,
        new DataRecordIdentifier(currentIdentifierValue), rightPage));
  }
View Full Code Here

    mockLeafPage.setPageRecord(PAGE_RECORD);
    return mockLeafPage;
  }

  private MockNonTerminalPage newMockNonTerminalPage() throws HeapException {
    final MockNonTerminalPage mockNonTerminalPage = new MockNonTerminalPage();
    mockNonTerminalPage.setPageRecord(PAGE_RECORD);
    return mockNonTerminalPage;
  }
View Full Code Here

TOP

Related Classes of net.sf.joafip.btreeplus.entity.mock.MockNonTerminalPage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.