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
5bda3218
Commit
5bda3218
authored
May 01, 2003
by
Jeremy Hylton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some level==2 tests of fsrecover.
parent
38ee97f4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
118 additions
and
0 deletions
+118
-0
src/ZODB/tests/testRecover.py
src/ZODB/tests/testRecover.py
+118
-0
No files found.
src/ZODB/tests/testRecover.py
0 → 100644
View file @
5bda3218
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests of the file storage recovery script."""
import
os
import
random
import
sys
import
tempfile
import
unittest
import
StringIO
import
ZODB
from
ZODB.FileStorage
import
FileStorage
from
ZODB.PersistentMapping
import
PersistentMapping
from
ZODB.fsrecover
import
recover
from
ZODB.tests.StorageTestBase
import
removefs
from
ZODB.fsdump
import
Dumper
class
RecoverTest
(
unittest
.
TestCase
):
level
=
2
path
=
None
def
setUp
(
self
):
self
.
path
=
tempfile
.
mktemp
(
suffix
=
".fs"
)
self
.
storage
=
FileStorage
(
self
.
path
)
self
.
populate
()
self
.
storage
.
close
()
self
.
dest
=
tempfile
.
mktemp
(
suffix
=
".fs"
)
self
.
recovered
=
None
def
tearDown
(
self
):
if
self
.
recovered
is
not
None
:
self
.
recovered
.
close
()
removefs
(
self
.
path
)
removefs
(
self
.
dest
)
def
populate
(
self
):
db
=
ZODB
.
DB
(
self
.
storage
)
cn
=
db
.
open
()
rt
=
cn
.
root
()
# create a whole bunch of objects,
# looks like a Data.fs > 1MB
for
i
in
range
(
100
):
d
=
rt
[
i
]
=
PersistentMapping
()
get_transaction
().
commit
()
for
j
in
range
(
100
):
d
[
j
]
=
"a"
*
j
get_transaction
().
commit
()
def
damage
(
self
,
num
,
size
):
# Drop size null bytes into num random spots.
for
i
in
range
(
num
):
offset
=
random
.
randint
(
0
,
self
.
storage
.
_pos
-
size
)
f
=
open
(
self
.
path
,
"a+b"
)
f
.
seek
(
offset
)
f
.
write
(
"
\
0
"
*
size
)
f
.
close
()
ITERATIONS
=
10
def
recover
(
self
,
source
,
dest
):
orig
=
sys
.
stdout
try
:
sys
.
stdout
=
StringIO
.
StringIO
()
try
:
recover
(
self
.
path
,
self
.
dest
,
verbose
=
0
,
partial
=
1
,
force
=
0
,
pack
=
1
)
except
SystemExit
:
raise
RuntimeError
,
"recover tried to exit"
finally
:
sys
.
stdout
=
orig
def
testOneBlock
(
self
):
for
i
in
range
(
self
.
ITERATIONS
):
self
.
damage
(
1
,
1024
)
self
.
recover
(
self
.
path
,
self
.
dest
)
self
.
recovered
=
FileStorage
(
self
.
dest
)
self
.
recovered
.
close
()
os
.
remove
(
self
.
path
)
os
.
rename
(
self
.
dest
,
self
.
path
)
def
testFourBlocks
(
self
):
for
i
in
range
(
self
.
ITERATIONS
):
self
.
damage
(
4
,
512
)
self
.
recover
(
self
.
path
,
self
.
dest
)
self
.
recovered
=
FileStorage
(
self
.
dest
)
self
.
recovered
.
close
()
os
.
remove
(
self
.
path
)
os
.
rename
(
self
.
dest
,
self
.
path
)
def
testBigBlock
(
self
):
for
i
in
range
(
self
.
ITERATIONS
):
self
.
damage
(
1
,
32
*
1024
)
self
.
recover
(
self
.
path
,
self
.
dest
)
self
.
recovered
=
FileStorage
(
self
.
dest
)
self
.
recovered
.
close
()
os
.
remove
(
self
.
path
)
os
.
rename
(
self
.
dest
,
self
.
path
)
def
test_suite
():
return
unittest
.
makeSuite
(
RecoverTest
)
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