-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
124 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "dictdatabase" | ||
version = "2.0.2" | ||
version = "2.0.3" | ||
repository = "https://github.com/mkrd/DictDataBase" | ||
description = "Easy-to-use database using dicts" | ||
authors = ["Marcel Kröker <[email protected]>"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import dictdatabase as DDB | ||
|
||
|
||
def test_delete(env, use_compression): | ||
DDB.at("test_delete").create({"a": 1}, force_overwrite=True) | ||
assert DDB.at("test_delete").read() == {"a": 1} | ||
DDB.at("test_delete").delete() | ||
assert DDB.at("test_delete").read() is None | ||
|
||
|
||
|
||
def test_delete_nonexistent(): | ||
DDB.at("test_delete_nonexistent").delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import dictdatabase as DDB | ||
from path_dict import pd | ||
from concurrent.futures import ThreadPoolExecutor, wait | ||
|
||
|
||
def increment_counters(n, tables): | ||
for _ in range(n): | ||
for t in range(tables): | ||
# Perform a useless read operation | ||
d = DDB.at(f"test_stress_threaded{t}").read() | ||
# Perform a counter increment | ||
with DDB.at(f"test_stress_threaded{t}").session(as_type=pd) as (session, d): | ||
d["counter"] = lambda x: (x or 0) + 1 | ||
session.write() | ||
return True | ||
|
||
|
||
|
||
def run_threaded(fns_args: list, max_threads=None): | ||
""" | ||
Run a list of tasks concurrently, and return their results as | ||
a list in the same order. A task is a 2-tuple of the function and an | ||
n-tuple of the function's n arguments. | ||
Remember: A 1-tuple needs a trailing comma, eg. (x,) | ||
Return: A list of results, in the order of the input tasks. | ||
""" | ||
if max_threads is None: | ||
max_threads = len(fns_args) | ||
results = [] | ||
with ThreadPoolExecutor(max_threads) as pool: | ||
for fn, args in fns_args: | ||
future = pool.submit(fn, *args) | ||
results.append(future) | ||
wait(results) | ||
return [r.result() for r in results] | ||
|
||
|
||
def test_stress_threaded(env): | ||
per_thread = 8 | ||
tables = 2 | ||
threads = 4 | ||
# Create tables | ||
for t in range(tables): | ||
DDB.at(f"test_stress_threaded{t}").create({}, force_overwrite=True) | ||
|
||
# Create tasks for concurrent execution | ||
tasks = [(increment_counters, (per_thread, tables)) for _ in range(threads)] | ||
|
||
# Run tasks concurrently | ||
results = run_threaded(tasks, max_threads=threads) | ||
|
||
# Check correctness of results | ||
assert results == [True] * threads | ||
for t in range(tables): | ||
db = DDB.at(f"test_stress_threaded{t}").read() | ||
assert db["counter"] == threads * per_thread |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters