public void testAscendingInsertBalance()
throws DatabaseException {
initEnv(false);
Locker txn = new BasicLocker(DbInternal.envGetEnvironmentImpl(env));
NullCursor cursor = new NullCursor(tree.getDatabase(), txn);
/* Fill up a db with data */
for (int i = 0; i < N_KEYS; i++) {
byte[] keyBytes = new byte[4];
TestUtils.putUnsignedInt(keyBytes, TestUtils.alphaKey(i));
insertAndRetrieve(cursor, keyBytes,
new LN((byte[]) null));
}
TestUtils.checkLatchCount();
/* Count the number of levels on the left. */
IN leftMostNode = tree.getFirstNode();
assertTrue(leftMostNode instanceof BIN);
int leftSideLevels = 0;
do {
SearchResult result =
tree.getParentINForChildIN(leftMostNode, true, true);
leftMostNode = result.parent;
leftSideLevels++;
} while (leftMostNode != null);
TestUtils.checkLatchCount();
/* Count the number of levels on the right. */
IN rightMostNode = tree.getLastNode();
assertTrue(rightMostNode instanceof BIN);
int rightSideLevels = 0;
do {
SearchResult result =
tree.getParentINForChildIN(rightMostNode, true, true);
rightMostNode = result.parent;
rightSideLevels++;
} while (rightMostNode != null);
TestUtils.checkLatchCount();
if (leftSideLevels > 10 ||
rightSideLevels > 10) {
fail("Levels too high (" +
leftSideLevels +
"/" +
rightSideLevels +
") on descending insert");
}
txn.operationEnd();
}