コード例 #1
0
def test_leveldb_and_text_store_equality(tmpdir):
    """
    This test verifies that TextFileStore and LeveldbStore behave equally
    """
    isLineNoKey = True
    storeContentHash = False
    ensureDurability = True
    dbDir = str(tmpdir)

    text_store = TextFileStore(dbDir=dbDir,
                               dbName="text_data",
                               isLineNoKey=isLineNoKey,
                               storeContentHash=storeContentHash,
                               ensureDurability=ensureDurability)

    leveldb_store = KeyValueStorageLeveldb(dbDir, "leveldb_data")

    for i in range(1, 10):
        value = "Some data {}".format(str(i))
        text_store.put(None, value)
        leveldb_store.put(str(i), value)
        assert text_store.get(str(i))
        assert leveldb_store.get(str(i)).decode() == text_store.get(str(i))

    assert list(v.decode() for k, v in leveldb_store.iterator()) == \
        list(v for k, v in text_store.iterator())
コード例 #2
0
ファイル: client_txn_log.py プロジェクト: aigoncharov/plenum
class ClientTxnLog(HasFileStorage):
    """
    An immutable log of transactions made by the client.
    """

    def __init__(self, name, baseDir=None):
        self.dataDir = "data/clients"
        self.name = name
        HasFileStorage.__init__(self, name,
                                baseDir=baseDir,
                                dataDir=self.dataDir)
        self.clientDataLocation = self.dataLocation
        if not os.path.exists(self.clientDataLocation):
            os.makedirs(self.clientDataLocation)
        # self.transactionLog = TextFileStore(self.clientDataLocation,
        #                                     "transactions")
        self.transactionLog = KeyValueStorageLeveldb(
            self.clientDataLocation, "transactions")
        self.serializer = ledger_txn_serializer

    def close(self):
        self.transactionLog.close()

    @property
    def txnFieldOrdering(self):
        fields = getTxnOrderedFields()
        return updateFieldsWithSeqNo(fields)

    def append(self, identifier: str, reqId, txn):
        key = '{}{}'.format(identifier, reqId)
        self.transactionLog.put(
            key=key, value=self.serializer.serialize(
                txn, fields=self.txnFieldOrdering, toBytes=False))

    def hasTxn(self, identifier, reqId) -> bool:
        key = '{}{}'.format(identifier, reqId)
        return key in self.transactionLog

    def reset(self):
        self.transactionLog.reset()
コード例 #3
0
def kv(request, tempdir) -> KeyValueStorage:
    global i

    if request.param == 'leveldb':
        kv = KeyValueStorageLeveldb(tempdir, 'kv{}'.format(i))
    else:
        kv = KeyValueStorageRocksdb(tempdir, 'kv{}'.format(i))

    assert kv.read_only is False

    kv.put('k1', 'v1')
    kv.put('k2', 'v2')
    kv.put('k3', 'v3')
    kv.close()

    if request.param == 'leveldb':
        kv = KeyValueStorageLeveldb(tempdir, 'kv{}'.format(i), read_only=True)
    else:
        kv = KeyValueStorageRocksdb(tempdir, 'kv{}'.format(i), read_only=True)

    i += 1
    yield kv
    kv.close()
コード例 #4
0
def kv(request, tempdir) -> KeyValueStorage:
    global i

    if request.param == 'leveldb':
        kv = KeyValueStorageLeveldb(tempdir, 'kv{}'.format(i))
    else:
        kv = KeyValueStorageRocksdb(tempdir, 'kv{}'.format(i))

    assert kv.read_only is False

    kv.put('k1', 'v1')
    kv.put('k2', 'v2')
    kv.put('k3', 'v3')
    kv.close()

    if request.param == 'leveldb':
        kv = KeyValueStorageLeveldb(tempdir, 'kv{}'.format(i), read_only=True)
    else:
        kv = KeyValueStorageRocksdb(tempdir, 'kv{}'.format(i), read_only=True)

    i += 1
    yield kv
    kv.close()