public abstract class AbstractBTreeTestCase extends TestCase2
BTree
tests.TestCase2.MyProperties, TestCase2.RandomType
Modifier and Type | Field and Description |
---|---|
protected IKeyBuilder |
keyBuilder |
protected static org.apache.log4j.Logger |
log
Logger for the test suites in this package.
|
protected Random |
r |
_randomType
Constructor and Description |
---|
AbstractBTreeTestCase() |
AbstractBTreeTestCase(String name) |
Modifier and Type | Method and Description |
---|---|
static void |
assertChildKeys(long[] childAddr,
Node node)
Special purpose helper used to vet
Node#childAddr . |
static void |
assertEntryCounts(int[] expected,
INodeData node)
Special purpose helper used to vet the per-child entry counts for an
INodeData . |
static void |
assertKeys(byte[][] keys,
AbstractNode<?> node)
Validate the keys in the node.
|
void |
assertKeys(int[] keys,
AbstractNode<?> node)
Test helper provides backwards compatibility for a large #of tests that
were written with
int keys. |
static void |
assertKeys(IRaba expected,
IRaba actual)
Test helper verifies the #of keys and their ordered values.
|
protected static void |
assertSameAbstractNodeData(IAbstractNodeData n1,
IAbstractNodeData n2)
Verify all data accessible from
INodeData . |
static void |
assertSameBTree(AbstractBTree expected,
IIndex actual)
A suite of tests designed to verify that one btree correctly represents
the information present in a ground truth btree.
|
static void |
assertSameEntryIterator(IIndex expected,
IIndex actual)
Verifies the data in the two indices using a batch-oriented key range
scans (this can be used to verify a key-range partitioned scale-out index
against a ground truth index) - only the keys and values of non-deleted
index entries in the expected index are inspected.
|
static void |
assertSameEntryIterator(ITupleIterator expectedItr,
ITupleIterator actualItr)
Verifies that the iterators visit tuples having the same data in the same
order.
|
static void |
assertSameIterator(byte[][] expected,
ITupleIterator actual)
Method verifies that the actual
ITupleIterator produces the
expected values in the expected order. |
static void |
assertSameIterator(String msg,
byte[][] expected,
ITupleIterator actual)
Method verifies that the actual
ITupleIterator produces
the expected values in the expected order. |
static void |
assertSameLeaf(Leaf n1,
Leaf n2)
Compares leaves for the same data.
|
static void |
assertSameLeafData(ILeafData n1,
ILeafData n2)
Verify all data accessible from
ILeafData . |
static void |
assertSameNode(Node n1,
Node n2)
Compares two nodes (or leaves) for the same data.
|
static void |
assertSameNodeData(INodeData n1,
INodeData n2)
Verify all data accessible from
INodeData . |
static void |
assertSameNodeOrLeaf(AbstractNode<?> n1,
AbstractNode<?> n2) |
static void |
assertSameRaba(IRaba expected,
IRaba actual)
Compares the data in two
IRaba s but not their
capacity or things which depend on their capacity, such as
IRaba.isFull() and whether or not they are
IRaba.isReadOnly() . |
void |
assertValues(Object[] values,
Leaf leaf) |
void |
assertValues(String msg,
Object[] values,
Leaf leaf)
Test helper verifies the #of values, their ordered values, and that all
values beyond the last defined value are
null . |
protected static long |
doEntryIteratorTest(ITupleIterator<?> expectedItr,
ITupleIterator<?> actualItr)
Compares the total ordering of two B+Trees as revealed by their range
iterators
|
protected static BTree |
doInsertKeySequenceTest(BTree btree,
int[] keys,
SimpleEntry[] entries,
int[] order,
int trace)
Insert key value pairs into the tree in the specified order and verify
the expected entry traversal afterwards.
|
void |
doInsertLookupRemoveStressTest(int m,
int nkeys,
int ntrials)
|
static BTree |
doInsertRandomKeySequenceTest(BTree btree,
int[] keys,
SimpleEntry[] entries,
int trace)
Insert key value pairs into the tree in a random order and verify the
expected entry traversal afterwards.
|
BTree |
doInsertRandomKeySequenceTest(BTree btree,
int ninserts,
int trace)
Insert dense key-value pairs into the tree in a random order and verify
the expected entry traversal afterwards.
|
static BTree |
doInsertRandomSparseKeySequenceTest(BTree btree,
int ninserts,
int trace)
Insert a sequence of monotonically increase keys with random spacing into
a tree in a random order and verify the expected entry traversal
afterwards.
|
static void |
doKnownKeySequenceTest(BTree btree,
int[] order,
int trace)
Present a known sequence.
|
static void |
doRandomIndexOfTest(String label,
AbstractBTree btree,
byte[][] keys,
byte[][] vals)
Tests the performance of random lookups of keys and values by entry
index.
|
protected void |
doRandomKeyInsertTest(BTree btree,
int[] keys,
SimpleEntry[] entries,
int[] order) |
static void |
doRandomLookupTest(String label,
IIndex btree,
byte[][] keys,
byte[][] vals)
Tests the performance of random
IAutoboxBTree.lookup(Object) s on the
btree. |
void |
doRemoveStructureStressTest(int m,
int nkeys)
Stress test for building up a tree and then removing all keys in a random
order.
|
void |
doSplitTest(int m,
int trace)
Stress test helper inserts random permutations of keys into btrees of
order m for several different btrees, #of keys to be inserted, and
permutations of keys.
|
void |
doSplitWithDecreasingKeySequence(BTree btree,
int m,
int ninserts)
Creates a sequence of keys in decreasing order and inserts them into the
tree.
|
void |
doSplitWithIncreasingKeySequence(BTree btree,
int m,
int ninserts)
Test helper for
#test_splitRootLeaf_increasingKeySequence() . |
BTree |
doSplitWithRandomDenseKeySequence(BTree btree,
int m,
int ninserts)
Creates a sequence of dense keys in random order and inserts them into
the tree.
|
BTree |
getBTree(int branchingFactor)
Return a new btree backed by a simple transient store that will NOT evict
leaves or nodes onto the store.
|
BTree |
getBTree(int branchingFactor,
ITupleSerializer tupleSer) |
static void |
getKeysAndValues(AbstractBTree btree,
byte[][] keys,
byte[][] vals)
Extract all keys and values from the btree in key order.
|
static byte[][] |
getRandomKeys(int maxKeys,
int nkeys)
Generate a set of N random distinct byte[] keys in sorted order using an
unsigned byte[] comparison function.
|
static KV[] |
getRandomKeyValues(int N)
Generate random key-value data in key order.
|
protected byte[] |
i2k(int v)
Encodes an integer as a unsigned byte[] key.
|
static long |
nextLong(Random r,
long n)
Utility method for random long integers within a range.
|
protected boolean |
useRawRecords()
Provide hook to allow specific test cases to determine if rawRecords
should be used, failing any overide the value is random.
|
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEqualsWithinUlps, assertSameArray, assertSameArray, assertSameBigDecimal, assertSameBigDecimal, assertSameBigInteger, assertSameBigInteger, assertSameIterator, assertSameIterator, assertSameIteratorAnyOrder, assertSameIteratorAnyOrder, assertSameValue, assertSameValue, assertZeroUlps, assertZeroUlps, fail, getInnerCause, getNormalInt, getProjectBuildPath, getProperties, getRandomObject, getRandomObject, getRandomOrder, getRandomString, getTestInputStream, getTestResource, getTestResource, getUlps, getUlps, isDEBUG, isDEBUG, isINFO, isINFO, isInnerCause, logProperties
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
protected Random r
protected IKeyBuilder keyBuilder
protected static final org.apache.log4j.Logger log
public AbstractBTreeTestCase()
public AbstractBTreeTestCase(String name)
name
- protected byte[] i2k(int v)
v
- An integer.public static void assertKeys(IRaba expected, IRaba actual)
expected
- A ground truth node.actual
- The actual node.public void assertKeys(int[] keys, AbstractNode<?> node)
int
keys. Each key is encoded by the
KeyBuilder
before comparison with the key at the corresponding
index in the node.keys
- An array of the defined int
keys.node
- The node whose keys will be tested.public void assertValues(String msg, Object[] values, Leaf leaf)
null
.msg
- A label, typically the node name.values
- An array containing the expected defined values. The #of
values in this array should be exactly the #of defined values
(that is, do not include trailing nulls or attempt to size the
array to the branching factor of the tree).public static void assertSameNodeOrLeaf(AbstractNode<?> n1, AbstractNode<?> n2)
public static void assertSameNode(Node n1, Node n2)
n1
- The expected node state.n2
- The actual node state.public static void assertSameLeaf(Leaf n1, Leaf n2)
n1
- The expected leaf state.n2
- The actual leaf state.protected static void assertSameAbstractNodeData(IAbstractNodeData n1, IAbstractNodeData n2)
INodeData
.public static void assertSameNodeData(INodeData n1, INodeData n2)
INodeData
.public static void assertSameLeafData(ILeafData n1, ILeafData n2)
ILeafData
.public static void assertSameRaba(IRaba expected, IRaba actual)
IRaba
s but not their
capacity
or things which depend on their capacity, such as
IRaba.isFull()
and whether or not they are
IRaba.isReadOnly()
. If the expected IRaba.isKeys()
, then
both must represent keys and the search API will also be tested.expected
- actual
- public static void assertChildKeys(long[] childAddr, Node node)
Node#childAddr
.childAddr
- An array all of whose values will be tested against the
corresponding child identities in the node.node
- The node.public static void assertKeys(byte[][] keys, AbstractNode<?> node)
keys
- An array all of whose entries will be tested against the
corresponding keys in the node.node
- The node.public static void assertEntryCounts(int[] expected, INodeData node)
INodeData
.expected
- An array all of whose values will be tested against the
corresponding elements in the node as returned by
INodeData#getChildEntryCounts()
. The sum of the
expected array is also tested against the value returned by
IAbstractNodeData#getSpannedTupleCount()
.node
- The node.public BTree getBTree(int branchingFactor)
branchingFactor
- The branching factor.public BTree getBTree(int branchingFactor, ITupleSerializer tupleSer)
protected boolean useRawRecords()
public void doSplitWithIncreasingKeySequence(BTree btree, int m, int ninserts)
#test_splitRootLeaf_increasingKeySequence()
.
creates a sequence of keys in increasing order and inserts them into the
tree. Note that you do not know, in general, how many inserts it will
take to split the root node since the split decisions are path dependent.
They depend on the manner in which the leaves get filled, whether or not
holes are created in the leaves, etc.
Once all keys have been inserted into the tree the keys are removed in
forward order (from the smallest to the largest). This stresses a
specific pattern of joining leaves and nodes together with their right
sibling.m
- The branching factor.ninserts
- The #of keys to insert.public void doSplitWithDecreasingKeySequence(BTree btree, int m, int ninserts)
m
- The branching factor.ninserts
- The #of keys to insert.public void doSplitTest(int m, int trace)
public BTree doInsertRandomKeySequenceTest(BTree btree, int ninserts, int trace)
m
- The branching factor. The tree.ninserts
- The #of distinct key-value pairs to insert.trace
- The trace level (zero disables most tracing).public static BTree doInsertRandomSparseKeySequenceTest(BTree btree, int ninserts, int trace)
m
- The branching factor for the source B+Tree.ninserts
- The #of distinct key-value pairs to insert.trace
- The trace level (zero disables most tracing).BTree
.public static BTree doInsertRandomKeySequenceTest(BTree btree, int[] keys, SimpleEntry[] entries, int trace)
m
- The branching factor for the source B+Tree.keys
- The keys.entries
- The entries.trace
- The trace level (zero disables most tracing).BTree
.public static void doKnownKeySequenceTest(BTree btree, int[] order, int trace)
m
- The branching factor.order
- The key presentation sequence.trace
- The trace level.protected static BTree doInsertKeySequenceTest(BTree btree, int[] keys, SimpleEntry[] entries, int[] order, int trace)
m
- The branching factor for the source B+Tree.keys
- The keys.entries
- The entries.order
- The order in which the key-entry pairs will be inserted.trace
- The trace level (zero disables most tracing).BTree
.public BTree doSplitWithRandomDenseKeySequence(BTree btree, int m, int ninserts)
m
- The branching factor.ninserts
- The #of keys to insert.protected void doRandomKeyInsertTest(BTree btree, int[] keys, SimpleEntry[] entries, int[] order)
public void doInsertLookupRemoveStressTest(int m, int nkeys, int ntrials)
BTree
against ground truth as
tracked by a TreeMap
.
Note: This test uses dense keys, but that is not a requirement.m
- The branching factornkeys
- The #of distinct keys.ntrials
- The #of trials.public void doRemoveStructureStressTest(int m, int nkeys)
public static void assertSameBTree(AbstractBTree expected, IIndex actual)
AbstractBTree.rangeIterator()
, and
also both lookup by key and lookup by entry index. The height, branching
factor, #of nodes and #of leaves may differ (the test does not presume
that the btrees were built with the same branching factor, but merely
with the same data and key type).expected
- The ground truth btree.actual
- The btree that is being validated.protected static long doEntryIteratorTest(ITupleIterator<?> expectedItr, ITupleIterator<?> actualItr)
expected
- The ground truth iterator.actual
- The iterator to be tested.#doRandomLookupTest(String, AbstractBTree, byte[][], Object[])
,
#doRandomIndexOfTest(String, AbstractBTree, byte[][], Object[])
public static void getKeysAndValues(AbstractBTree btree, byte[][] keys, byte[][] vals)
btree
- The btree.keys
- The keys in key order (out).vals
- The values in key order (out).public static void doRandomLookupTest(String label, IIndex btree, byte[][] keys, byte[][] vals)
IAutoboxBTree.lookup(Object)
s on the
btree. This vets the separator keys and the childAddr and/or childRef
arrays since those are responsible for lookup.label
- A descriptive label for error messages.btree
- The btree.keys
- the keys in key order.vals
- the values in key order.public static void doRandomIndexOfTest(String label, AbstractBTree btree, byte[][] keys, byte[][] vals)
label
- A descriptive label for error messages.btree
- The btree.keys
- the keys in key order.vals
- the values in key order.public static void assertSameIterator(byte[][] expected, ITupleIterator actual)
ITupleIterator
produces the
expected values in the expected order. Errors are reported if too few or
too many values are produced, etc.public static void assertSameIterator(String msg, byte[][] expected, ITupleIterator actual)
ITupleIterator
produces
the expected values in the expected order. Errors are reported if too few
or too many values are produced, etc.public static void assertSameEntryIterator(IIndex expected, IIndex actual)
expected
- actual
- public static void assertSameEntryIterator(ITupleIterator expectedItr, ITupleIterator actualItr)
expectedItr
- actualItr
- public static byte[][] getRandomKeys(int maxKeys, int nkeys)
maxKeys
- The capacity of the array.nkeys
- The #of keys to generate.public static KV[] getRandomKeyValues(int N)
Note: The auto-split feature of the scale-out indices depends on the assumption that the data are presented in key order.
Note: This method MAY return entries having duplicate keys.
N
- The #of key-value pairs to generate.ClientIndexView#submit(int, byte[][], byte[][],
com.bigdata.btree.IIndexProcedure.IIndexProcedureConstructor,
com.bigdata.btree.IResultHandler)
public static long nextLong(Random r, long n)
r
- The random number.n
- The range.IllegalArgumentException
- if n is negative.Random.nextInt(int)
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.