Commit 42e85ff1 authored by Julien Muchembled's avatar Julien Muchembled

tests: reuse backend to perform SQL queries in a separate connection

parent e17bcf25
...@@ -23,7 +23,7 @@ class CreationUndone(Exception): ...@@ -23,7 +23,7 @@ class CreationUndone(Exception):
class DatabaseManager(object): class DatabaseManager(object):
"""This class only describes an interface for database managers.""" """This class only describes an interface for database managers."""
def __init__(self, database, wait): def __init__(self, database, wait=0):
""" """
Initialize the object. Initialize the object.
""" """
......
...@@ -52,8 +52,8 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -52,8 +52,8 @@ class MySQLDatabaseManager(DatabaseManager):
# (tested with testOudatedCellsOnDownStorage). # (tested with testOudatedCellsOnDownStorage).
_use_partition = False _use_partition = False
def __init__(self, database, wait): def __init__(self, *args, **kw):
super(MySQLDatabaseManager, self).__init__(database, wait) super(MySQLDatabaseManager, self).__init__(*args, **kw)
self.conn = None self.conn = None
self._config = {} self._config = {}
self._connect() self._connect()
......
...@@ -41,6 +41,7 @@ from .. import DB_USER, setupMySQLdb, NeoTestBase, buildUrlFromString, \ ...@@ -41,6 +41,7 @@ from .. import DB_USER, setupMySQLdb, NeoTestBase, buildUrlFromString, \
ADDRESS_TYPE, IP_VERSION_FORMAT_DICT, getTempDirectory ADDRESS_TYPE, IP_VERSION_FORMAT_DICT, getTempDirectory
from ..cluster import SocketLock from ..cluster import SocketLock
from neo.client.Storage import Storage from neo.client.Storage import Storage
from neo.storage.database import buildDatabaseManager
command_dict = { command_dict = {
NodeTypes.MASTER: 'neomaster', NodeTypes.MASTER: 'neomaster',
...@@ -426,13 +427,7 @@ class NEOCluster(object): ...@@ -426,13 +427,7 @@ class NEOCluster(object):
def getSQLConnection(self, db): def getSQLConnection(self, db):
assert db in self.db_list assert db in self.db_list
if self.adapter == 'MySQL': return buildDatabaseManager(self.adapter, (self.db_template % db,))
conn = MySQLdb.Connect(user=self.db_user, passwd=self.db_password,
db=db)
conn.autocommit(True)
elif self.adapter == 'SQLite':
conn = sqlite3.connect(self.db_template % db, isolation_level=None)
return conn
def getMasterProcessList(self): def getMasterProcessList(self):
return self.process_dict.get(NodeTypes.MASTER) return self.process_dict.get(NodeTypes.MASTER)
......
...@@ -42,13 +42,6 @@ class StorageTests(NEOFunctionalTest): ...@@ -42,13 +42,6 @@ class StorageTests(NEOFunctionalTest):
self.neo.stop() self.neo.stop()
NEOFunctionalTest._tearDown(self, success) NEOFunctionalTest._tearDown(self, success)
def queryCount(self, db, query):
try:
db.query(query)
except AttributeError:
return db.execute(query).fetchone()[0]
return db.store_result().fetch_row()[0][0]
def __setup(self, storage_number=2, pending_number=0, replicas=1, def __setup(self, storage_number=2, pending_number=0, replicas=1,
partitions=10, master_count=2): partitions=10, master_count=2):
# create a neo cluster # create a neo cluster
...@@ -81,18 +74,16 @@ class StorageTests(NEOFunctionalTest): ...@@ -81,18 +74,16 @@ class StorageTests(NEOFunctionalTest):
db = self.neo.getSQLConnection(db_name) db = self.neo.getSQLConnection(db_name)
# wait for the sql transaction to be commited # wait for the sql transaction to be commited
def callback(last_try): def callback(last_try):
object_number = self.queryCount(db, 'select count(*) from obj') # One revision per object and two for the root, before and after
(object_number,), = db.query('select count(*) from obj')
return object_number == OBJECT_NUMBER + 2, object_number return object_number == OBJECT_NUMBER + 2, object_number
self.neo.expectCondition(callback) self.neo.expectCondition(callback)
# no more temporarily objects # no more temporarily objects
t_objects = self.queryCount(db, 'select count(*) from tobj') (t_objects,), = db.query('select count(*) from tobj')
self.assertEqual(t_objects, 0) self.assertEqual(t_objects, 0)
# One revision per object and two for the root, before and after
revisions = self.queryCount(db, 'select count(*) from obj')
self.assertEqual(revisions, OBJECT_NUMBER + 2)
# One object more for the root # One object more for the root
query = 'select count(*) from (select * from obj group by oid) as t' query = 'select count(*) from (select * from obj group by oid) as t'
objects = self.queryCount(db, query) (objects,), = db.query(query)
self.assertEqual(objects, OBJECT_NUMBER + 1) self.assertEqual(objects, OBJECT_NUMBER + 1)
# Check object content # Check object content
db, conn = self.neo.getZODBConnection() db, conn = self.neo.getZODBConnection()
......
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