def _makeBaseStorage(self): logger.info("setUp() %s", self.id()) port = get_port() zconf = forker.ZEOConfig(('', port)) zport, adminaddr, pid, path = forker.start_zeo_server(self.getConfig(), zconf, port) self._pids = [pid] self._servers = [adminaddr] self._conf_path = path _base = ClientStorage(zport, '1', cache_size=20000000, min_disconnect_poll=0.5, wait=1, wait_timeout=60) _base.registerDB(DummyDB(), None) return _base
def _new_storage(self): port = get_port(self) zconf = forker.ZEOConfig(("", port)) zport, adminaddr, pid, path = forker.start_zeo_server(self.getConfig(), zconf, port) self._pids.append(pid) self._servers.append(adminaddr) blob_cache_dir = tempfile.mkdtemp(dir=".") storage = ClientStorage( zport, "1", cache_size=20000000, min_disconnect_poll=0.5, wait=1, wait_timeout=60, blob_dir=blob_cache_dir ) storage.registerDB(DummyDB()) return storage
def _makeBaseStorage(self): logger.info("setUp() %s", self.id()) port = get_port() zconf = forker.ZEOConfig(('', port)) zport, adminaddr, pid, path = forker.start_zeo_server( self.getConfig(), zconf, port) self._pids = [pid] self._servers = [adminaddr] self._conf_path = path _base = ClientStorage(zport, '1', cache_size=20000000, min_disconnect_poll=0.5, wait=1, wait_timeout=60) _base.registerDB(DummyDB()) return _base
def checkConnectionInvalidationOnReconnect(self): storage = ClientStorage(self.addr, wait=1, min_disconnect_poll=0.1) self._storage = storage # and we'll wait for the storage to be reconnected: for i in range(100): if storage.is_connected(): break time.sleep(0.1) else: raise AssertionError("Couldn't connect to server") class DummyDB: _invalidatedCache = 0 def invalidateCache(self): self._invalidatedCache += 1 def invalidate(*a, **k): pass db = DummyDB() storage.registerDB(db) base = db._invalidatedCache # Now we'll force a disconnection and reconnection storage._connection.close() # and we'll wait for the storage to be reconnected: for i in range(100): if storage.is_connected(): break time.sleep(0.1) else: raise AssertionError("Couldn't connect to server") # Now, the root object in the connection should have been invalidated: self.assertEqual(db._invalidatedCache, base + 1)
def checkConnectionInvalidationOnReconnect(self): storage = ClientStorage(self.addr, wait=1, min_disconnect_poll=0.1) self._storage = storage # and we'll wait for the storage to be reconnected: for i in range(100): if storage.is_connected(): break time.sleep(0.1) else: raise AssertionError("Couldn't connect to server") class DummyDB: _invalidatedCache = 0 def invalidateCache(self): self._invalidatedCache += 1 def invalidate(*a, **k): pass db = DummyDB() storage.registerDB(db) base = db._invalidatedCache # Now we'll force a disconnection and reconnection storage._connection.close() # and we'll wait for the storage to be reconnected: for i in range(100): if storage.is_connected(): break time.sleep(0.1) else: raise AssertionError("Couldn't connect to server") # Now, the root object in the connection should have been invalidated: self.assertEqual(db._invalidatedCache, base + 1)
class GenericTests( # Base class for all ZODB tests StorageTestBase.StorageTestBase, # ZODB test mixin classes (in the same order as imported) BasicStorage.BasicStorage, PackableStorage.PackableStorage, Synchronization.SynchronizedStorage, MTStorage.MTStorage, ReadOnlyStorage.ReadOnlyStorage, # ZEO test mixin classes (in the same order as imported) CommitLockTests.CommitLockVoteTests, ThreadTests.ThreadTests, # Locally defined (see above) MiscZEOTests, ): """Combine tests from various origins in one class.""" shared_blob_dir = False blob_cache_dir = None def setUp(self): StorageTestBase.StorageTestBase.setUp(self) logger.info("setUp() %s", self.id()) port = get_port(self) zconf = forker.ZEOConfig(("", port)) zport, adminaddr, pid, path = forker.start_zeo_server(self.getConfig(), zconf, port) self._pids = [pid] self._servers = [adminaddr] self._conf_path = path if not self.blob_cache_dir: # This is the blob cache for ClientStorage self.blob_cache_dir = tempfile.mkdtemp("blob_cache", dir=os.path.abspath(os.getcwd())) self._storage = ClientStorage( zport, "1", cache_size=20000000, min_disconnect_poll=0.5, wait=1, wait_timeout=60, blob_dir=self.blob_cache_dir, shared_blob_dir=self.shared_blob_dir, ) self._storage.registerDB(DummyDB()) def tearDown(self): self._storage.close() for server in self._servers: forker.shutdown_zeo_server(server) if hasattr(os, "waitpid"): # Not in Windows Python until 2.3 for pid in self._pids: os.waitpid(pid, 0) StorageTestBase.StorageTestBase.tearDown(self) def runTest(self): try: super(GenericTests, self).runTest() except: self._failed = True raise else: self._failed = False def open(self, read_only=0): # Needed to support ReadOnlyStorage tests. Ought to be a # cleaner way. addr = self._storage._addr self._storage.close() self._storage = ClientStorage(addr, read_only=read_only, wait=1) def checkWriteMethods(self): # ReadOnlyStorage defines checkWriteMethods. The decision # about where to raise the read-only error was changed after # Zope 2.5 was released. So this test needs to detect Zope # of the 2.5 vintage and skip the test. # The __version__ attribute was not present in Zope 2.5. if hasattr(ZODB, "__version__"): ReadOnlyStorage.ReadOnlyStorage.checkWriteMethods(self) def checkSortKey(self): key = "%s:%s" % (self._storage._storage, self._storage._server_addr) self.assertEqual(self._storage.sortKey(), key)
class GenericTests( # Base class for all ZODB tests StorageTestBase.StorageTestBase, # ZODB test mixin classes (in the same order as imported) BasicStorage.BasicStorage, PackableStorage.PackableStorage, Synchronization.SynchronizedStorage, MTStorage.MTStorage, ReadOnlyStorage.ReadOnlyStorage, # ZEO test mixin classes (in the same order as imported) CommitLockTests.CommitLockVoteTests, ThreadTests.ThreadTests, # Locally defined (see above) MiscZEOTests): """Combine tests from various origins in one class.""" def setUp(self): logger.info("setUp() %s", self.id()) port = get_port() zconf = forker.ZEOConfig(('', port)) zport, adminaddr, pid, path = forker.start_zeo_server( self.getConfig(), zconf, port) self._pids = [pid] self._servers = [adminaddr] self._conf_path = path self._storage = ClientStorage(zport, '1', cache_size=20000000, min_disconnect_poll=0.5, wait=1, wait_timeout=60) self._storage.registerDB(DummyDB(), None) def tearDown(self): self._storage.close() os.remove(self._conf_path) for server in self._servers: forker.shutdown_zeo_server(server) if hasattr(os, 'waitpid'): # Not in Windows Python until 2.3 for pid in self._pids: os.waitpid(pid, 0) def open(self, read_only=0): # Needed to support ReadOnlyStorage tests. Ought to be a # cleaner way. addr = self._storage._addr self._storage.close() self._storage = ClientStorage(addr, read_only=read_only, wait=1) def checkWriteMethods(self): # ReadOnlyStorage defines checkWriteMethods. The decision # about where to raise the read-only error was changed after # Zope 2.5 was released. So this test needs to detect Zope # of the 2.5 vintage and skip the test. # The __version__ attribute was not present in Zope 2.5. if hasattr(ZODB, "__version__"): ReadOnlyStorage.ReadOnlyStorage.checkWriteMethods(self) def checkSortKey(self): key = '%s:%s' % (self._storage._storage, self._storage._server_addr) self.assertEqual(self._storage.sortKey(), key)
class GenericTests( # Base class for all ZODB tests StorageTestBase.StorageTestBase, # ZODB test mixin classes (in the same order as imported) BasicStorage.BasicStorage, PackableStorage.PackableStorage, Synchronization.SynchronizedStorage, MTStorage.MTStorage, ReadOnlyStorage.ReadOnlyStorage, # ZEO test mixin classes (in the same order as imported) CommitLockTests.CommitLockVoteTests, ThreadTests.ThreadTests, # Locally defined (see above) MiscZEOTests ): """Combine tests from various origins in one class.""" def setUp(self): logger.info("setUp() %s", self.id()) port = get_port() zconf = forker.ZEOConfig(('', port)) zport, adminaddr, pid, path = forker.start_zeo_server(self.getConfig(), zconf, port) self._pids = [pid] self._servers = [adminaddr] self._conf_path = path self._storage = ClientStorage(zport, '1', cache_size=20000000, min_disconnect_poll=0.5, wait=1, wait_timeout=60) self._storage.registerDB(DummyDB(), None) def tearDown(self): self._storage.close() os.remove(self._conf_path) for server in self._servers: forker.shutdown_zeo_server(server) if hasattr(os, 'waitpid'): # Not in Windows Python until 2.3 for pid in self._pids: os.waitpid(pid, 0) def open(self, read_only=0): # Needed to support ReadOnlyStorage tests. Ought to be a # cleaner way. addr = self._storage._addr self._storage.close() self._storage = ClientStorage(addr, read_only=read_only, wait=1) def checkWriteMethods(self): # ReadOnlyStorage defines checkWriteMethods. The decision # about where to raise the read-only error was changed after # Zope 2.5 was released. So this test needs to detect Zope # of the 2.5 vintage and skip the test. # The __version__ attribute was not present in Zope 2.5. if hasattr(ZODB, "__version__"): ReadOnlyStorage.ReadOnlyStorage.checkWriteMethods(self) def checkSortKey(self): key = '%s:%s' % (self._storage._storage, self._storage._server_addr) self.assertEqual(self._storage.sortKey(), key)