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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
ZODB
Commits
e7c339a3
Commit
e7c339a3
authored
Apr 15, 2002
by
Jeremy Hylton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a bunch more tests of the LRU cache mechanism and of DB methods.
Also, reformat a test in testTransaction.
parent
c17caeff
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
227 additions
and
14 deletions
+227
-14
trunk/src/ZODB/tests/testCache.py
trunk/src/ZODB/tests/testCache.py
+183
-4
trunk/src/ZODB/tests/testDB.py
trunk/src/ZODB/tests/testDB.py
+41
-0
trunk/src/ZODB/tests/testTransaction.py
trunk/src/ZODB/tests/testTransaction.py
+3
-10
No files found.
trunk/src/ZODB/tests/testCache.py
View file @
e7c339a3
...
@@ -4,6 +4,7 @@ Each DB Connection has a separate PickleCache. The Cache serves two
...
@@ -4,6 +4,7 @@ Each DB Connection has a separate PickleCache. The Cache serves two
purposes. It acts like a memo for unpickling. It also keeps recent
purposes. It acts like a memo for unpickling. It also keeps recent
objects in memory under the assumption that they may be used again.
objects in memory under the assumption that they may be used again.
"""
"""
from
__future__
import
nested_scopes
import
random
import
random
import
time
import
time
...
@@ -12,17 +13,20 @@ import unittest
...
@@ -12,17 +13,20 @@ import unittest
import
ZODB
import
ZODB
import
ZODB.MappingStorage
import
ZODB.MappingStorage
from
ZODB.cPickleCache
import
PickleCache
from
ZODB.POSException
import
ConflictError
from
ZODB.PersistentMapping
import
PersistentMapping
from
ZODB.PersistentMapping
import
PersistentMapping
from
ZODB.tests.MinPO
import
MinPO
from
ZODB.tests.MinPO
import
MinPO
from
ZODB.utils
import
p64
from
ZODB.utils
import
p64
from
Persistence
import
Persistent
class
CacheTestBase
(
unittest
.
TestCase
):
class
CacheTestBase
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
store
=
ZODB
.
MappingStorage
.
MappingStorage
()
store
=
ZODB
.
MappingStorage
.
MappingStorage
()
self
.
db
=
ZODB
.
DB
(
store
,
self
.
db
=
ZODB
.
DB
(
store
,
cache_size
=
self
.
CACHE_SIZE
,
cache_size
=
self
.
CACHE_SIZE
)
cache_deactivate_after
=
self
.
CACHE_DEACTIVATE_AFTER
)
self
.
conns
=
[]
self
.
conns
=
[]
def
tearDown
(
self
):
def
tearDown
(
self
):
...
@@ -33,12 +37,12 @@ class CacheTestBase(unittest.TestCase):
...
@@ -33,12 +37,12 @@ class CacheTestBase(unittest.TestCase):
NUM_COLLECTIONS
=
10
NUM_COLLECTIONS
=
10
MAX_OBJECTS
=
100
MAX_OBJECTS
=
100
CACHE_SIZE
=
20
CACHE_SIZE
=
20
CACHE_DEACTIVATE_AFTER
=
5
def
noodle_new_connection
(
self
):
def
noodle_new_connection
(
self
):
"""Do some reads and writes on a new connection."""
"""Do some reads and writes on a new connection."""
c
=
self
.
db
.
open
()
c
=
self
.
db
.
open
()
self
.
conns
.
append
(
c
)
self
.
noodle_connection
(
c
)
self
.
noodle_connection
(
c
)
def
noodle_connection
(
self
,
c
):
def
noodle_connection
(
self
,
c
):
...
@@ -106,5 +110,180 @@ class DBMethods(CacheTestBase):
...
@@ -106,5 +110,180 @@ class DBMethods(CacheTestBase):
# XXX same for the get and invalidate methods
# XXX same for the get and invalidate methods
def
checkLRUitems
(
self
):
# get a cache
c
=
self
.
conns
[
0
].
_cache
c
.
lru_items
()
def
checkClassItems
(
self
):
c
=
self
.
conns
[
0
].
_cache
c
.
klass_items
()
class
LRUCacheTests
(
CacheTestBase
):
def
checkLRU
(
self
):
# verify the LRU behavior of the cache
CACHE_SIZE
=
5
self
.
db
.
setCacheSize
(
CACHE_SIZE
)
c
=
self
.
db
.
open
()
r
=
c
.
root
()
l
=
[
None
]
*
10
for
i
in
range
(
10
):
l
[
i
]
=
r
[
i
]
=
MinPO
(
i
)
# the root is the only thing in the cache, because all the
# other objects are new
self
.
assertEqual
(
len
(
c
.
_cache
),
1
)
get_transaction
().
commit
()
# commit() will register the objects, placing them in the cache.
# at the end of commit, the cache will be reduced down to CACHE_SIZE
# items
self
.
assertEqual
(
c
.
_cache
.
ringlen
(),
CACHE_SIZE
)
x
=
c
.
_cache
.
get
(
p64
(
0
),
None
)
self
.
assertEqual
(
x
.
_p_changed
,
None
)
# the root is ghosted
for
i
in
range
(
len
(
l
)):
if
i
<
CACHE_SIZE
:
self
.
assertEqual
(
l
[
i
].
_p_changed
,
None
)
else
:
self
.
assertEqual
(
l
[
i
].
_p_changed
,
0
)
def
checkSize
(
self
):
self
.
assertEqual
(
self
.
db
.
cacheSize
(),
0
)
self
.
assertEqual
(
self
.
db
.
cacheDetailSize
(),
[])
CACHE_SIZE
=
10
self
.
db
.
setCacheSize
(
CACHE_SIZE
)
CONNS
=
3
for
i
in
range
(
CONNS
):
self
.
noodle_new_connection
()
self
.
assertEquals
(
self
.
db
.
cacheSize
(),
CACHE_SIZE
*
CONNS
)
details
=
self
.
db
.
cacheDetailSize
()
self
.
assertEquals
(
len
(
details
),
CONNS
)
for
d
in
details
:
self
.
assertEquals
(
d
[
'ngsize'
],
CACHE_SIZE
)
# the root is also in the cache as ghost, because
# the connection holds a reference to it
self
.
assertEquals
(
d
[
'size'
],
CACHE_SIZE
+
1
)
def
checkDetail
(
self
):
CACHE_SIZE
=
10
self
.
db
.
setCacheSize
(
CACHE_SIZE
)
CONNS
=
3
for
i
in
range
(
CONNS
):
self
.
noodle_new_connection
()
for
klass
,
count
in
self
.
db
.
cacheDetail
():
if
klass
.
endswith
(
'PersistentMapping'
):
# one root per connection
self
.
assertEqual
(
count
,
CONNS
)
if
klass
.
endswith
(
'MinPO'
):
self
.
assertEqual
(
count
,
CONNS
*
CACHE_SIZE
)
for
details
in
self
.
db
.
cacheExtremeDetail
():
# one dict per object. keys:
if
details
[
'klass'
].
endswith
(
'PersistentMapping'
):
self
.
assertEqual
(
details
[
'state'
],
None
)
else
:
self
.
assert_
(
details
[
'klass'
].
endswith
(
'MinPO'
))
self
.
assertEqual
(
details
[
'state'
],
0
)
class
StubDataManager
:
def
setklassstate
(
self
,
object
):
pass
class
StubObject
(
Persistent
):
pass
class
CacheErrors
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
jar
=
StubDataManager
()
self
.
cache
=
PickleCache
(
self
.
jar
)
def
checkGetBogusKey
(
self
):
self
.
assertRaises
(
KeyError
,
self
.
cache
.
get
,
p64
(
0
))
try
:
self
.
cache
[
12
]
except
KeyError
:
pass
else
:
self
.
fail
(
"expected KeyError"
)
try
:
self
.
cache
[
12
]
=
12
except
TypeError
:
pass
else
:
self
.
fail
(
"expected TyepError"
)
try
:
del
self
.
cache
[
12
]
except
TypeError
:
pass
else
:
self
.
fail
(
"expected TypeError"
)
def
checkBogusObject
(
self
):
def
add
(
key
,
obj
):
self
.
cache
[
key
]
=
obj
key
=
p64
(
2
)
# value isn't persistent
self
.
assertRaises
(
TypeError
,
add
,
key
,
12
)
o
=
StubObject
()
# o._p_oid == None
self
.
assertRaises
(
ValueError
,
add
,
key
,
o
)
o
.
_p_oid
=
key
# o._p_jar == None
self
.
assertRaises
(
Exception
,
add
,
key
,
o
)
o
.
_p_jar
=
self
.
jar
self
.
cache
[
key
]
=
o
# make sure it can be added multiple times
self
.
cache
[
key
]
=
o
# same object, different keys
self
.
assertRaises
(
ValueError
,
add
,
p64
(
0
),
o
)
def
checkTwoCaches
(
self
):
jar2
=
StubDataManager
()
cache2
=
PickleCache
(
jar2
)
o
=
StubObject
()
key
=
o
.
_p_oid
=
p64
(
1
)
o
.
_p_jar
=
jar2
cache2
[
key
]
=
o
try
:
self
.
cache
[
key
]
=
o
except
ValueError
:
pass
else
:
self
.
fail
(
"expected ValueError because object already in cache"
)
def
checkReadOnlyAttrsWhenCached
(
self
):
o
=
StubObject
()
key
=
o
.
_p_oid
=
p64
(
1
)
o
.
_p_jar
=
self
.
jar
self
.
cache
[
key
]
=
o
try
:
o
.
_p_oid
=
p64
(
2
)
except
ValueError
:
pass
else
:
self
.
fail
(
"expect that you can't change oid of cached object"
)
try
:
del
o
.
_p_jar
except
ValueError
:
pass
else
:
self
.
fail
(
"expect that you can't delete jar of cached object"
)
def
test_suite
():
def
test_suite
():
return
unittest
.
makeSuite
(
DBMethods
,
'check'
)
s
=
unittest
.
makeSuite
(
DBMethods
,
'check'
)
s
.
addTest
(
unittest
.
makeSuite
(
LRUCacheTests
,
'check'
))
s
.
addTest
(
unittest
.
makeSuite
(
CacheErrors
,
'check'
))
return
s
trunk/src/ZODB/tests/testDB.py
0 → 100644
View file @
e7c339a3
import
time
import
unittest
import
ZODB
import
ZODB.MappingStorage
from
ZODB.tests.MinPO
import
MinPO
class
DBTests
(
unittest
.
TestCase
):
def
setUp
(
self
):
store
=
ZODB
.
MappingStorage
.
MappingStorage
()
self
.
db
=
ZODB
.
DB
(
store
)
def
tearDown
(
self
):
self
.
db
.
close
()
def
dowork
(
self
,
version
=
''
):
c
=
self
.
db
.
open
(
version
)
r
=
c
.
root
()
o
=
r
[
time
.
time
()]
=
MinPO
(
0
)
get_transaction
().
commit
()
for
i
in
range
(
25
):
o
.
value
=
MinPO
(
i
)
get_transaction
().
commit
()
o
=
o
.
value
print
r
.
items
()
c
.
close
()
# make sure the basic methods are callable
def
testSets
(
self
):
# test set methods that have non-trivial implementations
self
.
db
.
setCacheDeactivateAfter
(
12
)
# deprecated
self
.
db
.
setCacheSize
(
15
)
self
.
db
.
setVersionCacheDeactivateAfter
(
12
)
# deprecated
self
.
db
.
setVersionCacheSize
(
15
)
def
test_suite
():
return
unittest
.
makeSuite
(
DBTests
)
trunk/src/ZODB/tests/testTransaction.py
View file @
e7c339a3
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
"""
"""
Revision information:
Revision information:
$Id: testTransaction.py,v 1.
6 2002/04/12 18:22:45
jeremy Exp $
$Id: testTransaction.py,v 1.
7 2002/04/15 18:55:11
jeremy Exp $
"""
"""
"""
"""
...
@@ -571,22 +571,15 @@ class DataObject:
...
@@ -571,22 +571,15 @@ class DataObject:
self
.
_p_jar
=
None
self
.
_p_jar
=
None
def
modify
(
self
,
nojar
=
0
,
tracing
=
0
):
def
modify
(
self
,
nojar
=
0
,
tracing
=
0
):
if
not
nojar
:
if
not
nojar
:
if
self
.
nost
:
if
self
.
nost
:
self
.
_p_jar
=
NoSubTransactionJar
(
tracing
=
tracing
)
self
.
_p_jar
=
NoSubTransactionJar
(
tracing
=
tracing
)
else
:
else
:
self
.
_p_jar
=
SubTransactionJar
(
tracing
=
tracing
)
self
.
_p_jar
=
SubTransactionJar
(
tracing
=
tracing
)
else
:
pass
get_transaction
().
register
(
self
)
get_transaction
().
register
(
self
)
class
TestTxnException
(
Exception
):
pass
class
TestTxnException
(
Exception
):
pass
class
BasicJar
:
class
BasicJar
:
...
...
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