예제 #1
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()
예제 #2
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()
예제 #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()