Commit 9d13627c authored by Julien Muchembled's avatar Julien Muchembled

DemoStorage: add support for conflict resolution

parent ee5a462b
...@@ -313,4 +313,9 @@ class ConflictResolvingStorage(object): ...@@ -313,4 +313,9 @@ class ConflictResolvingStorage(object):
def registerDB(self, wrapper): def registerDB(self, wrapper):
self._crs_untransform_record_data = wrapper.untransform_record_data self._crs_untransform_record_data = wrapper.untransform_record_data
self._crs_transform_record_data = wrapper.transform_record_data self._crs_transform_record_data = wrapper.transform_record_data
super(ConflictResolvingStorage, self).registerDB(wrapper) try:
m = super(ConflictResolvingStorage, self).registerDB
except AttributeError:
pass
else:
m(wrapper)
...@@ -31,12 +31,13 @@ import ZODB.MappingStorage ...@@ -31,12 +31,13 @@ import ZODB.MappingStorage
import ZODB.POSException import ZODB.POSException
import ZODB.utils import ZODB.utils
import zope.interface import zope.interface
from .ConflictResolution import ConflictResolvingStorage, ResolvedSerial
@zope.interface.implementer( @zope.interface.implementer(
ZODB.interfaces.IStorage, ZODB.interfaces.IStorage,
ZODB.interfaces.IStorageIteration, ZODB.interfaces.IStorageIteration,
) )
class DemoStorage(object): class DemoStorage(ConflictResolvingStorage):
def __init__(self, name=None, base=None, changes=None, def __init__(self, name=None, base=None, changes=None,
...@@ -112,7 +113,7 @@ class DemoStorage(object): ...@@ -112,7 +113,7 @@ class DemoStorage(object):
def _copy_methods_from_changes(self, changes): def _copy_methods_from_changes(self, changes):
for meth in ( for meth in (
'_lock_acquire', '_lock_release', '_lock_acquire', '_lock_release',
'getSize', 'history', 'isReadOnly', 'registerDB', 'getSize', 'history', 'isReadOnly',
'sortKey', 'tpc_transaction', 'tpc_vote', 'sortKey', 'tpc_transaction', 'tpc_vote',
): ):
setattr(self, meth, getattr(changes, meth)) setattr(self, meth, getattr(changes, meth))
...@@ -281,8 +282,9 @@ class DemoStorage(object): ...@@ -281,8 +282,9 @@ class DemoStorage(object):
old = serial old = serial
if old != serial: if old != serial:
raise ZODB.POSException.ConflictError( rdata = self.tryToResolveConflict(oid, old, serial, data)
oid=oid, serials=(old, serial)) # XXX untested branch self.changes.store(oid, old, rdata, '', transaction)
return ResolvedSerial
return self.changes.store(oid, serial, data, '', transaction) return self.changes.store(oid, serial, data, '', transaction)
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
from ZODB.DB import DB from ZODB.DB import DB
from ZODB.tests import ( from ZODB.tests import (
BasicStorage, BasicStorage,
ConflictResolution,
HistoryStorage, HistoryStorage,
IteratorStorage, IteratorStorage,
MTStorage, MTStorage,
...@@ -42,7 +43,7 @@ from zope.testing import renormalizing ...@@ -42,7 +43,7 @@ from zope.testing import renormalizing
class DemoStorageTests( class DemoStorageTests(
StorageTestBase.StorageTestBase, StorageTestBase.StorageTestBase,
BasicStorage.BasicStorage, BasicStorage.BasicStorage,
ConflictResolution.ConflictResolvingStorage,
HistoryStorage.HistoryStorage, HistoryStorage.HistoryStorage,
IteratorStorage.ExtendedIteratorStorage, IteratorStorage.ExtendedIteratorStorage,
IteratorStorage.IteratorStorage, IteratorStorage.IteratorStorage,
...@@ -144,11 +145,11 @@ def testSomeDelegation(): ...@@ -144,11 +145,11 @@ def testSomeDelegation():
>>> class S: >>> class S:
... def __init__(self, name): ... def __init__(self, name):
... self.name = name ... self.name = name
... def registerDB(self, db): ... def getSize(self):
... six.print_(self.name, db) ... six.print_(self.name, 'size')
... def close(self): ... def close(self):
... six.print_(self.name, 'closed') ... six.print_(self.name, 'closed')
... sortKey = getSize = __len__ = history = getTid = None ... sortKey = __len__ = history = getTid = None
... tpc_finish = tpc_vote = tpc_transaction = None ... tpc_finish = tpc_vote = tpc_transaction = None
... _lock_acquire = _lock_release = lambda self: None ... _lock_acquire = _lock_release = lambda self: None
... getName = lambda self: 'S' ... getName = lambda self: 'S'
...@@ -165,8 +166,8 @@ def testSomeDelegation(): ...@@ -165,8 +166,8 @@ def testSomeDelegation():
>>> from ZODB.DemoStorage import DemoStorage >>> from ZODB.DemoStorage import DemoStorage
>>> storage = DemoStorage(base=S(1), changes=S(2)) >>> storage = DemoStorage(base=S(1), changes=S(2))
>>> storage.registerDB(1) >>> storage.getSize()
2 1 2 size
>>> storage.close() >>> storage.close()
1 closed 1 closed
......
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