def testMeasureWriteTime(tempdir): store = TextFileStore(tempdir, 'benchWithSync', isLineNoKey=True, storeContentHash=False) hashes = [hexlify(h).decode() for h in generateHashes(1000)] start = time.time() for h in hashes: store.put(value=h) timeTakenWithSync = time.time() - start store = TextFileStore(tempdir, 'benchWithoutSync', isLineNoKey=True, storeContentHash=False, ensureDurability=False) start = time.time() for h in hashes: store.put(value=h) timeTakenWithoutSync = time.time() - start print("Time taken to write {} entries to file with fsync is {} " "seconds".format(len(hashes), timeTakenWithSync)) print("Time taken to write {} entries to file without fsync is {} " "seconds".format(len(hashes), timeTakenWithoutSync)) print("So the difference is {} seconds".format(timeTakenWithSync - timeTakenWithoutSync)) # On most platforms the ratio between write time with fsync and # write time without fsync typically must be greater than 100. # But on Windows Server 2012 this ratio may be less - down to 30. assert timeTakenWithoutSync*10 < timeTakenWithSync, "ratio is {}".\ format(timeTakenWithSync/timeTakenWithoutSync)
def test_add_get_txns(ledger_no_genesis): ledger = ledger_no_genesis txns = [] hashes = [hexlify(h).decode() for h in generateHashes(40)] for i in range(20): txns.append({ 'identifier': hashes.pop(), 'reqId': i, 'op': hashes.pop() }) for txn in txns: ledger.add(txn) check_ledger_generator(ledger) for frm, to in [(1, 20), (3, 8), (5, 17), (6, 10), (3, 3), (3, None), (None, 10), (None, None)]: for s, t in ledger.getAllTxn(frm=frm, to=to): assert txns[s - 1] == t # with pytest.raises(AssertionError): # list(ledger.getAllTxn(frm=3, to=1)) for frm, to in [(i, j) for i, j in itertools.permutations(range(1, 21), 2) if i <= j]: for s, t in ledger.getAllTxn(frm=frm, to=to): assert txns[s - 1] == t
def test_add_get_txns(ledger_no_genesis): ledger = ledger_no_genesis txns = [] hashes = [hexlify(h).decode() for h in generateHashes(40)] for i in range(20): txns.append({ 'identifier': hashes.pop(), 'reqId': i, 'op': hashes.pop() }) for txn in txns: ledger.add(txn) check_ledger_generator(ledger) for frm, to in [(1, 20), (3, 8), (5, 17), (6, 10), (3, 3), (3, None), (None, 10), (None, None)]: for s, t in ledger.getAllTxn(frm=frm, to=to): assert txns[s - 1] == t # with pytest.raises(AssertionError): # list(ledger.getAllTxn(frm=3, to=1)) for frm, to in [(i, j) for i, j in itertools.permutations(range(1, 21), 2) if i <= j]: for s, t in ledger.getAllTxn(frm=frm, to=to): assert txns[s - 1] == t
def testMeasureWriteTime(tempdir): store = TextFileStore(tempdir, 'benchWithSync', isLineNoKey=True, storeContentHash=False) hashes = [hexlify(h).decode() for h in generateHashes(1000)] start = time.time() for h in hashes: store.put(value=h) timeTakenWithSync = time.time() - start store = TextFileStore(tempdir, 'benchWithoutSync', isLineNoKey=True, storeContentHash=False, ensureDurability=False) start = time.time() for h in hashes: store.put(value=h) timeTakenWithoutSync = time.time() - start print("Time taken to write {} entries to file with fsync is {} " "seconds".format(len(hashes), timeTakenWithSync)) print("Time taken to write {} entries to file without fsync is {} " "seconds".format(len(hashes), timeTakenWithoutSync)) print("So the difference is {} seconds". format(timeTakenWithSync-timeTakenWithoutSync)) # On most platforms the ratio between write time with fsync and # write time without fsync typically must be greater than 100. # But on Windows Server 2012 this ratio may be less - down to 30. assert timeTakenWithoutSync*10 < timeTakenWithSync, "ratio is {}".\ format(timeTakenWithSync/timeTakenWithoutSync)
def test_add_get_txns(tempdir, ledger): txns = [] hashes = [hexlify(h).decode() for h in generateHashes(60)] for i in range(20): txns.append({ 'a': hashes.pop(), 'b': hashes.pop(), 'c': hashes.pop() }) for txn in txns: ledger.add(txn) check_ledger_generator(ledger) for s, t in ledger.getAllTxn(frm=1, to=20): assert txns[s-1] == t for s, t in ledger.getAllTxn(frm=3, to=8): assert txns[s-1] == t for s, t in ledger.getAllTxn(frm=5, to=17): assert txns[s-1] == t for s, t in ledger.getAllTxn(frm=6, to=10): assert txns[s-1] == t for s, t in ledger.getAllTxn(frm=3, to=3): assert txns[s-1] == t for s, t in ledger.getAllTxn(frm=3): assert txns[s-1] == t for s, t in ledger.getAllTxn(to=10): assert txns[s-1] == t for s, t in ledger.getAllTxn(): assert txns[s-1] == t with pytest.raises(AssertionError): list(ledger.getAllTxn(frm=3, to=1)) for frm, to in [(i, j) for i, j in itertools.permutations(range(1, 21), 2) if i <= j]: for s, t in ledger.getAllTxn(frm=frm, to=to): assert txns[s-1] == t
def testUniqueConstraint(odbhs: OrientDbHashStore): leafHash = generateHashes(1)[0] odbhs.writeLeaf(leafHash) with pytest.raises(pyorient.PyOrientORecordDuplicatedException): odbhs.writeLeaf(leafHash)