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