Commit 753585fe authored by Grégory Wisniewski's avatar Grégory Wisniewski

Fix tests to no more use a configuration file.

Remove related test module and its entry in the test runner.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1280 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 77803636
......@@ -72,7 +72,7 @@ class NeoTestBase(unittest.TestCase):
cursor = sql_connection.cursor()
# drop and create each database
for i in xrange(number):
database = "%s%d" % (prefix, i+1)
database = "%s%d" % (prefix, i)
cursor.execute('DROP DATABASE IF EXISTS %s' % (database, ))
cursor.execute('CREATE DATABASE %s' % (database, ))
cursor.execute('GRANT ALL ON %s.* TO "%s"@"localhost" IDENTIFIED BY ""' %
......@@ -80,6 +80,37 @@ class NeoTestBase(unittest.TestCase):
cursor.close()
sql_connection.close()
def getMasterConfiguration(self, cluster='main', master_number=2,
replicas=2, partitions=1009, uuid=None):
assert master_number >= 1 and master_number <= 10
masters = ['127.0.0.1:1001%d' % i for i in xrange(master_number)]
return {
'cluster': cluster,
'bind': masters[0],
'masters': ' '.join(masters),
'replicas': replicas,
'partitions': partitions,
'uuid': uuid,
}
def getStorageConfiguration(self, cluster='main', master_number=2,
index=0, prefix=DB_PREFIX, uuid=None):
assert master_number >= 1 and master_number <= 10
assert index >= 0 and index <= 9
masters = ['127.0.0.1:1001%d' % i for i in xrange(master_number)]
if DB_PASSWD is None:
database = '%s:@%s%d' % (DB_USER, prefix, index)
else:
database = '%s:%s@%s%d' % (DB_USER, DB_PASSWD, prefix, index)
return {
'cluster': cluster,
'bind': '127.0.0.1:1002%d' % (index, ),
'masters': ' '.join(masters),
'database': database,
'uuid': uuid,
'reset': False,
}
def getConfigFile(self, master_number=2, storage_number=2, user=DB_USER,
replicas=2, partitions=1009, database=DB_PREFIX):
# if already called
......
......@@ -76,11 +76,10 @@ class AlreadyStopped(Exception):
class NEOProcess:
pid = 0
def __init__(self, command, uuid, port, arg_dict):
def __init__(self, command, uuid, arg_dict):
self.command = command
self.arg_dict = arg_dict
self.setUUID(uuid)
self.port = port
def start(self):
# Prevent starting when already forked and wait wasn't called.
......@@ -91,7 +90,7 @@ class NEOProcess:
for arg, param in self.arg_dict.iteritems():
args.append(arg)
if param is not None:
args.append(param)
args.append(str(param))
self.pid = os.fork()
if self.pid == 0:
# Child
......@@ -148,10 +147,8 @@ class NEOProcess:
Note: for this change to take effect, the node must be restarted.
"""
self.uuid = uuid
self.arg_dict['-u'] = dump(uuid)
self.arg_dict['--uuid'] = dump(uuid)
def getPort(self):
return self.port
class NEOCluster(object):
......@@ -173,54 +170,49 @@ class NEOCluster(object):
temp_dir = tempfile.mkdtemp(prefix='neo_')
print 'Using temp directory %r.' % (temp_dir, )
self.temp_dir = temp_dir
self.config_file_path = os.path.join(temp_dir, 'neo.conf')
config_file = open(self.config_file_path, 'w')
neo_admin_port = self.__allocatePort()
self.cluster_name = cluster_name = 'neo_%s' % (random.randint(0, 100), )
master_node_dict = {}
for master in xrange(master_node_count):
master_node_dict[NEO_MASTER_ID % (master, )] = \
self.__allocatePort()
self.master_nodes = master_nodes = ' '.join('127.0.0.1:%s' %
(x, ) for x in master_node_dict.itervalues())
config_file.write(NEO_CONFIG_HEADER % {
'master_nodes': master_nodes,
'replicas': replicas,
'partitions': partitions,
'name': cluster_name,
'user': db_user,
'password': db_password,
'port': neo_admin_port,
self.cluster_name = 'neo_%s' % (random.randint(0, 100), )
master_node_list = [self.__allocatePort() for i in xrange(master_node_count)]
self.master_nodes = ' '.join('127.0.0.1:%s' % (x, ) for x in master_node_list)
# create admin node
admin_port = self.__allocatePort()
self.__newProcess(NEO_ADMIN, {
'--cluster': self.cluster_name,
'--name': 'admin',
'--bind': '127.0.0.1:%d' % (admin_port, ),
'--masters': self.master_nodes,
})
self.__newProcess(NEO_ADMIN, 'admin', neo_admin_port)
for config_id, port in master_node_dict.iteritems():
config_file.write(NEO_CONFIG_MASTER % {
'id': config_id,
'port': port,
# create master nodes
for index, port in enumerate(master_node_list):
self.__newProcess(NEO_MASTER, {
'--cluster': self.cluster_name,
'--name': 'master_%d' % index,
'--bind': '127.0.0.1:%d' % (port, ),
'--masters': self.master_nodes,
'--replicas': replicas,
'--partitions': partitions,
})
self.__newProcess(NEO_MASTER, config_id, port)
for storage, db in enumerate(db_list):
config_id = NEO_STORAGE_ID % (storage, )
# create storage nodes
for index, db in enumerate(db_list):
port = self.__allocatePort()
config_file.write(NEO_CONFIG_STORAGE % {
'id': config_id,
'db': db,
'port': port,
self.__newProcess(NEO_STORAGE, {
'--cluster': self.cluster_name,
'--name': 'storage_%d' % index,
'--bind': '127.0.0.1:%d' % (port, ),
'--masters': self.master_nodes,
'--database': '%s:%s@%s' % (db_user, db_password, db),
})
self.__newProcess(NEO_STORAGE, config_id, port)
config_file.close()
self.neoctl = NeoCTL('127.0.0.1', neo_admin_port,
# create neoctl
self.neoctl = NeoCTL('127.0.0.1', admin_port,
'SocketConnector')
def __newProcess(self, command, section, port):
def __newProcess(self, command, arguments):
uuid = self.__allocateUUID()
self.process_dict.setdefault(command, []).append(
NEOProcess(command, uuid, port, {
'-v': None,
'-c': self.config_file_path,
'-s': section,
'-l': os.path.join(self.temp_dir, '%s.log' % (section, ))
}))
arguments['--uuid'] = uuid
arguments['--verbose'] = None
logfile = arguments['--name']
arguments['--logfile'] = os.path.join(self.temp_dir, '%s.log' % (logfile, ))
self.process_dict.setdefault(command, []).append(
NEOProcess(command, uuid, arguments))
def __allocatePort(self):
port = self.last_port
......
......@@ -41,8 +41,8 @@ class MasterClientHandlerTests(NeoTestBase):
def setUp(self):
# create an application object
config = self.getConfigFile(master_number=1, replicas=1)
self.app = Application(config, "master1")
config = self.getMasterConfiguration(master_number=1, replicas=1)
self.app = Application(**config)
self.app.pt.clear()
self.app.pt.setID(pack('!Q', 1))
self.app.em = Mock({"getConnectionList" : []})
......
......@@ -65,8 +65,8 @@ class MasterClientElectionTests(NeoTestBase):
def setUp(self):
# create an application object
config = self.getConfigFile()
self.app = Application(config, "master1")
config = self.getMasterConfiguration()
self.app = Application(**config)
self.app.pt.clear()
self.app.em = Mock({"getConnectionList" : []})
self.app.finishing_transaction_dict = {}
......@@ -133,8 +133,8 @@ class MasterServerElectionTests(NeoTestBase):
def setUp(self):
# create an application object
config = self.getConfigFile()
self.app = Application(config, "master1")
config = self.getMasterConfiguration()
self.app = Application(**config)
self.app.pt.clear()
self.app.em = Mock({"getConnectionList" : []})
self.app.finishing_transaction_dict = {}
......
......@@ -28,8 +28,8 @@ class MasterAppTests(NeoTestBase):
def setUp(self):
# create an application object
config = self.getConfigFile()
self.app = Application(config, "master1")
config = self.getMasterConfiguration()
self.app = Application(**config)
self.app.pt.clear()
def tearDown(self):
......
......@@ -55,8 +55,8 @@ class MasterRecoveryTests(NeoTestBase):
def setUp(self):
# create an application object
config = self.getConfigFile()
self.app = Application(config, "master1")
config = self.getMasterConfiguration()
self.app = Application(**config)
self.app.pt.clear()
self.app.finishing_transaction_dict = {}
for server in self.app.master_node_list:
......
......@@ -41,8 +41,8 @@ class MasterStorageHandlerTests(NeoTestBase):
def setUp(self):
# create an application object
config = self.getConfigFile(master_number=1, replicas=1)
self.app = Application(config, "master1")
config = self.getMasterConfiguration(master_number=1, replicas=1)
self.app = Application(**config)
self.app.pt.clear()
self.app.pt.setID(pack('!Q', 1))
self.app.em = Mock({"getConnectionList" : []})
......
......@@ -43,8 +43,8 @@ class MasterVerificationTests(NeoTestBase):
def setUp(self):
# create an application object
config = self.getConfigFile(master_number=2)
self.app = Application(config, "master1")
config = self.getMasterConfiguration()
self.app = Application(**config)
self.app.pt.clear()
self.app.finishing_transaction_dict = {}
for server in self.app.master_node_list:
......
......@@ -46,8 +46,8 @@ class StorageClientHandlerTests(NeoTestBase):
def setUp(self):
self.prepareDatabase(number=1)
# create an application object
config = self.getConfigFile(master_number=1)
self.app = Application(config, "storage1")
config = self.getStorageConfiguration(master_number=1)
self.app = Application(**config)
self.app.num_partitions = 1
self.app.num_replicas = 1
self.app.transaction_dict = {}
......
......@@ -43,8 +43,8 @@ class StorageInitializationHandlerTests(NeoTestBase):
def setUp(self):
self.prepareDatabase(number=1)
# create an application object
config = self.getConfigFile(master_number=1)
self.app = Application(config, "storage1")
config = self.getStorageConfiguration(master_number=1)
self.app = Application(**config)
self.verification = InitializationHandler(self.app)
# define some variable to simulate client and storage node
self.master_port = 10010
......
......@@ -45,8 +45,8 @@ class StorageMasterHandlerTests(NeoTestBase):
def setUp(self):
self.prepareDatabase(number=1)
# create an application object
config = self.getConfigFile(master_number=1)
self.app = Application(config, "storage1")
config = self.getStorageConfiguration(master_number=1)
self.app = Application(**config)
self.app.num_partitions = 1
self.app.num_replicas = 1
self.app.transaction_dict = {}
......
......@@ -31,8 +31,8 @@ class StorageAppTests(NeoTestBase):
def setUp(self):
self.prepareDatabase(number=1)
# create an application object
config = self.getConfigFile(master_number=1)
self.app = Application(config, "storage1")
config = self.getStorageConfiguration(master_number=1)
self.app = Application(**config)
self.app.event_queue = deque()
def tearDown(self):
......
......@@ -43,8 +43,8 @@ class StorageStorageHandlerTests(NeoTestBase):
def setUp(self):
self.prepareDatabase(number=1)
# create an application object
config = self.getConfigFile(master_number=1)
self.app = Application(config, "storage1")
config = self.getStorageConfiguration(master_number=1)
self.app = Application(**config)
self.app.num_partitions = 1
self.app.num_replicas = 1
self.app.transaction_dict = {}
......
......@@ -25,7 +25,7 @@ from neo.tests import NeoTestBase
from neo.exception import DatabaseFailure
from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64
NEO_SQL_DATABASE = 'test_mysqldb1'
NEO_SQL_DATABASE = 'test_mysqldb0'
NEO_SQL_USER = 'test'
class StorageMySQSLdbTests(NeoTestBase):
......
......@@ -43,8 +43,8 @@ class StorageVerificationHandlerTests(NeoTestBase):
def setUp(self):
self.prepareDatabase(number=1)
# create an application object
config = self.getConfigFile(master_number=1)
self.app = Application(config, "storage1")
config = self.getStorageConfiguration(master_number=1)
self.app = Application(**config)
self.verification = VerificationHandler(self.app)
# define some variable to simulate client and storage node
self.master_port = 10010
......
#
# Copyright (C) 2009 Nexedi SA
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import unittest, os
from mock import Mock
from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, BROKEN_STATE, \
MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, INVALID_UUID
from neo.config import ConfigurationManager
from neo.tests import NeoTestBase
from tempfile import mkstemp
class ConfigurationManagerTests(NeoTestBase):
def setUp(self):
pass
def tearDown(self):
pass
def test_01_configuration_manager(self):
# initialisation
#create a fake configuration file
config_file_text = """# Default parameters.
[DEFAULT]
# The list of master nodes.
master_nodes: 127.0.0.2:10010 127.0.0.2
# The number of replicas.
replicas: 25
# The number of partitions.
partitions: 243125
# The name of this cluster.
name: unittest
# The user name for the database.
user: neotest
# The password for the database.
password: neotest
connector : SocketTestConnector
# The first master.
[mastertest]
server: 127.0.0.1:15010
# The first storage.
[storage1]
database: neotest1
server: 127.0.0.5
# The second storage.
[storage2]
database: neotest2
server: 127.0.0.1:15021
"""
tmp_id, self.tmp_path = mkstemp()
tmp_file = os.fdopen(tmp_id, "w+b")
tmp_file.write(config_file_text)
tmp_file.close()
config = ConfigurationManager(self.tmp_path, "mastertest")
self.assertNotEqual(config.parser, None)
self.assertEqual(config.section, "mastertest")
# some values will be get from default config into class
self.assertEqual(config.getDatabase(), "test")
self.assertEqual(config.getUser(), "neotest")
self.assertEqual(config.getPassword(), "neotest")
self.assertEqual(config.getServer(), ("127.0.0.1", 15010))
self.assertEqual(config.getReplicas(), 25)
self.assertEqual(config.getPartitions(), 243125)
self.assertEqual(config.getConnector(), "SocketTestConnector")
self.assertEqual(config.getName(), "unittest")
self.assertEqual(len(config.getMasterNodeList()), 2)
node_list = config.getMasterNodeList()
self.failUnless(("127.0.0.2", 10010) in node_list)
self.failUnless(("127.0.0.2", 10100) in node_list)
# test with a storage where no port is defined, must get the default one
config = ConfigurationManager(self.tmp_path, "storage1")
self.assertNotEqual(config.parser, None)
self.assertEqual(config.section, "storage1")
# some values will be get from default config into class
self.assertEqual(config.getDatabase(), "neotest1")
self.assertEqual(config.getUser(), "neotest")
self.assertEqual(config.getPassword(), "neotest")
self.assertEqual(config.getServer(), ("127.0.0.5", 10100))
self.assertEqual(config.getReplicas(), 25)
self.assertEqual(config.getPartitions(), 243125)
self.assertEqual(config.getConnector(), "SocketTestConnector")
self.assertEqual(config.getName(), "unittest")
self.assertEqual(len(config.getMasterNodeList()), 2)
node_list = config.getMasterNodeList()
self.failUnless(("127.0.0.2", 10010) in node_list)
self.failUnless(("127.0.0.2", 10100) in node_list)
if __name__ == '__main__':
unittest.main()
......@@ -27,7 +27,6 @@ import os
UNIT_TEST_MODULES = [
# generic parts
'neo.tests.testBootstrap',
'neo.tests.testConfig',
'neo.tests.testConnection',
'neo.tests.testEvent',
'neo.tests.testHandler',
......
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