Commit 870f2d58 authored by Jim Fulton's avatar Jim Fulton

Test that IMultiCommitStorages are supported

parent 572a9652
...@@ -1010,8 +1010,13 @@ class TransactionalUndo(object): ...@@ -1010,8 +1010,13 @@ class TransactionalUndo(object):
self._oids.update(result[1]) self._oids.update(result[1])
def tpc_vote(self, transaction): def tpc_vote(self, transaction):
for oid, _ in self._storage.tpc_vote(transaction) or (): result = self._storage.tpc_vote(transaction)
self._oids.add(oid) if result:
if isinstance(result[0], bytes):
self._oids.update(set(result))
else:
for oid, _ in result:
self._oids.add(oid)
def tpc_finish(self, transaction): def tpc_finish(self, transaction):
self._storage.tpc_finish( self._storage.tpc_finish(
......
...@@ -111,7 +111,12 @@ class TransactionalUndoStorage: ...@@ -111,7 +111,12 @@ class TransactionalUndoStorage:
undo_result = self._storage.undo(tid, t) undo_result = self._storage.undo(tid, t)
if undo_result: if undo_result:
oids.extend(undo_result[1]) oids.extend(undo_result[1])
oids.extend(oid for (oid, _) in self._storage.tpc_vote(t) or ()) v = self._storage.tpc_vote(t)
if v:
if isinstance(v[0], bytes):
oids.extend(v)
else:
oids.extend(oid for (oid, _) in v)
return oids return oids
def undo(self, tid, note): def undo(self, tid, note):
......
...@@ -390,10 +390,6 @@ stored are discarded. ...@@ -390,10 +390,6 @@ stored are discarded.
... '', t) ... '', t)
>>> serials = blob_storage.tpc_vote(t) >>> serials = blob_storage.tpc_vote(t)
>>> if s1 is None:
... s1 = [s for (oid, s) in serials if oid == blob._p_oid][0]
>>> if s2 is None:
... s2 = [s for (oid, s) in serials if oid == new_oid][0]
>>> blob_storage.tpc_abort(t) >>> blob_storage.tpc_abort(t)
...@@ -402,14 +398,7 @@ Now, the serial for the existing blob should be the same: ...@@ -402,14 +398,7 @@ Now, the serial for the existing blob should be the same:
>>> blob_storage.load(blob._p_oid, '') == (olddata, oldserial) >>> blob_storage.load(blob._p_oid, '') == (olddata, oldserial)
True True
And we shouldn't be able to read the data that we saved: The old data should be unaffected:
>>> blob_storage.loadBlob(blob._p_oid, s1)
Traceback (most recent call last):
...
POSKeyError: 'No blob file at <BLOB STORAGE PATH>'
Of course the old data should be unaffected:
>>> with open(blob_storage.loadBlob(blob._p_oid, oldserial)) as fp: >>> with open(blob_storage.loadBlob(blob._p_oid, oldserial)) as fp:
... fp.read() ... fp.read()
......
...@@ -36,6 +36,7 @@ from ZODB.tests import ReadOnlyStorage, RecoveryStorage ...@@ -36,6 +36,7 @@ from ZODB.tests import ReadOnlyStorage, RecoveryStorage
from ZODB.tests.StorageTestBase import MinPO, zodb_pickle from ZODB.tests.StorageTestBase import MinPO, zodb_pickle
from ZODB._compat import dump, dumps, _protocol from ZODB._compat import dump, dumps, _protocol
from .. import multicommitadapter
class FileStorageTests( class FileStorageTests(
StorageTestBase.StorageTestBase, StorageTestBase.StorageTestBase,
...@@ -322,6 +323,12 @@ class FileStorageHexTests(FileStorageTests): ...@@ -322,6 +323,12 @@ class FileStorageHexTests(FileStorageTests):
self._storage = ZODB.tests.hexstorage.HexStorage( self._storage = ZODB.tests.hexstorage.HexStorage(
ZODB.FileStorage.FileStorage('FileStorageTests.fs',**kwargs)) ZODB.FileStorage.FileStorage('FileStorageTests.fs',**kwargs))
class MultiFileStorageTests(FileStorageTests):
def open(self, **kwargs):
self._storage = multicommitadapter.MultiCommitAdapter(
ZODB.FileStorage.FileStorage('FileStorageTests.fs', **kwargs))
class FileStorageTestsWithBlobsEnabled(FileStorageTests): class FileStorageTestsWithBlobsEnabled(FileStorageTests):
...@@ -331,6 +338,7 @@ class FileStorageTestsWithBlobsEnabled(FileStorageTests): ...@@ -331,6 +338,7 @@ class FileStorageTestsWithBlobsEnabled(FileStorageTests):
kwargs['blob_dir'] = 'blobs' kwargs['blob_dir'] = 'blobs'
FileStorageTests.open(self, **kwargs) FileStorageTests.open(self, **kwargs)
class FileStorageHexTestsWithBlobsEnabled(FileStorageTests): class FileStorageHexTestsWithBlobsEnabled(FileStorageTests):
def open(self, **kwargs): def open(self, **kwargs):
...@@ -340,6 +348,16 @@ class FileStorageHexTestsWithBlobsEnabled(FileStorageTests): ...@@ -340,6 +348,16 @@ class FileStorageHexTestsWithBlobsEnabled(FileStorageTests):
FileStorageTests.open(self, **kwargs) FileStorageTests.open(self, **kwargs)
self._storage = ZODB.tests.hexstorage.HexStorage(self._storage) self._storage = ZODB.tests.hexstorage.HexStorage(self._storage)
class MultiFileStorageTestsWithBlobsEnabled(MultiFileStorageTests):
def open(self, **kwargs):
if 'blob_dir' not in kwargs:
kwargs = kwargs.copy()
kwargs['blob_dir'] = 'blobs'
MultiFileStorageTests.open(self, **kwargs)
class FileStorageRecoveryTest( class FileStorageRecoveryTest(
StorageTestBase.StorageTestBase, StorageTestBase.StorageTestBase,
RecoveryStorage.RecoveryStorage, RecoveryStorage.RecoveryStorage,
...@@ -702,6 +720,7 @@ def test_suite(): ...@@ -702,6 +720,7 @@ def test_suite():
FileStorageNoRestoreRecoveryTest, FileStorageNoRestoreRecoveryTest,
FileStorageTestsWithBlobsEnabled, FileStorageHexTestsWithBlobsEnabled, FileStorageTestsWithBlobsEnabled, FileStorageHexTestsWithBlobsEnabled,
AnalyzeDotPyTest, AnalyzeDotPyTest,
MultiFileStorageTests, MultiFileStorageTestsWithBlobsEnabled,
]: ]:
suite.addTest(unittest.makeSuite(klass, "check")) suite.addTest(unittest.makeSuite(klass, "check"))
suite.addTest(doctest.DocTestSuite( suite.addTest(doctest.DocTestSuite(
...@@ -723,6 +742,14 @@ def test_suite(): ...@@ -723,6 +742,14 @@ def test_suite():
test_blob_storage_recovery=True, test_blob_storage_recovery=True,
test_packing=True, test_packing=True,
)) ))
suite.addTest(ZODB.tests.testblob.storage_reusable_suite(
'BlobMultiFileStorage',
lambda name, blob_dir:
multicommitadapter.MultiCommitAdapter(
ZODB.FileStorage.FileStorage('%s.fs' % name, blob_dir=blob_dir)),
test_blob_storage_recovery=True,
test_packing=True,
))
suite.addTest(PackableStorage.IExternalGC_suite( suite.addTest(PackableStorage.IExternalGC_suite(
lambda : ZODB.FileStorage.FileStorage( lambda : ZODB.FileStorage.FileStorage(
'data.fs', blob_dir='blobs', pack_gc=False))) 'data.fs', blob_dir='blobs', pack_gc=False)))
......
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