Commit 4336dacb authored by Grégory Wisniewski's avatar Grégory Wisniewski

Update master/service.py tests for using getFakeConnection()


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@545 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 6ec521d6
......@@ -26,24 +26,11 @@ from neo import protocol
from neo.protocol import Packet, INVALID_UUID
from neo.master.service import ServiceEventHandler
from neo.master.app import Application
from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \
PING, PONG, ASK_PRIMARY_MASTER, ANSWER_PRIMARY_MASTER, ANNOUNCE_PRIMARY_MASTER, \
REELECT_PRIMARY_MASTER, NOTIFY_NODE_INFORMATION, START_OPERATION, \
STOP_OPERATION, ASK_LAST_IDS, ANSWER_LAST_IDS, ASK_PARTITION_TABLE, \
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, \
from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \
REELECT_PRIMARY_MASTER, NOTIFY_NODE_INFORMATION, \
ASK_LAST_IDS, ANSWER_LAST_IDS, NOTIFY_PARTITION_CHANGES, \
ASK_UNFINISHED_TRANSACTIONS, ASK_NEW_TID, FINISH_TRANSACTION, \
NOTIFY_INFORMATION_LOCKED, ASK_NEW_OIDS, ABORT_TRANSACTION, \
STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, MASTER_NODE_TYPE, \
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
......@@ -112,6 +99,9 @@ server: 127.0.0.1:10023
self.client_port = 11022
self.storage_port = 10021
self.master_port = 10010
self.master_address = ('127.0.0.1', self.master_port)
self.client_address = ('127.0.0.1', self.client_port)
self.storage_address = ('127.0.0.1', self.storage_port)
def tearDown(self):
# Delete tmp file
......@@ -128,7 +118,7 @@ server: 127.0.0.1:10023
args = (node_type, uuid, ip, port, self.app.name)
packet = protocol.requestNodeIdentification(*args)
# test alien cluster
conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None})
conn = self.getFakeConnection()
self.service.handleRequestNodeIdentification(conn, packet, *args)
self.checkAcceptNodeIdentification(conn, answered_packet=packet)
return uuid
......@@ -140,14 +130,14 @@ server: 127.0.0.1:10023
args = (STORAGE_NODE_TYPE, uuid, '127.0.0.1', self.storage_port, 'INVALID_NAME')
packet = protocol.requestNodeIdentification(*args)
# test alien cluster
conn = Mock({"_addPacket" : None, "abort" : None})
conn = self.getFakeConnection()
ptid = self.app.lptid
self.checkProtocolErrorRaised(service.handleRequestNodeIdentification, conn, packet, *args)
self.assertEquals(len(self.app.nm.getStorageNodeList()), 0)
self.assertEquals(self.app.lptid, ptid)
# test connection of a storage node
conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None})
conn = self.getFakeConnection()
ptid = self.app.lptid
service.handleRequestNodeIdentification(conn,
packet=packet,
......@@ -165,7 +155,7 @@ server: 127.0.0.1:10023
self.failUnless(self.app.lptid > ptid)
# send message again for the same storage node, MN must recognize it
conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None})
conn = self.getFakeConnection()
ptid = self.app.lptid
service.handleRequestNodeIdentification(conn,
packet=packet,
......@@ -184,7 +174,7 @@ server: 127.0.0.1:10023
# send message again for the same storage node but different uuid
# must be rejected as SN is considered as running
conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None})
conn = self.getFakeConnection()
ptid = self.app.lptid
new_uuid = self.getNewUUID()
......@@ -206,7 +196,7 @@ server: 127.0.0.1:10023
# same test, but set SN as not running before
# this new node must replaced the old one
conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None})
conn = self.getFakeConnection()
ptid = self.app.lptid
sn = self.app.nm.getStorageNodeList()[0]
self.assertEquals(sn.getState(), RUNNING_STATE)
......@@ -232,7 +222,7 @@ server: 127.0.0.1:10023
# send message again for the same storage node but different address
# A new UUID should be send and the node is added to the storage node list
conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None})
conn = self.getFakeConnection()
ptid = self.app.lptid
service.handleRequestNodeIdentification(conn,
packet=packet,
......@@ -258,7 +248,7 @@ server: 127.0.0.1:10023
self.failUnless(self.app.lptid > ptid)
# mark the node as broken and request identification, this must be forbidden
conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None})
conn = self.getFakeConnection()
ptid = self.app.lptid
sn = self.app.nm.getStorageNodeList()[0]
self.assertEquals(sn.getState(), RUNNING_STATE)
......@@ -288,14 +278,9 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode()
packet = protocol.askPrimaryMaster()
# test answer to a storage node
conn = Mock({"_addPacket" : None,
"answerPrimaryMaster" : None,
"notifyNodeInformation" : None,
"sendPartitionTable" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
service.handleAskPrimaryMaster(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.checkNotAborted(conn)
self.checkAnswerPrimaryMaster(conn, answered_packet=packet)
self.checkNotifyNodeInformation(conn, packet_number=0)
self.checkSendPartitionTable(conn, packet_number=1)
......@@ -305,11 +290,9 @@ server: 127.0.0.1:10023
# Same but identify as a client node, must not get start operation message
uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=11021)
packet = protocol.askPrimaryMaster()
conn = Mock({"_addPacket" : None, "abort" : None, "answerPrimaryMaster" : None,
"notifyNodeInformation" : None, "sendPartitionTable" : None,
"getUUID" : uuid, "getAddress" : ("127.0.0.1", 11021)})
conn = self.getFakeConnection(uuid, ("127.0.0.1", 11021))
service.handleAskPrimaryMaster(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.checkNotAborted(conn)
self.checkAnswerPrimaryMaster(conn, answered_packet=packet)
self.checkNotifyNodeInformation(conn, packet_number=0)
self.checkSendPartitionTable(conn, packet_number=1)
......@@ -319,13 +302,11 @@ server: 127.0.0.1:10023
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ANNOUNCE_PRIMARY_MASTER)
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
# must do a relection
self.assertRaises(ElectionFailure, service.handleAnnouncePrimaryMaster, conn, packet)
# if no uuid in conn, no reelection done
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
self.checkIdenficationRequired(service.handleAnnouncePrimaryMaster, conn, packet)
......@@ -333,8 +314,7 @@ server: 127.0.0.1:10023
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=REELECT_PRIMARY_MASTER)
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
# must do a relection
self.assertRaises(ElectionFailure, service.handleReelectPrimaryMaster, conn, packet)
......@@ -344,56 +324,48 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
node_list = []
self.checkIdenficationRequired(service.handleNotifyNodeInformation, conn, packet, node_list)
# tell the master node that is not running any longer, it must raises
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port, self.app.uuid, DOWN_STATE),]
self.assertRaises(RuntimeError, service.handleNotifyNodeInformation, conn, packet, node_list)
# tell the master node that it's running, nothing change
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port, self.app.uuid, RUNNING_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID")
# notify about a client node, don't care
new_uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(CLIENT_NODE_TYPE, '127.0.0.1', self.client_port, new_uuid, BROKEN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID")
# notify about an unknown node, don't care
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', 11010, new_uuid, BROKEN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID")
# notify about a known node but with bad address, don't care
self.app.nm.add(StorageNode(("127.0.0.1", 11011), self.getNewUUID()))
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', 11012, uuid, BROKEN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID")
# notify node is running, as PMN already know it, nothing is done
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', self.storage_port, uuid, RUNNING_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID")
# notify node is temp down, must be taken into account
ptid = self.app.lptid
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', self.storage_port, uuid, TEMPORARILY_DOWN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls():
......@@ -402,8 +374,7 @@ server: 127.0.0.1:10023
self.assertEquals(sn.getState(), TEMPORARILY_DOWN_STATE)
self.assertEquals(ptid, self.app.lptid)
# notify node is broken, must be taken into account and partition must changed
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', self.storage_port, uuid, BROKEN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls():
......@@ -420,8 +391,7 @@ server: 127.0.0.1:10023
ltid = self.app.ltid
lptid = self.app.lptid
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
node_list = []
self.checkIdenficationRequired(service.handleAnswerLastIDs, conn, packet, None, None, None)
self.assertEquals(loid, self.app.loid)
......@@ -429,16 +399,14 @@ server: 127.0.0.1:10023
self.assertEquals(lptid, self.app.lptid)
# do not care if client node call it
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=self.client_port)
conn = Mock({"getUUID" : client_uuid,
"getAddress" : ("127.0.0.1", self.client_port)})
conn = self.getFakeConnection(client_uuid, self.client_address)
node_list = []
self.checkUnexpectedPacketRaised(service.handleAnswerLastIDs, conn, packet, None, None, None)
self.assertEquals(loid, self.app.loid)
self.assertEquals(ltid, self.app.ltid)
self.assertEquals(lptid, self.app.lptid)
# send information which are later to what PMN knows, this must raise
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = []
new_ptid = unpack('!Q', lptid)[0]
new_ptid = pack('!Q', new_ptid + 1)
......@@ -455,21 +423,18 @@ server: 127.0.0.1:10023
packet = Packet(msg_type=ASK_NEW_TID)
ltid = self.app.ltid
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
node_list = []
self.checkIdenficationRequired(service.handleAskNewTID, conn, packet)
self.assertEquals(ltid, self.app.ltid)
# do not care if storage node call it
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = []
self.checkUnexpectedPacketRaised(service.handleAskNewTID, conn, packet)
self.assertEquals(ltid, self.app.ltid)
# client call it
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=self.client_port)
conn = Mock({"getUUID" : client_uuid,
"getAddress" : ("127.0.0.1", self.client_port)})
conn = self.getFakeConnection(client_uuid, self.client_address)
service.handleAskNewTID(conn, packet)
self.failUnless(ltid < self.app.ltid)
self.assertEquals(len(self.app.finishing_transaction_dict), 1)
......@@ -483,21 +448,18 @@ server: 127.0.0.1:10023
packet = Packet(msg_type=ASK_NEW_OIDS)
loid = self.app.loid
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
node_list = []
self.checkIdenficationRequired(service.handleAskNewOIDs, conn, packet, 1)
self.assertEquals(loid, self.app.loid)
# do not care if storage node call it
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = []
self.checkUnexpectedPacketRaised(service.handleAskNewOIDs, conn, packet, 1)
self.assertEquals(loid, self.app.loid)
# client call it
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=self.client_port)
conn = Mock({"getUUID" : client_uuid,
"getAddress" : ("127.0.0.1", self.client_port)})
conn = self.getFakeConnection(client_uuid, self.client_address)
service.handleAskNewOIDs(conn, packet, 1)
self.failUnless(loid < self.app.loid)
......@@ -507,20 +469,16 @@ server: 127.0.0.1:10023
packet = Packet(msg_type=FINISH_TRANSACTION)
packet.setId(9)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
node_list = []
self.checkIdenficationRequired(service.handleFinishTransaction, conn, packet, [], None, )
# do not care if storage node call it
storage_conn = conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port),
"getSockect" : uuid})
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = []
self.checkUnexpectedPacketRaised(service.handleFinishTransaction, conn, packet, [], None)
# give an older tid than the PMN known, must abort
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=self.client_port)
conn = Mock({"getUUID" : client_uuid,
"getAddress" : ("127.0.0.1", self.client_port)})
conn = self.getFakeConnection(client_uuid, self.client_address)
oid_list = []
upper, lower = unpack('!LL', self.app.ltid)
new_tid = pack('!LL', upper, lower + 10)
......@@ -532,22 +490,16 @@ server: 127.0.0.1:10023
# do the right job
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=self.client_port)
storage_uuid = self.identifyToMasterNode()
storage_conn = Mock({"getUUID" : storage_uuid,
"getAddress" : ("127.0.0.1", self.storage_port),
"getSockect" : 50,
"getDescriptor" : 50})
storage_conn = self.getFakeConnection(storage_uuid, self.storage_address)
self.assertNotEquals(uuid, client_uuid)
conn = Mock({"getUUID" : client_uuid,
"getAddress" : ("127.0.0.1", self.client_port)})
conn = self.getFakeConnection(client_uuid, self.client_address)
service.handleAskNewTID(conn, packet)
oid_list = []
tid = self.app.ltid
conn = Mock({"getUUID" : client_uuid,
"getAddress" : ("127.0.0.1", self.client_port)})
conn = self.getFakeConnection(client_uuid, self.client_address)
self.app.em = Mock({"getConnectionList" : [conn, storage_conn]})
service.handleFinishTransaction(conn, packet, oid_list, tid)
self.checkLockInformation(storage_conn)
self.assertEquals(len(storage_conn.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(self.app.finishing_transaction_dict), 1)
apptid = self.app.finishing_transaction_dict.keys()[0]
self.assertEquals(tid, apptid)
......@@ -561,19 +513,15 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode(port=10020)
packet = Packet(msg_type=NOTIFY_INFORMATION_LOCKED)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
node_list = []
self.checkIdenficationRequired(service.handleNotifyInformationLocked, conn, packet, None, )
# do not care if client node call it
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=11021)
client = conn = Mock({"getUUID" : client_uuid,
"getAddress" : ("127.0.0.1", 11020),
"getSockect" : client_uuid})
client = self.getFakeConnection(client_uuid, ('127.0.0.1', 11020))
self.checkUnexpectedPacketRaised(service.handleNotifyInformationLocked, conn, packet, None)
# give an older tid than the PMN known, must abort
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
oid_list = []
upper, lower = unpack('!LL', self.app.ltid)
new_tid = pack('!LL', upper, lower + 10)
......@@ -587,18 +535,9 @@ server: 127.0.0.1:10023
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=self.client_port)
storage_uuid_1 = self.identifyToMasterNode()
storage_uuid_2 = self.identifyToMasterNode(port=10022)
storage_conn_1 = Mock({"getUUID" : storage_uuid_1,
"getAddress" : ("127.0.0.1", self.storage_port),
"getSockect" : 1,
"getDescriptor" : 1})
storage_conn_2 = Mock({"getUUID" : storage_uuid_2,
"getAddress" : ("127.0.0.1", 10022),
"getSockect" : 2,
"getDescriptor" : 2})
conn = Mock({"getUUID" : client_uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"getSockect" : 3,
"getDescriptor" : 3})
storage_conn_1 = self.getFakeConnection(storage_uuid_1, ("127.0.0.1", self.storage_port))
storage_conn_2 = self.getFakeConnection(storage_uuid_2, ("127.0.0.1", 10022))
conn = self.getFakeConnection(client_uuid, self.client_address)
service.handleAskNewTID(conn, packet)
# clean mock object
conn.mockCalledMethods = {}
......@@ -610,20 +549,12 @@ server: 127.0.0.1:10023
self.checkLockInformation(storage_conn_1)
self.checkLockInformation(storage_conn_2)
self.assertFalse(self.app.finishing_transaction_dict.values()[0].allLocked())
self.assertEquals(len(storage_conn_1.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(storage_conn_2.mockGetNamedCalls("ask")), 1)
service.handleNotifyInformationLocked(storage_conn_1, packet, tid)
self.assertEquals(len(storage_conn_1.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(storage_conn_2.mockGetNamedCalls("ask")), 1)
self.checkLockInformation(storage_conn_1)
self.checkLockInformation(storage_conn_2)
self.assertFalse(self.app.finishing_transaction_dict.values()[0].allLocked())
service.handleNotifyInformationLocked(storage_conn_2, packet, tid)
self.checkNotifyTransactionFinished(conn)
self.assertEquals(len(storage_conn_1.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(storage_conn_1.mockGetNamedCalls("notify")), 1)
self.assertEquals(len(storage_conn_2.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(storage_conn_2.mockGetNamedCalls("notify")), 1)
self.checkLockInformation(storage_conn_1)
self.checkLockInformation(storage_conn_2)
......@@ -633,26 +564,21 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ABORT_TRANSACTION)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
node_list = []
self.checkIdenficationRequired(service.handleAbortTransaction, conn, packet, None, )
# do not answer if not a client
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = []
self.checkUnexpectedPacketRaised(service.handleAbortTransaction, conn, packet, None)
# give a bad tid, must not failed, just ignored it
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=self.client_port)
conn = Mock({"getUUID" : client_uuid,
"getAddress" : ("127.0.0.1", self.client_port)})
conn = self.getFakeConnection(client_uuid, self.client_address)
self.assertEqual(len(self.app.finishing_transaction_dict.keys()), 0)
service.handleAbortTransaction(conn, packet, None)
self.assertEqual(len(self.app.finishing_transaction_dict.keys()), 0)
# give a known tid
conn = Mock({"getUUID" : client_uuid,
"getAddress" : ("127.0.0.1", self.client_port)})
conn = self.getFakeConnection(client_uuid, self.client_address)
tid = self.app.ltid
self.app.finishing_transaction_dict[tid] = None
self.assertEqual(len(self.app.finishing_transaction_dict.keys()), 1)
......@@ -665,12 +591,10 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ASK_LAST_IDS)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
self.checkIdenficationRequired(service.handleAskLastIDs, conn, packet )
# give a uuid
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
ptid = self.app.lptid
tid = self.app.ltid
oid = self.app.loid
......@@ -687,13 +611,11 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ASK_UNFINISHED_TRANSACTIONS)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
self.checkIdenficationRequired(service.handleAskUnfinishedTransactions,
conn, packet)
# give a uuid
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
service.handleAskUnfinishedTransactions(conn, packet)
packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet)
tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0]
......@@ -701,13 +623,11 @@ server: 127.0.0.1:10023
# create some transaction
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE,
port=self.client_port)
conn = Mock({"getUUID" : client_uuid,
"getAddress" : ("127.0.0.1", self.client_port)})
conn = self.getFakeConnection(client_uuid, self.client_address)
service.handleAskNewTID(conn, packet)
service.handleAskNewTID(conn, packet)
service.handleAskNewTID(conn, packet)
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
service.handleAskUnfinishedTransactions(conn, packet)
packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet)
tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0]
......@@ -719,21 +639,18 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
self.checkIdenficationRequired(service.handleNotifyPartitionChanges,
conn, packet, None, None)
# do not answer if not a storage node
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE,
port=self.client_port)
conn = Mock({"getUUID" : client_uuid,
"getAddress" : ("127.0.0.1", self.client_port)})
conn = self.getFakeConnection(client_uuid, self.client_address)
self.checkUnexpectedPacketRaised(service.handleNotifyPartitionChanges,
conn, packet, None, None)
# send a bad state, must not be take into account
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
storage_uuid = self.identifyToMasterNode(port=self.storage_port+1)
offset = 1
cell_list = [(offset, uuid, FEEDING_STATE),]
......@@ -746,8 +663,7 @@ server: 127.0.0.1:10023
self.assertEquals(state, OUT_OF_DATE_STATE)
# send for another node, must not be take into account
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
offset = 1
cell_list = [(offset, storage_uuid, UP_TO_DATE_STATE),]
cells = self.app.pt.getRow(offset)
......@@ -760,8 +676,7 @@ server: 127.0.0.1:10023
# send for itself, must be taken into account
# and the feeding node must be removed
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
cell_list = [(offset, uuid, UP_TO_DATE_STATE),]
cells = self.app.pt.getRow(offset)
for cell, state in cells:
......@@ -791,8 +706,7 @@ server: 127.0.0.1:10023
service = self.service
uuid = self.identifyToMasterNode()
# do nothing if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
self.assertEquals(self.app.nm.getNodeByUUID(uuid).getState(), RUNNING_STATE)
service.peerBroken(conn)
self.assertEquals(self.app.nm.getNodeByUUID(uuid).getState(), RUNNING_STATE)
......@@ -803,16 +717,14 @@ server: 127.0.0.1:10023
self.app.pt.make(self.app.nm.getStorageNodeList())
self.assertTrue(self.app.pt.filled())
self.assertTrue(self.app.pt.operational())
conn = Mock({"getUUID" : storage_uuid,
"getAddress" : ("127.0.0.1", self.storage_port+1)})
conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1))
lptid = self.app.lptid
self.assertEquals(self.app.nm.getNodeByUUID(storage_uuid).getState(), RUNNING_STATE)
service.peerBroken(conn)
self.assertEquals(self.app.nm.getNodeByUUID(storage_uuid).getState(), BROKEN_STATE)
self.failUnless(lptid < self.app.lptid)
# give an uuid, must raise as no other storage node available
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.lptid
self.assertEquals(self.app.nm.getNodeByUUID(uuid).getState(), RUNNING_STATE)
self.assertRaises(OperationFailure, service.peerBroken, conn)
......@@ -821,8 +733,7 @@ server: 127.0.0.1:10023
# give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE,
port = self.client_port)
conn = Mock({"getUUID" : client_uuid,
"getAddress" : ("127.0.0.1", self.client_port)})
conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.lptid
packet = Packet(msg_type=ASK_NEW_TID)
service.handleAskNewTID(conn, packet)
......@@ -841,8 +752,7 @@ server: 127.0.0.1:10023
service = self.service
uuid = self.identifyToMasterNode()
# do nothing if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
self.assertEquals(self.app.nm.getNodeByUUID(uuid).getState(), RUNNING_STATE)
service.timeoutExpired(conn)
self.assertEquals(self.app.nm.getNodeByUUID(uuid).getState(), RUNNING_STATE)
......@@ -853,16 +763,14 @@ server: 127.0.0.1:10023
self.app.pt.make(self.app.nm.getStorageNodeList())
self.assertTrue(self.app.pt.filled())
self.assertTrue(self.app.pt.operational())
conn = Mock({"getUUID" : storage_uuid,
"getAddress" : ("127.0.0.1", self.storage_port+1)})
conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1))
lptid = self.app.lptid
self.assertEquals(self.app.nm.getNodeByUUID(storage_uuid).getState(), RUNNING_STATE)
service.timeoutExpired(conn)
self.assertEquals(self.app.nm.getNodeByUUID(storage_uuid).getState(), TEMPORARILY_DOWN_STATE)
self.assertEquals(lptid, self.app.lptid)
# give an uuid, must raise as no other storage node available
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.lptid
self.assertEquals(self.app.nm.getNodeByUUID(uuid).getState(), RUNNING_STATE)
self.assertRaises(OperationFailure, service.timeoutExpired, conn)
......@@ -871,8 +779,7 @@ server: 127.0.0.1:10023
# give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE,
port = self.client_port)
conn = Mock({"getUUID" : client_uuid,
"getAddress" : ("127.0.0.1", self.client_port)})
conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.lptid
packet = Packet(msg_type=ASK_NEW_TID)
service.handleAskNewTID(conn, packet)
......@@ -891,8 +798,7 @@ server: 127.0.0.1:10023
service = self.service
uuid = self.identifyToMasterNode()
# do nothing if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
self.assertEquals(self.app.nm.getNodeByUUID(uuid).getState(), RUNNING_STATE)
service.connectionClosed(conn)
self.assertEquals(self.app.nm.getNodeByUUID(uuid).getState(), RUNNING_STATE)
......@@ -903,16 +809,14 @@ server: 127.0.0.1:10023
self.app.pt.make(self.app.nm.getStorageNodeList())
self.assertTrue(self.app.pt.filled())
self.assertTrue(self.app.pt.operational())
conn = Mock({"getUUID" : storage_uuid,
"getAddress" : ("127.0.0.1", self.storage_port+1)})
conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1))
lptid = self.app.lptid
self.assertEquals(self.app.nm.getNodeByUUID(storage_uuid).getState(), RUNNING_STATE)
service.connectionClosed(conn)
self.assertEquals(self.app.nm.getNodeByUUID(storage_uuid).getState(), TEMPORARILY_DOWN_STATE)
self.assertEquals(lptid, self.app.lptid)
# give an uuid, must raise as no other storage node available
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.lptid
self.assertEquals(self.app.nm.getNodeByUUID(uuid).getState(), RUNNING_STATE)
self.assertRaises(OperationFailure, service.connectionClosed, conn)
......@@ -921,8 +825,7 @@ server: 127.0.0.1:10023
# give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE,
port = self.client_port)
conn = Mock({"getUUID" : client_uuid,
"getAddress" : ("127.0.0.1", self.client_port)})
conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.lptid
packet = Packet(msg_type=ASK_NEW_TID)
service.handleAskNewTID(conn, packet)
......
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