Commit a1979325 authored by Vincent Pelletier's avatar Vincent Pelletier

Don't refuse undoing object creation, except for root object.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1862 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 29a13a07
...@@ -808,8 +808,12 @@ class Application(object): ...@@ -808,8 +808,12 @@ class Application(object):
try: try:
result = self.loadBefore(oid, transaction_id) result = self.loadBefore(oid, transaction_id)
except NEOStorageNotFoundError: except NEOStorageNotFoundError:
# no previous revision, can't undo (as in filestorage) if oid == '\x00' * 8:
raise UndoError("no previous record", oid) # Refuse undoing root object creation.
raise UndoError("no previous record", oid)
else:
# Undo object creation
result = ('', None, transaction_id)
data, start, end = result data, start, end = result
# end must be TID we are going to undone otherwise it means # end must be TID we are going to undone otherwise it means
# a later transaction modify the object # a later transaction modify the object
......
...@@ -713,8 +713,7 @@ class ClientApplicationTests(NeoTestBase): ...@@ -713,8 +713,7 @@ class ClientApplicationTests(NeoTestBase):
self.assertEquals(app.local_var.txn, old_txn) self.assertEquals(app.local_var.txn, old_txn)
def test_undo2(self): def test_undo2(self):
# Four tests here : # Three tests here :
# undo txn1 where obj1 was created -> fail
# undo txn2 where obj2 was modified in tid3 -> fail # undo txn2 where obj2 was modified in tid3 -> fail
# undo txn3 where there is a conflict on obj2 # undo txn3 where there is a conflict on obj2
# undo txn3 where obj2 was altered from tid2 -> ok # undo txn3 where obj2 was altered from tid2 -> ok
...@@ -722,13 +721,8 @@ class ClientApplicationTests(NeoTestBase): ...@@ -722,13 +721,8 @@ class ClientApplicationTests(NeoTestBase):
app = self.getApp() app = self.getApp()
app.num_partitions = 2 app.num_partitions = 2
oid1, oid2 = self.makeOID(1), self.makeOID(2) oid1, oid2 = self.makeOID(1), self.makeOID(2)
tid1, tid2 = self.makeTID(1), self.makeTID(2) tid2 = self.makeTID(2)
tid3, tid4 = self.makeTID(3), self.makeTID(4) tid3, tid4 = self.makeTID(3), self.makeTID(4)
# commit version 1 of object 1
txn1 = self.beginTransaction(app, tid=tid1)
self.storeObject(app, oid=oid1, data='O1V1')
self.voteTransaction(app)
self.askFinishTransaction(app)
# commit version 1 of object 2 # commit version 1 of object 2
txn2 = self.beginTransaction(app, tid=tid2) txn2 = self.beginTransaction(app, tid=tid2)
self.storeObject(app, oid=oid2, data='O1V2') self.storeObject(app, oid=oid2, data='O1V2')
...@@ -739,10 +733,6 @@ class ClientApplicationTests(NeoTestBase): ...@@ -739,10 +733,6 @@ class ClientApplicationTests(NeoTestBase):
self.storeObject(app, oid=oid2, data='O2V2') self.storeObject(app, oid=oid2, data='O2V2')
self.voteTransaction(app) self.voteTransaction(app)
self.askFinishTransaction(app) self.askFinishTransaction(app)
# undo 1 -> no previous revision
u1p1 = Packets.AnswerTransactionInformation(tid1, '', '', '',
False, (oid1, ))
u1p2 = Errors.OidNotFound('oid not found')
# undo 2 -> not end tid # undo 2 -> not end tid
u2p1 = Packets.AnswerTransactionInformation(tid2, '', '', '', u2p1 = Packets.AnswerTransactionInformation(tid2, '', '', '',
False, (oid2, )) False, (oid2, ))
...@@ -758,14 +748,13 @@ class ClientApplicationTests(NeoTestBase): ...@@ -758,14 +748,13 @@ class ClientApplicationTests(NeoTestBase):
u4p2 = Packets.AnswerObject(oid2, tid3, tid3, 0, makeChecksum('O2V2'), 'O2V2') u4p2 = Packets.AnswerObject(oid2, tid3, tid3, 0, makeChecksum('O2V2'), 'O2V2')
u4p3 = Packets.AnswerStoreObject(conflicting=0, oid=oid2, serial=tid2) u4p3 = Packets.AnswerStoreObject(conflicting=0, oid=oid2, serial=tid2)
# test logic # test logic
packets = (u1p1, u1p2, u2p1, u2p2, u3p1, u3p2, u3p3, u4p1, u4p2, u4p3) packets = (u2p1, u2p2, u3p1, u3p2, u3p3, u4p1, u4p2, u4p3)
for i, p in enumerate(packets): for i, p in enumerate(packets):
p.setId(p) p.setId(p)
storage_address = ('127.0.0.1', 10010) storage_address = ('127.0.0.1', 10010)
conn = Mock({ conn = Mock({
'getNextId': 1, 'getNextId': 1,
'fakeReceived': ReturnValues( 'fakeReceived': ReturnValues(
u1p1, u1p2,
u2p1, u2p2, u2p1, u2p2,
u4p1, u4p2, u4p1, u4p2,
u3p1, u3p2, u3p1, u3p2,
...@@ -788,8 +777,6 @@ class ClientApplicationTests(NeoTestBase): ...@@ -788,8 +777,6 @@ class ClientApplicationTests(NeoTestBase):
app.nm.createStorage(address=storage_address) app.nm.createStorage(address=storage_address)
txn4 = self.beginTransaction(app, tid=tid4) txn4 = self.beginTransaction(app, tid=tid4)
# all start here # all start here
self.assertRaises(UndoError, app.undo, tid1, txn4,
tryToResolveConflict)
self.assertRaises(UndoError, app.undo, tid2, txn4, self.assertRaises(UndoError, app.undo, tid2, txn4,
tryToResolveConflict) tryToResolveConflict)
app.local_var.queue.put((conn, u4p3)) app.local_var.queue.put((conn, u4p3))
......
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