[Checkins] SVN: gocept.zeoraid/branches/distributed-remote-calls/src/gocept/zeoraid/tests/ Adding (working) tests for distributing _apply_single_storage calls()

Dirceu Pereira Tiegs dirceutiegs at gmail.com
Mon Jun 23 10:05:45 EDT 2008


Log message for revision 87669:
  Adding (working) tests for distributing _apply_single_storage calls()

Changed:
  U   gocept.zeoraid/branches/distributed-remote-calls/src/gocept/zeoraid/tests/component.xml
  A   gocept.zeoraid/branches/distributed-remote-calls/src/gocept/zeoraid/tests/dumbstorage.py
  U   gocept.zeoraid/branches/distributed-remote-calls/src/gocept/zeoraid/tests/test_basics.py

-=-
Modified: gocept.zeoraid/branches/distributed-remote-calls/src/gocept/zeoraid/tests/component.xml
===================================================================
--- gocept.zeoraid/branches/distributed-remote-calls/src/gocept/zeoraid/tests/component.xml	2008-06-23 14:03:59 UTC (rev 87668)
+++ gocept.zeoraid/branches/distributed-remote-calls/src/gocept/zeoraid/tests/component.xml	2008-06-23 14:05:44 UTC (rev 87669)
@@ -2,12 +2,12 @@
 
 <!-- Support for unit testing with storages that simulate errors. -->
 
-<component prefix="gocept.zeoraid.tests.failingstorage">
+<component prefix="gocept.zeoraid.tests">
 
     <sectiontype
         name="failingstorage"
         implements="ZODB.storage"
-        datatype=".Opener">
+        datatype=".failingstorage.Opener">
 
       <key name="blob-dir" required="no">
         <description>
@@ -17,4 +17,14 @@
 
     </sectiontype>
 
+    <sectiontype 
+        name="dumbstorage" 
+        implements="ZODB.storage"
+        datatype=".dumbstorage.Opener">
+      
+      <key name="name" default="Demo Storage"/>
+      <section type="ZODB.storage" name="*" attribute="base"/>
+
+    </sectiontype>
+
 </component>

Added: gocept.zeoraid/branches/distributed-remote-calls/src/gocept/zeoraid/tests/dumbstorage.py
===================================================================
--- gocept.zeoraid/branches/distributed-remote-calls/src/gocept/zeoraid/tests/dumbstorage.py	                        (rev 0)
+++ gocept.zeoraid/branches/distributed-remote-calls/src/gocept/zeoraid/tests/dumbstorage.py	2008-06-23 14:05:44 UTC (rev 87669)
@@ -0,0 +1,39 @@
+##############################################################################
+#
+# Copyright (c) 2007-2008 Zope Foundation and contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Unit test support."""
+
+import ZODB.DemoStorage
+import ZODB.config
+
+
+class Opener(ZODB.config.BaseConfig):
+
+    def open(self):
+        name = self.config.name
+        return DumbStorage(name)
+
+
+class DumbStorage(ZODB.DemoStorage.DemoStorage):
+
+    def __init__(self, name=''):
+        ZODB.DemoStorage.DemoStorage.__init__(self)
+        self._name = name
+        self._log = []
+
+    def getSize(self):
+        self._log.append("Storage '%s' called." % self._name)
+        ZODB.DemoStorage.DemoStorage.getSize(self)
+
+    def supportsUndo(self):
+        return True
\ No newline at end of file

Modified: gocept.zeoraid/branches/distributed-remote-calls/src/gocept/zeoraid/tests/test_basics.py
===================================================================
--- gocept.zeoraid/branches/distributed-remote-calls/src/gocept/zeoraid/tests/test_basics.py	2008-06-23 14:03:59 UTC (rev 87668)
+++ gocept.zeoraid/branches/distributed-remote-calls/src/gocept/zeoraid/tests/test_basics.py	2008-06-23 14:05:44 UTC (rev 87669)
@@ -35,6 +35,7 @@
 
 import gocept.zeoraid.storage
 import gocept.zeoraid.tests.test_recovery
+from gocept.zeoraid.tests.dumbstorage import DumbStorage
 
 from ZEO.ClientStorage import ClientStorage
 from ZEO.tests import forker, CommitLockTests, ThreadTests
@@ -1371,9 +1372,47 @@
     pass
 
 
+class DumbStorageOpener(object):
+
+    def __init__(self, name, **kwargs):
+        self.name = name
+
+    def open(self, **kwargs):
+        return DumbStorage(self.name)
+
+
+class DumbStorageTestSetup(StorageTestBase.StorageTestBase):
+
+    backend_count = 5
+
+    def _backend(self, index):
+        return self._storage.storages[
+            self._storage.storages_optimal[index]]
+
+    def setUp(self):
+        self._storages = []
+        for i in xrange(self.backend_count):
+            self._storages.append(DumbStorageOpener(str(i)))
+        self._storage = gocept.zeoraid.storage.RAIDStorage(
+            'teststorage', self._storages)
+
+    def tearDown(self):
+        self._storage.close()
+
+
+class DumbStorageDistributedTests(DumbStorageTestSetup):
+    def test_distributed_single_calls(self):
+        for i in xrange(50):
+            self._storage.getSize()
+        # assert that every storage gets called at least one time
+        for x in xrange(5):
+            self.assertEquals(len(self._backend(x)._log) >= 1, True)
+
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(ZEOReplicationStorageTests, "check"))
     suite.addTest(unittest.makeSuite(FailingStorageTests))
     suite.addTest(unittest.makeSuite(FailingStorageSharedBlobTests))
+    suite.addTest(unittest.makeSuite(DumbStorageDistributedTests))
     return suite



More information about the Checkins mailing list