コード例 #1
0
 def test_consistency_verify(self):
     a = ImmudbClient()
     try:
         a = ImmudbClient("localhost:3322")
         a.login("immudb", "immudb")
     except grpc._channel._InactiveRpcError as e:
         pytest.skip("Cannot reach immudb server")
     a.safeSet(b'dummy', b'dummy')
     root = a.currentRoot()
     a.safeSet(b'dummy1', b'dummy1')
     print(root)
     cns = a.stub.Consistency(schema_pb2.Index(index=root.index))
     print(cns)
     ret = verify(cns, root)
     assert ret == True
コード例 #2
0
ファイル: test_execAll.py プロジェクト: codenotary/immudb-py
    def test_execAll_zadd(self):
        try:
            a = ImmudbClient("localhost:3322")
            a.login("immudb", "immudb")
        except grpc.RpcError as e:
            pytest.skip("Cannot reach immudb server")
        kvsend = []
        zaddsend = []
        zsetname = "execAll_zadd_set_{:04d}".format(randint(
            0, 10000)).encode('utf-8')
        for t in range(0, 10):
            key = "execAll_zadd_key_{:04d}".format(t)
            value = "execAll_zadd_value_{:04d}".format(t)
            score = float(t)

            kvsend.append(
                KeyValue(key=key.encode('utf8'), value=value.encode('utf8')))

            zaddsend.append(
                ZAddRequest(key=key.encode(), set=zsetname, score=score))

        resp = a.execAll(kvsend)
        assert resp.nentries == len(kvsend)
        resp = a.execAll(zaddsend)
        assert resp.nentries == len(zaddsend)

        resp = a.zScan(zsetname, b'execAll_zadd_set_', 0, 0, True, 100, False,
                       0.0, 100.0, 0)

        assert len(resp.entries) == 10
コード例 #3
0
 def test_property(self):
     try:
         a = ImmudbClient()
         a.login("immudb", "immudb")
     except grpc._channel._InactiveRpcError as e:
         pytest.skip("Cannot reach immudb server")
     assert isinstance(a.stub, object)
コード例 #4
0
ファイル: test_database.py プロジェクト: opvizor/immudb-py
    def test_list_use(self):
        try:
            a = ImmudbClient("localhost:3322")
            a.login("immudb", "immudb")
        except grpc._channel._InactiveRpcError as e:
            pytest.skip("Cannot reach immudb server")
        resp = a.databaseList()
        assert resp.dblist.databases[0].databasename == "defaultdb"
        resp = a.databaseUse(b"defaultdb")
        assert type(resp.reply.token) == str

        # create a new DB with a random name (must be lowercase)
        newdb = "testdb{:04x}".format(randint(0, 65536)).encode('utf8')
        resp = a.databaseCreate(newdb)
        assert type(resp.reply) == google.protobuf.empty_pb2.Empty
        # try and use the new DB
        resp = a.databaseUse(newdb)
        assert type(resp.reply.token) == str

        key = "test_key_{:04d}".format(randint(0, 10000))
        value = "test_value_{:04d}".format(randint(0, 10000))

        resp = a.safeSet(key.encode('utf8'), value.encode('utf8'))
        assert resp.verified == True
        readback = a.safeGet(key.encode('utf8'))
        assert readback.verified == True
        assert value == readback.value
コード例 #5
0
    def test_get_set(self):
        try:
            a = ImmudbClient("localhost:3322")
            a.login("immudb", "immudb")
        except grpc._channel._InactiveRpcError as e:
            pytest.skip("Cannot reach immudb server")
        key = "test_key_{:04d}".format(randint(0, 10000))
        value = "test_value_{:04d}".format(randint(0, 10000))

        resp = a.safeSet(key.encode('utf8'), value.encode('utf8'))
        assert resp.verified == True
        readback = a.safeGet(key.encode('utf8'))
        assert readback.verified == True
        assert value == readback.value
コード例 #6
0
    def test_root(self):
        try:
            a = ImmudbClient()
            a.login("immudb", "immudb")
        except grpc._channel._InactiveRpcError as e:
            pytest.skip("Cannot reach immudb server")
        r1 = a.currentRoot()
        key = "test_key_{:04d}".format(randint(0, 10000))
        value = "test_value_{:04d}".format(randint(0, 10000))
        a.safeSet(key.encode('utf8'), value.encode('utf8'))
        r2 = a.currentRoot()

        assert r2.index > r1.index
        a.logout()
        a.shutdown()
コード例 #7
0
    def test_basic(self):
        try:
            a = ImmudbClient()
            a.login("immudb", "immudb")
        except grpc._channel._InactiveRpcError as e:
            pytest.skip("Cannot reach immudb server")
        key = "test_key_{:04d}".format(randint(0, 10000))
        value = "test_value_{:04d}".format(randint(0, 10000))

        resp = a.set(key.encode('utf8'), value.encode('utf8'))
        readback = a.get(key.encode('utf8'))
        assert value == readback.value.decode('utf8')

        a.logout()
        a.shutdown()
コード例 #8
0
 def test_new_rootfile(self):
     import immudb.constants, tempfile, os.path, os
     tdir = tempfile.TemporaryDirectory()
     tfile = os.path.join(tdir.name, "rootfile")
     oldroot = immudb.constants.ROOT_CACHE_PATH
     immudb.constants.ROOT_CACHE_PATH = tfile
     try:
         a = ImmudbClient()
         a.login("immudb", "immudb")
         os.unlink(tfile)
         key = "test_key_{:04d}".format(randint(0, 10000))
         value = "test_value_{:04d}".format(randint(0, 10000))
         a.safeSet(key.encode('utf8'), value.encode('utf8'))
     except grpc._channel._InactiveRpcError as e:
         pytest.skip("Cannot reach immudb server")
     finally:
         immudb.constants.ROOT_CACHE_PATH = oldroot
コード例 #9
0
def test_basic(rootfile):
    try:
        a = ImmudbClient(rs=PersistentRootService(rootfile))
        a.login("immudb", "immudb")
    except grpc.RpcError as e:
        pytest.skip("Cannot reach immudb server")
    key = "test_key_{:04d}".format(randint(0, 10000))
    value = "test_value_{:04d}".format(randint(0, 10000))

    resp = a.set(key.encode('utf8'), value.encode('utf8'))
    readback = a.get(key.encode('utf8'))
    assert value == readback.value.decode('utf8')
    val = a.getValue(key.encode('utf8'))
    assert val == value.encode('utf-8')
    assert None == a.getValue(b'non_existing_key')
    assert a.healthCheck()
    a.logout()
    a.shutdown()
コード例 #10
0
 def test_get_set_batch(self):
     try:
         a = ImmudbClient("localhost:3322")
         a.login("immudb", "immudb")
     except grpc._channel._InactiveRpcError as e:
         pytest.skip("Cannot reach immudb server")
     xset = {b'gorilla': b'banana', b'zebra': b'grass', b'lion': b'zebra'}
     assert type(a.setAll(xset)) != int
     # test getAll
     resp = a.getAll(xset.keys())
     for i in resp.keys():
         assert i in xset
         assert xset[i] == resp[i]
     for i in xset.keys():
         assert i in resp
         assert xset[i] == resp[i]
     # test getAllItems
     resp = a.getAllItems(xset.keys())
     for i in resp.itemlist.items:
         assert i.key in xset
         assert xset[i.key] == i.value.payload
コード例 #11
0
def massive_test(taskid: int):
    ic = ImmudbClient("localhost:3322")
    ic.login("immudb", "immudb")

    # let's fill a big dictionary:
    big_dict = {}
    for i in range(0, SIZE):
        big_dict["verymassif:{:08X}".format(i).encode(
            'utf8')] = "value:{:08f}".format(random.random()).encode('utf8')

    # now we put all the key/value pairs in immudb
    written = 0
    t0 = time.time()
    for chunk in chunked(big_dict.items(), CHUNKSIZE):
        response = ic.setAll(chunk)
        # the response holds the new index position of the merkele tree
        assert type(response) != int
        written += CHUNKSIZE
    t1 = time.time()
    print("TASK{}:  {} keys written in {:3.2f} seconds".format(
        taskid, SIZE, t1 - t0))
    return t1 - t0
コード例 #12
0
 def test_get_set_massive(self):
     try:
         a = ImmudbClient("localhost:3322")
         a.login("immudb", "immudb")
     except grpc._channel._InactiveRpcError as e:
         pytest.skip("Cannot reach immudb server")
     xset = {}
     for i in range(0, 10000):
         xset["massif:{:04X}".format(i).encode('utf8')] = get_random_string(
             32).encode('utf8')
     assert type(a.setAll(xset)) != int
     # test getAll
     resp = a.getAll(xset.keys())
     for i in resp.keys():
         assert i in xset
         assert xset[i] == resp[i]
     for i in xset.keys():
         assert i in resp
         assert xset[i] == resp[i]
     # test getAllItems
     resp = a.getAllItems(xset.keys())
     for i in resp.itemlist.items:
         assert i.key in xset
         assert xset[i.key] == i.value.payload
コード例 #13
0
ファイル: devtest.py プロジェクト: codenotary/immudb-py
#!/usr/bin/env python3
from immudb.client import ImmudbClient

a = ImmudbClient()
a.login("immudb", "immudb")
kvs = {}
for t in range(0, 100):
    value = "test_sago_value_{:04d}".format(t)
    key = "test_sago_key_{:04d}".format(t)
    kvs[key.encode('ascii')] = value.encode('ascii')
a.setAll(kvs)
コード例 #14
0
import time

SIZE = 5000000
CHUNKSIZE = 5000


def chunked(it, size):
    it = iter(it)
    while True:
        p = dict(itertools.islice(it, size))
        if not p:
            break
        yield p


ic = ImmudbClient("localhost:3322")
ic.login("immudb", "immudb")

print("Preparing dictionary:")
# let's fill a big dictionary:
big_dict = {}
for i in range(0, SIZE):
    big_dict["verymassif:{:08X}".format(i).encode(
        'utf8')] = "value:{:08f}".format(random.random()).encode('utf8')
    if (i % CHUNKSIZE) == 0:
        print("\r{:02.1f}%".format(i * 100.0 / SIZE), end='')

print("\nDone\nInserting {} values:".format(SIZE))

# now we put all the key/value pairs in immudb
written = 0
コード例 #15
0
 def test_no_server(self):
     try:
         a = ImmudbClient("localhost:9999")
         a.login("immudb", "immudb")
     except grpc._channel._InactiveRpcError as e:
         pass
コード例 #16
0
 def test_no_server(self):
     try:
         a = ImmudbClient("localhost:9999")
         a.login("immudb", "immudb")
     except grpc.RpcError:
         pass