Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Nicolas Wavrant
ZODB
Commits
965bf84a
Commit
965bf84a
authored
Jun 17, 2016
by
Jim Fulton
Committed by
GitHub
Jun 17, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #70 from zopefoundation/stop-calling-load
Stop calling load
parents
1e783423
df2ebe37
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
107 additions
and
94 deletions
+107
-94
src/ZODB/BaseStorage.py
src/ZODB/BaseStorage.py
+2
-11
src/ZODB/FileStorage/tests.py
src/ZODB/FileStorage/tests.py
+2
-1
src/ZODB/blob.py
src/ZODB/blob.py
+1
-1
src/ZODB/scripts/fsrefs.py
src/ZODB/scripts/fsrefs.py
+3
-3
src/ZODB/scripts/netspace.py
src/ZODB/scripts/netspace.py
+3
-3
src/ZODB/scripts/space.py
src/ZODB/scripts/space.py
+2
-2
src/ZODB/tests/BasicStorage.py
src/ZODB/tests/BasicStorage.py
+13
-11
src/ZODB/tests/ConflictResolution.py
src/ZODB/tests/ConflictResolution.py
+3
-1
src/ZODB/tests/Corruption.py
src/ZODB/tests/Corruption.py
+4
-1
src/ZODB/tests/IteratorStorage.py
src/ZODB/tests/IteratorStorage.py
+2
-2
src/ZODB/tests/MTStorage.py
src/ZODB/tests/MTStorage.py
+4
-2
src/ZODB/tests/PackableStorage.py
src/ZODB/tests/PackableStorage.py
+10
-9
src/ZODB/tests/PersistentStorage.py
src/ZODB/tests/PersistentStorage.py
+4
-2
src/ZODB/tests/ReadOnlyStorage.py
src/ZODB/tests/ReadOnlyStorage.py
+3
-1
src/ZODB/tests/RecoveryStorage.py
src/ZODB/tests/RecoveryStorage.py
+5
-3
src/ZODB/tests/RevisionStorage.py
src/ZODB/tests/RevisionStorage.py
+3
-3
src/ZODB/tests/TransactionalUndoStorage.py
src/ZODB/tests/TransactionalUndoStorage.py
+26
-27
src/ZODB/tests/testDemoStorage.py
src/ZODB/tests/testDemoStorage.py
+7
-4
src/ZODB/tests/testFileStorage.py
src/ZODB/tests/testFileStorage.py
+6
-5
src/ZODB/tests/testblob.py
src/ZODB/tests/testblob.py
+4
-2
No files found.
src/ZODB/BaseStorage.py
View file @
965bf84a
...
@@ -28,7 +28,7 @@ from persistent.TimeStamp import TimeStamp
...
@@ -28,7 +28,7 @@ from persistent.TimeStamp import TimeStamp
import
ZODB.interfaces
import
ZODB.interfaces
from
.
import
POSException
,
utils
from
.
import
POSException
,
utils
from
.utils
import
z64
,
oid_repr
,
byte_ord
,
byte_chr
from
.utils
import
z64
,
oid_repr
,
byte_ord
,
byte_chr
,
load_current
from
.UndoLogCompatible
import
UndoLogCompatible
from
.UndoLogCompatible
import
UndoLogCompatible
from
._compat
import
dumps
,
_protocol
,
py2_hasattr
from
._compat
import
dumps
,
_protocol
,
py2_hasattr
...
@@ -275,16 +275,7 @@ class BaseStorage(UndoLogCompatible):
...
@@ -275,16 +275,7 @@ class BaseStorage(UndoLogCompatible):
def
getTid
(
self
,
oid
):
def
getTid
(
self
,
oid
):
self
.
_lock_acquire
()
self
.
_lock_acquire
()
try
:
try
:
v
=
''
return
load_current
(
self
,
oid
)[
1
]
try
:
supportsVersions
=
self
.
supportsVersions
except
AttributeError
:
pass
else
:
if
supportsVersions
():
v
=
self
.
modifiedInVersion
(
oid
)
pickledata
,
serial
=
self
.
load
(
oid
,
v
)
return
serial
finally
:
finally
:
self
.
_lock_release
()
self
.
_lock_release
()
...
...
src/ZODB/FileStorage/tests.py
View file @
965bf84a
...
@@ -119,7 +119,8 @@ def pack_with_repeated_blob_records():
...
@@ -119,7 +119,8 @@ def pack_with_repeated_blob_records():
>>> transaction.commit()
>>> transaction.commit()
>>> tm = transaction.TransactionManager()
>>> tm = transaction.TransactionManager()
>>> oid = conn.root()[1]._p_oid
>>> oid = conn.root()[1]._p_oid
>>> blob_record, oldserial = fs.load(oid)
>>> from ZODB.utils import load_current
>>> blob_record, oldserial = load_current(fs, oid)
Now, create a transaction with multiple saves:
Now, create a transaction with multiple saves:
...
...
src/ZODB/blob.py
View file @
965bf84a
...
@@ -796,7 +796,7 @@ class BlobStorage(BlobStorageMixin):
...
@@ -796,7 +796,7 @@ class BlobStorage(BlobStorageMixin):
for
oid
,
oid_path
in
self
.
fshelper
.
listOIDs
():
for
oid
,
oid_path
in
self
.
fshelper
.
listOIDs
():
exists
=
True
exists
=
True
try
:
try
:
self
.
load
(
oid
,
None
)
# no version support
utils
.
load_current
(
self
,
oid
)
except
(
POSKeyError
,
KeyError
):
except
(
POSKeyError
,
KeyError
):
exists
=
False
exists
=
False
...
...
src/ZODB/scripts/fsrefs.py
View file @
965bf84a
...
@@ -66,7 +66,7 @@ import traceback
...
@@ -66,7 +66,7 @@ import traceback
from
ZODB.FileStorage
import
FileStorage
from
ZODB.FileStorage
import
FileStorage
from
ZODB.TimeStamp
import
TimeStamp
from
ZODB.TimeStamp
import
TimeStamp
from
ZODB.utils
import
u64
,
oid_repr
,
get_pickle_metadata
from
ZODB.utils
import
u64
,
oid_repr
,
get_pickle_metadata
,
load_current
from
ZODB.serialize
import
get_refs
from
ZODB.serialize
import
get_refs
from
ZODB.POSException
import
POSKeyError
from
ZODB.POSException
import
POSKeyError
...
@@ -120,7 +120,7 @@ def main(path=None):
...
@@ -120,7 +120,7 @@ def main(path=None):
for
oid
in
fs
.
_index
.
keys
():
for
oid
in
fs
.
_index
.
keys
():
try
:
try
:
data
,
serial
=
fs
.
load
(
oid
,
""
)
data
,
serial
=
load_current
(
fs
,
oid
)
except
(
KeyboardInterrupt
,
SystemExit
):
except
(
KeyboardInterrupt
,
SystemExit
):
raise
raise
except
POSKeyError
:
except
POSKeyError
:
...
@@ -135,7 +135,7 @@ def main(path=None):
...
@@ -135,7 +135,7 @@ def main(path=None):
for
oid
in
fs
.
_index
.
keys
():
for
oid
in
fs
.
_index
.
keys
():
if
oid
in
inactive
:
if
oid
in
inactive
:
continue
continue
data
,
serial
=
fs
.
load
(
oid
,
""
)
data
,
serial
=
load_current
(
fs
,
oid
)
refs
=
get_refs
(
data
)
refs
=
get_refs
(
data
)
missing
=
[]
# contains 3-tuples of oid, klass-metadata, reason
missing
=
[]
# contains 3-tuples of oid, klass-metadata, reason
for
ref
,
klass
in
refs
:
for
ref
,
klass
in
refs
:
...
...
src/ZODB/scripts/netspace.py
View file @
965bf84a
...
@@ -9,7 +9,7 @@ usage: netspace.py [-P | -v] data.fs
...
@@ -9,7 +9,7 @@ usage: netspace.py [-P | -v] data.fs
from
__future__
import
print_function
from
__future__
import
print_function
import
ZODB
import
ZODB
from
ZODB.FileStorage
import
FileStorage
from
ZODB.FileStorage
import
FileStorage
from
ZODB.utils
import
U64
,
get_pickle_metadata
from
ZODB.utils
import
U64
,
get_pickle_metadata
,
load_current
from
ZODB.serialize
import
referencesf
from
ZODB.serialize
import
referencesf
from
six.moves
import
filter
from
six.moves
import
filter
...
@@ -64,7 +64,7 @@ def main(path):
...
@@ -64,7 +64,7 @@ def main(path):
v
=
cache
.
get
(
oid
)
v
=
cache
.
get
(
oid
)
if
v
is
not
None
:
if
v
is
not
None
:
return
v
return
v
data
,
serialno
=
fs
.
load
(
oid
,
''
)
data
,
serialno
=
load_current
(
fs
,
oid
)
size
=
len
(
data
)
size
=
len
(
data
)
for
suboid
in
referencesf
(
data
):
for
suboid
in
referencesf
(
data
):
if
suboid
in
seen
:
if
suboid
in
seen
:
...
@@ -89,7 +89,7 @@ def main(path):
...
@@ -89,7 +89,7 @@ def main(path):
fmt
=
"%8s %5d %8d %s %s.%s"
fmt
=
"%8s %5d %8d %s %s.%s"
for
oid
in
keys
:
for
oid
in
keys
:
data
,
serialno
=
fs
.
load
(
oid
,
''
)
data
,
serialno
=
load_current
(
fs
,
oid
)
mod
,
klass
=
get_pickle_metadata
(
data
)
mod
,
klass
=
get_pickle_metadata
(
data
)
refs
=
referencesf
(
data
)
refs
=
referencesf
(
data
)
path
=
paths
.
get
(
oid
,
'-'
)
path
=
paths
.
get
(
oid
,
'-'
)
...
...
src/ZODB/scripts/space.py
View file @
965bf84a
...
@@ -9,7 +9,7 @@ Current limitations / simplifications: Ignores revisions and versions.
...
@@ -9,7 +9,7 @@ Current limitations / simplifications: Ignores revisions and versions.
"""
"""
from
__future__
import
print_function
from
__future__
import
print_function
from
ZODB.FileStorage
import
FileStorage
from
ZODB.FileStorage
import
FileStorage
from
ZODB.utils
import
U64
,
get_pickle_metadata
from
ZODB.utils
import
U64
,
get_pickle_metadata
,
load_current
import
six
import
six
def
run
(
path
,
v
=
0
):
def
run
(
path
,
v
=
0
):
...
@@ -21,7 +21,7 @@ def run(path, v=0):
...
@@ -21,7 +21,7 @@ def run(path, v=0):
iter
=
fs
.
_index
.
keys
()
iter
=
fs
.
_index
.
keys
()
totals
=
{}
totals
=
{}
for
oid
in
iter
:
for
oid
in
iter
:
data
,
serialno
=
fs
.
load
(
oid
,
''
)
data
,
serialno
=
load_current
(
fs
,
oid
)
mod
,
klass
=
get_pickle_metadata
(
data
)
mod
,
klass
=
get_pickle_metadata
(
data
)
key
=
"%s.%s"
%
(
mod
,
klass
)
key
=
"%s.%s"
%
(
mod
,
klass
)
bytes
,
count
=
totals
.
get
(
key
,
(
0
,
0
))
bytes
,
count
=
totals
.
get
(
key
,
(
0
,
0
))
...
...
src/ZODB/tests/BasicStorage.py
View file @
965bf84a
...
@@ -73,7 +73,7 @@ class BasicStorage:
...
@@ -73,7 +73,7 @@ class BasicStorage:
r2
=
self
.
_storage
.
tpc_vote
(
txn
)
r2
=
self
.
_storage
.
tpc_vote
(
txn
)
self
.
_storage
.
tpc_finish
(
txn
)
self
.
_storage
.
tpc_finish
(
txn
)
newrevid
=
handle_serials
(
oid
,
r1
,
r2
)
newrevid
=
handle_serials
(
oid
,
r1
,
r2
)
data
,
revid
=
self
.
_storage
.
load
(
oid
,
''
)
data
,
revid
=
utils
.
load_current
(
self
.
_storage
,
oid
)
value
=
zodb_unpickle
(
data
)
value
=
zodb_unpickle
(
data
)
eq
(
value
,
MinPO
(
11
))
eq
(
value
,
MinPO
(
11
))
eq
(
revid
,
newrevid
)
eq
(
revid
,
newrevid
)
...
@@ -88,14 +88,14 @@ class BasicStorage:
...
@@ -88,14 +88,14 @@ class BasicStorage:
eq
=
self
.
assertEqual
eq
=
self
.
assertEqual
oid
=
self
.
_storage
.
new_oid
()
oid
=
self
.
_storage
.
new_oid
()
self
.
_dostore
(
oid
=
oid
,
data
=
MinPO
(
7
))
self
.
_dostore
(
oid
=
oid
,
data
=
MinPO
(
7
))
data
,
revid
=
self
.
_storage
.
load
(
oid
,
''
)
data
,
revid
=
utils
.
load_current
(
self
.
_storage
,
oid
)
value
=
zodb_unpickle
(
data
)
value
=
zodb_unpickle
(
data
)
eq
(
value
,
MinPO
(
7
))
eq
(
value
,
MinPO
(
7
))
# Now do a bunch of updates to an object
# Now do a bunch of updates to an object
for
i
in
range
(
13
,
22
):
for
i
in
range
(
13
,
22
):
revid
=
self
.
_dostore
(
oid
,
revid
=
revid
,
data
=
MinPO
(
i
))
revid
=
self
.
_dostore
(
oid
,
revid
=
revid
,
data
=
MinPO
(
i
))
# Now get the latest revision of the object
# Now get the latest revision of the object
data
,
revid
=
self
.
_storage
.
load
(
oid
,
''
)
data
,
revid
=
utils
.
load_current
(
self
.
_storage
,
oid
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
21
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
21
))
def
checkConflicts
(
self
):
def
checkConflicts
(
self
):
...
@@ -132,7 +132,7 @@ class BasicStorage:
...
@@ -132,7 +132,7 @@ class BasicStorage:
revid
=
self
.
_dostore
(
oid
=
oid
,
data
=
MinPO
(
6
))
revid
=
self
.
_dostore
(
oid
=
oid
,
data
=
MinPO
(
6
))
for
oid
,
revid
in
[(
oid1
,
revid1
),
(
oid
,
revid
)]:
for
oid
,
revid
in
[(
oid1
,
revid1
),
(
oid
,
revid
)]:
data
,
_revid
=
self
.
_storage
.
load
(
oid
,
''
)
data
,
_revid
=
utils
.
load_current
(
self
.
_storage
,
oid
)
self
.
assertEqual
(
revid
,
_revid
)
self
.
assertEqual
(
revid
,
_revid
)
def
checkStoreTwoObjects
(
self
):
def
checkStoreTwoObjects
(
self
):
...
@@ -270,8 +270,10 @@ class BasicStorage:
...
@@ -270,8 +270,10 @@ class BasicStorage:
self
.
_storage
.
tpc_finish
(
t
)
self
.
_storage
.
tpc_finish
(
t
)
thread
.
join
(
33
)
thread
.
join
(
33
)
tid3
=
self
.
_storage
.
load
(
oid
)[
1
]
tid3
=
utils
.
load_current
(
self
.
_storage
,
oid
)[
1
]
self
.
assertTrue
(
tid3
>
self
.
_storage
.
load
(
b'
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
xf3
'
)[
1
])
self
.
assertTrue
(
tid3
>
utils
.
load_current
(
self
.
_storage
,
b'
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
xf3
'
)[
1
])
#----------------------------------------------------------------------
#----------------------------------------------------------------------
# non-stale competing trans after checkCurrentSerialInTransaction
# non-stale competing trans after checkCurrentSerialInTransaction
...
@@ -296,9 +298,10 @@ class BasicStorage:
...
@@ -296,9 +298,10 @@ class BasicStorage:
else
:
else
:
self
.
_storage
.
tpc_finish
(
t
)
self
.
_storage
.
tpc_finish
(
t
)
thread
.
join
()
thread
.
join
()
tid4
=
self
.
_storage
.
load
(
oid
)[
1
]
tid4
=
utils
.
load_current
(
self
.
_storage
,
oid
)[
1
]
self
.
assertTrue
(
tid4
>
self
.
assertTrue
(
self
.
_storage
.
load
(
b'
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
xf4
'
)[
1
])
tid4
>
utils
.
load_current
(
self
.
_storage
,
b'
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
xf4
'
)[
1
])
def
check_tid_ordering_w_commit
(
self
):
def
check_tid_ordering_w_commit
(
self
):
...
@@ -363,7 +366,7 @@ class BasicStorage:
...
@@ -363,7 +366,7 @@ class BasicStorage:
@
run_in_thread
@
run_in_thread
def
load
():
def
load
():
update_attempts
()
update_attempts
()
results
[
'load'
]
=
self
.
_storage
.
load
(
ZERO
,
''
)[
1
]
results
[
'load'
]
=
utils
.
load_current
(
self
.
_storage
,
ZERO
)[
1
]
expected_attempts
=
2
expected_attempts
=
2
...
@@ -397,4 +400,3 @@ class BasicStorage:
...
@@ -397,4 +400,3 @@ class BasicStorage:
self
.
assertEqual
(
results
.
pop
(
'lastTransaction'
),
tids
[
1
])
self
.
assertEqual
(
results
.
pop
(
'lastTransaction'
),
tids
[
1
])
for
m
,
tid
in
results
.
items
():
for
m
,
tid
in
results
.
items
():
self
.
assertEqual
(
tid
,
tids
[
1
])
self
.
assertEqual
(
tid
,
tids
[
1
])
src/ZODB/tests/ConflictResolution.py
View file @
965bf84a
...
@@ -17,6 +17,8 @@ from ZODB.POSException import ConflictError, UndoError
...
@@ -17,6 +17,8 @@ from ZODB.POSException import ConflictError, UndoError
from
persistent
import
Persistent
from
persistent
import
Persistent
from
transaction
import
Transaction
from
transaction
import
Transaction
from
ZODB.utils
import
load_current
from
ZODB.tests.StorageTestBase
import
zodb_unpickle
,
zodb_pickle
from
ZODB.tests.StorageTestBase
import
zodb_unpickle
,
zodb_pickle
class
PCounter
(
Persistent
):
class
PCounter
(
Persistent
):
...
@@ -71,7 +73,7 @@ class ConflictResolvingStorage:
...
@@ -71,7 +73,7 @@ class ConflictResolvingStorage:
revid2
=
self
.
_dostoreNP
(
oid
,
revid
=
revid1
,
data
=
zodb_pickle
(
obj
))
revid2
=
self
.
_dostoreNP
(
oid
,
revid
=
revid1
,
data
=
zodb_pickle
(
obj
))
revid3
=
self
.
_dostoreNP
(
oid
,
revid
=
revid1
,
data
=
zodb_pickle
(
obj
))
revid3
=
self
.
_dostoreNP
(
oid
,
revid
=
revid1
,
data
=
zodb_pickle
(
obj
))
data
,
serialno
=
self
.
_storage
.
load
(
oid
,
''
)
data
,
serialno
=
load_current
(
self
.
_storage
,
oid
)
inst
=
zodb_unpickle
(
data
)
inst
=
zodb_unpickle
(
data
)
self
.
assertEqual
(
inst
.
_value
,
5
)
self
.
assertEqual
(
inst
.
_value
,
5
)
...
...
src/ZODB/tests/Corruption.py
View file @
965bf84a
...
@@ -18,6 +18,9 @@ import random
...
@@ -18,6 +18,9 @@ import random
import
stat
import
stat
import
ZODB.FileStorage
import
ZODB.FileStorage
from
ZODB.utils
import
load_current
from
.StorageTestBase
import
StorageTestBase
from
.StorageTestBase
import
StorageTestBase
class
FileStorageCorruptTests
(
StorageTestBase
):
class
FileStorageCorruptTests
(
StorageTestBase
):
...
@@ -36,7 +39,7 @@ class FileStorageCorruptTests(StorageTestBase):
...
@@ -36,7 +39,7 @@ class FileStorageCorruptTests(StorageTestBase):
def
_check_stores
(
self
,
oids
):
def
_check_stores
(
self
,
oids
):
for
oid
,
revid
in
oids
:
for
oid
,
revid
in
oids
:
data
,
s_revid
=
self
.
_storage
.
load
(
oid
,
''
)
data
,
s_revid
=
load_current
(
self
.
_storage
,
oid
)
self
.
assertEqual
(
s_revid
,
revid
)
self
.
assertEqual
(
s_revid
,
revid
)
def
checkTruncatedIndex
(
self
):
def
checkTruncatedIndex
(
self
):
...
...
src/ZODB/tests/IteratorStorage.py
View file @
965bf84a
...
@@ -20,7 +20,7 @@ all these tests.
...
@@ -20,7 +20,7 @@ all these tests.
from
ZODB.tests.MinPO
import
MinPO
from
ZODB.tests.MinPO
import
MinPO
from
ZODB.tests.StorageTestBase
import
zodb_pickle
,
zodb_unpickle
from
ZODB.tests.StorageTestBase
import
zodb_pickle
,
zodb_unpickle
from
ZODB.utils
import
U64
,
p64
from
ZODB.utils
import
U64
,
p64
,
load_current
from
transaction
import
Transaction
from
transaction
import
Transaction
...
@@ -122,7 +122,7 @@ class IteratorStorage(IteratorCompare):
...
@@ -122,7 +122,7 @@ class IteratorStorage(IteratorCompare):
def
checkLoad_was_checkLoadEx
(
self
):
def
checkLoad_was_checkLoadEx
(
self
):
oid
=
self
.
_storage
.
new_oid
()
oid
=
self
.
_storage
.
new_oid
()
self
.
_dostore
(
oid
,
data
=
42
)
self
.
_dostore
(
oid
,
data
=
42
)
data
,
tid
=
self
.
_storage
.
load
(
oid
,
""
)
data
,
tid
=
load_current
(
self
.
_storage
,
oid
)
self
.
assertEqual
(
zodb_unpickle
(
data
),
MinPO
(
42
))
self
.
assertEqual
(
zodb_unpickle
(
data
),
MinPO
(
42
))
match
=
False
match
=
False
for
txn
in
self
.
_storage
.
iterator
():
for
txn
in
self
.
_storage
.
iterator
():
...
...
src/ZODB/tests/MTStorage.py
View file @
965bf84a
...
@@ -13,6 +13,8 @@ from ZODB.tests.StorageTestBase import handle_serials
...
@@ -13,6 +13,8 @@ from ZODB.tests.StorageTestBase import handle_serials
from
ZODB.tests.MinPO
import
MinPO
from
ZODB.tests.MinPO
import
MinPO
from
ZODB.POSException
import
ConflictError
from
ZODB.POSException
import
ConflictError
from
ZODB.utils
import
load_current
SHORT_DELAY
=
0.01
SHORT_DELAY
=
0.01
class
TestThread
(
threading
.
Thread
):
class
TestThread
(
threading
.
Thread
):
...
@@ -124,7 +126,7 @@ class StorageClientThread(TestThread):
...
@@ -124,7 +126,7 @@ class StorageClientThread(TestThread):
def
check
(
self
):
def
check
(
self
):
for
oid
,
revid
in
self
.
oids
.
items
():
for
oid
,
revid
in
self
.
oids
.
items
():
data
,
serial
=
self
.
storage
.
load
(
oid
,
''
)
data
,
serial
=
load_current
(
self
.
storage
,
oid
)
self
.
test
.
assertEqual
(
serial
,
revid
)
self
.
test
.
assertEqual
(
serial
,
revid
)
obj
=
zodb_unpickle
(
data
)
obj
=
zodb_unpickle
(
data
)
self
.
test
.
assertEqual
(
obj
.
value
[
0
],
self
.
getName
())
self
.
test
.
assertEqual
(
obj
.
value
[
0
],
self
.
getName
())
...
@@ -192,7 +194,7 @@ class ExtStorageClientThread(StorageClientThread):
...
@@ -192,7 +194,7 @@ class ExtStorageClientThread(StorageClientThread):
def
do_load
(
self
):
def
do_load
(
self
):
oid
=
self
.
pick_oid
()
oid
=
self
.
pick_oid
()
self
.
storage
.
load
(
oid
,
''
)
load_current
(
self
.
storage
,
oid
)
def
do_loadSerial
(
self
):
def
do_loadSerial
(
self
):
oid
=
self
.
pick_oid
()
oid
=
self
.
pick_oid
()
...
...
src/ZODB/tests/PackableStorage.py
View file @
965bf84a
...
@@ -32,6 +32,7 @@ import ZODB.interfaces
...
@@ -32,6 +32,7 @@ import ZODB.interfaces
import
ZODB.tests.util
import
ZODB.tests.util
import
zope.testing.setupstack
import
zope.testing.setupstack
from
ZODB.utils
import
load_current
ZERO
=
b'
\
0
'
*
8
ZERO
=
b'
\
0
'
*
8
...
@@ -141,7 +142,7 @@ class PackableStorageBase:
...
@@ -141,7 +142,7 @@ class PackableStorageBase:
def
_initroot
(
self
):
def
_initroot
(
self
):
try
:
try
:
self
.
_storage
.
load
(
ZERO
,
''
)
load_current
(
self
.
_storage
,
ZERO
)
except
KeyError
:
except
KeyError
:
from
transaction
import
Transaction
from
transaction
import
Transaction
file
=
BytesIO
()
file
=
BytesIO
()
...
@@ -393,7 +394,7 @@ class PackableStorage(PackableStorageBase):
...
@@ -393,7 +394,7 @@ class PackableStorage(PackableStorageBase):
root
.
value
=
0
root
.
value
=
0
revid0
=
self
.
_dostoreNP
(
ZERO
,
data
=
dumps
(
root
))
revid0
=
self
.
_dostoreNP
(
ZERO
,
data
=
dumps
(
root
))
# Make sure the root can be retrieved
# Make sure the root can be retrieved
data
,
revid
=
self
.
_storage
.
load
(
ZERO
,
''
)
data
,
revid
=
load_current
(
self
.
_storage
,
ZERO
)
eq
(
revid
,
revid0
)
eq
(
revid
,
revid0
)
eq
(
loads
(
data
).
value
,
0
)
eq
(
loads
(
data
).
value
,
0
)
# Commit three different revisions of the other object
# Commit three different revisions of the other object
...
@@ -424,7 +425,7 @@ class PackableStorage(PackableStorageBase):
...
@@ -424,7 +425,7 @@ class PackableStorage(PackableStorageBase):
self
.
_storage
.
pack
(
packtime
,
referencesf
)
self
.
_storage
.
pack
(
packtime
,
referencesf
)
# Make sure the revisions are gone, but that object zero and revision
# Make sure the revisions are gone, but that object zero and revision
# 3 are still there and correct
# 3 are still there and correct
data
,
revid
=
self
.
_storage
.
load
(
ZERO
,
''
)
data
,
revid
=
load_current
(
self
.
_storage
,
ZERO
)
eq
(
revid
,
revid0
)
eq
(
revid
,
revid0
)
eq
(
loads
(
data
).
value
,
0
)
eq
(
loads
(
data
).
value
,
0
)
raises
(
KeyError
,
self
.
_storage
.
loadSerial
,
oid
,
revid1
)
raises
(
KeyError
,
self
.
_storage
.
loadSerial
,
oid
,
revid1
)
...
@@ -433,7 +434,7 @@ class PackableStorage(PackableStorageBase):
...
@@ -433,7 +434,7 @@ class PackableStorage(PackableStorageBase):
pobj
=
loads
(
data
)
pobj
=
loads
(
data
)
eq
(
pobj
.
getoid
(),
oid
)
eq
(
pobj
.
getoid
(),
oid
)
eq
(
pobj
.
value
,
3
)
eq
(
pobj
.
value
,
3
)
data
,
revid
=
self
.
_storage
.
load
(
oid
,
''
)
data
,
revid
=
load_current
(
self
.
_storage
,
oid
)
eq
(
revid
,
revid3
)
eq
(
revid
,
revid3
)
pobj
=
loads
(
data
)
pobj
=
loads
(
data
)
eq
(
pobj
.
getoid
(),
oid
)
eq
(
pobj
.
getoid
(),
oid
)
...
@@ -461,7 +462,7 @@ class PackableStorage(PackableStorageBase):
...
@@ -461,7 +462,7 @@ class PackableStorage(PackableStorageBase):
root
.
value
=
0
root
.
value
=
0
revid0
=
self
.
_dostoreNP
(
ZERO
,
data
=
dumps
(
root
))
revid0
=
self
.
_dostoreNP
(
ZERO
,
data
=
dumps
(
root
))
# Make sure the root can be retrieved
# Make sure the root can be retrieved
data
,
revid
=
self
.
_storage
.
load
(
ZERO
,
''
)
data
,
revid
=
load_current
(
self
.
_storage
,
ZERO
)
eq
(
revid
,
revid0
)
eq
(
revid
,
revid0
)
eq
(
loads
(
data
).
value
,
0
)
eq
(
loads
(
data
).
value
,
0
)
# Commit three different revisions of the first object
# Commit three different revisions of the first object
...
@@ -501,7 +502,7 @@ class PackableStorage(PackableStorageBase):
...
@@ -501,7 +502,7 @@ class PackableStorage(PackableStorageBase):
self
.
_storage
.
pack
(
packtime
,
referencesf
)
self
.
_storage
.
pack
(
packtime
,
referencesf
)
# Make sure the revisions are gone, but that object zero, object2, and
# Make sure the revisions are gone, but that object zero, object2, and
# revision 3 of object1 are still there and correct.
# revision 3 of object1 are still there and correct.
data
,
revid
=
self
.
_storage
.
load
(
ZERO
,
''
)
data
,
revid
=
load_current
(
self
.
_storage
,
ZERO
)
eq
(
revid
,
revid0
)
eq
(
revid
,
revid0
)
eq
(
loads
(
data
).
value
,
0
)
eq
(
loads
(
data
).
value
,
0
)
raises
(
KeyError
,
self
.
_storage
.
loadSerial
,
oid1
,
revid1
)
raises
(
KeyError
,
self
.
_storage
.
loadSerial
,
oid1
,
revid1
)
...
@@ -510,12 +511,12 @@ class PackableStorage(PackableStorageBase):
...
@@ -510,12 +511,12 @@ class PackableStorage(PackableStorageBase):
pobj
=
loads
(
data
)
pobj
=
loads
(
data
)
eq
(
pobj
.
getoid
(),
oid1
)
eq
(
pobj
.
getoid
(),
oid1
)
eq
(
pobj
.
value
,
3
)
eq
(
pobj
.
value
,
3
)
data
,
revid
=
self
.
_storage
.
load
(
oid1
,
''
)
data
,
revid
=
load_current
(
self
.
_storage
,
oid1
)
eq
(
revid
,
revid3
)
eq
(
revid
,
revid3
)
pobj
=
loads
(
data
)
pobj
=
loads
(
data
)
eq
(
pobj
.
getoid
(),
oid1
)
eq
(
pobj
.
getoid
(),
oid1
)
eq
(
pobj
.
value
,
3
)
eq
(
pobj
.
value
,
3
)
data
,
revid
=
self
.
_storage
.
load
(
oid2
,
''
)
data
,
revid
=
load_current
(
self
.
_storage
,
oid2
)
eq
(
revid
,
revid4
)
eq
(
revid
,
revid4
)
eq
(
loads
(
data
).
value
,
11
)
eq
(
loads
(
data
).
value
,
11
)
data
=
self
.
_storage
.
loadSerial
(
oid2
,
revid4
)
data
=
self
.
_storage
.
loadSerial
(
oid2
,
revid4
)
...
@@ -649,7 +650,7 @@ class PackableUndoStorage(PackableStorageBase):
...
@@ -649,7 +650,7 @@ class PackableUndoStorage(PackableStorageBase):
pass
pass
# This object would be removed by the second pack, even though
# This object would be removed by the second pack, even though
# it is reachable.
# it is reachable.
self
.
_storage
.
load
(
lost_oid
,
""
)
load_current
(
self
.
_storage
,
lost_oid
)
def
checkPackUndoLog
(
self
):
def
checkPackUndoLog
(
self
):
self
.
_initroot
()
self
.
_initroot
()
...
...
src/ZODB/tests/PersistentStorage.py
View file @
965bf84a
...
@@ -13,6 +13,8 @@
...
@@ -13,6 +13,8 @@
##############################################################################
##############################################################################
"""Test that a storage's values persist across open and close."""
"""Test that a storage's values persist across open and close."""
from
ZODB.utils
import
load_current
class
PersistentStorage
:
class
PersistentStorage
:
def
checkUpdatesPersist
(
self
):
def
checkUpdatesPersist
(
self
):
...
@@ -36,7 +38,7 @@ class PersistentStorage:
...
@@ -36,7 +38,7 @@ class PersistentStorage:
# keep copies of all the objects
# keep copies of all the objects
objects
=
[]
objects
=
[]
for
oid
in
oids
:
for
oid
in
oids
:
p
,
s
=
self
.
_storage
.
load
(
oid
,
''
)
p
,
s
=
load_current
(
self
.
_storage
,
oid
)
objects
.
append
((
oid
,
''
,
p
,
s
))
objects
.
append
((
oid
,
''
,
p
,
s
))
self
.
_storage
.
close
()
self
.
_storage
.
close
()
...
@@ -44,6 +46,6 @@ class PersistentStorage:
...
@@ -44,6 +46,6 @@ class PersistentStorage:
# keep copies of all the objects
# keep copies of all the objects
for
oid
,
ver
,
p
,
s
in
objects
:
for
oid
,
ver
,
p
,
s
in
objects
:
_p
,
_s
=
self
.
_storage
.
load
(
oid
,
ver
)
_p
,
_s
=
load_current
(
self
.
_storage
,
oid
)
self
.
assertEqual
(
p
,
_p
)
self
.
assertEqual
(
p
,
_p
)
self
.
assertEqual
(
s
,
_s
)
self
.
assertEqual
(
s
,
_s
)
src/ZODB/tests/ReadOnlyStorage.py
View file @
965bf84a
...
@@ -14,6 +14,8 @@
...
@@ -14,6 +14,8 @@
from
ZODB.POSException
import
ReadOnlyError
,
Unsupported
from
ZODB.POSException
import
ReadOnlyError
,
Unsupported
import
transaction
import
transaction
from
ZODB.utils
import
load_current
class
ReadOnlyStorage
:
class
ReadOnlyStorage
:
def
_create_data
(
self
):
def
_create_data
(
self
):
...
@@ -34,7 +36,7 @@ class ReadOnlyStorage:
...
@@ -34,7 +36,7 @@ class ReadOnlyStorage:
self
.
_make_readonly
()
self
.
_make_readonly
()
# Note that this doesn't check _all_ read methods.
# Note that this doesn't check _all_ read methods.
for
oid
in
self
.
oids
.
keys
():
for
oid
in
self
.
oids
.
keys
():
data
,
revid
=
self
.
_storage
.
load
(
oid
,
''
)
data
,
revid
=
load_current
(
self
.
_storage
,
oid
)
self
.
assertEqual
(
revid
,
self
.
oids
[
oid
])
self
.
assertEqual
(
revid
,
self
.
oids
[
oid
])
# Storages without revisions may not have loadSerial().
# Storages without revisions may not have loadSerial().
try
:
try
:
...
...
src/ZODB/tests/RecoveryStorage.py
View file @
965bf84a
...
@@ -20,6 +20,8 @@ from ZODB.tests.StorageTestBase import MinPO, snooze
...
@@ -20,6 +20,8 @@ from ZODB.tests.StorageTestBase import MinPO, snooze
from
ZODB
import
DB
from
ZODB
import
DB
from
ZODB.serialize
import
referencesf
from
ZODB.serialize
import
referencesf
from
ZODB.utils
import
load_current
import
time
import
time
...
@@ -88,9 +90,9 @@ class RecoveryStorage(IteratorDeepCompare):
...
@@ -88,9 +90,9 @@ class RecoveryStorage(IteratorDeepCompare):
self
.
_dst
.
pack
(
time
.
time
(),
referencesf
)
self
.
_dst
.
pack
(
time
.
time
(),
referencesf
)
# And check to see that the root object exists, but not the other
# And check to see that the root object exists, but not the other
# objects.
# objects.
data
,
serial
=
self
.
_dst
.
load
(
root
.
_p_oid
,
''
)
data
,
serial
=
load_current
(
self
.
_dst
,
root
.
_p_oid
)
raises
(
KeyError
,
self
.
_dst
.
load
,
obj1
.
_p_oid
,
''
)
raises
(
KeyError
,
load_current
,
self
.
_dst
,
obj1
.
_p_oid
)
raises
(
KeyError
,
self
.
_dst
.
load
,
obj2
.
_p_oid
,
''
)
raises
(
KeyError
,
load_current
,
self
.
_dst
,
obj2
.
_p_oid
)
def
checkRestoreWithMultipleObjectsInUndoRedo
(
self
):
def
checkRestoreWithMultipleObjectsInUndoRedo
(
self
):
from
ZODB.FileStorage
import
FileStorage
from
ZODB.FileStorage
import
FileStorage
...
...
src/ZODB/tests/RevisionStorage.py
View file @
965bf84a
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
from
ZODB.tests.MinPO
import
MinPO
from
ZODB.tests.MinPO
import
MinPO
from
ZODB.tests.StorageTestBase
import
zodb_unpickle
,
zodb_pickle
,
snooze
from
ZODB.tests.StorageTestBase
import
zodb_unpickle
,
zodb_pickle
,
snooze
from
ZODB.tests.StorageTestBase
import
handle_serials
from
ZODB.tests.StorageTestBase
import
handle_serials
from
ZODB.utils
import
p64
,
u64
from
ZODB.utils
import
p64
,
u64
,
load_current
import
transaction
import
transaction
...
@@ -52,7 +52,7 @@ class RevisionStorage:
...
@@ -52,7 +52,7 @@ class RevisionStorage:
snooze
()
snooze
()
snooze
()
snooze
()
revid
=
self
.
_dostore
(
oid
,
revid
,
data
=
MinPO
(
i
))
revid
=
self
.
_dostore
(
oid
,
revid
,
data
=
MinPO
(
i
))
revs
.
append
(
self
.
_storage
.
load
(
oid
,
""
))
revs
.
append
(
load_current
(
self
.
_storage
,
oid
))
prev
=
u64
(
revs
[
0
][
1
])
prev
=
u64
(
revs
[
0
][
1
])
for
i
in
range
(
1
,
10
):
for
i
in
range
(
1
,
10
):
...
@@ -123,7 +123,7 @@ class RevisionStorage:
...
@@ -123,7 +123,7 @@ class RevisionStorage:
# Always undo the most recent txn, so the value will
# Always undo the most recent txn, so the value will
# alternate between 3 and 4.
# alternate between 3 and 4.
self
.
_undo
(
tid
,
note
=
"undo %d"
%
i
)
self
.
_undo
(
tid
,
note
=
"undo %d"
%
i
)
revs
.
append
(
self
.
_storage
.
load
(
oid
,
""
))
revs
.
append
(
load_current
(
self
.
_storage
,
oid
))
prev_tid
=
None
prev_tid
=
None
for
i
,
(
data
,
tid
)
in
enumerate
(
revs
):
for
i
,
(
data
,
tid
)
in
enumerate
(
revs
):
...
...
src/ZODB/tests/TransactionalUndoStorage.py
View file @
965bf84a
...
@@ -23,7 +23,7 @@ from transaction import Transaction
...
@@ -23,7 +23,7 @@ from transaction import Transaction
from
ZODB
import
POSException
from
ZODB
import
POSException
from
ZODB.serialize
import
referencesf
from
ZODB.serialize
import
referencesf
from
ZODB.utils
import
p64
from
ZODB.utils
import
p64
,
load_current
from
ZODB
import
DB
from
ZODB
import
DB
from
ZODB.tests.MinPO
import
MinPO
from
ZODB.tests.MinPO
import
MinPO
...
@@ -125,26 +125,25 @@ class TransactionalUndoStorage:
...
@@ -125,26 +125,25 @@ class TransactionalUndoStorage:
info
=
self
.
_storage
.
undoInfo
()
info
=
self
.
_storage
.
undoInfo
()
# Now start an undo transaction
# Now start an undo transaction
self
.
_undo
(
info
[
0
][
"id"
],
[
oid
],
note
=
"undo1"
)
self
.
_undo
(
info
[
0
][
"id"
],
[
oid
],
note
=
"undo1"
)
data
,
revid
=
self
.
_storage
.
load
(
oid
,
''
)
data
,
revid
=
load_current
(
self
.
_storage
,
oid
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
24
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
24
))
# Do another one
# Do another one
info
=
self
.
_storage
.
undoInfo
()
info
=
self
.
_storage
.
undoInfo
()
self
.
_undo
(
info
[
2
][
"id"
],
[
oid
],
note
=
"undo2"
)
self
.
_undo
(
info
[
2
][
"id"
],
[
oid
],
note
=
"undo2"
)
data
,
revid
=
self
.
_storage
.
load
(
oid
,
''
)
data
,
revid
=
load_current
(
self
.
_storage
,
oid
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
23
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
23
))
# Try to undo the first record
# Try to undo the first record
info
=
self
.
_storage
.
undoInfo
()
info
=
self
.
_storage
.
undoInfo
()
self
.
_undo
(
info
[
4
][
"id"
],
[
oid
],
note
=
"undo3"
)
self
.
_undo
(
info
[
4
][
"id"
],
[
oid
],
note
=
"undo3"
)
# This should fail since we've undone the object's creation
# This should fail since we've undone the object's creation
self
.
assertRaises
(
KeyError
,
self
.
assertRaises
(
KeyError
,
load_current
,
self
.
_storage
,
oid
)
self
.
_storage
.
load
,
oid
,
''
)
# And now let's try to redo the object's creation
# And now let's try to redo the object's creation
info
=
self
.
_storage
.
undoInfo
()
info
=
self
.
_storage
.
undoInfo
()
self
.
_undo
(
info
[
0
][
"id"
],
[
oid
])
self
.
_undo
(
info
[
0
][
"id"
],
[
oid
])
data
,
revid
=
self
.
_storage
.
load
(
oid
,
''
)
data
,
revid
=
load_current
(
self
.
_storage
,
oid
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
23
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
23
))
self
.
_iterate
()
self
.
_iterate
()
...
@@ -171,14 +170,14 @@ class TransactionalUndoStorage:
...
@@ -171,14 +170,14 @@ class TransactionalUndoStorage:
# Undo the last transaction
# Undo the last transaction
info
=
self
.
_storage
.
undoInfo
()
info
=
self
.
_storage
.
undoInfo
()
self
.
_undo
(
info
[
0
][
'id'
],
[
oid
])
self
.
_undo
(
info
[
0
][
'id'
],
[
oid
])
data
,
revid
=
self
.
_storage
.
load
(
oid
,
''
)
data
,
revid
=
load_current
(
self
.
_storage
,
oid
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
11
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
11
))
# Now from here, we can either redo the last undo, or undo the object
# Now from here, we can either redo the last undo, or undo the object
# creation. Let's undo the object creation.
# creation. Let's undo the object creation.
info
=
self
.
_storage
.
undoInfo
()
info
=
self
.
_storage
.
undoInfo
()
self
.
_undo
(
info
[
2
][
'id'
],
[
oid
])
self
.
_undo
(
info
[
2
][
'id'
],
[
oid
])
self
.
assertRaises
(
KeyError
,
self
.
_storage
.
load
,
oid
,
''
)
self
.
assertRaises
(
KeyError
,
load_current
,
self
.
_storage
,
oid
)
# Loading current data via loadBefore should raise a POSKeyError too:
# Loading current data via loadBefore should raise a POSKeyError too:
self
.
assertRaises
(
KeyError
,
self
.
_storage
.
loadBefore
,
oid
,
self
.
assertRaises
(
KeyError
,
self
.
_storage
.
loadBefore
,
oid
,
...
@@ -193,13 +192,13 @@ class TransactionalUndoStorage:
...
@@ -193,13 +192,13 @@ class TransactionalUndoStorage:
# Undo the last transaction
# Undo the last transaction
info
=
self
.
_storage
.
undoInfo
()
info
=
self
.
_storage
.
undoInfo
()
self
.
_undo
(
info
[
0
][
'id'
],
[
oid
])
self
.
_undo
(
info
[
0
][
'id'
],
[
oid
])
data
,
revid
=
self
.
_storage
.
load
(
oid
,
''
)
data
,
revid
=
load_current
(
self
.
_storage
,
oid
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
11
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
11
))
# Now from here, we can either redo the last undo, or undo the object
# Now from here, we can either redo the last undo, or undo the object
# creation. Let's redo the last undo
# creation. Let's redo the last undo
info
=
self
.
_storage
.
undoInfo
()
info
=
self
.
_storage
.
undoInfo
()
self
.
_undo
(
info
[
0
][
'id'
],
[
oid
])
self
.
_undo
(
info
[
0
][
'id'
],
[
oid
])
data
,
revid
=
self
.
_storage
.
load
(
oid
,
''
)
data
,
revid
=
load_current
(
self
.
_storage
,
oid
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
12
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
12
))
self
.
_iterate
()
self
.
_iterate
()
...
@@ -236,17 +235,17 @@ class TransactionalUndoStorage:
...
@@ -236,17 +235,17 @@ class TransactionalUndoStorage:
self
.
_storage
.
tpc_finish
(
t
)
self
.
_storage
.
tpc_finish
(
t
)
eq
(
revid1
,
revid2
)
eq
(
revid1
,
revid2
)
# Make sure the objects have the current value
# Make sure the objects have the current value
data
,
revid1
=
self
.
_storage
.
load
(
oid1
,
''
)
data
,
revid1
=
load_current
(
self
.
_storage
,
oid1
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
32
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
32
))
data
,
revid2
=
self
.
_storage
.
load
(
oid2
,
''
)
data
,
revid2
=
load_current
(
self
.
_storage
,
oid2
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
52
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
52
))
# Now attempt to undo the transaction containing two objects
# Now attempt to undo the transaction containing two objects
info
=
self
.
_storage
.
undoInfo
()
info
=
self
.
_storage
.
undoInfo
()
self
.
_undo
(
info
[
0
][
'id'
],
[
oid1
,
oid2
])
self
.
_undo
(
info
[
0
][
'id'
],
[
oid1
,
oid2
])
data
,
revid1
=
self
.
_storage
.
load
(
oid1
,
''
)
data
,
revid1
=
load_current
(
self
.
_storage
,
oid1
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
31
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
31
))
data
,
revid2
=
self
.
_storage
.
load
(
oid2
,
''
)
data
,
revid2
=
load_current
(
self
.
_storage
,
oid2
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
51
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
51
))
self
.
_iterate
()
self
.
_iterate
()
...
@@ -279,9 +278,9 @@ class TransactionalUndoStorage:
...
@@ -279,9 +278,9 @@ class TransactionalUndoStorage:
revid2
=
self
.
_transaction_newserial
(
oid2
)
revid2
=
self
.
_transaction_newserial
(
oid2
)
eq
(
revid1
,
revid2
)
eq
(
revid1
,
revid2
)
# Make sure the objects have the current value
# Make sure the objects have the current value
data
,
revid1
=
self
.
_storage
.
load
(
oid1
,
''
)
data
,
revid1
=
load_current
(
self
.
_storage
,
oid1
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
32
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
32
))
data
,
revid2
=
self
.
_storage
.
load
(
oid2
,
''
)
data
,
revid2
=
load_current
(
self
.
_storage
,
oid2
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
52
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
52
))
# Now attempt to undo the transaction containing two objects
# Now attempt to undo the transaction containing two objects
info
=
self
.
_storage
.
undoInfo
()
info
=
self
.
_storage
.
undoInfo
()
...
@@ -293,17 +292,17 @@ class TransactionalUndoStorage:
...
@@ -293,17 +292,17 @@ class TransactionalUndoStorage:
# We may get the finalization stuff called an extra time,
# We may get the finalization stuff called an extra time,
# depending on the implementation.
# depending on the implementation.
self
.
assertEqual
(
set
(
oids
),
set
((
oid1
,
oid2
)))
self
.
assertEqual
(
set
(
oids
),
set
((
oid1
,
oid2
)))
data
,
revid1
=
self
.
_storage
.
load
(
oid1
,
''
)
data
,
revid1
=
load_current
(
self
.
_storage
,
oid1
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
30
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
30
))
data
,
revid2
=
self
.
_storage
.
load
(
oid2
,
''
)
data
,
revid2
=
load_current
(
self
.
_storage
,
oid2
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
50
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
50
))
# Now try to undo the one we just did to undo, whew
# Now try to undo the one we just did to undo, whew
info
=
self
.
_storage
.
undoInfo
()
info
=
self
.
_storage
.
undoInfo
()
self
.
_undo
(
info
[
0
][
'id'
],
[
oid1
,
oid2
])
self
.
_undo
(
info
[
0
][
'id'
],
[
oid1
,
oid2
])
data
,
revid1
=
self
.
_storage
.
load
(
oid1
,
''
)
data
,
revid1
=
load_current
(
self
.
_storage
,
oid1
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
32
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
32
))
data
,
revid2
=
self
.
_storage
.
load
(
oid2
,
''
)
data
,
revid2
=
load_current
(
self
.
_storage
,
oid2
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
52
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
52
))
self
.
_iterate
()
self
.
_iterate
()
...
@@ -333,9 +332,9 @@ class TransactionalUndoStorage:
...
@@ -333,9 +332,9 @@ class TransactionalUndoStorage:
# Now attempt to undo the transaction containing two objects
# Now attempt to undo the transaction containing two objects
info
=
self
.
_storage
.
undoInfo
()
info
=
self
.
_storage
.
undoInfo
()
self
.
_undo
(
info
[
0
][
"id"
],
[
oid1
,
oid2
])
self
.
_undo
(
info
[
0
][
"id"
],
[
oid1
,
oid2
])
data
,
revid1
=
self
.
_storage
.
load
(
oid1
,
''
)
data
,
revid1
=
load_current
(
self
.
_storage
,
oid1
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
31
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
31
))
data
,
revid2
=
self
.
_storage
.
load
(
oid2
,
''
)
data
,
revid2
=
load_current
(
self
.
_storage
,
oid2
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
51
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
51
))
# Like the above, but this time, the second transaction contains only
# Like the above, but this time, the second transaction contains only
# one object.
# one object.
...
@@ -362,9 +361,9 @@ class TransactionalUndoStorage:
...
@@ -362,9 +361,9 @@ class TransactionalUndoStorage:
eq
(
len
(
oids
),
1
)
eq
(
len
(
oids
),
1
)
self
.
assertTrue
(
oid1
in
oids
)
self
.
assertTrue
(
oid1
in
oids
)
self
.
assertTrue
(
not
oid2
in
oids
)
self
.
assertTrue
(
not
oid2
in
oids
)
data
,
revid1
=
self
.
_storage
.
load
(
oid1
,
''
)
data
,
revid1
=
load_current
(
self
.
_storage
,
oid1
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
33
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
33
))
data
,
revid2
=
self
.
_storage
.
load
(
oid2
,
''
)
data
,
revid2
=
load_current
(
self
.
_storage
,
oid2
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
54
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
54
))
self
.
_iterate
()
self
.
_iterate
()
...
@@ -403,9 +402,9 @@ class TransactionalUndoStorage:
...
@@ -403,9 +402,9 @@ class TransactionalUndoStorage:
revid2
=
self
.
_transaction_newserial
(
oid2
)
revid2
=
self
.
_transaction_newserial
(
oid2
)
eq
(
revid1
,
revid2
)
eq
(
revid1
,
revid2
)
# Make sure the objects have the expected values
# Make sure the objects have the expected values
data
,
revid_11
=
self
.
_storage
.
load
(
oid1
,
''
)
data
,
revid_11
=
load_current
(
self
.
_storage
,
oid1
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
81
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
81
))
data
,
revid_22
=
self
.
_storage
.
load
(
oid2
,
''
)
data
,
revid_22
=
load_current
(
self
.
_storage
,
oid2
)
eq
(
zodb_unpickle
(
data
),
MinPO
(
91
))
eq
(
zodb_unpickle
(
data
),
MinPO
(
91
))
eq
(
revid_11
,
revid1
)
eq
(
revid_11
,
revid1
)
eq
(
revid_22
,
revid2
)
eq
(
revid_22
,
revid2
)
...
@@ -461,7 +460,7 @@ class TransactionalUndoStorage:
...
@@ -461,7 +460,7 @@ class TransactionalUndoStorage:
self
.
_storage
.
tpc_finish
(
t
)
self
.
_storage
.
tpc_finish
(
t
)
self
.
assertEqual
(
len
(
oids
),
1
)
self
.
assertEqual
(
len
(
oids
),
1
)
self
.
assertEqual
(
oids
[
0
],
oid
)
self
.
assertEqual
(
oids
[
0
],
oid
)
data
,
revid
=
self
.
_storage
.
load
(
oid
,
''
)
data
,
revid
=
load_current
(
self
.
_storage
,
oid
)
# The object must now be at the second state
# The object must now be at the second state
self
.
assertEqual
(
zodb_unpickle
(
data
),
MinPO
(
52
))
self
.
assertEqual
(
zodb_unpickle
(
data
),
MinPO
(
52
))
self
.
_iterate
()
self
.
_iterate
()
...
...
src/ZODB/tests/testDemoStorage.py
View file @
965bf84a
...
@@ -37,6 +37,9 @@ import ZODB.DemoStorage
...
@@ -37,6 +37,9 @@ import ZODB.DemoStorage
import
ZODB.tests.hexstorage
import
ZODB.tests.hexstorage
import
ZODB.tests.util
import
ZODB.tests.util
import
ZODB.utils
import
ZODB.utils
from
ZODB.utils
import
load_current
from
zope.testing
import
renormalizing
from
zope.testing
import
renormalizing
...
@@ -67,8 +70,8 @@ class DemoStorageTests(
...
@@ -67,8 +70,8 @@ class DemoStorageTests(
# Minimal test of loadEX w/o version -- ironically
# Minimal test of loadEX w/o version -- ironically
db
=
DB
(
self
.
_storage
)
# creates object 0. :)
db
=
DB
(
self
.
_storage
)
# creates object 0. :)
s2
=
ZODB
.
DemoStorage
.
DemoStorage
(
base
=
self
.
_storage
)
s2
=
ZODB
.
DemoStorage
.
DemoStorage
(
base
=
self
.
_storage
)
self
.
assertEqual
(
s2
.
load
(
ZODB
.
utils
.
z64
,
''
),
self
.
assertEqual
(
load_current
(
s2
,
ZODB
.
utils
.
z64
),
self
.
_storage
.
load
(
ZODB
.
utils
.
z64
,
''
))
load_current
(
self
.
_storage
,
ZODB
.
utils
.
z64
))
def
checkLengthAndBool
(
self
):
def
checkLengthAndBool
(
self
):
self
.
assertEqual
(
len
(
self
.
_storage
),
0
)
self
.
assertEqual
(
len
(
self
.
_storage
),
0
)
...
@@ -238,7 +241,7 @@ def load_before_base_storage_current():
...
@@ -238,7 +241,7 @@ def load_before_base_storage_current():
>>> transaction.commit()
>>> transaction.commit()
>>> oid = ZODB.utils.z64
>>> oid = ZODB.utils.z64
>>> base_current =
storage.base.load(
oid)
>>> base_current =
load_current(storage.base,
oid)
>>> tid = ZODB.utils.p64(ZODB.utils.u64(base_current[1]) + 1)
>>> tid = ZODB.utils.p64(ZODB.utils.u64(base_current[1]) + 1)
>>> base_record = storage.base.loadBefore(oid, tid)
>>> base_record = storage.base.loadBefore(oid, tid)
>>> base_record[-1] is None
>>> base_record[-1] is None
...
@@ -253,7 +256,7 @@ def load_before_base_storage_current():
...
@@ -253,7 +256,7 @@ def load_before_base_storage_current():
>>> t[:2] == base_record[:2]
>>> t[:2] == base_record[:2]
True
True
>>> t[-1] ==
storage.changes.load(
oid)[1]
>>> t[-1] ==
load_current(storage.changes,
oid)[1]
True
True
>>> conn.close()
>>> conn.close()
...
...
src/ZODB/tests/testFileStorage.py
View file @
965bf84a
...
@@ -26,7 +26,7 @@ import zope.testing.setupstack
...
@@ -26,7 +26,7 @@ import zope.testing.setupstack
from
ZODB
import
POSException
from
ZODB
import
POSException
from
ZODB
import
DB
from
ZODB
import
DB
from
ZODB.fsIndex
import
fsIndex
from
ZODB.fsIndex
import
fsIndex
from
ZODB.utils
import
U64
,
p64
,
z64
from
ZODB.utils
import
U64
,
p64
,
z64
,
load_current
from
ZODB.tests
import
StorageTestBase
,
BasicStorage
,
TransactionalUndoStorage
from
ZODB.tests
import
StorageTestBase
,
BasicStorage
,
TransactionalUndoStorage
from
ZODB.tests
import
PackableStorage
,
Synchronization
,
ConflictResolution
from
ZODB.tests
import
PackableStorage
,
Synchronization
,
ConflictResolution
...
@@ -279,7 +279,7 @@ class FileStorageTests(
...
@@ -279,7 +279,7 @@ class FileStorageTests(
oid
,
tid
,
data
,
next_oid
=
self
.
_storage
.
record_iternext
(
key
)
oid
,
tid
,
data
,
next_oid
=
self
.
_storage
.
record_iternext
(
key
)
self
.
assertEqual
(
oid
,
(
b'
\
000
'
*
7
)
+
x
)
self
.
assertEqual
(
oid
,
(
b'
\
000
'
*
7
)
+
x
)
key
=
next_oid
key
=
next_oid
expected_data
,
expected_tid
=
self
.
_storage
.
load
(
oid
,
''
)
expected_data
,
expected_tid
=
load_current
(
self
.
_storage
,
oid
)
self
.
assertEqual
(
expected_data
,
data
)
self
.
assertEqual
(
expected_data
,
data
)
self
.
assertEqual
(
expected_tid
,
tid
)
self
.
assertEqual
(
expected_tid
,
tid
)
if
x
==
b'
\
002
'
:
if
x
==
b'
\
002
'
:
...
@@ -296,13 +296,14 @@ class FileStorageTests(
...
@@ -296,13 +296,14 @@ class FileStorageTests(
storage
.
tpc_vote
(
t
)
storage
.
tpc_vote
(
t
)
# Read operations are done with separate 'file' objects with their
# Read operations are done with separate 'file' objects with their
# own buffers: here, the buffer also includes voted data.
# own buffers: here, the buffer also includes voted data.
storage
.
load
(
z64
)
load_current
(
storage
,
z64
)
# This must invalidate all read buffers.
# This must invalidate all read buffers.
storage
.
tpc_abort
(
t
)
storage
.
tpc_abort
(
t
)
self
.
_dostore
(
z64
,
r0
,
b'bar'
,
1
)
self
.
_dostore
(
z64
,
r0
,
b'bar'
,
1
)
# In the case that read buffers were not invalidated, return value
# In the case that read buffers were not invalidated, return value
# is based on what was cached during the first load.
# is based on what was cached during the first load.
self
.
assertEqual
(
storage
.
load
(
z64
)[
0
],
b'foo'
if
fail
else
b'bar'
)
self
.
assertEqual
(
load_current
(
storage
,
z64
)[
0
],
b'foo'
if
fail
else
b'bar'
)
# We want to be sure that the above test detects any regression
# We want to be sure that the above test detects any regression
# in the code it checks, because any bug here is like a time bomb: not
# in the code it checks, because any bug here is like a time bomb: not
...
@@ -642,7 +643,7 @@ def deal_with_finish_failures():
...
@@ -642,7 +643,7 @@ def deal_with_finish_failures():
>>> handler.uninstall()
>>> handler.uninstall()
>>>
fs.load(b'\0'*8, b''
) # doctest: +ELLIPSIS
>>>
load_current(fs, b'\0'*8
) # doctest: +ELLIPSIS
Traceback (most recent call last):
Traceback (most recent call last):
...
...
ValueError: ...
ValueError: ...
...
...
src/ZODB/tests/testblob.py
View file @
965bf84a
...
@@ -568,14 +568,16 @@ def loadblob_tmpstore():
...
@@ -568,14 +568,16 @@ def loadblob_tmpstore():
def
is_blob_record
():
def
is_blob_record
():
r"""
r"""
>>> from ZODB.utils import load_current
>>> bs = create_storage()
>>> bs = create_storage()
>>> db = DB(bs)
>>> db = DB(bs)
>>> conn = db.open()
>>> conn = db.open()
>>> conn.root()['blob'] = ZODB.blob.Blob()
>>> conn.root()['blob'] = ZODB.blob.Blob()
>>> transaction.commit()
>>> transaction.commit()
>>> ZODB.blob.is_blob_record(
bs.load(ZODB.utils.p64(0), ''
)[0])
>>> ZODB.blob.is_blob_record(
load_current(bs, ZODB.utils.p64(0)
)[0])
False
False
>>> ZODB.blob.is_blob_record(
bs.load(ZODB.utils.p64(1), ''
)[0])
>>> ZODB.blob.is_blob_record(
load_current(bs, ZODB.utils.p64(1)
)[0])
True
True
An invalid pickle yields a false value:
An invalid pickle yields a false value:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment