示例#1
0
    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
示例#2
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)
示例#3
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()
示例#4
0
    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
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
示例#6
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
示例#7
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
示例#8
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
 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
示例#10
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()
示例#11
0
#!/usr/bin/env python
from immudb.client import ImmudbClient

a = ImmudbClient()
a.login("immudb", "immudb")
print(a.databaseUse(b"defaultdb"))
#print(a.databaseCreate(b"testdb"))
print(a.databaseList())
print("Use:")
print(a.databaseUse(b"defaultdb"))

# print(a.databaseUse(b"testdb"))

# b = a.safeSet(b"pythonkey",b"thisismyvalue")
# print(b)
# print(a.safeGet(bytes("pythonkey", encoding="utf-8")))

# arr=[]
# for i in range(0,100):
#     k="key_{}".format(i).encode('utf8')
#     v="value_{}".format(i).encode('utf8')
#     a.safeSet(k,v)
#     arr.append(k)
# resp=a.getAll(arr)
# print(resp)

xset = {b"key1": b"value1", b"key2": b"value2"}
print(a.setAll(xset))
print(a.getAll(xset.keys()))
#!/usr/bin/env python

from immudb.client import ImmudbClient

ic = ImmudbClient()
ic.login("immudb", "immudb")

key = "Hello".encode('utf8')
value = "Immutable world!".encode('utf8')

# set a key/value pair
ic.set(key, value)

#reads back the value
readback = ic.get(key)
saved_value = readback.value.decode('utf8')
print("Hello", saved_value)

# you have the timestamp of the set that inserted the value
print("The set was made in timestamp", readback.timestamp)
from immudb.client import ImmudbClient
import string, random


def get_random_string(length):
    return ''.join(random.choice(string.printable) for i in range(length))


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

# let's fill a big dictionary:
xset = {}
for i in range(0, 1000):
    xset["massif:{:04X}".format(i).encode('utf8')] = get_random_string(
        32).encode('utf8')

# now we put all the key/value pairs in immudb
response = ic.setAll(xset)

# the response holds the new index position of the merkele tree
assert type(ic.setAll(xset)) != int

# let's read back all the values in another dictionary,
# and check the values
yset = ic.getAll(xset.keys())
for i in yset.keys():
    assert xset[i] == yset[i]
示例#14
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
示例#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
示例#17
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
示例#18
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()
示例#19
0
#!/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)
#!/usr/bin/env python

from immudb.client import ImmudbClient

ic = ImmudbClient()
ic.login("immudb", "immudb")

key = "a_very_important_key".encode('utf8')
value = "a_very_important_value".encode('utf8')

# let's insert the value in the DB and check
# if it was correctly inserted
response = ic.safeSet(key, value)

# here response is a structure holding many informations
# about the merkele tree, but the most important is that
# the insert was correctly verified
assert response.verified == True

print("Key inserted (and verified) with index", response.index)

#reads back the value
readback = ic.safeGet(key)

# in the readback we also have the index and the verified field
assert response.verified == True
print("The value is", readback.value, "at index", response.index,
      "with timestamp", readback.timestamp)