Commit 7544eb06 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Update tests affected with changes introduced with previous commit.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@482 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent f11bafed
This diff is collapsed.
......@@ -20,6 +20,7 @@ import unittest
import logging
import threading
from mock import Mock, ReturnValues
from neo import protocol
from neo.protocol import Packet, INVALID_UUID
from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \
PING, PONG, ASK_PRIMARY_MASTER, ANSWER_PRIMARY_MASTER, ANNOUNCE_PRIMARY_MASTER, \
......@@ -100,7 +101,7 @@ class ClientEventHandlerTest(unittest.TestCase):
dispatcher = self.getDispatcher()
client_handler = BaseClientEventHandler(None, dispatcher)
conn = self.getConnection()
client_handler.packetReceived(conn, Packet().ping(1))
client_handler.packetReceived(conn, protocol.ping(1))
pong = conn.mockGetNamedCalls('addPacket')[0].getParam(0)
self.assertTrue(isinstance(pong, Packet))
self.assertEquals(pong.getType(), PONG)
......
......@@ -21,6 +21,7 @@ import logging
from tempfile import mkstemp
from mock import Mock
from struct import pack, unpack
from neo import protocol
from neo.protocol import Packet, INVALID_UUID
from neo.master.election import ElectionEventHandler
from neo.master.app import Application
......@@ -158,8 +159,9 @@ server: 127.0.0.1:10023
port=10021):
"""Do first step of identification to MN
"""
packet = Packet(msg_id=1)
uuid = self.getNewUUID()
args = (node_type, uuid, ip, port, self.app.name)
packet = protocol.requestNodeIdentification(1, *args)
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None,
"isServerConnection" : True})
......@@ -298,16 +300,9 @@ server: 127.0.0.1:10023
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), BROKEN_STATE)
def test_07_packetReceived(self):
p = Packet()
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port)
p.acceptNodeIdentification(1,
MASTER_NODE_TYPE,
uuid,
"127.0.0.1",
self.master_port,
1009,
2,
self.app.uuid)
p = protocol.acceptNodeIdentification(1, MASTER_NODE_TYPE, uuid,
"127.0.0.1", self.master_port, 1009, 2, self.app.uuid)
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector)
......@@ -326,7 +321,9 @@ server: 127.0.0.1:10023
uuid = self.getNewUUID()
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector)
p = Packet()
args = (MASTER_NODE_TYPE, uuid, '127.0.0.1', self.master_port,
self.app.num_partitions, self.app.num_replicas, self.app.uuid)
p = protocol.acceptNodeIdentification(1, *args)
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), None)
......@@ -347,7 +344,9 @@ server: 127.0.0.1:10023
uuid = self.getNewUUID()
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector)
p = Packet()
args = (MASTER_NODE_TYPE, uuid, '127.0.0.1', self.master_port,
self.app.num_partitions, self.app.num_replicas, self.app.uuid)
p = protocol.acceptNodeIdentification(1, *args)
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), None)
......@@ -365,7 +364,9 @@ server: 127.0.0.1:10023
uuid = self.getNewUUID()
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector)
p = Packet()
args = (MASTER_NODE_TYPE, uuid, '127.0.0.1', self.master_port,
self.app.num_partitions, self.app.num_replicas, self.app.uuid)
p = protocol.acceptNodeIdentification(1, *args)
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), None)
......@@ -391,7 +392,7 @@ server: 127.0.0.1:10023
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector)
conn.setUUID(uuid)
p = Packet()
p = protocol.askPrimaryMaster(0)
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1)
......@@ -412,7 +413,7 @@ server: 127.0.0.1:10023
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector)
conn.setUUID(uuid)
p = Packet()
p = protocol.askPrimaryMaster(0)
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1)
......@@ -431,7 +432,7 @@ server: 127.0.0.1:10023
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector)
conn.setUUID(uuid)
p = Packet()
p = protocol.askPrimaryMaster(0)
self.app.nm.add(MasterNode(("127.0.0.1", self.master_port), uuid))
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
......@@ -453,7 +454,7 @@ server: 127.0.0.1:10023
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector)
conn.setUUID(uuid)
p = Packet()
p = protocol.askPrimaryMaster(1)
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1)
......@@ -474,7 +475,7 @@ server: 127.0.0.1:10023
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector)
conn.setUUID(uuid)
p = Packet()
p = protocol.askPrimaryMaster(1)
self.app.nm.add(MasterNode(("127.0.0.1", self.master_port), uuid))
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
......@@ -495,8 +496,9 @@ server: 127.0.0.1:10023
def test_10_handleRequestNodeIdentification(self):
election = self.election
packet = Packet(msg_id=1)
uuid = self.getNewUUID()
args = (MASTER_NODE_TYPE, uuid, '127.0.0.1', self.storage_port, 'INVALID_NAME')
packet = protocol.requestNodeIdentification(1, *args)
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None,
"isServerConnection" : True})
......@@ -577,7 +579,7 @@ server: 127.0.0.1:10023
def test_11_handleAskPrimaryMaster(self):
election = self.election
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_id=2)
packet = protocol.askPrimaryMaster(0)
conn = Mock({"addPacket" : None,
"getUUID" : uuid,
"isServerConnection" : True,
......@@ -623,7 +625,7 @@ server: 127.0.0.1:10023
def test_13_handleReelectPrimaryMaster(self):
election = self.election
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet()
packet = protocol.askPrimaryMaster(0)
# No uuid
conn = Mock({"addPacket" : None,
"getUUID" : None,
......
......@@ -21,6 +21,7 @@ import logging
from tempfile import mkstemp
from mock import Mock
from struct import pack, unpack
from neo import protocol
from neo.protocol import Packet, INVALID_UUID
from neo.master.recovery import RecoveryEventHandler
from neo.master.app import Application
......@@ -144,17 +145,12 @@ server: 127.0.0.1:10023
port=10021):
"""Do first step of identification to MN
"""
packet = Packet(msg_id=1)
uuid = self.getNewUUID()
args = (node_type, uuid, ip, port,self.app.name)
packet = protocol.requestNodeIdentification(1, *args)
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None})
self.recovery.handleRequestNodeIdentification(conn,
packet=packet,
node_type=node_type,
uuid=uuid,
ip_address=ip,
port=port,
name=self.app.name,)
self.recovery.handleRequestNodeIdentification(conn, packet, *args)
self.checkCalledAcceptNodeIdentification(conn)
return uuid
......@@ -245,8 +241,9 @@ server: 127.0.0.1:10023
def test_04_handleRequestNodeIdentification(self):
recovery = self.recovery
packet = Packet(msg_id=1)
uuid = self.getNewUUID()
args = (MASTER_NODE_TYPE, uuid, '127.0.0.1', self.storage_port, "INVALID_NAME")
packet = protocol.requestNodeIdentification(1, *args)
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None})
recovery.handleRequestNodeIdentification(conn,
......@@ -502,7 +499,7 @@ server: 127.0.0.1:10023
def test_05_handleAskPrimaryMaster(self):
recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_id=2)
packet = protocol.askPrimaryMaster(msg_id=2)
conn = Mock({"addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
......@@ -516,7 +513,7 @@ server: 127.0.0.1:10023
# if storage node, expect message
uuid = self.identifyToMasterNode(STORAGE_NODE_TYPE, port=self.storage_port)
packet = Packet(msg_id=2)
packet = protocol.askPrimaryMaster(msg_id=2)
conn = Mock({"addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
......@@ -553,7 +550,7 @@ server: 127.0.0.1:10023
def test_07_handleReelectPrimaryMaster(self):
recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet()
packet = protocol.askPrimaryMaster(msg_id=0)
# No uuid
conn = Mock({"addPacket" : None,
"getUUID" : None,
......
......@@ -21,6 +21,7 @@ import logging
from tempfile import mkstemp
from mock import Mock
from struct import pack, unpack
from neo import protocol
from neo.protocol import Packet, INVALID_UUID
from neo.master.service import ServiceEventHandler
from neo.master.app import Application
......@@ -216,35 +217,25 @@ server: 127.0.0.1:10023
port=10021):
"""Do first step of identification to MN
"""
packet = Packet(msg_id=1)
uuid = self.getNewUUID()
args = (node_type, uuid, ip, port, self.app.name)
packet = protocol.requestNodeIdentification(1, *args)
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None})
self.service.handleRequestNodeIdentification(conn,
packet=packet,
node_type=node_type,
uuid=uuid,
ip_address=ip,
port=port,
name=self.app.name,)
self.service.handleRequestNodeIdentification(conn, packet, *args)
self.checkCalledAcceptNodeIdentification(conn)
return uuid
# Tests
def test_01_handleRequestNodeIdentification(self):
service = self.service
packet = Packet(msg_id=1)
uuid = self.getNewUUID()
args = (STORAGE_NODE_TYPE, uuid, '127.0.0.1', self.storage_port, 'INVALID_NAME')
packet = protocol.requestNodeIdentification(1, *args)
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None})
ptid = self.app.lptid
service.handleRequestNodeIdentification(conn,
packet=packet,
node_type=STORAGE_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.1',
port=self.storage_port,
name="INVALID_NAME",)
service.handleRequestNodeIdentification(conn, packet, *args)
self.checkCalledAbort(conn)
self.assertEquals(len(self.app.nm.getStorageNodeList()), 0)
self.assertEquals(self.app.lptid, ptid)
......@@ -387,7 +378,7 @@ server: 127.0.0.1:10023
def test_02_handleAskPrimaryMaster(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_id=2)
packet = protocol.askPrimaryMaster(msg_id=2)
# test answer to a storage node
conn = Mock({"addPacket" : None,
"answerPrimaryMaster" : None,
......@@ -406,7 +397,7 @@ 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 = Packet(msg_id=2)
packet = protocol.askPrimaryMaster(msg_id=2)
conn = Mock({"addPacket" : None, "abort" : None, "answerPrimaryMaster" : None,
"notifyNodeInformation" : None, "sendPartitionTable" : None,
"getUUID" : uuid, "getAddress" : ("127.0.0.1", 11021)})
......
......@@ -24,6 +24,7 @@ from struct import pack, unpack
from neo.protocol import Packet, INVALID_UUID
from neo.master.verification import VerificationEventHandler
from neo.master.app import Application
from neo import protocol
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, \
......@@ -147,17 +148,12 @@ server: 127.0.0.1:10023
port=10021):
"""Do first step of identification to MN
"""
packet = Packet(msg_id=1)
uuid = self.getNewUUID()
args = (node_type, uuid, ip, port, self.app.name)
packet = protocol.requestNodeIdentification(1, *args)
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None})
self.verification.handleRequestNodeIdentification(conn,
packet=packet,
node_type=node_type,
uuid=uuid,
ip_address=ip,
port=port,
name=self.app.name,)
self.verification.handleRequestNodeIdentification(conn, packet, *args)
self.checkCalledAcceptNodeIdentification(conn)
return uuid
......@@ -267,12 +263,12 @@ server: 127.0.0.1:10023
def test_04_handleRequestNodeIdentification(self):
verification = self.verification
packet = Packet(msg_id=1)
uuid = self.getNewUUID()
args = ( MASTER_NODE_TYPE, uuid, '127.0.0.1', self.storage_port, "INVALID_NAME")
packet = protocol.requestNodeIdentification(1, *args)
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None})
verification.handleRequestNodeIdentification(conn,
packet=packet,
verification.handleRequestNodeIdentification(conn, packet=packet,
node_type=MASTER_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.1',
......@@ -523,7 +519,7 @@ server: 127.0.0.1:10023
def test_05_handleAskPrimaryMaster(self):
verification = self.verification
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_id=2)
packet = protocol.askPrimaryMaster(msg_id=2)
conn = Mock({"addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
......@@ -536,7 +532,7 @@ server: 127.0.0.1:10023
self.checkCalledNotifyNodeInformation(conn, 1)
# if storage node, expect messages
uuid = self.identifyToMasterNode(STORAGE_NODE_TYPE, port=self.storage_port)
packet = Packet(msg_id=2)
packet = protocol.askPrimaryMaster(msg_id=2)
conn = Mock({"addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
......@@ -571,7 +567,7 @@ server: 127.0.0.1:10023
def test_07_handleReelectPrimaryMaster(self):
verification = self.verification
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet()
packet = protocol.askPrimaryMaster(0)
# No uuid
conn = Mock({"addPacket" : None,
"getUUID" : None,
......
......@@ -16,6 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import unittest, os
from mock import Mock
from neo import protocol
from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, BROKEN_STATE, \
MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, INVALID_UUID
from neo.node import Node, MasterNode, StorageNode, ClientNode, NodeManager
......@@ -409,12 +410,11 @@ class testConnection(unittest.TestCase):
# packet witch raise protocol error
# change the max packet size and create a to big message
# be careful not to set the max packet size < error message
p = Packet()
master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, 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", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p.answerPrimaryMaster(1, getNewUUID(), master_list)
p = protocol.answerPrimaryMaster(1, getNewUUID(), master_list)
OLD_MAX_PACKET_SIZE = protocol.MAX_PACKET_SIZE
protocol.MAX_PACKET_SIZE = 0x55
......@@ -425,7 +425,7 @@ class testConnection(unittest.TestCase):
self.assertNotEqual(bc.getConnector(), None)
bc.addPacket(p)
self.assertNotEqual(bc.write_buf, "testdata")
self.assertEqual(len(bc.write_buf), len(p.encode()))
self.assertRaises(ProtocolError, p.encode)
self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 2)
# check it sends error packet
packet = Packet.parse(bc.write_buf)
......@@ -478,12 +478,11 @@ class testConnection(unittest.TestCase):
self.assertEqual(len(bc.event_dict), 0)
# give some data to analyse
p = Packet()
master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, 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", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p.answerPrimaryMaster(1, getNewUUID(), master_list)
p = protocol.answerPrimaryMaster(1, getNewUUID(), master_list)
data = p.encode()
bc.read_buf += data
self.assertEqual(len(bc.event_dict), 0)
......@@ -505,21 +504,19 @@ class testConnection(unittest.TestCase):
bc = Connection(em, handler, connector_handler=DoNothingConnector,
connector=connector, addr=("127.0.0.7", 93413))
# packet 1
p1 = Packet()
master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, 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", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p1.answerPrimaryMaster(1, getNewUUID(), master_list)
p1 = protocol.answerPrimaryMaster(1, getNewUUID(), master_list)
data = p1.encode()
bc.read_buf += data
# packet 2
p2 = Packet()
master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, 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", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p2.answerPrimaryMaster(2, getNewUUID(), master_list)
p2 = protocol.answerPrimaryMaster(2, getNewUUID(), master_list)
data = p2.encode()
bc.read_buf += data
self.assertEqual(len(bc.read_buf), len(p1.encode()) + len(p2.encode()))
......@@ -562,12 +559,11 @@ class testConnection(unittest.TestCase):
bc = Connection(em, handler, connector_handler=DoNothingConnector,
connector=connector, addr=("127.0.0.7", 93413))
p = Packet()
master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, 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", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p.answerPrimaryMaster(1, getNewUUID(), master_list)
p = protocol.answerPrimaryMaster(1, getNewUUID(), master_list)
data = p.encode()
bc.read_buf += data
self.assertEqual(len(bc.event_dict), 0)
......@@ -688,13 +684,12 @@ class testConnection(unittest.TestCase):
handler = Mock()
# patch receive method to return data
def receive(self):
p = Packet()
master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2136, 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", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
uuid = getNewUUID()
p.answerPrimaryMaster(1, uuid, master_list)
p = protocol.answerPrimaryMaster(1, uuid, master_list)
data = p.encode()
return data
DoNothingConnector.receive = receive
......
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