Commit 96faf1f6 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Rename getStorage() and getConnection() with 'ZODB' to avoid confusion with NEO

terms. Use them in testImportExport and switch some methods to private
visibility.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1219 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 2d056029
...@@ -285,16 +285,15 @@ class NEOCluster(object): ...@@ -285,16 +285,15 @@ class NEOCluster(object):
def getNEOCTL(self): def getNEOCTL(self):
return self.neoctl return self.neoctl
def getStorage(self): def getZODBStorage(self):
return Storage( return Storage(
master_nodes=self.master_nodes, master_nodes=self.master_nodes,
name=self.cluster_name, name=self.cluster_name,
connector='SocketConnector') connector='SocketConnector')
def getConnection(self): def getZODBConnection(self):
""" Return a tuple with the database and a connection """ """ Return a tuple with the database and a connection """
storage = self.getStorage() db = ZODB.DB(storage=self.getZODBStorage())
db = ZODB.DB(storage=self.getStorage())
return (db, db.open()) return (db, db.open())
def _getProcessList(self, type): def _getProcessList(self, type):
......
...@@ -47,20 +47,24 @@ class ImportExportTests(unittest.TestCase): ...@@ -47,20 +47,24 @@ class ImportExportTests(unittest.TestCase):
def setUp(self): def setUp(self):
self.temp_dir = tempfile.mkdtemp(prefix='neo_import_export_') self.temp_dir = tempfile.mkdtemp(prefix='neo_import_export_')
print "using the temp directory %s" % self.temp_dir print "using the temp directory %s" % self.temp_dir
# create a neo cluster
databases = ['test_neo1', 'test_neo2']
self.neo = NEOCluster(databases, port_base=20000, master_node_count=2)
self.neo.setupDB()
def tearDown(self): def tearDown(self):
pass self.neo.stop()
def checkTree(self, tree, depth=TREE_SIZE): def __checkTree(self, tree, depth=TREE_SIZE):
self.assertTrue(isinstance(tree, Tree)) self.assertTrue(isinstance(tree, Tree))
self.assertEqual(depth, tree.depth) self.assertEqual(depth, tree.depth)
depth -= 1 depth -= 1
if depth <= 0: if depth <= 0:
return return
self.checkTree(tree.right, depth) self.__checkTree(tree.right, depth)
self.checkTree(tree.left, depth) self.__checkTree(tree.left, depth)
def getDataFS(self, reset=False): def __getDataFS(self, reset=False):
name = os.path.join(self.temp_dir, 'data.fs') name = os.path.join(self.temp_dir, 'data.fs')
if reset and os.path.exists(name): if reset and os.path.exists(name):
os.remove(name) os.remove(name)
...@@ -68,7 +72,7 @@ class ImportExportTests(unittest.TestCase): ...@@ -68,7 +72,7 @@ class ImportExportTests(unittest.TestCase):
db = ZODB.DB(storage=storage) db = ZODB.DB(storage=storage)
return (db, storage) return (db, storage)
def populate(self, db, tree_size=TREE_SIZE): def __populate(self, db, tree_size=TREE_SIZE):
conn = db.open() conn = db.open()
root = conn.root() root = conn.root()
root['trees'] = Tree(tree_size) root['trees'] = Tree(tree_size)
...@@ -78,52 +82,37 @@ class ImportExportTests(unittest.TestCase): ...@@ -78,52 +82,37 @@ class ImportExportTests(unittest.TestCase):
def testImport(self): def testImport(self):
# source database # source database
dfs_db, dfs_storage = self.getDataFS() dfs_db, dfs_storage = self.__getDataFS()
self.populate(dfs_db) self.__populate(dfs_db)
# create a neo cluster
databases = ['test_neo1', 'test_neo2']
neo = NEOCluster(databases, port_base=20000, master_node_count=2)
neo.setupDB()
neo.start()
# create a neo storage # create a neo storage
neo_args = {'connector': 'SocketConnector', 'name': neo.cluster_name} self.neo.start()
neo_storage = NEOStorage(master_nodes=neo.master_nodes, **neo_args) neo_storage = self.neo.getZODBStorage()
# copy data fs to neo # copy data fs to neo
neo_storage.copyTransactionsFrom(dfs_storage, verbose=0) neo_storage.copyTransactionsFrom(dfs_storage, verbose=0)
# check neo content # check neo content
neo_db = ZODB.DB(storage=neo_storage) (neo_db, neo_conn) = self.neo.getZODBConnection()
conn = neo_db.open() self.__checkTree(neo_conn.root()['trees'])
root = conn.root()
self.checkTree(root['trees'])
def testExport(self): def testExport(self):
# create a neo cluster
databases = ['test_neo1', 'test_neo2']
neo = NEOCluster(databases, port_base=20000, master_node_count=2)
neo.setupDB()
neo.start()
# create a neo storage # create a neo storage
neo_args = {'connector': 'SocketConnector', 'name': neo.cluster_name} self.neo.start()
neo_storage = NEOStorage(master_nodes=neo.master_nodes, **neo_args) (neo_db, neo_conn) = self.neo.getZODBConnection()
neo_db = ZODB.DB(storage=neo_storage) self.__populate(neo_db)
self.populate(neo_db)
# copy neo to data fs # copy neo to data fs
dfs_db, dfs_storage = self.getDataFS(reset=True) dfs_db, dfs_storage = self.__getDataFS(reset=True)
neo_storage = self.neo.getZODBStorage()
dfs_storage.copyTransactionsFrom(neo_storage, verbose=0) dfs_storage.copyTransactionsFrom(neo_storage, verbose=0)
# check data fs content # check data fs content
conn = dfs_db.open() conn = dfs_db.open()
root = conn.root() root = conn.root()
self.checkTree(root['trees']) self.__checkTree(root['trees'])
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -31,7 +31,7 @@ class MasterTests(unittest.TestCase): ...@@ -31,7 +31,7 @@ class MasterTests(unittest.TestCase):
def setUp(self): def setUp(self):
neo.stop() neo.stop()
neo.start() neo.start()
self.storage = neo.getStorage() self.storage = neo.getZODBStorage()
self.neoctl = neo.getNEOCTL() self.neoctl = neo.getNEOCTL()
def tearDown(self): def tearDown(self):
......
...@@ -67,7 +67,7 @@ class StorageTests(unittest.TestCase): ...@@ -67,7 +67,7 @@ class StorageTests(unittest.TestCase):
return (started_processes, stopped_processes) return (started_processes, stopped_processes)
def __populate(self): def __populate(self):
db, conn = self.neo.getConnection() db, conn = self.neo.getZODBConnection()
root = conn.root() root = conn.root()
for i in xrange(OBJECT_NUMBER): for i in xrange(OBJECT_NUMBER):
root[i] = PObject(i) root[i] = PObject(i)
......
...@@ -48,7 +48,7 @@ class ZODBTests(unittest.TestCase): ...@@ -48,7 +48,7 @@ class ZODBTests(unittest.TestCase):
neo.stop() neo.stop()
neo.setupDB() neo.setupDB()
neo.start() neo.start()
self._storage = neo.getStorage() self._storage = neo.getZODBStorage()
self._db = ZODB.DB(self._storage) self._db = ZODB.DB(self._storage)
def populate(self): def populate(self):
......
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