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

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


  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[] {
View Full Code Here


    int currentKeyValue = 5;
    // 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);
    leafPageA.setLastKey(new DataRecordIdentifier(currentKeyValue));
    currentKeyValue += 10;

    final MockLeafPage leafPageB = newMockLeafPage();
    final long pageBPositionInFile = 2000;
    leafPageB.setPositionInFile(pageBPositionInFile);
    leafPageB.setLastKey(new DataRecordIdentifier(currentKeyValue));
    currentKeyValue += 10;
    final DataRecordIdentifier key10 = new DataRecordIdentifier(10);
    nonTerminalPage.setEntry(0, leafPageA.getPositionInFile(), key10);
    nonTerminalPage.setEntry(1, leafPageB.getPositionInFile(), null);
    nonTerminalPage.updateByteSize();
    assertTrue("bad keys", nonTerminalPage.checkKeys());

    MockLeafPage leftPage = leafPageB;
    final int maxNumberOfEntries = maxNumberOfEntries();
    while (nonTerminalPage.getNumberOfKeyEntries() < maxNumberOfEntries) {
      final MockLeafPage rightPage = newMockLeafPage();
      rightPage.setLastKey(new DataRecordIdentifier(currentKeyValue));// NOPMD
      currentKeyValue += 10;
      leftPage.setInParentIndex(nonTerminalPage.getNumberOfKeyEntries());
      // leftPage.setLastKey(key10);
      assertTrue("must not need split",
          nonTerminalPage.add(leftPage, rightPage));
      leftPage = rightPage;
    }
    final MockLeafPage rightPage = newMockLeafPage();
    rightPage.setLastKey(new DataRecordIdentifier(currentKeyValue));
    leftPage.setInParentIndex(nonTerminalPage.getNumberOfKeyEntries());
    assertFalse("must need split", nonTerminalPage.add(leftPage, rightPage));
  }
View Full Code Here

    }
    return pointers;
  }

  private MockLeafPage newMockLeafPage() throws HeapException {
    final MockLeafPage mockLeafPage = new MockLeafPage();
    mockLeafPage.setPageRecord(PAGE_RECORD);
    return mockLeafPage;
  }
View Full Code Here

TOP

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

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.