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

Update all tests according to previous commit.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@484 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 0d82139d
This diff is collapsed.
...@@ -47,6 +47,7 @@ from neo.exception import ElectionFailure ...@@ -47,6 +47,7 @@ from neo.exception import ElectionFailure
from neo.client.handler import BaseClientEventHandler, PrimaryBoostrapEventHandler, \ from neo.client.handler import BaseClientEventHandler, PrimaryBoostrapEventHandler, \
PrimaryEventHandler, StorageBootstrapEventHandler, StorageEventHandler PrimaryEventHandler, StorageBootstrapEventHandler, StorageEventHandler
from neo.node import StorageNode from neo.node import StorageNode
from neo.util import dump
MARKER = [] MARKER = []
...@@ -101,8 +102,8 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -101,8 +102,8 @@ class ClientEventHandlerTest(unittest.TestCase):
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = BaseClientEventHandler(None, dispatcher) client_handler = BaseClientEventHandler(None, dispatcher)
conn = self.getConnection() conn = self.getConnection()
client_handler.packetReceived(conn, protocol.ping(1)) client_handler.packetReceived(conn, protocol.ping())
pong = conn.mockGetNamedCalls('addPacket')[0].getParam(0) pong = conn.mockGetNamedCalls('answer')[0].getParam(0)
self.assertTrue(isinstance(pong, Packet)) self.assertTrue(isinstance(pong, Packet))
self.assertEquals(pong.getType(), PONG) self.assertEquals(pong.getType(), PONG)
...@@ -136,7 +137,14 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -136,7 +137,14 @@ class ClientEventHandlerTest(unittest.TestCase):
primary_master_node = Mock({'getUUID': self.getUUID()}) primary_master_node = Mock({'getUUID': self.getUUID()})
nm = Mock({'getNodeByServer': fake_storage_node}) nm = Mock({'getNodeByServer': fake_storage_node})
cp = Mock({'removeConnection': None}) cp = Mock({'removeConnection': None})
master_conn = self.getConnection(next_id=ReturnValues(master_node_next_packet_id)) master_conn = Mock({
'addPacket': None,
'getUUID': self.getUUID(),
'getAddress': ('127.0.0.1', 10010),
'getNextId': master_node_next_packet_id,
'lock': None,
'unlock': None
})
app = App() app = App()
conn = self.getConnection(port=storage_port, ip=storage_ip) conn = self.getConnection(port=storage_port, ip=storage_ip)
key_1 = (id(conn), 0) key_1 = (id(conn), 0)
...@@ -150,13 +158,14 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -150,13 +158,14 @@ class ClientEventHandlerTest(unittest.TestCase):
dispatcher = Dispatcher() dispatcher = Dispatcher()
method(dispatcher, app, handler_class, conn=conn) method(dispatcher, app, handler_class, conn=conn)
# Check that master was notified of the failure # Check that master was notified of the failure
addPacket_call_list = app.master_conn.mockGetNamedCalls('addPacket') addPacket_call_list = app.master_conn.mockGetNamedCalls('notify')
# Test sanity check # Test sanity check
self.assertEqual(len(addPacket_call_list), 1) self.assertEqual(len(addPacket_call_list), 1)
node_status_packet = addPacket_call_list[0].getParam(0) node_status_packet = addPacket_call_list[0].getParam(0)
self.assertTrue(isinstance(node_status_packet, Packet)) self.assertTrue(isinstance(node_status_packet, Packet))
# Test sanity check # Test sanity check
self.assertEquals(node_status_packet.getId(), master_node_next_packet_id) # the test below is disabled because the msg_id is now set by the connection
#self.assertEquals(node_status_packet.getId(), master_node_next_packet_id)
self.assertEquals(node_status_packet.getType(), NOTIFY_NODE_INFORMATION) self.assertEquals(node_status_packet.getType(), NOTIFY_NODE_INFORMATION)
self.assertEquals(node_status_packet.decode()[0], self.assertEquals(node_status_packet.decode()[0],
[(STORAGE_NODE_TYPE, storage_ip, storage_port, [(STORAGE_NODE_TYPE, storage_ip, storage_port,
......
...@@ -161,13 +161,13 @@ server: 127.0.0.1:10023 ...@@ -161,13 +161,13 @@ server: 127.0.0.1:10023
self.app.broadcastNodeInformation(c_node) self.app.broadcastNodeInformation(c_node)
# check conn # check conn
self.assertEquals(len(client_conn.mockGetNamedCalls("addPacket")), 0) self.assertEquals(len(client_conn.mockGetNamedCalls("addPacket")), 0)
self.assertEquals(len(master_conn.mockGetNamedCalls("addPacket")), 1) self.assertEquals(len(master_conn.mockGetNamedCalls("notify")), 1)
call = master_conn.mockGetNamedCalls("addPacket")[0] call = master_conn.mockGetNamedCalls("notify")[0]
packet = call.getParam(0) packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet)) self.assertTrue(isinstance(packet, Packet))
self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION) self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION)
self.assertEquals(len(storage_conn.mockGetNamedCalls("addPacket")), 1) self.assertEquals(len(storage_conn.mockGetNamedCalls("notify")), 1)
call = storage_conn.mockGetNamedCalls("addPacket")[0] call = storage_conn.mockGetNamedCalls("notify")[0]
packet = call.getParam(0) packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet)) self.assertTrue(isinstance(packet, Packet))
self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION) self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION)
...@@ -181,13 +181,13 @@ server: 127.0.0.1:10023 ...@@ -181,13 +181,13 @@ server: 127.0.0.1:10023
self.app.broadcastNodeInformation(c_node) self.app.broadcastNodeInformation(c_node)
# check conn # check conn
self.assertEquals(len(client_conn.mockGetNamedCalls("addPacket")), 0) self.assertEquals(len(client_conn.mockGetNamedCalls("addPacket")), 0)
self.assertEquals(len(master_conn.mockGetNamedCalls("addPacket")), 1) self.assertEquals(len(master_conn.mockGetNamedCalls("notify")), 1)
call = master_conn.mockGetNamedCalls("addPacket")[0] call = master_conn.mockGetNamedCalls("notify")[0]
packet = call.getParam(0) packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet)) self.assertTrue(isinstance(packet, Packet))
self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION) self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION)
self.assertEquals(len(storage_conn.mockGetNamedCalls("addPacket")), 1) self.assertEquals(len(storage_conn.mockGetNamedCalls("notify")), 1)
call = storage_conn.mockGetNamedCalls("addPacket")[0] call = storage_conn.mockGetNamedCalls("notify")[0]
packet = call.getParam(0) packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet)) self.assertTrue(isinstance(packet, Packet))
self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION) self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION)
...@@ -200,18 +200,18 @@ server: 127.0.0.1:10023 ...@@ -200,18 +200,18 @@ server: 127.0.0.1:10023
s_node = StorageNode(uuid = self.getNewUUID(), server=("127.0.0.1", 1351)) s_node = StorageNode(uuid = self.getNewUUID(), server=("127.0.0.1", 1351))
self.app.broadcastNodeInformation(s_node) self.app.broadcastNodeInformation(s_node)
# check conn # check conn
self.assertEquals(len(client_conn.mockGetNamedCalls("addPacket")), 1) self.assertEquals(len(client_conn.mockGetNamedCalls("notify")), 1)
call = client_conn.mockGetNamedCalls("addPacket")[0] call = client_conn.mockGetNamedCalls("notify")[0]
packet = call.getParam(0) packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet)) self.assertTrue(isinstance(packet, Packet))
self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION) self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION)
self.assertEquals(len(master_conn.mockGetNamedCalls("addPacket")), 1) self.assertEquals(len(master_conn.mockGetNamedCalls("notify")), 1)
call = master_conn.mockGetNamedCalls("addPacket")[0] call = master_conn.mockGetNamedCalls("notify")[0]
packet = call.getParam(0) packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet)) self.assertTrue(isinstance(packet, Packet))
self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION) self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION)
self.assertEquals(len(storage_conn.mockGetNamedCalls("addPacket")), 1) self.assertEquals(len(storage_conn.mockGetNamedCalls("notify")), 1)
call = storage_conn.mockGetNamedCalls("addPacket")[0] call = storage_conn.mockGetNamedCalls("notify")[0]
packet = call.getParam(0) packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet)) self.assertTrue(isinstance(packet, Packet))
self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION) self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION)
......
...@@ -122,10 +122,9 @@ server: 127.0.0.1:10023 ...@@ -122,10 +122,9 @@ server: 127.0.0.1:10023
def checkCalledAcceptNodeIdentification(self, conn, packet_number=0): def checkCalledAcceptNodeIdentification(self, conn, packet_number=0):
""" Check Accept Node Identification has been send""" """ Check Accept Node Identification has been send"""
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1) self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0) self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1) call = conn.mockGetNamedCalls("answer")[packet_number]
call = conn.mockGetNamedCalls("addPacket")[packet_number]
packet = call.getParam(0) packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet)) self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ACCEPT_NODE_IDENTIFICATION) self.assertEquals(packet.getType(), ACCEPT_NODE_IDENTIFICATION)
...@@ -147,7 +146,7 @@ server: 127.0.0.1:10023 ...@@ -147,7 +146,7 @@ server: 127.0.0.1:10023
""" """
uuid = self.getNewUUID() uuid = self.getNewUUID()
args = (node_type, uuid, ip, port,self.app.name) args = (node_type, uuid, ip, port,self.app.name)
packet = protocol.requestNodeIdentification(1, *args) packet = protocol.requestNodeIdentification(*args)
# test alien cluster # test alien cluster
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None}) conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None})
self.recovery.handleRequestNodeIdentification(conn, packet, *args) self.recovery.handleRequestNodeIdentification(conn, packet, *args)
...@@ -175,24 +174,28 @@ server: 127.0.0.1:10023 ...@@ -175,24 +174,28 @@ server: 127.0.0.1:10023
def checkCalledAbort(self, conn, packet_number=0): def checkCalledAbort(self, conn, packet_number=0):
"""Check the abort method has been called and an error packet has been sent""" """Check the abort method has been called and an error packet has been sent"""
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1) # XXX required here ???? send_calls_len = len(conn.mockGetNamedCalls("send"))
answer_calls_len = len(conn.mockGetNamedCalls('answer'))
self.assertEquals(send_calls_len + answer_calls_len, 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 1) self.assertEquals(len(conn.mockGetNamedCalls("abort")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0) if send_calls_len == 1:
call = conn.mockGetNamedCalls("addPacket")[packet_number] call = conn.mockGetNamedCalls("send")[packet_number]
else:
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0) packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet)) self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ERROR) self.assertEquals(packet.getType(), ERROR)
def checkCalledNotifyNodeInformation(self, conn, packet_number=0): def checkCalledNotifyNodeInformation(self, conn, packet_number=0):
""" Check Notify Node Information message has been send""" """ Check Notify Node Information message has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number] call = conn.mockGetNamedCalls("notify")[packet_number]
packet = call.getParam(0) packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet)) self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), NOTIFY_NODE_INFORMATION) self.assertEquals(packet.getType(), NOTIFY_NODE_INFORMATION)
def checkCalledAnswerPrimaryMaster(self, conn, packet_number=0): def checkCalledAnswerPrimaryMaster(self, conn, packet_number=0):
""" Check Answer primaty master message has been send""" """ Check Answer primaty master message has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number] call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0) packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet)) self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_PRIMARY_MASTER) self.assertEquals(packet.getType(), ANSWER_PRIMARY_MASTER)
...@@ -207,7 +210,7 @@ server: 127.0.0.1:10023 ...@@ -207,7 +210,7 @@ server: 127.0.0.1:10023
def checkCalledAskLastIDs(self, conn, packet_number=0): def checkCalledAskLastIDs(self, conn, packet_number=0):
""" Check start operation message has been send""" """ Check start operation message has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number] call = conn.mockGetNamedCalls("ask")[packet_number]
packet = call.getParam(0) packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet)) self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ASK_LAST_IDS) self.assertEquals(packet.getType(), ASK_LAST_IDS)
...@@ -243,7 +246,7 @@ server: 127.0.0.1:10023 ...@@ -243,7 +246,7 @@ server: 127.0.0.1:10023
recovery = self.recovery recovery = self.recovery
uuid = self.getNewUUID() uuid = self.getNewUUID()
args = (MASTER_NODE_TYPE, uuid, '127.0.0.1', self.storage_port, "INVALID_NAME") args = (MASTER_NODE_TYPE, uuid, '127.0.0.1', self.storage_port, "INVALID_NAME")
packet = protocol.requestNodeIdentification(1, *args) packet = protocol.requestNodeIdentification(*args)
# test alien cluster # test alien cluster
conn = Mock({"addPacket" : None, "abort" : None}) conn = Mock({"addPacket" : None, "abort" : None})
recovery.handleRequestNodeIdentification(conn, recovery.handleRequestNodeIdentification(conn,
...@@ -391,7 +394,7 @@ server: 127.0.0.1:10023 ...@@ -391,7 +394,7 @@ server: 127.0.0.1:10023
self.assertEqual(len(self.app.nm.getMasterNodeList()), 2) self.assertEqual(len(self.app.nm.getMasterNodeList()), 2)
self.checkCalledAcceptNodeIdentification(conn) self.checkCalledAcceptNodeIdentification(conn)
# a new uuid is sent # a new uuid is sent
call = conn.mockGetNamedCalls('addPacket')[0] call = conn.mockGetNamedCalls('answer')[0]
body = call.getParam(0)._body body = call.getParam(0)._body
new_uuid = body[:-16] new_uuid = body[:-16]
self.assertNotEquals(new_uuid, uuid) self.assertNotEquals(new_uuid, uuid)
...@@ -499,38 +502,39 @@ server: 127.0.0.1:10023 ...@@ -499,38 +502,39 @@ server: 127.0.0.1:10023
def test_05_handleAskPrimaryMaster(self): def test_05_handleAskPrimaryMaster(self):
recovery = self.recovery recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = protocol.askPrimaryMaster(msg_id=2) packet = protocol.askPrimaryMaster()
conn = Mock({"addPacket" : None, conn = Mock({"addPacket" : None,
"getUUID" : uuid, "getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1) self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
recovery.handleAskPrimaryMaster(conn, packet) recovery.handleAskPrimaryMaster(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 2) self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("notify")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0) self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0)
self.checkCalledAnswerPrimaryMaster(conn, 0) self.checkCalledAnswerPrimaryMaster(conn, 0)
self.checkCalledNotifyNodeInformation(conn, 1) self.checkCalledNotifyNodeInformation(conn, 0)
# if storage node, expect message # if storage node, expect message
uuid = self.identifyToMasterNode(STORAGE_NODE_TYPE, port=self.storage_port) uuid = self.identifyToMasterNode(STORAGE_NODE_TYPE, port=self.storage_port)
packet = protocol.askPrimaryMaster(msg_id=2) packet = protocol.askPrimaryMaster()
conn = Mock({"addPacket" : None, conn = Mock({"addPacket" : None,
"getUUID" : uuid, "getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)}) "getAddress" : ("127.0.0.1", self.storage_port)})
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1) self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
recovery.handleAskPrimaryMaster(conn, packet) recovery.handleAskPrimaryMaster(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 3) 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.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
self.checkCalledAnswerPrimaryMaster(conn, 0) self.checkCalledAnswerPrimaryMaster(conn, 0)
self.checkCalledNotifyNodeInformation(conn, 1) self.checkCalledNotifyNodeInformation(conn, 0)
self.checkCalledAskLastIDs(conn, 2) self.checkCalledAskLastIDs(conn, 0)
def test_06_handleAnnouncePrimaryMaster(self): def test_06_handleAnnouncePrimaryMaster(self):
recovery = self.recovery recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_id=3, msg_type=ANNOUNCE_PRIMARY_MASTER) packet = Packet(msg_type=ANNOUNCE_PRIMARY_MASTER)
# No uuid # No uuid
conn = Mock({"addPacket" : None, conn = Mock({"addPacket" : None,
"getUUID" : None, "getUUID" : None,
...@@ -550,7 +554,7 @@ server: 127.0.0.1:10023 ...@@ -550,7 +554,7 @@ server: 127.0.0.1:10023
def test_07_handleReelectPrimaryMaster(self): def test_07_handleReelectPrimaryMaster(self):
recovery = self.recovery recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = protocol.askPrimaryMaster(msg_id=0) packet = protocol.askPrimaryMaster()
# No uuid # No uuid
conn = Mock({"addPacket" : None, conn = Mock({"addPacket" : None,
"getUUID" : None, "getUUID" : None,
...@@ -561,7 +565,7 @@ server: 127.0.0.1:10023 ...@@ -561,7 +565,7 @@ server: 127.0.0.1:10023
def test_08_handleNotifyNodeInformation(self): def test_08_handleNotifyNodeInformation(self):
recovery = self.recovery recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_id=5, msg_type=NOTIFY_NODE_INFORMATION) packet = Packet(msg_type=NOTIFY_NODE_INFORMATION)
# do not answer if no uuid # do not answer if no uuid
conn = Mock({"getUUID" : None, conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
...@@ -625,7 +629,7 @@ server: 127.0.0.1:10023 ...@@ -625,7 +629,7 @@ server: 127.0.0.1:10023
def test_09_handleAnswerLastIDs(self): def test_09_handleAnswerLastIDs(self):
recovery = self.recovery recovery = self.recovery
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_id=5, msg_type=ANSWER_LAST_IDS) packet = Packet(msg_type=ANSWER_LAST_IDS)
loid = self.app.loid loid = self.app.loid
ltid = self.app.ltid ltid = self.app.ltid
lptid = self.app.lptid lptid = self.app.lptid
...@@ -672,7 +676,7 @@ server: 127.0.0.1:10023 ...@@ -672,7 +676,7 @@ server: 127.0.0.1:10023
def test_10_handleAnswerPartitionTable(self): def test_10_handleAnswerPartitionTable(self):
recovery = self.recovery recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_type=ANSWER_PARTITION_TABLE, msg_id=10) packet = Packet(msg_type=ANSWER_PARTITION_TABLE)
# No uuid # No uuid
conn = Mock({"addPacket" : None, conn = Mock({"addPacket" : None,
"getUUID" : None, "getUUID" : None,
......
This diff is collapsed.
This diff is collapsed.
...@@ -410,31 +410,36 @@ class testConnection(unittest.TestCase): ...@@ -410,31 +410,36 @@ class testConnection(unittest.TestCase):
# packet witch raise protocol error # packet witch raise protocol error
# change the max packet size and create a to big message # change the max packet size and create a to big message
# be careful not to set the max packet size < error message # be careful not to set the max packet size < error message
master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, getNewUUID()), # this part of the test is disabled because the case where a too big
("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()), # message is send is handled in protocol.Packet.encode
("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()), # master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, getNewUUID()),
("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID())) # ("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()),
p = protocol.answerPrimaryMaster(1, getNewUUID(), master_list) # ("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
OLD_MAX_PACKET_SIZE = protocol.MAX_PACKET_SIZE # ("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
protocol.MAX_PACKET_SIZE = 0x55 # p = protocol.answerPrimaryMaster(getNewUUID(), master_list)
# p.setId(1)
connector = DoNothingConnector() # OLD_MAX_PACKET_SIZE = protocol.MAX_PACKET_SIZE
bc = Connection(em, handler, connector_handler=DoNothingConnector, # protocol.MAX_PACKET_SIZE = 0x55
connector=connector, addr=("127.0.0.7", 93413)) #
self.assertEqual(bc.write_buf, '') # connector = DoNothingConnector()
self.assertNotEqual(bc.getConnector(), None) # bc = Connection(em, handler, connector_handler=DoNothingConnector,
bc.addPacket(p) # connector=connector, addr=("127.0.0.7", 93413))
self.assertNotEqual(bc.write_buf, "testdata") # self.assertEqual(bc.write_buf, '')
self.assertRaises(ProtocolError, p.encode) # self.assertNotEqual(bc.getConnector(), None)
self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 2) # import pdb
# check it sends error packet # pdb.set_trace()
packet = Packet.parse(bc.write_buf) # bc.addPacket(p)
self.assertEqual(packet.getType(), ERROR) # self.assertNotEqual(bc.write_buf, "testdata")
code, message = packet.decode() # self.assertRaises(ProtocolError, p.encode)
self.assertEqual(code, INTERNAL_ERROR_CODE) # self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 2)
self.assertEqual(message, "internal error: message too big (206)") # # check it sends error packet
# reset value # packet = Packet.parse(bc.write_buf)
protocol.MAX_PACKET_SIZE = OLD_MAX_PACKET_SIZE # self.assertEqual(packet.getType(), ERROR)
# code, message = packet.decode()
# self.assertEqual(code, INTERNAL_ERROR_CODE)
# self.assertEqual(message, "internal error: message too big (206)")
# # reset value
# protocol.MAX_PACKET_SIZE = OLD_MAX_PACKET_SIZE
def test_08_Connection_expectMessage(self): def test_08_Connection_expectMessage(self):
...@@ -482,7 +487,8 @@ class testConnection(unittest.TestCase): ...@@ -482,7 +487,8 @@ class testConnection(unittest.TestCase):
("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()), ("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()),
("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()), ("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID())) ("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p = protocol.answerPrimaryMaster(1, getNewUUID(), master_list) p = protocol.answerPrimaryMaster(getNewUUID(), master_list)
p.setId(1)
data = p.encode() data = p.encode()
bc.read_buf += data bc.read_buf += data
self.assertEqual(len(bc.event_dict), 0) self.assertEqual(len(bc.event_dict), 0)
...@@ -508,7 +514,8 @@ class testConnection(unittest.TestCase): ...@@ -508,7 +514,8 @@ class testConnection(unittest.TestCase):
("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()), ("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()),
("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()), ("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID())) ("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p1 = protocol.answerPrimaryMaster(1, getNewUUID(), master_list) p1 = protocol.answerPrimaryMaster(getNewUUID(), master_list)
p1.setId(1)
data = p1.encode() data = p1.encode()
bc.read_buf += data bc.read_buf += data
# packet 2 # packet 2
...@@ -516,7 +523,8 @@ class testConnection(unittest.TestCase): ...@@ -516,7 +523,8 @@ class testConnection(unittest.TestCase):
("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()), ("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()),
("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()), ("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID())) ("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p2 = protocol.answerPrimaryMaster(2, getNewUUID(), master_list) p2 = protocol.answerPrimaryMaster( getNewUUID(), master_list)
p2.setId(2)
data = p2.encode() data = p2.encode()
bc.read_buf += data bc.read_buf += data
self.assertEqual(len(bc.read_buf), len(p1.encode()) + len(p2.encode())) self.assertEqual(len(bc.read_buf), len(p1.encode()) + len(p2.encode()))
...@@ -563,7 +571,8 @@ class testConnection(unittest.TestCase): ...@@ -563,7 +571,8 @@ class testConnection(unittest.TestCase):
("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()), ("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()),
("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()), ("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID())) ("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p = protocol.answerPrimaryMaster(1, getNewUUID(), master_list) p = protocol.answerPrimaryMaster(getNewUUID(), master_list)
p.setId(1)
data = p.encode() data = p.encode()
bc.read_buf += data bc.read_buf += data
self.assertEqual(len(bc.event_dict), 0) self.assertEqual(len(bc.event_dict), 0)
...@@ -689,7 +698,8 @@ class testConnection(unittest.TestCase): ...@@ -689,7 +698,8 @@ class testConnection(unittest.TestCase):
("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()), ("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID())) ("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
uuid = getNewUUID() uuid = getNewUUID()
p = protocol.answerPrimaryMaster(1, uuid, master_list) p = protocol.answerPrimaryMaster(uuid, master_list)
p.setId(1)
data = p.encode() data = p.encode()
return data return data
DoNothingConnector.receive = receive DoNothingConnector.receive = receive
...@@ -1077,5 +1087,6 @@ class testConnection(unittest.TestCase): ...@@ -1077,5 +1087,6 @@ class testConnection(unittest.TestCase):
# XXX check locking ??? # XXX check locking ???
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -160,11 +160,11 @@ class testEvent(unittest.TestCase): ...@@ -160,11 +160,11 @@ class testEvent(unittest.TestCase):
self.assertEquals(len(conn.mockGetNamedCalls("getHandler")), 0) self.assertEquals(len(conn.mockGetNamedCalls("getHandler")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("close")), 0) self.assertEquals(len(conn.mockGetNamedCalls("close")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("unlock")), 1) self.assertEquals(len(conn.mockGetNamedCalls("unlock")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 2) self.assertEquals(len(conn.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1) self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 0) self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 0)
# check ping packet sent # check ping packet sent
call = conn.mockGetNamedCalls("addPacket")[0] call = conn.mockGetNamedCalls("ask")[0]
packet = call.getParam(0) packet = call.getParam(0)
self.failUnless(isinstance(packet, Packet)) self.failUnless(isinstance(packet, Packet))
self.assertEqual(packet.getType(), PING) self.assertEqual(packet.getType(), PING)
...@@ -178,8 +178,8 @@ class testEvent(unittest.TestCase): ...@@ -178,8 +178,8 @@ class testEvent(unittest.TestCase):
self.assertEquals(len(conn.mockGetNamedCalls("getHandler")), 1) self.assertEquals(len(conn.mockGetNamedCalls("getHandler")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("close")), 1) self.assertEquals(len(conn.mockGetNamedCalls("close")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("unlock")), 2) self.assertEquals(len(conn.mockGetNamedCalls("unlock")), 2)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 2) self.assertEquals(len(conn.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1) self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 1) self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 1)
# same test with additional time < 5 # same test with additional time < 5
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment