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
8e70c116
Commit
8e70c116
authored
May 02, 2002
by
Toby Dickenson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rearranged checkLRU to use more than one transaction
parent
b96b07b0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
18 deletions
+30
-18
trunk/src/ZODB/tests/testCache.py
trunk/src/ZODB/tests/testCache.py
+30
-18
No files found.
trunk/src/ZODB/tests/testCache.py
View file @
8e70c116
...
@@ -123,30 +123,42 @@ class LRUCacheTests(CacheTestBase):
...
@@ -123,30 +123,42 @@ class LRUCacheTests(CacheTestBase):
def
checkLRU
(
self
):
def
checkLRU
(
self
):
# verify the LRU behavior of the cache
# verify the LRU behavior of the cache
CACHE_SIZE
=
5
dataset_size
=
5
CACHE_SIZE
=
dataset_size
*
2
+
1
# a cache big enough to hold the objects added in two
# transactions, plus the root object
self
.
db
.
setCacheSize
(
CACHE_SIZE
)
self
.
db
.
setCacheSize
(
CACHE_SIZE
)
c
=
self
.
db
.
open
()
c
=
self
.
db
.
open
()
r
=
c
.
root
()
r
=
c
.
root
()
l
=
[
None
]
*
10
l
=
{}
for
i
in
range
(
10
):
l
[
i
]
=
r
[
i
]
=
MinPO
(
i
)
# the root is the only thing in the cache, because all the
# the root is the only thing in the cache, because all the
# other objects are new
# other objects are new
self
.
assertEqual
(
len
(
c
.
_cache
),
1
)
self
.
assertEqual
(
len
(
c
.
_cache
),
1
)
get_transaction
().
commit
()
# run several transactions
# commit() will register the objects, placing them in the cache.
for
t
in
range
(
5
):
# at the end of commit, the cache will be reduced down to CACHE_SIZE
for
i
in
range
(
dataset_size
):
# items
l
[(
t
,
i
)]
=
r
[
i
]
=
MinPO
(
i
)
self
.
assertEqual
(
c
.
_cache
.
ringlen
(),
CACHE_SIZE
)
get_transaction
().
commit
()
x
=
c
.
_cache
.
get
(
p64
(
0
),
None
)
# commit() will register the objects, placing them in the cache.
self
.
assertEqual
(
x
.
_p_changed
,
None
)
# the root is ghosted
# at the end of commit, the cache will be reduced down to CACHE_SIZE
for
i
in
range
(
len
(
l
)):
# items
if
i
<
CACHE_SIZE
:
if
len
(
l
)
>
CACHE_SIZE
:
# Changes are flushed but objects not ghostified
self
.
assertEqual
(
c
.
_cache
.
ringlen
(),
CACHE_SIZE
)
self
.
assertEqual
(
l
[
i
].
_p_changed
,
0
)
for
i
in
range
(
dataset_size
):
else
:
# Check objects added in the first two transactions.
# Objects are ghostified and evicted from the cache
# They must all be ghostified.
self
.
assertEqual
(
l
[
i
].
_p_changed
,
None
)
self
.
assertEqual
(
l
[(
0
,
i
)].
_p_changed
,
None
)
self
.
assertEqual
(
l
[(
1
,
i
)].
_p_changed
,
None
)
# Check objects added in the last two transactions.
# They must all still exist in memory, but have
# had their changes flushed
self
.
assertEqual
(
l
[(
3
,
i
)].
_p_changed
,
0
)
self
.
assertEqual
(
l
[(
4
,
i
)].
_p_changed
,
0
)
# Of the objects added in the middle transaction, most
# will have been ghostified. There is one cache slot
# that may be occupied by either one of those objects or
# the root, depending on precise order of access. We do
# not bother to check this
def
checkSize
(
self
):
def
checkSize
(
self
):
self
.
assertEqual
(
self
.
db
.
cacheSize
(),
0
)
self
.
assertEqual
(
self
.
db
.
cacheSize
(),
0
)
...
...
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