예제 #1
0
def test_insert_list():
    tree = BTree(test_file_name)
    tree.insert('l1', [1, 2, 3], override=True)
    tree.insert('l2', [2.1, 'cannon', 0], override=True)
    assert tree['l1'] == [1, 2, 3]
    assert tree['l2'] == [2.1, 'cannon', 0]
    tree.commit()
    tree.close()
예제 #2
0
def test_insert_float():
    tree = BTree(test_file_name)
    tree.insert('f1', 1.1613168453135168, override=True)
    assert tree['f1'] == 1.1613168453135168
    tree.insert('f2', 1546646.55845454548, override=True)
    assert tree['f2'] == 1546646.55845454548
    tree.commit()
    tree.close()
예제 #3
0
def test_insert_dict():
    tree = BTree(test_file_name)
    tree.insert('d1', {'a': 1, 'b': 2, 'c': 3}, override=True)
    assert tree['d1'] == {'a': 1, 'b': 2, 'c': 3}
    d2 = {'d': -1, 'f': 'asd', 'test': 'inside'}
    tree.insert('d2', d2, override=True)
    assert tree['d2'] == d2
    tree.commit()
    tree.close()
예제 #4
0
def test_overflow():
    test_of_name = refine_test_file('test_overflow')
    test_tree = BTree(test_of_name, 3, 32, 8, 12, 0)
    test_tree.insert('1234', 1234, override=True)
    test_tree.insert('4567', 4567, override=True)
    test_tree.insert('6789', 6789, override=True)
    assert test_tree['1234'] == 1234
    assert test_tree['4567'] == 4567
    assert test_tree['6789'] == 6789
예제 #5
0
def __test_scale_insert():
    """ Time-consumed """
    tree = BTree(test_file_name)
    nums = [random.randrange(0, 0xFFFFFF) for _ in range(TEST_RANDOM_NUMS)]
    tree.set_auto_commit(False)
    for num in nums:
        tree.insert(str(num), num, override=True)
    tree.commit()
    tree.close()
    tree = BTree(test_file_name)
    for num in nums:
        assert tree.get(str(num)) == num
    tree.commit()
    tree.close()
예제 #6
0
def test_normal_insert():
    tree = BTree(test_file_name)
    tree.insert('a', 1, override=True)
    tree.insert('b', 2, override=True)
    tree.insert('123', 'python', override=True)
    tree.insert('list', [2, 3, 4], override=True)
    tree.insert('dict', {1: 1, 2: 2, 3: 3}, override=True)
    tree.commit()
    assert tree['a'] == 1
    assert tree['b'] == 2
    assert tree.get('123') == 'python'
    assert tree.get('list') == [2, 3, 4]
    assert tree.get('dict') == {1: 1, 2: 2, 3: 3}
    tree.close()
예제 #7
0
from cannondb.btree import BTree
from cannondb.node import BNode, KeyValPair
from cannondb.constants import TreeConf
from tests.util import refine_test_file

file_name = refine_test_file('test_node')
test_tree = BTree(file_name, 3, 1024, 8, 12, cache_size=0)
test_tree_conf = TreeConf(3, 1024, 8, 12)
test_contents = [
    KeyValPair(test_tree_conf, '1', 1),
    KeyValPair(test_tree_conf, '2', 2),
    KeyValPair(test_tree_conf, '3', 3),
    KeyValPair(test_tree_conf, '4', 4),
    KeyValPair(test_tree_conf, '5', 5)
]
test_children = [0, 1, 2, 3, 4, 6]
"""
Actually there is no so much cases to independently test on BNode,
the insert/remove/grow/shrink operations should reflect on the ops 
in BTree.
"""


def test_load_dump():
    node = BNode(test_tree,
                 test_tree_conf,
                 contents=test_contents,
                 children=test_children)
    dumped = node.dump()
    loaded_node = BNode(test_tree, test_tree_conf, data=dumped)
    print(repr(loaded_node))