Skip to content

Commit

Permalink
DemoStorage: add support for conflict resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
jmuchemb committed May 9, 2016
1 parent ee5a462 commit 9d13627
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/ZODB/ConflictResolution.py
Expand Up @@ -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)
10 changes: 6 additions & 4 deletions src/ZODB/DemoStorage.py
Expand Up @@ -31,12 +31,13 @@
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,
Expand Down Expand Up @@ -112,7 +113,7 @@ def close(self):
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))
Expand Down Expand Up @@ -281,8 +282,9 @@ def store(self, oid, serial, data, version, transaction):
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)

Expand Down
13 changes: 7 additions & 6 deletions src/ZODB/tests/testDemoStorage.py
Expand Up @@ -14,6 +14,7 @@
from ZODB.DB import DB
from ZODB.tests import (
BasicStorage,
ConflictResolution,
HistoryStorage,
IteratorStorage,
MTStorage,
Expand Down Expand Up @@ -42,7 +43,7 @@
class DemoStorageTests(
StorageTestBase.StorageTestBase,
BasicStorage.BasicStorage,

ConflictResolution.ConflictResolvingStorage,
HistoryStorage.HistoryStorage,
IteratorStorage.ExtendedIteratorStorage,
IteratorStorage.IteratorStorage,
Expand Down Expand Up @@ -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'
Expand All @@ -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
Expand Down

0 comments on commit 9d13627

Please sign in to comment.