Commit 5ed602dd authored by Grégory Wisniewski's avatar Grégory Wisniewski

Add close() method on database manager interface and its implementation in the

MySQLdb adapter. Fix a test for storage operation handler.
Fix a test


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@621 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 60a622a5
......@@ -22,6 +22,10 @@ class DatabaseManager(object):
"""Initialize the object."""
pass
def close(self):
""" close the database connection """
raise NotImplementedError('this method must be overridden')
def setup(self, reset = 0):
"""Set up a database. If reset is true, existing data must be
discarded."""
......
......@@ -45,6 +45,9 @@ class MySQLDatabaseManager(DatabaseManager):
self.connect()
super(MySQLDatabaseManager, self).__init__(**kwargs)
def close(self):
self.conn.close()
def connect(self):
kwd = {'db' : self.db, 'user' : self.user}
if self.passwd is not None:
......
......@@ -42,7 +42,7 @@ class StorageBootstrapTests(NeoTestBase):
self.app = Application(config, "master1")
for server in self.app.master_node_list:
self.app.nm.add(MasterNode(server = server))
self.trying_master_node = self.app.nm.getMasterNodeList()[0 ]
self.trying_master_node = self.app.nm.getMasterNodeList()[0]
self.bootstrap = BootstrapEventHandler(self.app)
# define some variable to simulate client and storage node
self.master_port = 10010
......
......@@ -40,7 +40,7 @@ class StorageMySQSLdbTests(NeoTestBase):
)
def tearDown(self):
pass
self.db.close()
def checkCalledQuery(self, query=None, call=0):
self.assertTrue(len(self.db.conn.mockGetNamedCalls('query')) > call)
......@@ -142,6 +142,8 @@ class StorageMySQSLdbTests(NeoTestBase):
# OperationalError > raise DatabaseFailure exception
from MySQLdb import OperationalError
class FakeConn(object):
def close(self):
pass
def query(*args):
raise OperationalError(-1, 'this is a test')
self.db.conn = FakeConn()
......
......@@ -489,9 +489,10 @@ class StorageOperationTests(NeoTestBase):
self.assertEquals(app.nm.getNodeByUUID(uuid).getState(), TEMPORARILY_DOWN_STATE)
# pt calls
calls = self.app.pt.mockGetNamedCalls('setCell')
self.assertEquals(len(calls), 2)
self.assertEquals(len(calls), 3)
calls[0].checkArgs(0, app.nm.getNodeByUUID(uuid), UP_TO_DATE_STATE)
calls[1].checkArgs(2, app.nm.getNodeByUUID(app.uuid), OUT_OF_DATE_STATE)
calls[1].checkArgs(1, app.nm.getNodeByUUID(app.uuid), DISCARDED_STATE)
calls[2].checkArgs(2, app.nm.getNodeByUUID(app.uuid), OUT_OF_DATE_STATE)
# replicator calls
calls = self.app.replicator.mockGetNamedCalls('removePartition')
self.assertEquals(len(calls), 1)
......
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