Commit c60df608 authored by Barry Warsaw's avatar Barry Warsaw

Added two tests to specifically (and only) focus in on the one

remaining problem with full Berkeley storage's transactionalUndo().
Specifically:

    tid 1: create object 1
    tid 2: modify object 1
    tid 3: undo tid 2
    ----------------------
    tid 4: undo tid 1 (1st alternative universe)
    ----------------------
    tid 4: undo tid 3 (2nd alternative universe)

The new tests are checkUndoCreationBranch1() and
checkUndoCreationBranch2(), corresponding to alternative universes 1
and 2, respectively.  Full storage currently fails a.u. #2.
FileStorage passes.
parent f8d1d748
...@@ -65,6 +65,61 @@ class TransactionalUndoStorage: ...@@ -65,6 +65,61 @@ class TransactionalUndoStorage:
data, revid = self._storage.load(oid, '') data, revid = self._storage.load(oid, '')
assert pickle.loads(data) == 23 assert pickle.loads(data) == 23
def checkUndoCreationBranch1(self):
oid = self._storage.new_oid()
revid = self._dostore(oid, data=11)
revid = self._dostore(oid, revid=revid, data=12)
# Undo the last transaction
info = self._storage.undoInfo()
tid = info[0]['id']
self._storage.tpc_begin(self._transaction)
oids = self._storage.transactionalUndo(tid, self._transaction)
self._storage.tpc_vote(self._transaction)
self._storage.tpc_finish(self._transaction)
assert len(oids) == 1
assert oids[0] == oid
data, revid = self._storage.load(oid, '')
assert pickle.loads(data) == 11
# Now from here, we can either redo the last undo, or undo the object
# creation. Let's undo the object creation.
info = self._storage.undoInfo()
tid = info[2]['id']
self._storage.tpc_begin(self._transaction)
oids = self._storage.transactionalUndo(tid, self._transaction)
self._storage.tpc_vote(self._transaction)
self._storage.tpc_finish(self._transaction)
assert len(oids) == 1
assert oids[0] == oid
self.assertRaises(KeyError, self._storage.load, oid, '')
def checkUndoCreationBranch2(self):
oid = self._storage.new_oid()
revid = self._dostore(oid, data=11)
revid = self._dostore(oid, revid=revid, data=12)
# Undo the last transaction
info = self._storage.undoInfo()
tid = info[0]['id']
self._storage.tpc_begin(self._transaction)
oids = self._storage.transactionalUndo(tid, self._transaction)
self._storage.tpc_vote(self._transaction)
self._storage.tpc_finish(self._transaction)
assert len(oids) == 1
assert oids[0] == oid
data, revid = self._storage.load(oid, '')
assert pickle.loads(data) == 11
# Now from here, we can either redo the last undo, or undo the object
# creation. Let's redo the last undo
info = self._storage.undoInfo()
tid = info[0]['id']
self._storage.tpc_begin(self._transaction)
oids = self._storage.transactionalUndo(tid, self._transaction)
self._storage.tpc_vote(self._transaction)
self._storage.tpc_finish(self._transaction)
assert len(oids) == 1
assert oids[0] == oid
data, revid = self._storage.load(oid, '')
assert pickle.loads(data) == 12
def checkTwoObjectUndo(self): def checkTwoObjectUndo(self):
# Convenience # Convenience
p31, p32, p51, p52 = map(pickle.dumps, (31, 32, 51, 52)) p31, p32, p51, p52 = map(pickle.dumps, (31, 32, 51, 52))
...@@ -160,7 +215,6 @@ class TransactionalUndoStorage: ...@@ -160,7 +215,6 @@ class TransactionalUndoStorage:
assert pickle.loads(data) == 30 assert pickle.loads(data) == 30
data, revid2 = self._storage.load(oid2, '') data, revid2 = self._storage.load(oid2, '')
assert pickle.loads(data) == 50 assert pickle.loads(data) == 50
# Now try to undo the one we just did to undo, whew # Now try to undo the one we just did to undo, whew
info = self._storage.undoInfo() info = self._storage.undoInfo()
tid = info[0]['id'] tid = info[0]['id']
...@@ -169,12 +223,12 @@ class TransactionalUndoStorage: ...@@ -169,12 +223,12 @@ class TransactionalUndoStorage:
self._storage.tpc_vote(self._transaction) self._storage.tpc_vote(self._transaction)
self._storage.tpc_finish(self._transaction) self._storage.tpc_finish(self._transaction)
assert len(oids) == 2 assert len(oids) == 2
assert oid1 in oids and oid2 in oids
data, revid1 = self._storage.load(oid1, '') data, revid1 = self._storage.load(oid1, '')
assert pickle.loads(data) == 32 assert pickle.loads(data) == 32
data, revid2 = self._storage.load(oid2, '') data, revid2 = self._storage.load(oid2, '')
assert pickle.loads(data) == 52 assert pickle.loads(data) == 52
def checkTwoObjectUndoAgain(self): def checkTwoObjectUndoAgain(self):
p32, p33, p52, p53 = map(pickle.dumps, (32, 33, 52, 53)) p32, p33, p52, p53 = map(pickle.dumps, (32, 33, 52, 53))
# Like the above, but the first revision of the objects are stored in # Like the above, but the first revision of the objects are stored in
......
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