Commit 55144777 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Factorize configuration file generation for master and storage tests.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@617 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 5dc59a4f
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import unittest, logging, os import unittest, logging, os
from tempfile import mkstemp
from mock import Mock from mock import Mock
from neo.tests.base import NeoTestBase from neo.tests.base import NeoTestBase
from neo.master.app import Application from neo.master.app import Application
...@@ -30,57 +29,12 @@ class MasterAppTests(NeoTestBase): ...@@ -30,57 +29,12 @@ class MasterAppTests(NeoTestBase):
def setUp(self): def setUp(self):
logging.basicConfig(level = logging.WARNING) logging.basicConfig(level = logging.WARNING)
# create an application object # create an application object
config_file_text = """# Default parameters. config = self.getConfigFile()
[DEFAULT] self.app = Application(config, "master1")
# The list of master nodes.
master_nodes: 127.0.0.1:10010
# The number of replicas.
replicas: 2
# The number of partitions.
partitions: 1009
# The name of this cluster.
name: main
# The user name for the database.
user: neo
# The password for the database.
password: neo
connector: SocketConnector
# The first master.
[mastertest]
server: 127.0.0.1:10010
# The first storage.
[storage1]
database: neotest1
server: 127.0.0.1:10020
# The second storage.
[storage2]
database: neotest2
server: 127.0.0.1:10021
# The third storage.
[storage3]
database: neotest3
server: 127.0.0.1:10022
# The fourth storage.
[storage4]
database: neotest4
server: 127.0.0.1:10023
"""
tmp_id, self.tmp_path = mkstemp()
tmp_file = os.fdopen(tmp_id, "w+b")
tmp_file.write(config_file_text)
tmp_file.close()
self.app = Application(self.tmp_path, "mastertest")
self.app.pt.clear() self.app.pt.clear()
def tearDown(self): def tearDown(self):
# Delete tmp file NeoTestBase.tearDown(self)
os.remove(self.tmp_path)
def test_01_getNextPartitionTableID(self): def test_01_getNextPartitionTableID(self):
# must raise as we don"t have one # must raise as we don"t have one
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
import os import os
import unittest import unittest
import logging import logging
from tempfile import mkstemp
from mock import Mock from mock import Mock
from struct import pack, unpack from struct import pack, unpack
from neo.tests.base import NeoTestBase from neo.tests.base import NeoTestBase
...@@ -68,50 +67,8 @@ class MasterElectionTests(NeoTestBase): ...@@ -68,50 +67,8 @@ class MasterElectionTests(NeoTestBase):
def setUp(self): def setUp(self):
logging.basicConfig(level = logging.WARNING) logging.basicConfig(level = logging.WARNING)
# create an application object # create an application object
config_file_text = """# Default parameters. config = self.getConfigFile()
[DEFAULT] self.app = Application(config, "master1")
# The list of master nodes.
master_nodes: 127.0.0.1:10010 127.0.0.1:10011
# The number of replicas.
replicas: 2
# The number of partitions.
partitions: 1009
# The name of this cluster.
name: main
# The user name for the database.
user: neo
# The password for the database.
password: neo
connector : SocketConnector
# The first master.
[mastertest]
server: 127.0.0.1:10010
# The first storage.
[storage1]
database: neotest1
server: 127.0.0.1:10020
# The second storage.
[storage2]
database: neotest2
server: 127.0.0.1:10021
# The third storage.
[storage3]
database: neotest3
server: 127.0.0.1:10022
# The fourth storage.
[storage4]
database: neotest4
server: 127.0.0.1:10023
"""
tmp_id, self.tmp_path = mkstemp()
tmp_file = os.fdopen(tmp_id, "w+b")
tmp_file.write(config_file_text)
tmp_file.close()
self.app = Application(self.tmp_path, "mastertest")
self.app.pt.clear() self.app.pt.clear()
self.app.em = Mock({"getConnectionList" : []}) self.app.em = Mock({"getConnectionList" : []})
self.app.finishing_transaction_dict = {} self.app.finishing_transaction_dict = {}
...@@ -134,8 +91,7 @@ server: 127.0.0.1:10023 ...@@ -134,8 +91,7 @@ server: 127.0.0.1:10023
ClientConnection.expectMessage = expectMessage ClientConnection.expectMessage = expectMessage
def tearDown(self): def tearDown(self):
# Delete tmp file NeoTestBase.tearDown(self)
os.remove(self.tmp_path)
# restore environnement # restore environnement
ClientConnection._addPacket = self._addPacket ClientConnection._addPacket = self._addPacket
ClientConnection.expectMessage = self.expectMessage ClientConnection.expectMessage = self.expectMessage
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
import os import os
import unittest import unittest
import logging import logging
from tempfile import mkstemp
from mock import Mock from mock import Mock
from struct import pack, unpack from struct import pack, unpack
from neo.tests.base import NeoTestBase from neo.tests.base import NeoTestBase
...@@ -57,50 +56,8 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -57,50 +56,8 @@ class MasterRecoveryTests(NeoTestBase):
def setUp(self): def setUp(self):
logging.basicConfig(level = logging.WARNING) logging.basicConfig(level = logging.WARNING)
# create an application object # create an application object
config_file_text = """# Default parameters. config = self.getConfigFile()
[DEFAULT] self.app = Application(config, "master1")
# The list of master nodes.
master_nodes: 127.0.0.1:10010 127.0.0.1:10011
# The number of replicas.
replicas: 2
# The number of partitions.
partitions: 1009
# The name of this cluster.
name: main
# The user name for the database.
user: neo
# The password for the database.
password: neo
connector : SocketConnector
# The first master.
[mastertest]
server: 127.0.0.1:10010
# The first storage.
[storage1]
database: neotest1
server: 127.0.0.1:10020
# The second storage.
[storage2]
database: neotest2
server: 127.0.0.1:10021
# The third storage.
[storage3]
database: neotest3
server: 127.0.0.1:10022
# The fourth storage.
[storage4]
database: neotest4
server: 127.0.0.1:10023
"""
tmp_id, self.tmp_path = mkstemp()
tmp_file = os.fdopen(tmp_id, "w+b")
tmp_file.write(config_file_text)
tmp_file.close()
self.app = Application(self.tmp_path, "mastertest")
self.app.pt.clear() self.app.pt.clear()
self.app.finishing_transaction_dict = {} self.app.finishing_transaction_dict = {}
for server in self.app.master_node_list: for server in self.app.master_node_list:
...@@ -120,8 +77,7 @@ server: 127.0.0.1:10023 ...@@ -120,8 +77,7 @@ server: 127.0.0.1:10023
self.storage_address = ('127.0.0.1', self.storage_port) self.storage_address = ('127.0.0.1', self.storage_port)
def tearDown(self): def tearDown(self):
# Delete tmp file NeoTestBase.tearDown(self)
os.remove(self.tmp_path)
# Common methods # Common methods
def getLastUUID(self): def getLastUUID(self):
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
import os import os
import unittest import unittest
import logging import logging
from tempfile import mkstemp
from mock import Mock from mock import Mock
from struct import pack, unpack from struct import pack, unpack
from neo.tests.base import NeoTestBase from neo.tests.base import NeoTestBase
...@@ -42,52 +41,8 @@ class MasterServiceTests(NeoTestBase): ...@@ -42,52 +41,8 @@ class MasterServiceTests(NeoTestBase):
def setUp(self): def setUp(self):
logging.basicConfig(level = logging.WARNING) logging.basicConfig(level = logging.WARNING)
# create an application object # create an application object
config_file_text = """# Default parameters. config = self.getConfigFile(master_number=1, replicas=1)
[DEFAULT] self.app = Application(config, "master1")
# The list of master nodes.
master_nodes: 127.0.0.1:10010
# The number of replicas.
replicas: 1
# The number of partitions.
partitions: 1009
# The name of this cluster.
name: main
# The user name for the database.
user: neo
# The password for the database.
password: neo
connector: SocketConnector
# The first master.
[mastertest]
server: 127.0.0.1:10010
# The first storage.
[storage1]
database: neotest1
server: 127.0.0.1:10020
# The second storage.
[storage2]
database: neotest2
server: 127.0.0.1:10021
# The third storage.
[storage3]
database: neotest3
server: 127.0.0.1:10022
# The fourth storage.
[storage4]
database: neotest4
server: 127.0.0.1:10023
"""
tmp_id, self.tmp_path = mkstemp()
tmp_file = os.fdopen(tmp_id, "w+b")
tmp_file.write(config_file_text)
tmp_file.close()
self.app = Application(self.tmp_path, "mastertest")
self.app.pt.clear() self.app.pt.clear()
self.app.lptid = pack('!Q', 1) self.app.lptid = pack('!Q', 1)
self.app.em = Mock({"getConnectionList" : []}) self.app.em = Mock({"getConnectionList" : []})
...@@ -104,8 +59,7 @@ server: 127.0.0.1:10023 ...@@ -104,8 +59,7 @@ server: 127.0.0.1:10023
self.storage_address = ('127.0.0.1', self.storage_port) self.storage_address = ('127.0.0.1', self.storage_port)
def tearDown(self): def tearDown(self):
# Delete tmp file NeoTestBase.tearDown(self)
os.remove(self.tmp_path)
def getLastUUID(self): def getLastUUID(self):
return self.uuid return self.uuid
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
import os import os
import unittest import unittest
import logging import logging
from tempfile import mkstemp
from mock import Mock from mock import Mock
from struct import pack, unpack from struct import pack, unpack
from neo.tests.base import NeoTestBase from neo.tests.base import NeoTestBase
...@@ -26,24 +25,10 @@ from neo.protocol import Packet, INVALID_UUID ...@@ -26,24 +25,10 @@ from neo.protocol import Packet, INVALID_UUID
from neo.master.verification import VerificationEventHandler from neo.master.verification import VerificationEventHandler
from neo.master.app import Application from neo.master.app import Application
from neo import protocol from neo import protocol
from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \ from neo.protocol import ERROR, ANNOUNCE_PRIMARY_MASTER, \
PING, PONG, ASK_PRIMARY_MASTER, ANSWER_PRIMARY_MASTER, ANNOUNCE_PRIMARY_MASTER, \ NOTIFY_NODE_INFORMATION, ANSWER_LAST_IDS, ANSWER_PARTITION_TABLE, \
REELECT_PRIMARY_MASTER, NOTIFY_NODE_INFORMATION, START_OPERATION, \ ANSWER_UNFINISHED_TRANSACTIONS, ANSWER_OBJECT_PRESENT, \
STOP_OPERATION, ASK_LAST_IDS, ANSWER_LAST_IDS, ASK_PARTITION_TABLE, \ ANSWER_TRANSACTION_INFORMATION, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \
ANSWER_PARTITION_TABLE, SEND_PARTITION_TABLE, NOTIFY_PARTITION_CHANGES, \
ASK_UNFINISHED_TRANSACTIONS, ANSWER_UNFINISHED_TRANSACTIONS, \
ASK_OBJECT_PRESENT, ANSWER_OBJECT_PRESENT, \
DELETE_TRANSACTION, COMMIT_TRANSACTION, ASK_NEW_TID, ANSWER_NEW_TID, \
FINISH_TRANSACTION, NOTIFY_TRANSACTION_FINISHED, LOCK_INFORMATION, \
NOTIFY_INFORMATION_LOCKED, INVALIDATE_OBJECTS, UNLOCK_INFORMATION, \
ASK_NEW_OIDS, ANSWER_NEW_OIDS, ASK_STORE_OBJECT, ANSWER_STORE_OBJECT, \
ABORT_TRANSACTION, ASK_STORE_TRANSACTION, ANSWER_STORE_TRANSACTION, \
ASK_OBJECT, ANSWER_OBJECT, ASK_TIDS, ANSWER_TIDS, ASK_TRANSACTION_INFORMATION, \
ANSWER_TRANSACTION_INFORMATION, ASK_OBJECT_HISTORY, ANSWER_OBJECT_HISTORY, \
ASK_OIDS, ANSWER_OIDS, \
NOT_READY_CODE, OID_NOT_FOUND_CODE, SERIAL_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \
PROTOCOL_ERROR_CODE, TIMEOUT_ERROR_CODE, BROKEN_NODE_DISALLOWED_CODE, \
INTERNAL_ERROR_CODE, \
STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, MASTER_NODE_TYPE, \ STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, MASTER_NODE_TYPE, \
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \ RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
...@@ -58,50 +43,8 @@ class MasterVerificationeTests(NeoTestBase): ...@@ -58,50 +43,8 @@ class MasterVerificationeTests(NeoTestBase):
def setUp(self): def setUp(self):
logging.basicConfig(level = logging.WARNING) logging.basicConfig(level = logging.WARNING)
# create an application object # create an application object
config_file_text = """# Default parameters. config = self.getConfigFile(master_number=2)
[DEFAULT] self.app = Application(config, "master1")
# The list of master nodes.
master_nodes: 127.0.0.1:10010 127.0.0.1:10011
# The number of replicas.
replicas: 2
# The number of partitions.
partitions: 1009
# The name of this cluster.
name: main
# The user name for the database.
user: neo
# The password for the database.
password: neo
connector : SocketConnector
# The first master.
[mastertest]
server: 127.0.0.1:10010
# The first storage.
[storage1]
database: neotest1
server: 127.0.0.1:10020
# The second storage.
[storage2]
database: neotest2
server: 127.0.0.1:10021
# The third storage.
[storage3]
database: neotest3
server: 127.0.0.1:10022
# The fourth storage.
[storage4]
database: neotest4
server: 127.0.0.1:10023
"""
tmp_id, self.tmp_path = mkstemp()
tmp_file = os.fdopen(tmp_id, "w+b")
tmp_file.write(config_file_text)
tmp_file.close()
self.app = Application(self.tmp_path, "mastertest")
self.app.pt.clear() self.app.pt.clear()
self.app.finishing_transaction_dict = {} self.app.finishing_transaction_dict = {}
for server in self.app.master_node_list: for server in self.app.master_node_list:
...@@ -123,8 +66,7 @@ server: 127.0.0.1:10023 ...@@ -123,8 +66,7 @@ server: 127.0.0.1:10023
self.storage_address = ('127.0.0.1', self.storage_port) self.storage_address = ('127.0.0.1', self.storage_port)
def tearDown(self): def tearDown(self):
# Delete tmp file NeoTestBase.tearDown(self)
os.remove(self.tmp_path)
# Common methods # Common methods
def getLastUUID(self): def getLastUUID(self):
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import unittest, logging, os import unittest, logging, os
from tempfile import mkstemp
from mock import Mock from mock import Mock
from neo.tests.base import NeoTestBase
from neo.storage.app import Application from neo.storage.app import Application
from neo.protocol import INVALID_PTID, INVALID_OID, INVALID_TID, \ from neo.protocol import INVALID_PTID, INVALID_OID, INVALID_TID, \
INVALID_UUID, Packet, NOTIFY_NODE_INFORMATION, UP_TO_DATE_STATE INVALID_UUID, Packet, NOTIFY_NODE_INFORMATION, UP_TO_DATE_STATE
...@@ -25,65 +25,19 @@ from neo.node import MasterNode, ClientNode, StorageNode ...@@ -25,65 +25,19 @@ from neo.node import MasterNode, ClientNode, StorageNode
from neo.storage.mysqldb import p64, u64, MySQLDatabaseManager from neo.storage.mysqldb import p64, u64, MySQLDatabaseManager
from collections import deque from collections import deque
from neo.pt import PartitionTable from neo.pt import PartitionTable
import MySQLdb
SQL_ADMIN_USER = 'root' class StorageAppTests(NeoTestBase):
SQL_ADMIN_PASSWORD = None
NEO_SQL_USER = 'test'
NEO_SQL_DATABASE = 'test_storage_neo1'
class StorageAppTests(unittest.TestCase):
def setUp(self): def setUp(self):
logging.basicConfig(level = logging.WARNING) logging.basicConfig(level = logging.WARNING)
self.prepareDatabase(number=1)
# create an application object # create an application object
config_file_text = """# Default parameters. config = self.getConfigFile(master_number=1)
[DEFAULT] self.app = Application(config, "storage1")
# The list of master nodes.
master_nodes: 127.0.0.1:10010
# The number of replicas.
replicas: 2
# The number of partitions.
partitions: 1009
# The name of this cluster.
name: main
# The user name for the database.
user: %(user)s
connector : SocketConnector
# The first master.
[mastertest]
server: 127.0.0.1:10010
[storagetest]
database: %(database)s
server: 127.0.0.1:10020
""" % {
'database': NEO_SQL_DATABASE,
'user': NEO_SQL_USER,
}
# SQL connection
connect_arg_dict = {'user': SQL_ADMIN_USER}
if SQL_ADMIN_PASSWORD is not None:
connect_arg_dict['passwd'] = SQL_ADMIN_PASSWORD
sql_connection = MySQLdb.Connect(**connect_arg_dict)
cursor = sql_connection.cursor()
# new database
cursor.execute('DROP DATABASE IF EXISTS %s' % (NEO_SQL_DATABASE, ))
cursor.execute('CREATE DATABASE %s' % (NEO_SQL_DATABASE, ))
cursor.execute('GRANT ALL ON %s.* TO "%s"@"localhost" IDENTIFIED BY ""' %
(NEO_SQL_DATABASE, NEO_SQL_USER))
cursor.close()
sql_connection.close()
tmp_id, self.tmp_path = mkstemp()
tmp_file = os.fdopen(tmp_id, "w+b")
tmp_file.write(config_file_text)
tmp_file.close()
self.app = Application(self.tmp_path, "storagetest")
self.app.event_queue = deque() self.app.event_queue = deque()
def tearDown(self): def tearDown(self):
# Delete tmp file NeoTestBase.tearDown(self)
os.remove(self.tmp_path)
def getNewUUID(self): def getNewUUID(self):
uuid = INVALID_UUID uuid = INVALID_UUID
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
import os import os
import unittest import unittest
import logging import logging
import MySQLdb
from tempfile import mkstemp
from mock import Mock from mock import Mock
from neo.tests.base import NeoTestBase from neo.tests.base import NeoTestBase
from neo.master.app import MasterNode from neo.master.app import MasterNode
...@@ -34,59 +32,14 @@ from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION ...@@ -34,59 +32,14 @@ from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION
from neo.protocol import ERROR, BROKEN_NODE_DISALLOWED_CODE, ASK_PRIMARY_MASTER from neo.protocol import ERROR, BROKEN_NODE_DISALLOWED_CODE, ASK_PRIMARY_MASTER
from neo.protocol import ANSWER_PRIMARY_MASTER from neo.protocol import ANSWER_PRIMARY_MASTER
SQL_ADMIN_USER = 'root'
SQL_ADMIN_PASSWORD = None
NEO_SQL_USER = 'test'
NEO_SQL_DATABASE = 'test_storage_neo1'
class StorageBootstrapTests(NeoTestBase): class StorageBootstrapTests(NeoTestBase):
def setUp(self): def setUp(self):
logging.basicConfig(level = logging.ERROR) logging.basicConfig(level = logging.ERROR)
self.prepareDatabase(number=1)
# create an application object # create an application object
config_file_text = """# Default parameters. config = self.getConfigFile()
[DEFAULT] self.app = Application(config, "master1")
# The list of master nodes.
master_nodes: 127.0.0.1:10010
# The number of replicas.
replicas: 2
# The number of partitions.
partitions: 1009
# The name of this cluster.
name: main
# The user name for the database.
user: %(user)s
connector : SocketConnector
# The first master.
[mastertest]
server: 127.0.0.1:10010
[storagetest]
database: %(database)s
server: 127.0.0.1:10020
""" % {
'database': NEO_SQL_DATABASE,
'user': NEO_SQL_USER,
}
# SQL connection
connect_arg_dict = {'user': SQL_ADMIN_USER}
if SQL_ADMIN_PASSWORD is not None:
connect_arg_dict['passwd'] = SQL_ADMIN_PASSWORD
sql_connection = MySQLdb.Connect(**connect_arg_dict)
cursor = sql_connection.cursor()
# new database
cursor.execute('DROP DATABASE IF EXISTS %s' % (NEO_SQL_DATABASE, ))
cursor.execute('CREATE DATABASE %s' % (NEO_SQL_DATABASE, ))
cursor.execute('GRANT ALL ON %s.* TO "%s"@"localhost" IDENTIFIED BY ""' %
(NEO_SQL_DATABASE, NEO_SQL_USER))
cursor.close()
sql_connection.close()
# config file
tmp_id, self.tmp_path = mkstemp()
tmp_file = os.fdopen(tmp_id, "w+b")
tmp_file.write(config_file_text)
tmp_file.close()
self.app = Application(self.tmp_path, "storagetest")
for server in self.app.master_node_list: for server in self.app.master_node_list:
self.app.nm.add(MasterNode(server = server)) 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 ]
...@@ -98,8 +51,7 @@ server: 127.0.0.1:10020 ...@@ -98,8 +51,7 @@ server: 127.0.0.1:10020
self.num_replicas = 2 self.num_replicas = 2
def tearDown(self): def tearDown(self):
# Delete tmp file NeoTestBase.tearDown(self)
os.remove(self.tmp_path)
# Common methods # Common methods
def getLastUUID(self): def getLastUUID(self):
......
...@@ -21,31 +21,18 @@ import logging ...@@ -21,31 +21,18 @@ import logging
import MySQLdb import MySQLdb
from mock import Mock from mock import Mock
from neo.protocol import * from neo.protocol import *
from neo.tests.base import NeoTestBase
from neo.exception import DatabaseFailure from neo.exception import DatabaseFailure
from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64 from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64
SQL_ADMIN_USER = 'root' NEO_SQL_DATABASE = 'test_mysqldb_1'
SQL_ADMIN_PASSWORD = None
NEO_SQL_USER = 'test' NEO_SQL_USER = 'test'
NEO_SQL_DATABASE = 'test_storage_neo1'
class StorageMySQSLdbTests(unittest.TestCase): class StorageMySQSLdbTests(NeoTestBase):
def setUp(self): def setUp(self):
logging.basicConfig(level = logging.ERROR) logging.basicConfig(level = logging.ERROR)
# SQL connection self.prepareDatabase(number=1, prefix=NEO_SQL_DATABASE[:-1])
connect_arg_dict = {'user': SQL_ADMIN_USER}
if SQL_ADMIN_PASSWORD is not None:
connect_arg_dict['passwd'] = SQL_ADMIN_PASSWORD
sql_connection = MySQLdb.Connect(**connect_arg_dict)
cursor = sql_connection.cursor()
# new database
cursor.execute('DROP DATABASE IF EXISTS %s' % (NEO_SQL_DATABASE, ))
cursor.execute('CREATE DATABASE %s' % (NEO_SQL_DATABASE, ))
cursor.execute('GRANT ALL ON %s.* TO "%s"@"localhost" IDENTIFIED BY ""' %
(NEO_SQL_DATABASE, NEO_SQL_USER))
cursor.close()
sql_connection.close()
# db manager # db manager
self.db = MySQLDatabaseManager( self.db = MySQLDatabaseManager(
database=NEO_SQL_DATABASE, database=NEO_SQL_DATABASE,
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
import os import os
import unittest import unittest
import logging import logging
import MySQLdb
from tempfile import mkstemp
from struct import pack, unpack from struct import pack, unpack
from mock import Mock from mock import Mock
from collections import deque from collections import deque
...@@ -32,11 +30,6 @@ from neo.pt import PartitionTable ...@@ -32,11 +30,6 @@ from neo.pt import PartitionTable
from neo import protocol from neo import protocol
from neo.protocol import * from neo.protocol import *
SQL_ADMIN_USER = 'root'
SQL_ADMIN_PASSWORD = None
NEO_SQL_USER = 'test'
NEO_SQL_DATABASE = 'test_storage_neo1'
class StorageOperationTests(NeoTestBase): class StorageOperationTests(NeoTestBase):
def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs): def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs):
...@@ -51,49 +44,10 @@ class StorageOperationTests(NeoTestBase): ...@@ -51,49 +44,10 @@ class StorageOperationTests(NeoTestBase):
def setUp(self): def setUp(self):
logging.basicConfig(level = logging.ERROR) logging.basicConfig(level = logging.ERROR)
self.prepareDatabase(number=1)
# create an application object # create an application object
config_file_text = """# Default parameters. config = self.getConfigFile(master_number=1)
[DEFAULT] self.app = Application(config, "storage1")
# The list of master nodes.
master_nodes: 127.0.0.1:10010
# The number of replicas.
replicas: 2
# The number of partitions.
partitions: 1009
# The name of this cluster.
name: main
# The user name for the database.
user: %(user)s
connector : SocketConnector
# The first master.
[mastertest]
server: 127.0.0.1:10010
[storagetest]
database: %(database)s
server: 127.0.0.1:10020
""" % {
'database': NEO_SQL_DATABASE,
'user': NEO_SQL_USER,
}
# SQL connection
connect_arg_dict = {'user': SQL_ADMIN_USER}
if SQL_ADMIN_PASSWORD is not None:
connect_arg_dict['passwd'] = SQL_ADMIN_PASSWORD
sql_connection = MySQLdb.Connect(**connect_arg_dict)
cursor = sql_connection.cursor()
# new database
cursor.execute('DROP DATABASE IF EXISTS %s' % (NEO_SQL_DATABASE, ))
cursor.execute('CREATE DATABASE %s' % (NEO_SQL_DATABASE, ))
cursor.execute('GRANT ALL ON %s.* TO "%s"@"localhost" IDENTIFIED BY ""' %
(NEO_SQL_DATABASE, NEO_SQL_USER))
# config file
tmp_id, self.tmp_path = mkstemp()
tmp_file = os.fdopen(tmp_id, "w+b")
tmp_file.write(config_file_text)
tmp_file.close()
# main application
self.app = Application(self.tmp_path, "storagetest")
self.app.num_partitions = 1 self.app.num_partitions = 1
self.app.num_replicas = 1 self.app.num_replicas = 1
self.app.transaction_dict = {} self.app.transaction_dict = {}
...@@ -113,7 +67,7 @@ server: 127.0.0.1:10020 ...@@ -113,7 +67,7 @@ server: 127.0.0.1:10020
self.master_port = 10010 self.master_port = 10010
def tearDown(self): def tearDown(self):
os.remove(self.tmp_path) NeoTestBase.tearDown(self)
def test_01_TransactionInformation(self): def test_01_TransactionInformation(self):
uuid = self.getNewUUID() uuid = self.getNewUUID()
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
import os import os
import unittest import unittest
import logging import logging
import MySQLdb
from tempfile import mkstemp
from mock import Mock from mock import Mock
from neo.tests.base import NeoTestBase from neo.tests.base import NeoTestBase
from neo import protocol from neo import protocol
...@@ -32,67 +30,22 @@ from neo.protocol import BROKEN_STATE, RUNNING_STATE, Packet, INVALID_UUID, \ ...@@ -32,67 +30,22 @@ from neo.protocol import BROKEN_STATE, RUNNING_STATE, Packet, INVALID_UUID, \
UP_TO_DATE_STATE, INVALID_OID, INVALID_TID, PROTOCOL_ERROR_CODE UP_TO_DATE_STATE, INVALID_OID, INVALID_TID, PROTOCOL_ERROR_CODE
from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION, \ from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION, \
NOTIFY_PARTITION_CHANGES, STOP_OPERATION, ASK_LAST_IDS, ASK_PARTITION_TABLE, \ NOTIFY_PARTITION_CHANGES, STOP_OPERATION, ASK_LAST_IDS, ASK_PARTITION_TABLE, \
ANSWER_LAST_IDS, ASK_UNFINISHED_TRANSACTIONS, ANSWER_UNFINISHED_TRANSACTIONS, \
ANSWER_OBJECT_PRESENT, ASK_OBJECT_PRESENT, OID_NOT_FOUND_CODE, LOCK_INFORMATION, \ ANSWER_OBJECT_PRESENT, ASK_OBJECT_PRESENT, OID_NOT_FOUND_CODE, LOCK_INFORMATION, \
UNLOCK_INFORMATION, TID_NOT_FOUND_CODE, ASK_TRANSACTION_INFORMATION, ANSWER_TRANSACTION_INFORMATION, \ UNLOCK_INFORMATION, TID_NOT_FOUND_CODE, ASK_TRANSACTION_INFORMATION, \
ANSWER_PARTITION_TABLE,SEND_PARTITION_TABLE, COMMIT_TRANSACTION COMMIT_TRANSACTION, ASK_UNFINISHED_TRANSACTIONS, SEND_PARTITION_TABLE
from neo.protocol import ERROR, BROKEN_NODE_DISALLOWED_CODE, ASK_PRIMARY_MASTER from neo.protocol import ERROR, BROKEN_NODE_DISALLOWED_CODE, ASK_PRIMARY_MASTER
from neo.protocol import ANSWER_PRIMARY_MASTER from neo.protocol import ANSWER_PRIMARY_MASTER
from neo.exception import PrimaryFailure, OperationFailure from neo.exception import PrimaryFailure, OperationFailure
from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64 from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64
SQL_ADMIN_USER = 'root'
SQL_ADMIN_PASSWORD = None
NEO_SQL_USER = 'test'
NEO_SQL_DATABASE = 'test_storage_neo1'
class StorageVerificationTests(NeoTestBase): class StorageVerificationTests(NeoTestBase):
def setUp(self): def setUp(self):
logging.basicConfig(level = logging.ERROR) logging.basicConfig(level = logging.ERROR)
self.prepareDatabase(number=1)
# create an application object # create an application object
config_file_text = """# Default parameters. config = self.getConfigFile(master_number=1)
[DEFAULT] self.app = Application(config, "storage1")
# The list of master nodes.
master_nodes: 127.0.0.1:10010
# The number of replicas.
replicas: 2
# The number of partitions.
partitions: 1009
# The name of this cluster.
name: main
# The user name for the database.
user: %(user)s
connector : SocketConnector
# The first master.
[mastertest]
server: 127.0.0.1:10010
[storagetest]
database: %(database)s
server: 127.0.0.1:10020
""" % {
'database': NEO_SQL_DATABASE,
'user': NEO_SQL_USER,
}
# SQL connection
connect_arg_dict = {'user': SQL_ADMIN_USER}
if SQL_ADMIN_PASSWORD is not None:
connect_arg_dict['raise NotImplementedErrorwd'] = SQL_ADMIN_PASSWORD
sql_connection = MySQLdb.Connect(**connect_arg_dict)
cursor = sql_connection.cursor()
# new database
cursor.execute('DROP DATABASE IF EXISTS %s' % (NEO_SQL_DATABASE, ))
cursor.execute('CREATE DATABASE %s' % (NEO_SQL_DATABASE, ))
cursor.execute('GRANT ALL ON %s.* TO "%s"@"localhost" IDENTIFIED BY ""' %
(NEO_SQL_DATABASE, NEO_SQL_USER))
cursor.close()
# config file
tmp_id, self.tmp_path = mkstemp()
tmp_file = os.fdopen(tmp_id, "w+b")
tmp_file.write(config_file_text)
tmp_file.close()
self.app = Application(self.tmp_path, "storagetest")
self.verification = VerificationEventHandler(self.app) self.verification = VerificationEventHandler(self.app)
# define some variable to simulate client and storage node # define some variable to simulate client and storage node
self.master_port = 10010 self.master_port = 10010
...@@ -108,8 +61,7 @@ server: 127.0.0.1:10020 ...@@ -108,8 +61,7 @@ server: 127.0.0.1:10020
def tearDown(self): def tearDown(self):
# Delete tmp file NeoTestBase.tearDown(self)
os.remove(self.tmp_path)
# Common methods # Common methods
def getLastUUID(self): def getLastUUID(self):
......
...@@ -15,13 +15,95 @@ ...@@ -15,13 +15,95 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import unittest, os import os
import unittest
import tempfile
import MySQLdb
from mock import Mock from mock import Mock
from neo import protocol from neo import protocol
base_config = """
[DEFAULT]
master_nodes: %(master_nodes)s
replicas: %(replicas)d
partitions: %(partitions)d
name: main
user: %(user)s
connector: SocketConnector
"""
master_config = """
[master%(id)d]
server: 127.0.0.1:1001%(index)d
"""
storage_config = """
[storage%(id)d]
database: %(db)s%(id)d
server: 127.0.0.1:1002%(index)d
"""
DB_PREFIX = 'test_neo_'
DB_ADMIN = 'root'
DB_PASSWD = None
DB_USER = 'test'
class NeoTestBase(unittest.TestCase): class NeoTestBase(unittest.TestCase):
""" Base class for neo tests, implements common checks """ """ Base class for neo tests, implements common checks """
config_file = None
def prepareDatabase(self, number, admin=DB_ADMIN, password=DB_PASSWD,
user=DB_USER, prefix=DB_PREFIX):
""" create empties databases """
# SQL connection
connect_arg_dict = {'user': admin}
if password is not None:
connect_arg_dict['passwd'] = password
sql_connection = MySQLdb.Connect(**connect_arg_dict)
cursor = sql_connection.cursor()
# drop and create each database
for i in xrange(number):
database = "%s%d" % (prefix, i+1)
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 ""' %
(database, user))
cursor.close()
sql_connection.close()
def getConfigFile(self, master_number=2, storage_number=2, user=DB_USER,
replicas=2, partitions=1009, database=DB_PREFIX):
# if already called
if self.config_file is not None:
os.remove(self.config_file)
# global config
master_nodes = ''
for i in xrange(master_number):
master_nodes += '127.0.0.1:1001%d ' % i
config = base_config % {
'master_nodes': master_nodes,
'replicas': replicas,
'partitions': partitions,
'user':user,
}
# append masters
for i in xrange(master_number):
config += master_config % {'index':i, 'id':i+1}
# and storages
for i in xrange(storage_number):
config += storage_config % { 'index':i, 'id':i+1, 'db':database}
tmp_id, self.config_file = tempfile.mkstemp()
tmp_file = os.fdopen(tmp_id, "w+b")
tmp_file.write(config)
tmp_file.close()
return self.config_file
def tearDown(self):
if self.config_file is not None:
os.remove(self.config_file)
# XXX: according to changes with namespaced UUIDs, it would be better to # XXX: according to changes with namespaced UUIDs, it would be better to
# implement get<NodeType>UUID() methods # implement get<NodeType>UUID() methods
def getNewUUID(self): def getNewUUID(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