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
nexedi
ZODB
Commits
c0b7812b
Commit
c0b7812b
authored
Jun 13, 2013
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bend over backward to avoid ResourceWarnings.
parent
25ebff76
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
33 deletions
+48
-33
src/ZODB/tests/blob_transaction.txt
src/ZODB/tests/blob_transaction.txt
+48
-33
No files found.
src/ZODB/tests/blob_transaction.txt
View file @
c0b7812b
...
...
@@ -27,7 +27,8 @@ Aborting a blob add leaves the blob unchanged:
>>> blob1._p_oid
>>> blob1._p_jar
>>> with blob1.open() as fp: fp.read()
>>> with blob1.open() as fp:
... fp.read()
'this is blob 1'
It doesn't clear the file because there is no previously committed version:
...
...
@@ -51,7 +52,8 @@ state:
>>> with blob1.open('w') as file:
... _ = file.write(b'this is new blob 1')
>>> with blob1.open() as fp: fp.read()
>>> with blob1.open() as fp:
... fp.read()
'this is new blob 1'
>>> fname = blob1._p_blob_uncommitted
>>> os.path.exists(fname)
...
...
@@ -62,7 +64,8 @@ state:
False
>>> blob1._p_blob_uncommitted
>>> with blob1.open() as fp: fp.read()
>>> with blob1.open() as fp:
... fp.read()
'this is blob 1'
Opening a blob gives us a filehandle. Getting data out of the
...
...
@@ -103,12 +106,12 @@ when we start)::
>>> bool(blob1a._p_changed)
False
>>> with blob1a.open('r') as fp: fp.read()
>>> with blob1a.open('r') as fp:
... fp.read()
'this is blob 1'
>>> blob1afh3 = blob1a.open('a')
>>> bool(blob1a._p_changed)
True
>>> _ = blob1afh3.write(b'woot!')
>>> with blob1a.open('a') as blob1afh3:
... assert(bool(blob1a._p_changed))
... _ = blob1afh3.write(b'woot!')
>>> blob1afh3.close()
We can open more than one blob object during the course of a single
...
...
@@ -124,11 +127,14 @@ Since we committed the current transaction above, the aggregate
changes we've made to blob, blob1a (these refer to the same object) and
blob2 (a different object) should be evident::
>>> with blob1.open('r') as fp: fp.read()
>>> with blob1.open('r') as fp:
... fp.read()
'this is blob 1woot!'
>>> with blob1a.open('r') as fp: fp.read()
>>> with blob1a.open('r') as fp:
... fp.read()
'this is blob 1woot!'
>>> with blob2.open('r') as fp: fp.read()
>>> with blob2.open('r') as fp:
... fp.read()
'this is blob 3'
We shouldn't be able to persist a blob filehandle at commit time
...
...
@@ -136,8 +142,9 @@ We shouldn't be able to persist a blob filehandle at commit time
pickled appears to be particulary unhelpful for casual users at the
moment)::
>>> root1['wontwork'] = blob1.open('r')
>>> transaction.commit()
>>> with blob1.open('r') as f:
... root1['wontwork'] = f
... transaction.commit()
Traceback (most recent call last):
...
TypeError: ...
...
...
@@ -160,7 +167,8 @@ connections should result in a write conflict error::
>>> with blob1c4.open('a') as blob1c4fh1:
... _ = blob1c4fh1.write(b'this is from connection 4')
>>> tm1.commit()
>>> with root3['blob1'].open('r') as fp: fp.read()
>>> with root3['blob1'].open('r') as fp:
... fp.read()
'this is blob 1woot!this is from connection 3'
>>> tm2.commit()
Traceback (most recent call last):
...
...
@@ -170,10 +178,12 @@ connections should result in a write conflict error::
After the conflict, the winning transaction's result is visible on both
connections::
>>> with root3['blob1'].open('r') as fp: fp.read()
>>> with root3['blob1'].open('r') as fp:
... fp.read()
'this is blob 1woot!this is from connection 3'
>>> tm2.abort()
>>> with root4['blob1'].open('r') as fp: fp.read()
>>> with root4['blob1'].open('r') as fp:
... fp.read()
'this is blob 1woot!this is from connection 3'
You can't commit a transaction while blob files are open:
...
...
@@ -205,21 +215,22 @@ We do support optimistic savepoints:
>>> connection5 = database.open()
>>> root5 = connection5.root()
>>> blob = ZODB.blob.Blob()
>>> blob_fh = blob.open("w")
>>> _ = blob_fh.write(b"I'm a happy blob.")
>>> blob_fh.close()
>>> with blob.open("w") as blob_fh:
... _ = blob_fh.write(b"I'm a happy blob.")
>>> root5['blob'] = blob
>>> transaction.commit()
>>> with root5['blob'].open("r") as fp: fp.read()
>>> with root5['blob'].open("r") as fp:
... fp.read()
"I'm a happy blob."
>>>
blob_fh = root5['blob'].open("a")
>>>
_ = blob_fh.write(b" And I'm singing.")
>>>
blob_fh.close()
>>> with root5['blob'].open("r") as fp:
fp.read()
>>>
with root5['blob'].open("a") as blob_fh:
...
_ = blob_fh.write(b" And I'm singing.")
>>>
with root5['blob'].open("r") as fp:
...
fp.read()
"I'm a happy blob. And I'm singing."
>>> savepoint = transaction.savepoint(optimistic=True)
>>> with root5['blob'].open("r") as fp: fp.read()
>>> with root5['blob'].open("r") as fp:
... fp.read()
"I'm a happy blob. And I'm singing."
Savepoints store the blobs in temporary directories in the temporary
...
...
@@ -241,7 +252,8 @@ We support non-optimistic savepoints too:
>>> with root5['blob'].open("a") as file:
... _ = file.write(b" And I'm dancing.")
>>> with root5['blob'].open("r") as fp: fp.read()
>>> with root5['blob'].open("r") as fp:
... fp.read()
"I'm a happy blob. And I'm singing. And I'm dancing."
>>> savepoint = transaction.savepoint()
...
...
@@ -255,7 +267,8 @@ Again, the savepoint creates a new savepoints directory:
... _ = file.write(b" And the weather is beautiful.")
>>> savepoint.rollback()
>>> with root5['blob'].open("r") as fp: fp.read()
>>> with root5['blob'].open("r") as fp:
... fp.read()
"I'm a happy blob. And I'm singing. And I'm dancing."
>>> transaction.abort()
...
...
@@ -275,12 +288,12 @@ file that can be opened.
>>> connection6 = database.open()
>>> root6 = connection6.root()
>>> blob = ZODB.blob.Blob()
>>> blob_fh = blob.open("w")
>>> _ = blob_fh.write(b"I'm a happy blob.")
>>> blob_fh.close()
>>> with blob.open("w") as blob_fh:
... _ = blob_fh.write(b"I'm a happy blob.")
>>> root6['blob'] = blob
>>> transaction.commit()
>>> with open(blob.committed()) as fp: fp.read()
>>> with open(blob.committed()) as fp:
... fp.read()
"I'm a happy blob."
We can also read committed data by calling open with a 'c' flag:
...
...
@@ -344,7 +357,8 @@ uncommitted changes:
BlobError: Uncommitted changes
>>> transaction.commit()
>>> with open(blob.committed()) as fp: fp.read()
>>> with open(blob.committed()) as fp:
... fp.read()
"I'm a happy blob."
You can't open a committed blob file for writing:
...
...
@@ -397,7 +411,8 @@ And we shouldn't be able to read the data that we saved:
Of course the old data should be unaffected:
>>> with open(blob_storage.loadBlob(blob._p_oid, oldserial)) as fp: fp.read()
>>> with open(blob_storage.loadBlob(blob._p_oid, oldserial)) as fp:
... fp.read()
"I'm a happy blob."
Similarly, the new object wasn't added to the storage:
...
...
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