Commit 6ec521d6 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Remove duplicate check methods, add getFakeConnection() to base test class and

use it in some tests.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@544 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 5e061ed5
......@@ -149,28 +149,7 @@ class ClientApplicationTest(NeoTestBase):
def checkDispatcherRegisterCalled(self, app, conn):
calls = app.dispatcher.mockGetNamedCalls('register')
self.assertEquals(len(calls), 1)
self.assertTrue(calls[0].getParam(0) is conn)
self.assertEquals(calls[0].getParam(2), app.local_var.queue)
def checkPacketSent(self, conn, packet_type, method='_addPacket'):
calls = conn.mockGetNamedCalls(method)
self.assertEquals(len(calls), 1)
packet = calls[0].getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet._type, packet_type)
def checkAsk(self, conn, packet_type):
self.checkPacketSent(conn, packet_type, 'ask')
def checkNotify(self, conn, packet_type):
self.checkPacketSent(conn, packet_type, 'notify')
def checkNoPacketSent(self, conn):
self.assertEquals(len(conn.mockGetNamedCalls('notify')), 0)
self.assertEquals(len(conn.mockGetNamedCalls('answer')), 0)
self.assertEquals(len(conn.mockGetNamedCalls('ask')), 0)
# tests
calls[0].checkArgs(conn, None, app.local_var.queue)
def test_getQueue(self):
app = self.getApp()
......@@ -568,9 +547,9 @@ class ClientApplicationTest(NeoTestBase):
app.local_var.data_dict = {oid1: '', oid2: ''}
app.tpc_abort(txn)
# will check if there was just one call/packet :
self.checkNotify(conn1, ABORT_TRANSACTION)
self.checkNotify(conn2, ABORT_TRANSACTION)
self.checkNotify(app.master_conn, ABORT_TRANSACTION)
self.checkNotifyPacket(conn1, ABORT_TRANSACTION)
self.checkNotifyPacket(conn2, ABORT_TRANSACTION)
self.checkNotifyPacket(app.master_conn, ABORT_TRANSACTION)
self.assertEquals(app.local_var.tid, None)
self.assertEquals(app.local_var.txn, None)
self.assertEquals(app.local_var.data_dict, {})
......
......@@ -566,12 +566,8 @@ class ClientEventHandlerTest(NeoTestBase):
# Check that partition table cell got added
setCell_call_list = app.pt.mockGetNamedCalls('setCell')
self.assertEquals(len(setCell_call_list), 1)
offset = setCell_call_list[0].getParam(0)
node = setCell_call_list[0].getParam(1)
state = setCell_call_list[0].getParam(2)
self.assertEqual(offset, test_row_list[0][0])
self.assertTrue(node is created_node)
self.assertEqual(state, test_row_list[0][1][0][1])
setCell_call_list[0].checkArgs(test_row_list[0][0], created_node,
test_row_list[0][1][0][1])
def test_knownNodeSendPartitionTable(self):
test_node = Mock({'getNodeType': MASTER_NODE_TYPE})
......@@ -592,12 +588,8 @@ class ClientEventHandlerTest(NeoTestBase):
# Check that partition table cell got added
setCell_call_list = app.pt.mockGetNamedCalls('setCell')
self.assertEquals(len(setCell_call_list), 1)
offset = setCell_call_list[0].getParam(0)
node = setCell_call_list[0].getParam(1)
state = setCell_call_list[0].getParam(2)
self.assertEqual(offset, test_row_list[0][0])
self.assertTrue(node is test_node)
self.assertEqual(state, test_row_list[0][1][0][1])
setCell_call_list[0].checkArgs(test_row_list[0][0], test_node,
test_row_list[0][1][0][1])
def test_initialNotifyNodeInformation(self):
client_handler = PrimaryBoostrapEventHandler(None, self.getDispatcher())
......@@ -811,13 +803,8 @@ class ClientEventHandlerTest(NeoTestBase):
# Check that partition got updated
self.assertEqual(app.ptid, test_ptid + 1)
setCell_call_list = app.pt.mockGetNamedCalls('setCell')
self.assertEqual(len(setCell_call_list), 1)
offset = setCell_call_list[0].getParam(0)
node = setCell_call_list[0].getParam(1)
state = setCell_call_list[0].getParam(2)
self.assertEqual(offset, test_cell_list[0][0])
self.assertTrue(node is added_node)
self.assertEqual(state, test_cell_list[0][2])
setCell_call_list[0].checkArgs(test_cell_list[0][0], added_node,
test_cell_list[0][2])
# TODO: confirm condition under which an unknown node should be added with a TEMPORARILY_DOWN_STATE (implementation is unclear)
......
......@@ -116,6 +116,8 @@ server: 127.0.0.1:10023
self.client_port = 11022
self.storage_port = 10021
self.master_port = 10011
self.master_address = ('127.0.0.1', self.master_port)
self.storage_address = ('127.0.0.1', self.storage_port)
def tearDown(self):
# Delete tmp file
......@@ -133,72 +135,22 @@ 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 = Mock({})
self.recovery.handleRequestNodeIdentification(conn, packet, *args)
self.checkAcceptNodeIdentification(conn)
return uuid
# Method to test the kind of packet returned in answer
def checkCalledRequestNodeIdentification(self, conn, packet_number=0):
""" Check Request Node Identification has been send"""
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
call = conn.mockGetNamedCalls("_addPacket")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), REQUEST_NODE_IDENTIFICATION)
def checkCalledAskPrimaryMaster(self, conn, packet_number=0):
""" Check ask primary master has been send"""
call = conn.mockGetNamedCalls("_addPacket")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(),ASK_PRIMARY_MASTER)
def checkCalledNotifyNodeInformation(self, conn, packet_number=0):
""" Check Notify Node Information message has been send"""
call = conn.mockGetNamedCalls("notify")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), NOTIFY_NODE_INFORMATION)
def checkCalledAnswerPrimaryMaster(self, conn, packet_number=0):
""" Check Answer primaty master message has been send"""
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_PRIMARY_MASTER)
def checkCalledAnswerLastIDs(self, conn, packet_number=0):
""" Check start operation message has been send"""
call = conn.mockGetNamedCalls("_addPacket")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_LAST_IDS)
return packet._decodeAnswerLastIDs()
def checkCalledAskLastIDs(self, conn, packet_number=0):
""" Check start operation message has been send"""
call = conn.mockGetNamedCalls("ask")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ASK_LAST_IDS)
return protocol._decodeAskLastIDs(packet._body)
# Tests
def test_01_connectionClosed(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port)
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), RUNNING_STATE)
self.recovery.connectionClosed(conn)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE)
def test_02_timeoutExpired(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port)
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), RUNNING_STATE)
self.recovery.timeoutExpired(conn)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE)
......@@ -206,8 +158,7 @@ server: 127.0.0.1:10023
def test_03_peerBroken(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port)
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), RUNNING_STATE)
self.recovery.peerBroken(conn)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), BROKEN_STATE)
......@@ -218,7 +169,7 @@ server: 127.0.0.1:10023
args = (MASTER_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 = Mock({})
self.checkProtocolErrorRaised(
recovery.handleRequestNodeIdentification,
conn,
......@@ -230,7 +181,7 @@ server: 127.0.0.1:10023
name="INVALID_NAME",)
# test connection from a client node, rejectet
uuid = self.getNewUUID()
conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None})
conn = Mock({})
self.checkNotReadyErrorRaised(
recovery.handleRequestNodeIdentification,
conn,
......@@ -243,11 +194,7 @@ server: 127.0.0.1:10023
# 1. unknown storage node with known address, must be rejected
uuid = self.getNewUUID()
conn = Mock({"_addPacket" : None,
"abort" : None,
"expectMessage" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
self.assertEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
......@@ -267,11 +214,7 @@ server: 127.0.0.1:10023
# 2. unknown master node with known address, will be accepted
uuid = self.getNewUUID()
conn = Mock({"_addPacket" : None,
"abort" : None,
"expectMessage" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
self.assertEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
......@@ -292,11 +235,7 @@ server: 127.0.0.1:10023
# 3. unknown master node with known address but different uuid, will be replaced
old_uuid = uuid
uuid = self.getNewUUID()
conn = Mock({"_addPacket" : None,
"abort" : None,
"expectMessage" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
node = self.app.nm.getNodeByServer(conn.getAddress())
......@@ -315,11 +254,7 @@ server: 127.0.0.1:10023
# 4. unknown master node with known address but different uuid and broken state, will be accepted
uuid = self.getNewUUID()
conn = Mock({"_addPacket" : None,
"abort" : None,
"expectMessage" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
node = self.app.nm.getNodeByServer(conn.getAddress())
......@@ -344,11 +279,7 @@ server: 127.0.0.1:10023
known_uuid = uuid
# 5. known by uuid, but different address -> conflict / new master
conn = Mock({"_addPacket" : None,
"abort" : None,
"expectMessage" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertNotEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
node = self.app.nm.getNodeByServer(conn.getAddress())
......@@ -374,11 +305,7 @@ server: 127.0.0.1:10023
self.assertNotEquals(new_uuid, uuid)
# 6.known by uuid, but different address and non running state -> conflict
conn = Mock({"_addPacket" : None,
"abort" : None,
"expectMessage" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertNotEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
node = self.app.nm.getNodeByServer(conn.getAddress())
......@@ -398,11 +325,7 @@ server: 127.0.0.1:10023
name=self.app.name,)
# 7. known node but broken
conn = Mock({"_addPacket" : None,
"abort" : None,
"expectMessage" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertNotEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
node = self.app.nm.getNodeByServer(conn.getAddress())
......@@ -422,11 +345,7 @@ server: 127.0.0.1:10023
name=self.app.name,)
# 8. known node but down
conn = Mock({"_addPacket" : None,
"abort" : None,
"expectMessage" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertNotEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
node = self.app.nm.getNodeByServer(conn.getAddress())
......@@ -451,11 +370,7 @@ server: 127.0.0.1:10023
# 9. New node
uuid = self.getNewUUID()
conn = Mock({"_addPacket" : None,
"abort" : None,
"expectMessage" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.3", self.master_port)})
conn = self.getFakeConnection(uuid, ('127.0.0.3', self.master_port))
self.assertEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 2)
......@@ -478,32 +393,23 @@ server: 127.0.0.1:10023
recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = protocol.askPrimaryMaster()
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
recovery.handleAskPrimaryMaster(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("notify")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.checkCalledAnswerPrimaryMaster(conn, 0)
self.checkCalledNotifyNodeInformation(conn, 0)
self.checkNotAborted(conn)
self.checkAnswerPrimaryMaster(conn)
self.checkNotifyNodeInformation(conn)
# if storage node, expect message
uuid = self.identifyToMasterNode(STORAGE_NODE_TYPE, port=self.storage_port)
packet = protocol.askPrimaryMaster()
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_port)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
recovery.handleAskPrimaryMaster(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("notify")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.checkCalledAnswerPrimaryMaster(conn, 0)
self.checkCalledNotifyNodeInformation(conn, 0)
self.checkCalledAskLastIDs(conn, 0)
self.checkNotAborted(conn)
self.checkAnswerPrimaryMaster(conn)
self.checkNotifyNodeInformation(conn)
self.checkAskLastIDs(conn)
def test_06_handleAnnouncePrimaryMaster(self):
......@@ -511,15 +417,11 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_type=ANNOUNCE_PRIMARY_MASTER)
# No uuid
conn = Mock({"_addPacket" : None,
"getUUID" : None,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(None, self.master_address)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
self.checkIdenficationRequired(recovery.handleAnnouncePrimaryMaster, conn, packet)
# announce
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.primary, None)
self.assertEqual(self.app.primary_master_node, None)
self.assertRaises(ElectionFailure, recovery.handleAnnouncePrimaryMaster, conn, packet)
......@@ -530,9 +432,7 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = protocol.askPrimaryMaster()
# No uuid
conn = Mock({"_addPacket" : None,
"getUUID" : None,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertRaises(ElectionFailure, recovery.handleReelectPrimaryMaster, conn, packet)
......@@ -541,21 +441,18 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(None, self.master_address)
node_list = []
self.checkIdenficationRequired(recovery.handleNotifyNodeInformation, conn, packet, node_list)
# tell about a client node, do nothing
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(CLIENT_NODE_TYPE, '127.0.0.1', self.client_port, self.getNewUUID(), DOWN_STATE),]
self.assertEqual(len(self.app.nm.getClientNodeList()), 0)
recovery.handleNotifyNodeInformation(conn, packet, node_list)
self.assertEqual(len(self.app.nm.getClientNodeList()), 0)
# tell the master node about itself, if running must do nothing
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port-1, self.app.uuid, RUNNING_STATE),]
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port-1))
self.assertEqual(node, None)
......@@ -563,24 +460,21 @@ server: 127.0.0.1:10023
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port-1))
# tell the master node about itself, if down must raise
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port-1, self.app.uuid, DOWN_STATE),]
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port-1))
self.assertEqual(node, None)
self.assertRaises(RuntimeError, recovery.handleNotifyNodeInformation, conn, packet, node_list)
# tell about an unknown storage node, do nothing
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', self.master_port - 1, self.getNewUUID(), DOWN_STATE),]
self.assertEqual(len(self.app.nm.getStorageNodeList()), 0)
recovery.handleNotifyNodeInformation(conn, packet, node_list)
self.assertEqual(len(self.app.nm.getStorageNodeList()), 0)
# tell about a known node but different address
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.2', self.master_port, uuid, DOWN_STATE),]
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port))
self.assertEqual(node.getState(), RUNNING_STATE)
......@@ -589,8 +483,7 @@ server: 127.0.0.1:10023
self.assertEqual(node.getState(), RUNNING_STATE)
# tell about a known node
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port, uuid, DOWN_STATE),]
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port))
self.assertEqual(node.getState(), RUNNING_STATE)
......@@ -607,8 +500,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_port)
node_list = []
self.checkIdenficationRequired(recovery.handleAnswerLastIDs, conn, packet, None, None, None)
self.assertEquals(loid, self.app.loid)
......@@ -616,16 +508,14 @@ server: 127.0.0.1:10023
self.assertEquals(lptid, self.app.lptid)
# do not care if master node call it
master_uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port)
conn = Mock({"getUUID" : master_uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(master_uuid, self.master_address)
node_list = []
self.checkUnexpectedPacketRaised(recovery.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 update target node
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_port)
node_list = []
new_ptid = unpack('!Q', lptid)[0]
new_ptid = pack('!Q', new_ptid + 1)
......@@ -649,20 +539,14 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_type=ANSWER_PARTITION_TABLE)
# No uuid
conn = Mock({"_addPacket" : None,
"getUUID" : None,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(None, self.master_address)
self.checkIdenficationRequired(recovery.handleAnswerPartitionTable, conn, packet, None, [])
# not a storage node
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.checkUnexpectedPacketRaised(recovery.handleAnswerPartitionTable, conn, packet, None, [])
# not from target node, ignore
uuid = self.identifyToMasterNode(STORAGE_NODE_TYPE, port=self.storage_port)
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_port)
self.assertNotEquals(self.app.target_uuid, uuid)
offset = 1
cell_list = [(offset, uuid, UP_TO_DATE_STATE)]
......@@ -674,9 +558,7 @@ server: 127.0.0.1:10023
for cell, state in cells:
self.assertEquals(state, OUT_OF_DATE_STATE)
# from target node, taken into account
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_port)
self.assertNotEquals(self.app.target_uuid, uuid)
self.app.target_uuid = uuid
self.assertEquals(self.app.target_uuid, uuid)
......@@ -690,9 +572,7 @@ server: 127.0.0.1:10023
for cell, state in cells:
self.assertEquals(state, UP_TO_DATE_STATE)
# give a bad offset, must send error
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_port)
self.assertEquals(self.app.target_uuid, uuid)
offset = 1000000
self.assertFalse(self.app.pt.hasOffset(offset))
......
......@@ -119,6 +119,8 @@ server: 127.0.0.1:10023
self.client_port = 11022
self.storage_port = 10021
self.master_port = 10011
self.master_address = ('127.0.0.1', self.master_port)
self.storage_address = ('127.0.0.1', self.storage_port)
def tearDown(self):
# Delete tmp file
......@@ -136,101 +138,47 @@ 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.verification.handleRequestNodeIdentification(conn, packet, *args)
self.checkAcceptNodeIdentification(conn)
return uuid
# Method to test the kind of packet returned in answer
def checkCalledRequestNodeIdentification(self, conn, packet_number=0):
""" Check Request Node Identification has been send"""
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
call = conn.mockGetNamedCalls("_addPacket")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), REQUEST_NODE_IDENTIFICATION)
def checkCalledAskPrimaryMaster(self, conn, packet_number=0):
""" Check ask primary master has been send"""
call = conn.mockGetNamedCalls("_addPacket")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(),ASK_PRIMARY_MASTER)
def checkCalledNotifyNodeInformation(self, conn, packet_number=0):
""" Check Notify Node Information message has been send"""
call = conn.mockGetNamedCalls("notify")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), NOTIFY_NODE_INFORMATION)
def checkCalledAnswerPrimaryMaster(self, conn, packet_number=0):
""" Check Answer primaty master message has been send"""
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_PRIMARY_MASTER)
def checkCalledAnswerLastIDs(self, conn, packet_number=0):
""" Check start operation message has been send"""
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_LAST_IDS)
return packet._decodeAnswerLastIDs()
def checkCalledSendPartitionTable(self, conn, packet_number=0):
""" Check partition table has been send"""
call = conn.mockGetNamedCalls("notify")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), SEND_PARTITION_TABLE)
# Tests
def test_01_connectionClosed(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port)
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), RUNNING_STATE)
self.verification.connectionClosed(conn)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE)
# test a storage, must raise as cluster no longer op
uuid = self.identifyToMasterNode()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), RUNNING_STATE)
self.assertRaises(VerificationFailure, self.verification.connectionClosed,conn)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE)
def test_02_timeoutExpired(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port)
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), RUNNING_STATE)
self.verification.timeoutExpired(conn)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE)
# test a storage, must raise as cluster no longer op
uuid = self.identifyToMasterNode()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), RUNNING_STATE)
self.assertRaises(VerificationFailure, self.verification.connectionClosed,conn)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE)
def test_03_peerBroken(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port)
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), RUNNING_STATE)
self.verification.peerBroken(conn)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), BROKEN_STATE)
# test a storage, must raise as cluster no longer op
uuid = self.identifyToMasterNode()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), RUNNING_STATE)
self.assertRaises(VerificationFailure, self.verification.connectionClosed,conn)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE)
......@@ -241,7 +189,7 @@ server: 127.0.0.1:10023
args = ( MASTER_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()
self.checkProtocolErrorRaised(
verification.handleRequestNodeIdentification,
conn, packet=packet,
......@@ -252,7 +200,7 @@ server: 127.0.0.1:10023
name="INVALID_NAME",)
# test connection from a client node, rejectet
uuid = self.getNewUUID()
conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None})
conn = self.getFakeConnection()
self.checkNotReadyErrorRaised(
verification.handleRequestNodeIdentification,
conn,
......@@ -265,11 +213,7 @@ server: 127.0.0.1:10023
# 1. unknown storage node with known address, must be rejected
uuid = self.getNewUUID()
conn = Mock({"_addPacket" : None,
"abort" : None,
"expectMessage" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
self.assertEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
......@@ -289,11 +233,7 @@ server: 127.0.0.1:10023
# 2. unknown master node with known address, will be accepted
uuid = self.getNewUUID()
conn = Mock({"_addPacket" : None,
"abort" : None,
"expectMessage" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
self.assertEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
......@@ -307,18 +247,14 @@ server: 127.0.0.1:10023
node = self.app.nm.getNodeByUUID(conn.getUUID())
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
self.assertEqual(node.getUUID(), uuid)
self.checkUUIDSet(conn, uuid)
self.assertEqual(node.getState(), RUNNING_STATE)
self.checkAcceptNodeIdentification(conn)
# 3. unknown master node with known address but different uuid, will be replaced
old_uuid = uuid
uuid = self.getNewUUID()
conn = Mock({"_addPacket" : None,
"abort" : None,
"expectMessage" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
node = self.app.nm.getNodeByServer(conn.getAddress())
......@@ -337,11 +273,7 @@ server: 127.0.0.1:10023
# 4. unknown master node with known address but different uuid and broken state, will be accepted
uuid = self.getNewUUID()
conn = Mock({"_addPacket" : None,
"abort" : None,
"expectMessage" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
node = self.app.nm.getNodeByServer(conn.getAddress())
......@@ -365,11 +297,7 @@ server: 127.0.0.1:10023
self.checkAcceptNodeIdentification(conn)
# 5. known by uuid, but different address
conn = Mock({"_addPacket" : None,
"abort" : None,
"expectMessage" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertNotEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
node = self.app.nm.getNodeByServer(conn.getAddress())
......@@ -395,11 +323,7 @@ server: 127.0.0.1:10023
self.assertNotEquals(new_uuid, uuid)
# 6.known by uuid, but different address and non running state
conn = Mock({"_addPacket" : None,
"abort" : None,
"expectMessage" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertNotEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
node = self.app.nm.getNodeByServer(conn.getAddress())
......@@ -419,11 +343,7 @@ server: 127.0.0.1:10023
name=self.app.name,)
# 7. known node but broken
conn = Mock({"_addPacket" : None,
"abort" : None,
"expectMessage" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertNotEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
node = self.app.nm.getNodeByServer(conn.getAddress())
......@@ -443,11 +363,7 @@ server: 127.0.0.1:10023
name=self.app.name,)
# 8. known node but down
conn = Mock({"_addPacket" : None,
"abort" : None,
"expectMessage" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertNotEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
node = self.app.nm.getNodeByServer(conn.getAddress())
......@@ -472,11 +388,7 @@ server: 127.0.0.1:10023
# 9. New node
uuid = self.getNewUUID()
conn = Mock({"_addPacket" : None,
"abort" : None,
"expectMessage" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.3", self.master_port)})
conn = self.getFakeConnection(uuid, ('127.0.0.3', self.master_port))
self.assertEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 2)
......@@ -499,46 +411,34 @@ server: 127.0.0.1:10023
verification = self.verification
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = protocol.askPrimaryMaster()
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
verification.handleAskPrimaryMaster(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("notify")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.checkCalledAnswerPrimaryMaster(conn, 0)
self.checkCalledNotifyNodeInformation(conn, 0)
self.checkNotAborted(conn)
self.checkAnswerPrimaryMaster(conn)
self.checkNotifyNodeInformation(conn)
# if storage node, expect messages
uuid = self.identifyToMasterNode(STORAGE_NODE_TYPE, port=self.storage_port)
packet = protocol.askPrimaryMaster()
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
verification.handleAskPrimaryMaster(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("notify")), 3)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.checkCalledAnswerPrimaryMaster(conn, 0)
self.checkCalledNotifyNodeInformation(conn, 0)
self.checkCalledSendPartitionTable(conn, 1)
self.checkCalledSendPartitionTable(conn, 2)
self.checkNotAborted(conn)
self.checkAnswerPrimaryMaster(conn)
self.checkNotifyNodeInformation(conn, packet_number=0)
self.checkSendPartitionTable(conn, packet_number=1)
self.checkSendPartitionTable(conn, packet_number=2)
def test_06_handleAnnouncePrimaryMaster(self):
verification = self.verification
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_type=ANNOUNCE_PRIMARY_MASTER)
# No uuid
conn = Mock({"_addPacket" : None,
"getUUID" : None,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(None, self.master_address)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
self.checkIdenficationRequired(verification.handleAnnouncePrimaryMaster, conn, packet)
# announce
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.primary, None)
self.assertEqual(self.app.primary_master_node, None)
self.assertRaises(ElectionFailure, verification.handleAnnouncePrimaryMaster, conn, packet)
......@@ -548,9 +448,7 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = protocol.askPrimaryMaster()
# No uuid
conn = Mock({"_addPacket" : None,
"getUUID" : None,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(None, self.master_address)
self.assertRaises(ElectionFailure, verification.handleReelectPrimaryMaster, conn, packet)
def test_08_handleNotifyNodeInformation(self):
......@@ -558,21 +456,18 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(None, self.master_address)
node_list = []
self.checkIdenficationRequired(verification.handleNotifyNodeInformation, conn, packet, node_list)
# tell about a client node, do nothing
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(CLIENT_NODE_TYPE, '127.0.0.1', self.client_port, self.getNewUUID(), DOWN_STATE),]
self.assertEqual(len(self.app.nm.getClientNodeList()), 0)
verification.handleNotifyNodeInformation(conn, packet, node_list)
self.assertEqual(len(self.app.nm.getClientNodeList()), 0)
# tell the master node about itself, if running must do nothing
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port-1, self.app.uuid, RUNNING_STATE),]
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port-1))
self.assertEqual(node, None)
......@@ -580,24 +475,21 @@ server: 127.0.0.1:10023
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port-1))
# tell the master node about itself, if down must raise
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port-1, self.app.uuid, DOWN_STATE),]
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port-1))
self.assertEqual(node, None)
self.assertRaises(RuntimeError, verification.handleNotifyNodeInformation, conn, packet, node_list)
# tell about an unknown storage node, do nothing
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', self.master_port - 1, self.getNewUUID(), DOWN_STATE),]
self.assertEqual(len(self.app.nm.getStorageNodeList()), 0)
verification.handleNotifyNodeInformation(conn, packet, node_list)
self.assertEqual(len(self.app.nm.getStorageNodeList()), 0)
# tell about a known node but different address
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.2', self.master_port, uuid, DOWN_STATE),]
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port))
self.assertEqual(node.getState(), RUNNING_STATE)
......@@ -606,8 +498,7 @@ server: 127.0.0.1:10023
self.assertEqual(node.getState(), RUNNING_STATE)
# tell about a known node
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port, uuid, DOWN_STATE),]
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port))
self.assertEqual(node.getState(), RUNNING_STATE)
......@@ -623,8 +514,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(verification.handleAnswerLastIDs, conn, packet, None, None, None)
self.assertEquals(loid, self.app.loid)
......@@ -632,16 +522,14 @@ server: 127.0.0.1:10023
self.assertEquals(lptid, self.app.lptid)
# do not care if master node call it
master_uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port)
conn = Mock({"getUUID" : master_uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(master_uuid, self.master_address)
node_list = []
self.checkUnexpectedPacketRaised(verification.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)
......@@ -661,9 +549,7 @@ server: 127.0.0.1:10023
verification = self.verification
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_type=ANSWER_PARTITION_TABLE, )
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(uuid, self.master_address)
verification.handleAnswerPartitionTable(conn, packet, None, [])
self.assertEqual(len(conn.mockGetAllCalls()), 0)
......@@ -672,20 +558,14 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ANSWER_UNFINISHED_TRANSACTIONS)
# reject when no uuid
conn = Mock({"_addPacket" : None,
"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
self.checkIdenficationRequired(verification.handleAnswerUnfinishedTransactions, conn, packet, [])
# reject master node
master_uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
conn = Mock({"_addPacket" : None,
"getUUID" : master_uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(master_uuid, self.master_address)
self.checkUnexpectedPacketRaised(verification.handleAnswerUnfinishedTransactions, conn, packet, [])
# do nothing
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 0)
self.app.asking_uuid_dict[uuid] = True
self.assertTrue(self.app.asking_uuid_dict.has_key(uuid))
......@@ -695,9 +575,7 @@ server: 127.0.0.1:10023
verification.handleAnswerUnfinishedTransactions(conn, packet, [new_tid])
self.assertEquals(len(self.app.unfinished_tid_set), 0)
# update dict
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
self.app.asking_uuid_dict[uuid] = False
self.assertTrue(self.app.asking_uuid_dict.has_key(uuid))
self.assertEquals(len(self.app.unfinished_tid_set), 0)
......@@ -714,20 +592,14 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ANSWER_TRANSACTION_INFORMATION)
# reject when no uuid
conn = Mock({"_addPacket" : None,
"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
self.checkIdenficationRequired(verification.handleAnswerTransactionInformation, conn, packet, None, None, None, None, None)
# reject master node
master_uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
conn = Mock({"_addPacket" : None,
"getUUID" : master_uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(master_uuid, self.storage_address)
self.checkUnexpectedPacketRaised(verification.handleAnswerTransactionInformation, conn, packet, None, None, None, None, None)
# do nothing, as unfinished_oid_set is None
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 0)
self.app.asking_uuid_dict[uuid] = False
self.app.unfinished_oid_set = None
......@@ -740,9 +612,7 @@ server: 127.0.0.1:10023
"user", "desc", "ext", [new_oid,])
self.assertEquals(self.app.unfinished_oid_set, None)
# do nothing as asking_uuid_dict is True
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 1)
self.app.asking_uuid_dict[uuid] = True
self.app.unfinished_oid_set = set()
......@@ -752,9 +622,7 @@ server: 127.0.0.1:10023
"user", "desc", "ext", [new_oid,])
self.assertEquals(len(self.app.unfinished_oid_set), 0)
# do work
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 1)
self.app.asking_uuid_dict[uuid] = False
self.assertTrue(self.app.asking_uuid_dict.has_key(uuid))
......@@ -764,9 +632,7 @@ server: 127.0.0.1:10023
self.assertEquals(len(self.app.unfinished_oid_set), 1)
self.assertTrue(new_oid in self.app.unfinished_oid_set)
# do not work as oid is diff
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 1)
self.app.asking_uuid_dict[uuid] = False
self.assertTrue(self.app.asking_uuid_dict.has_key(uuid))
......@@ -784,20 +650,14 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=TID_NOT_FOUND_CODE)
# reject when no uuid
conn = Mock({"_addPacket" : None,
"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
self.checkIdenficationRequired(verification.handleTidNotFound, conn, packet, [])
# reject master node
master_uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
conn = Mock({"_addPacket" : None,
"getUUID" : master_uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(master_uuid, self.master_address)
self.checkUnexpectedPacketRaised(verification.handleTidNotFound, conn, packet, [])
# do nothing as asking_uuid_dict is True
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 0)
self.app.asking_uuid_dict[uuid] = True
self.app.unfinished_oid_set = []
......@@ -805,9 +665,7 @@ server: 127.0.0.1:10023
verification.handleTidNotFound(conn, packet, "msg")
self.assertNotEqual(self.app.unfinished_oid_set, None)
# do work as asking_uuid_dict is False
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 1)
self.app.asking_uuid_dict[uuid] = False
self.app.unfinished_oid_set = []
......@@ -820,32 +678,24 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ANSWER_OBJECT_PRESENT)
# reject when no uuid
conn = Mock({"_addPacket" : None,
"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
self.checkIdenficationRequired(verification.handleAnswerObjectPresent, conn, packet, None, None)
# reject master node
master_uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
conn = Mock({"_addPacket" : None,
"getUUID" : master_uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(master_uuid, self.master_address)
self.checkUnexpectedPacketRaised(verification.handleAnswerObjectPresent, conn, packet, None, None)
# do nothing as asking_uuid_dict is True
upper, lower = unpack('!LL', self.app.ltid)
new_tid = pack('!LL', upper, lower + 10)
oid = unpack('!Q', self.app.loid)[0]
new_oid = pack('!Q', oid + 1)
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 0)
self.app.asking_uuid_dict[uuid] = True
self.assertTrue(self.app.asking_uuid_dict.has_key(uuid))
verification.handleAnswerObjectPresent(conn, packet, new_oid, new_tid)
# do work
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 1)
self.app.asking_uuid_dict[uuid] = False
self.assertFalse(self.app.asking_uuid_dict[uuid])
......@@ -857,20 +707,14 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=OID_NOT_FOUND_CODE)
# reject when no uuid
conn = Mock({"_addPacket" : None,
"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(None, self.storage_address)
self.checkIdenficationRequired(verification.handleOidNotFound, conn, packet, [])
# reject master node
master_uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
conn = Mock({"_addPacket" : None,
"getUUID" : master_uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
conn = self.getFakeConnection(master_uuid, self.master_address)
self.checkUnexpectedPacketRaised(verification.handleOidNotFound, conn, packet, [])
# do nothinf as asking_uuid_dict is True
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 0)
self.app.asking_uuid_dict[uuid] = True
self.app.object_present = True
......@@ -878,9 +722,7 @@ server: 127.0.0.1:10023
verification.handleOidNotFound(conn, packet, "msg")
self.assertTrue(self.app.object_present)
# do work as asking_uuid_dict is False
conn = Mock({"_addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 1)
self.app.asking_uuid_dict[uuid] = False
self.assertFalse(self.app.asking_uuid_dict[uuid ])
......
......@@ -39,6 +39,12 @@ class NeoTestBase(unittest.TestCase):
return min(ptids), max(ptids)
ptid = min(ptids)
def getFakeConnection(self, uuid=None, address=('127.0.0.1', 10000)):
return Mock({
'getUUID': uuid,
'getAddress': address,
})
def checkProtocolErrorRaised(self, method, *args, **kwargs):
""" Check if the ProtocolError exception was raised """
self.assertRaises(protocol.ProtocolError, method, *args, **kwargs)
......@@ -194,6 +200,9 @@ class NeoTestBase(unittest.TestCase):
def checkAskNewTid(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_NEW_TID, **kw)
def checkAskLastIDs(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_LAST_IDS, **kw)
def checkAcceptNodeIdentification(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ACCEPT_NODE_IDENTIFICATION, **kw)
......
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