Commit 7e30718b authored by Grégory Wisniewski's avatar Grégory Wisniewski

Factorise test cases.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1424 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent f19d345d
...@@ -293,14 +293,12 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -293,14 +293,12 @@ class MasterClientHandlerTests(NeoTestBase):
tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0] tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0]
self.assertEqual(len(tid_list), 3) self.assertEqual(len(tid_list), 3)
def __testWithMethod(self, method, state):
def test_15_peerBroken(self):
service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
# add a second storage node and then declare it as broken # add a second storage node and then declare it as broken
self.identifyToMasterNode(port = self.storage_port+2) self.identifyToMasterNode(port = self.storage_port+2)
storage_uuid = self.identifyToMasterNode(port = self.storage_port+1) storage_uuid = self.identifyToMasterNode(port = self.storage_port+1)
# filled the pt # fill the pt
self.app.pt.make(self.app.nm.getStorageList()) self.app.pt.make(self.app.nm.getStorageList())
self.assertTrue(self.app.pt.filled()) self.assertTrue(self.app.pt.filled())
self.assertTrue(self.app.pt.operational()) self.assertTrue(self.app.pt.operational())
...@@ -308,16 +306,16 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -308,16 +306,16 @@ class MasterClientHandlerTests(NeoTestBase):
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.RUNNING) NodeStates.RUNNING)
service.peerBroken(conn) # call the method
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), method(conn)
NodeStates.BROKEN) self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), state)
self.failUnless(lptid < self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give an uuid, must raise as no other storage node available # give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.peerBroken, conn) self.assertRaises(OperationFailure, method, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.BROKEN) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), state)
self.failUnless(lptid < self.app.pt.getID()) self.failUnless(lptid < self.app.pt.getID())
# give a client uuid which have unfinished transactions # give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
...@@ -325,107 +323,28 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -325,107 +323,28 @@ class MasterClientHandlerTests(NeoTestBase):
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
packet = AskBeginTransaction() packet = AskBeginTransaction()
service.askBeginTransaction(conn, packet) self.service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet) self.service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet) self.service.askBeginTransaction(conn, packet)
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(), self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING) NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.peerBroken(conn) method(conn)
# node must be have been remove, and no more transaction must remains # node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None) self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0)
def test_15_peerBroken(self):
self.__testWithMethod(self.service.peerBroken, NodeStates.BROKEN)
def test_16_timeoutExpired(self): def test_16_timeoutExpired(self):
service = self.service self.__testWithMethod(self.service.timeoutExpired,
uuid = self.identifyToMasterNode()
# add a second storage node and then declare it as temp down
self.identifyToMasterNode(port = self.storage_port+2)
storage_uuid = self.identifyToMasterNode(port = self.storage_port+1)
# filled the pt
self.app.pt.make(self.app.nm.getStorageList())
self.assertTrue(self.app.pt.filled())
self.assertTrue(self.app.pt.operational())
conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1))
lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.RUNNING)
service.timeoutExpired(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.TEMPORARILY_DOWN) NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
# give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.timeoutExpired, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
# give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
port = self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID()
packet = AskBeginTransaction()
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.timeoutExpired(conn)
# node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0)
def test_17_connectionClosed(self): def test_17_connectionClosed(self):
service = self.service self.__testWithMethod(self.service.connectionClosed,
uuid = self.identifyToMasterNode() NodeStates.TEMPORARILY_DOWN)
# add a second storage node and then declare it as temp down
self.identifyToMasterNode(port = self.storage_port+2)
storage_uuid = self.identifyToMasterNode(port = self.storage_port+1)
# filled the pt
self.app.pt.make(self.app.nm.getStorageList())
self.assertTrue(self.app.pt.filled())
self.assertTrue(self.app.pt.operational())
conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1))
lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.RUNNING)
service.connectionClosed(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
# give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.connectionClosed, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
# give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
port = self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID()
packet = AskBeginTransaction()
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.connectionClosed(conn)
# node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0)
if __name__ == '__main__': if __name__ == '__main__':
......
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