Commit ec536904 authored by Jim Fulton's avatar Jim Fulton

Added a test to check that abortVersion and commitVersion assign new

serials. Modified FileStorage and DemoStorage to pass this test.
parent 7a089e71
......@@ -79,7 +79,7 @@ method::
and call it to monitor the storage.
"""
__version__='$Revision: 1.12 $'[11:-2]
__version__='$Revision: 1.13 $'[11:-2]
import base64, time, string
from ZODB import POSException, BaseStorage, utils
......@@ -137,6 +137,7 @@ class DemoStorage(BaseStorage.BaseStorage):
v=self._vindex.get(src, None)
if not v: return
newserial = self._serial
tindex=self._tindex
oids=[]
for r in v.values():
......@@ -144,7 +145,7 @@ class DemoStorage(BaseStorage.BaseStorage):
if nv:
oids.append(oid)
oid, serial, pre, vdata, p = nv
tindex.append([oid, serial, r, None, p])
tindex.append([oid, newserial, r, None, p])
else:
# effectively, delete the thing
tindex.append([oid, None, r, None, None])
......@@ -168,6 +169,7 @@ class DemoStorage(BaseStorage.BaseStorage):
v=self._vindex.get(src, None)
if v is None: return
newserial = self._serial
tindex=self._tindex
oids=[]
for r in v.values():
......@@ -178,7 +180,7 @@ class DemoStorage(BaseStorage.BaseStorage):
new_vdata = dest, vdata[1]
else:
new_vdata = None
tindex.append([oid, serial, r, new_vdata, p])
tindex.append([oid, newserial, r, new_vdata, p])
return oids
......
......@@ -115,7 +115,7 @@
# may have a back pointer to a version record or to a non-version
# record.
#
__version__='$Revision: 1.95 $'[11:-2]
__version__='$Revision: 1.96 $'[11:-2]
import base64
from cPickle import Pickler, Unpickler, loads
......@@ -483,6 +483,7 @@ class FileStorage(BaseStorage.BaseStorage,
current_oids = {}
t = None
tstatus = ' '
newserial = self._serial
while srcpos:
self._file.seek(srcpos)
......@@ -494,7 +495,7 @@ class FileStorage(BaseStorage.BaseStorage,
# This is a current record!
self._tindex[oid] = here
oids.append(oid)
self._tfile.write(h[:16] + spos + middle)
self._tfile.write(oid + newserial + spos + middle)
if dest:
self._tvindex[dest] = here
self._tfile.write(pnv + sd + dest)
......
......@@ -206,6 +206,71 @@ class VersionStorage:
finally:
self._storage.tpc_abort(t)
def checkNewSerialOnAbortVersion(self):
eq = self.assertEqual
oid, version = self._setup_version()
data, vserial = self._storage.load(oid, version)
data, nserial = self._storage.load(oid, '')
# Now abort the version
t = Transaction()
self._storage.tpc_begin(t)
oids = self._storage.abortVersion(version, t)
self._storage.tpc_vote(t)
self._storage.tpc_finish(t)
# Now check the new serial
data, serial = self._storage.load(oid, version)
self.failUnless(serial != vserial and serial != nserial,
"New serial, %r, should be different from the old "
"version, %r, and non-version, %r, serials."
% (serial, vserial, nserial))
def checkNewSerialOnCommitVersion(self):
eq = self.assertEqual
oid, version = self._setup_version()
data, vserial = self._storage.load(oid, version)
data, nserial = self._storage.load(oid, '')
# Now commit the version
t = Transaction()
self._storage.tpc_begin(t)
oids = self._storage.commitVersion(version, '', t)
self._storage.tpc_vote(t)
self._storage.tpc_finish(t)
# Now check the new serial
data, serial = self._storage.load(oid, '')
self.failUnless(serial != vserial and serial != nserial,
"New serial, %r, should be different from the old "
"version, %r, and non-version, %r, serials."
% (serial, vserial, nserial))
def checkNewSerialOnCommitVersionToVersion(self):
eq = self.assertEqual
oid, version = self._setup_version()
data, vserial = self._storage.load(oid, version)
data, nserial = self._storage.load(oid, '')
# Now commit the version
t = Transaction()
self._storage.tpc_begin(t)
version2 = 'test version 2'
oids = self._storage.commitVersion(version, version2, t)
self._storage.tpc_vote(t)
self._storage.tpc_finish(t)
# Now check the new serial
data, serial = self._storage.load(oid, version2)
self.failUnless(serial != vserial and serial != nserial,
"New serial, %r, should be different from the old "
"version, %r, and non-version, %r, serials."
% (serial, vserial, nserial))
def checkModifyAfterAbortVersion(self):
eq = self.assertEqual
oid, version = self._setup_version()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment