Commit 912e0a4d authored by Grégory Wisniewski's avatar Grégory Wisniewski

Fix bad indentation in tests modules.


git-svn-id: https://svn.erp5.org/repos/neo/trunk@1345 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent e3926ad4
...@@ -309,50 +309,45 @@ class NeoTestBase(unittest.TestCase): ...@@ -309,50 +309,45 @@ class NeoTestBase(unittest.TestCase):
connector_cpt = 0 connector_cpt = 0
class DoNothingConnector(Mock): class DoNothingConnector(Mock):
def __init__(self, s=None): def __init__(self, s=None):
logging.info("initializing connector") logging.info("initializing connector")
self.desc = globals()['connector_cpt'] self.desc = globals()['connector_cpt']
globals()['connector_cpt'] = globals()['connector_cpt']+ 1 globals()['connector_cpt'] = globals()['connector_cpt']+ 1
self.packet_cpt = 0 self.packet_cpt = 0
Mock.__init__(self) Mock.__init__(self)
def getAddress(self): def getAddress(self):
return self.addr return self.addr
def makeClientConnection(self, addr):
self.addr = addr
def getDescriptor(self): def makeClientConnection(self, addr):
return self.desc self.addr = addr
def getDescriptor(self):
return self.desc
class TestElectionConnector(DoNothingConnector): class TestElectionConnector(DoNothingConnector):
def receive(self):
""" simulate behavior of election """ def receive(self):
if self.packet_cpt == 0: """ simulate behavior of election """
# first : identify if self.packet_cpt == 0:
logging.info("in patched analyse / IDENTIFICATION") # first : identify
p = protocol.Packet() logging.info("in patched analyse / IDENTIFICATION")
self.uuid = getNewUUID() p = protocol.Packet()
p.acceptNodeIdentification(1, self.uuid = getNewUUID()
NodeType.MASTER, p.acceptNodeIdentification(1, NodeType.MASTER, self.uuid,
self.uuid, self.getAddress()[0], self.getAddress()[1], 1009, 2)
self.getAddress()[0], self.packet_cpt += 1
self.getAddress()[1], return p.encode()
1009, elif self.packet_cpt == 1:
2 # second : answer primary master nodes
) logging.info("in patched analyse / ANSWER PM")
self.packet_cpt += 1 p = protocol.Packet()
return p.encode() p.answerPrimaryMaster(2, protocol.INVALID_UUID, [])
elif self.packet_cpt == 1: self.packet_cpt += 1
# second : answer primary master nodes return p.encode()
logging.info("in patched analyse / ANSWER PM") else:
p = protocol.Packet() # then do nothing
p.answerPrimaryMaster(2, protocol.INVALID_UUID, []) from neo.connector import ConnectorTryAgainException
self.packet_cpt += 1 raise ConnectorTryAgainException
return p.encode()
else:
# then do nothing
from neo.connector import ConnectorTryAgainException
raise ConnectorTryAgainException
...@@ -47,7 +47,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -47,7 +47,7 @@ class ClientHandlerTests(NeoTestBase):
'unlock': None}) 'unlock': None})
def getDispatcher(self, queue=None): def getDispatcher(self, queue=None):
return Mock({'getQueue': queue, 'connectToPrimaryMasterNode': None}) return Mock({'getQueue': queue, 'connectToPrimaryMasterNode': None})
def buildHandler(self, handler_class, app, dispatcher): def buildHandler(self, handler_class, app, dispatcher):
# some handlers do not accept the second argument # some handlers do not accept the second argument
......
...@@ -296,13 +296,12 @@ class NEOCluster(object): ...@@ -296,13 +296,12 @@ class NEOCluster(object):
for master in self.getMasterProcessList(): for master in self.getMasterProcessList():
master_uuid = master.getUUID() master_uuid = master.getUUID()
is_primary = master_uuid == primary_uuid is_primary = master_uuid == primary_uuid
if primary and is_primary or \ if primary and is_primary or not (primary or is_primary):
not (primary or is_primary): killed_uuid_list.append(master_uuid)
killed_uuid_list.append(master_uuid) master.kill()
master.kill() master.wait()
master.wait() if not all:
if not all: break
break
return killed_uuid_list return killed_uuid_list
def killPrimaryMaster(self): def killPrimaryMaster(self):
...@@ -367,7 +366,7 @@ class NEOCluster(object): ...@@ -367,7 +366,7 @@ class NEOCluster(object):
opaque_history.append(opaque) opaque_history.append(opaque)
time.sleep(delay) time.sleep(delay)
else: else:
raise AssertionError, 'Timeout while expecting condition. ' \ raise AssertionError, 'Timeout while expecting condition. ' \
'History: %s' % (opaque_history, ) 'History: %s' % (opaque_history, )
def expectAllMasters(self, node_count, state=None, timeout=0, delay=1): def expectAllMasters(self, node_count, state=None, timeout=0, delay=1):
......
...@@ -33,99 +33,99 @@ class MasterAppTests(NeoTestBase): ...@@ -33,99 +33,99 @@ class MasterAppTests(NeoTestBase):
NeoTestBase.tearDown(self) NeoTestBase.tearDown(self)
def test_02_getNextOID(self): def test_02_getNextOID(self):
# must raise as we don"t have one # must raise as we don"t have one
self.assertEqual(self.app.loid, None) self.assertEqual(self.app.loid, None)
self.app.loid = None self.app.loid = None
self.assertRaises(RuntimeError, self.app.getNextOID) self.assertRaises(RuntimeError, self.app.getNextOID)
# set one # set one
self.app.loid = p64(23) self.app.loid = p64(23)
noid = self.app.getNextOID() noid = self.app.getNextOID()
self.assertEqual(self.app.loid, noid) self.assertEqual(self.app.loid, noid)
self.failUnless(u64(self.app.loid) > 23) self.failUnless(u64(self.app.loid) > 23)
self.assertEqual(u64(self.app.loid), 24) self.assertEqual(u64(self.app.loid), 24)
def test_03_getNextTID(self): def test_03_getNextTID(self):
self.assertEqual(self.app.ltid, None) self.assertEqual(self.app.ltid, None)
ntid = self.app.getNextTID() ntid = self.app.getNextTID()
self.assertEqual(self.app.ltid, ntid) self.assertEqual(self.app.ltid, ntid)
# generate new one # generate new one
tid = self.app.getNextTID() tid = self.app.getNextTID()
self.assertEqual(self.app.ltid, tid) self.assertEqual(self.app.ltid, tid)
self.failUnless(tid > ntid) self.failUnless(tid > ntid)
def test_04_getPartition(self): def test_04_getPartition(self):
self.app.pt.num_partitions = 3 self.app.pt.num_partitions = 3
p = self.app.getPartition(p64(1)) p = self.app.getPartition(p64(1))
self.assertEqual(p, 1) self.assertEqual(p, 1)
p = self.app.getPartition(p64(2)) p = self.app.getPartition(p64(2))
self.assertEqual(p, 2) self.assertEqual(p, 2)
p = self.app.getPartition(p64(1009)) # 1009 defined in config p = self.app.getPartition(p64(1009)) # 1009 defined in config
self.assertEqual(p, 0) self.assertEqual(p, 0)
def test_05_getNewOIDList(self): def test_05_getNewOIDList(self):
self.app.loid = p64(1) self.app.loid = p64(1)
oid_list = self.app.getNewOIDList(15) oid_list = self.app.getNewOIDList(15)
self.assertEqual(len(oid_list), 15) self.assertEqual(len(oid_list), 15)
i = 2 i = 2
# begin from 0, so generated oid from 1 to 15 # begin from 0, so generated oid from 1 to 15
for oid in oid_list: for oid in oid_list:
self.assertEqual(u64(oid), i) self.assertEqual(u64(oid), i)
i+=1 i+=1
def test_06_broadcastNodeInformation(self): def test_06_broadcastNodeInformation(self):
# defined some nodes to which data will be send # defined some nodes to which data will be send
master_uuid = self.getNewUUID() master_uuid = self.getNewUUID()
self.app.nm.createMaster(uuid=master_uuid) self.app.nm.createMaster(uuid=master_uuid)
storage_uuid = self.getNewUUID() storage_uuid = self.getNewUUID()
storage = self.app.nm.createStorage(uuid=storage_uuid) storage = self.app.nm.createStorage(uuid=storage_uuid)
client_uuid = self.getNewUUID() client_uuid = self.getNewUUID()
client = self.app.nm.createClient(uuid=client_uuid) client = self.app.nm.createClient(uuid=client_uuid)
self.app.nm.add(storage) self.app.nm.add(storage)
self.app.nm.add(client) self.app.nm.add(client)
# create conn and patch em # create conn and patch em
master_conn = Mock({"getUUID" : master_uuid}) master_conn = Mock({"getUUID" : master_uuid})
storage_conn = Mock({"getUUID" : storage_uuid}) storage_conn = Mock({"getUUID" : storage_uuid})
client_conn = Mock({"getUUID" : client_uuid}) client_conn = Mock({"getUUID" : client_uuid})
self.app.em = Mock({"getConnectionList" : (master_conn, storage_conn, client_conn)}) self.app.em = Mock({"getConnectionList" : (master_conn, storage_conn, client_conn)})
# no address defined, not send to client node # no address defined, not send to client node
c_node = self.app.nm.createClient(uuid = self.getNewUUID()) c_node = self.app.nm.createClient(uuid = self.getNewUUID())
self.app.broadcastNodeInformation(c_node) self.app.broadcastNodeInformation(c_node)
# check conn # check conn
self.checkNoPacketSent(client_conn) self.checkNoPacketSent(client_conn)
self.checkNotifyNodeInformation(master_conn) self.checkNotifyNodeInformation(master_conn)
self.checkNotifyNodeInformation(storage_conn) self.checkNotifyNodeInformation(storage_conn)
# address defined and client type # address defined and client type
master_conn = Mock({"getUUID" : master_uuid}) master_conn = Mock({"getUUID" : master_uuid})
storage_conn = Mock({"getUUID" : storage_uuid}) storage_conn = Mock({"getUUID" : storage_uuid})
client_conn = Mock({"getUUID" : client_uuid}) client_conn = Mock({"getUUID" : client_uuid})
self.app.em = Mock({"getConnectionList" : (master_conn, storage_conn, client_conn)}) self.app.em = Mock({"getConnectionList" : (master_conn, storage_conn, client_conn)})
s_node = self.app.nm.createClient( s_node = self.app.nm.createClient(
uuid = self.getNewUUID(), uuid = self.getNewUUID(),
address=("127.1.0.1", 3361) address=("127.1.0.1", 3361)
) )
self.app.broadcastNodeInformation(c_node) self.app.broadcastNodeInformation(c_node)
# check conn # check conn
self.checkNoPacketSent(client_conn) self.checkNoPacketSent(client_conn)
self.checkNotifyNodeInformation(master_conn) self.checkNotifyNodeInformation(master_conn)
self.checkNotifyNodeInformation(storage_conn) self.checkNotifyNodeInformation(storage_conn)
# address defined and storage type # address defined and storage type
master_conn = Mock({"getUUID" : master_uuid}) master_conn = Mock({"getUUID" : master_uuid})
storage_conn = Mock({"getUUID" : storage_uuid}) storage_conn = Mock({"getUUID" : storage_uuid})
client_conn = Mock({"getUUID" : client_uuid}) client_conn = Mock({"getUUID" : client_uuid})
self.app.em = Mock({"getConnectionList" : (master_conn, storage_conn, client_conn)}) self.app.em = Mock({"getConnectionList" : (master_conn, storage_conn, client_conn)})
s_node = self.app.nm.createStorage( s_node = self.app.nm.createStorage(
uuid=self.getNewUUID(), uuid=self.getNewUUID(),
address=("127.0.0.1", 1351) address=("127.0.0.1", 1351)
) )
self.app.broadcastNodeInformation(s_node) self.app.broadcastNodeInformation(s_node)
# check conn # check conn
self.checkNotifyNodeInformation(client_conn) self.checkNotifyNodeInformation(client_conn)
self.checkNotifyNodeInformation(master_conn) self.checkNotifyNodeInformation(master_conn)
self.checkNotifyNodeInformation(storage_conn) self.checkNotifyNodeInformation(storage_conn)
if __name__ == '__main__': if __name__ == '__main__':
......
This diff is collapsed.
This diff is collapsed.
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