Ejemplo n.º 1
0
def test_left_record_node_in_tree():
    b = BPlusTree(filename, order=3)
    assert b._left_record_node == b._root_node
    assert isinstance(b._left_record_node, LonelyRootNode)
    b.insert(1, b'1')
    b.insert(2, b'2')
    b.insert(3, b'3')
    assert isinstance(b._left_record_node, LeafNode)
    b.close()
Ejemplo n.º 2
0
def test_length_hint_tree():
    b = BPlusTree(order=100)
    assert b.__length_hint__() == 49
    b.insert(1, b'foo')
    assert b.__length_hint__() == 49
    for i in range(2, 10001):
        b.insert(i, str(i).encode())
    assert b.__length_hint__() == 7242
    b.close()
Ejemplo n.º 3
0
def test_create_and_load_file(clean_file):
    b = BPlusTree(filename=filename)
    assert isinstance(b._mem, FileMemory)
    b.insert(5, b'foo')
    b.close()

    b = BPlusTree(filename=filename)
    assert isinstance(b._mem, FileMemory)
    assert b.get(5) == b'foo'
    b.close()
Ejemplo n.º 4
0
def b():
    b = BPlusTree()
    yield b
    b.close()
Ejemplo n.º 5
0
def test_insert_split_in_tree(iterator, order, page_size, k_size, v_size,
                              filename, clean_file):
    inserted = set()

    b = BPlusTree(filename=filename,
                  order=order,
                  page_size=page_size,
                  key_size=k_size,
                  value_size=v_size,
                  fsync=Fsync.NEVER)

    for i in iterator:
        b.insert(i, str(i).encode())
        inserted.add(i)

    if filename:
        # Reload tree from file before checking values
        b.close()
        b = BPlusTree(filename=filename,
                      order=order,
                      page_size=page_size,
                      key_size=k_size,
                      value_size=v_size)

    for x in inserted:
        assert b.get(x) == str(x).encode()

    b.close()
Ejemplo n.º 6
0
def test_closing_context_manager(mock_close):
    with BPlusTree(filename, page_size=512, value_size=128) as b:
        pass
    mock_close.assert_called_once_with()
Ejemplo n.º 7
0
def test_insert_split_in_tree(iterator, order, page_size, k_size, v_size,
                              serialize_class, cache_size):

    inserted = list()
    for i in iterator:
        v = str(i).encode()
        k = i
        if serialize_class is StrSerializer:
            k = str(i)
        inserted.append((k, v))

    b = BPlusTree(filename, order=order, page_size=page_size,
                  key_size=k_size, value_size=v_size, cache_size=cache_size,
                  serializer=serialize_class())

    if sorted(inserted) == inserted:
        b.batch_insert(inserted)
    else:
        for k, v in inserted:
            b.insert(k, v)

    # Reload tree from file before checking values
    b.close()
    b = BPlusTree(filename, order=order, page_size=page_size,
                  key_size=k_size, value_size=v_size, cache_size=cache_size,
                  serializer=serialize_class())

    for k, v in inserted:
        assert b.get(k) == v

    b.close()
Ejemplo n.º 8
0
def b():
    b = BPlusTree(filename, key_size=16, value_size=16, order=4)
    yield b
    b.close()