File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed
tests/trinity/core/database Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -94,3 +94,19 @@ def test_db_over_ipc_manager(manager):
94
94
95
95
with pytest .raises (KeyError ):
96
96
db [b'not-present' ]
97
+
98
+
99
+ def test_atomic_batch_over_ipc_manager (manager ):
100
+ db = manager .get_db ()
101
+
102
+ assert b'key-b' not in db
103
+ assert b'key-c' not in db
104
+
105
+ with db .atomic_batch () as batch :
106
+ batch .set (b'key-b' , b'value-b' )
107
+ batch .set (b'key-c' , b'value-c' )
108
+
109
+ assert b'key-b' in db
110
+ assert db [b'key-b' ] == b'value-b'
111
+ assert b'key-c' in db
112
+ assert db [b'key-c' ] == b'value-c'
Original file line number Diff line number Diff line change
1
+ from contextlib import contextmanager
2
+ from typing import (
3
+ Generator ,
4
+ )
1
5
# Typeshed definitions for multiprocessing.managers is incomplete, so ignore them for now:
2
6
# https://github.com/python/typeshed/blob/85a788dbcaa5e9e9a62e55f15d44530cd28ba830/stdlib/3/multiprocessing/managers.pyi#L3
3
7
from multiprocessing .managers import ( # type: ignore
4
8
BaseProxy ,
5
9
)
6
10
7
11
from eth .db .backends .base import BaseDB
12
+ from eth .db .atomic import AtomicDBWriteBatch
8
13
9
14
from trinity .utils .mp import async_method
10
15
@@ -15,12 +20,13 @@ class DBProxy(BaseProxy):
15
20
'__delitem__' ,
16
21
'__getitem__' ,
17
22
'__setitem__' ,
23
+ 'atomic_batch' ,
24
+ 'coro_set' ,
25
+ 'coro_exists' ,
18
26
'delete' ,
19
27
'exists' ,
20
28
'get' ,
21
29
'set' ,
22
- 'coro_set' ,
23
- 'coro_exists' ,
24
30
)
25
31
coro_set = async_method ('set' )
26
32
coro_exists = async_method ('exists' )
@@ -49,6 +55,11 @@ def exists(self, key: bytes) -> bool:
49
55
def __contains__ (self , key : bytes ) -> bool :
50
56
return self ._callmethod ('__contains__' , (key ,))
51
57
58
+ @contextmanager
59
+ def atomic_batch (self ) -> Generator ['AtomicDBWriteBatch' , None , None ]:
60
+ with AtomicDBWriteBatch ._commit_unless_raises (self ) as readable_batch :
61
+ yield readable_batch
62
+
52
63
53
64
class AsyncBaseDB (BaseDB ):
54
65
You can’t perform that action at this time.
0 commit comments