Commit 3d93441b authored by Grégory Wisniewski's avatar Grégory Wisniewski

All-in-one commit :

- Some private methods of Connection prefixed with '_'
- Thus those methods are no more overriden in MT* classes 
- Add description of notify/ask/answer methods and lockCheckWrapper
- Remove a forgotten addPacket from storage handler and another from master
service handler that requires to add an optional msg_id parameter to notify
- Update tests


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@509 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent ddb2d2bd
...@@ -153,7 +153,7 @@ class Connection(BaseConnection): ...@@ -153,7 +153,7 @@ class Connection(BaseConnection):
def setUUID(self, uuid): def setUUID(self, uuid):
self.uuid = uuid self.uuid = uuid
def getNextId(self): def _getNextId(self):
next_id = self.cur_id next_id = self.cur_id
# Deal with an overflow. # Deal with an overflow.
if self.cur_id == 0xffffffff: if self.cur_id == 0xffffffff:
...@@ -189,7 +189,7 @@ class Connection(BaseConnection): ...@@ -189,7 +189,7 @@ class Connection(BaseConnection):
def writable(self): def writable(self):
"""Called when self is writable.""" """Called when self is writable."""
self.send() self._send()
if not self.pending(): if not self.pending():
if self.aborted: if self.aborted:
self.close() self.close()
...@@ -198,7 +198,7 @@ class Connection(BaseConnection): ...@@ -198,7 +198,7 @@ class Connection(BaseConnection):
def readable(self): def readable(self):
"""Called when self is readable.""" """Called when self is readable."""
self.recv() self._recv()
self.analyse() self.analyse()
if self.aborted: if self.aborted:
...@@ -237,7 +237,7 @@ class Connection(BaseConnection): ...@@ -237,7 +237,7 @@ class Connection(BaseConnection):
def pending(self): def pending(self):
return self.connector is not None and self.write_buf return self.connector is not None and self.write_buf
def recv(self): def _recv(self):
"""Receive data from a connector.""" """Receive data from a connector."""
try: try:
data = self.connector.receive() data = self.connector.receive()
...@@ -259,7 +259,7 @@ class Connection(BaseConnection): ...@@ -259,7 +259,7 @@ class Connection(BaseConnection):
# unhandled connector exception # unhandled connector exception
raise raise
def send(self): def _send(self):
"""Send data to a connector.""" """Send data to a connector."""
if not self.write_buf: if not self.write_buf:
return return
...@@ -278,7 +278,7 @@ class Connection(BaseConnection): ...@@ -278,7 +278,7 @@ class Connection(BaseConnection):
# unhandled connector exception # unhandled connector exception
raise raise
def addPacket(self, packet): def _addPacket(self, packet):
"""Add a packet into the write buffer.""" """Add a packet into the write buffer."""
if self.connector is None: if self.connector is None:
return return
...@@ -324,23 +324,27 @@ class Connection(BaseConnection): ...@@ -324,23 +324,27 @@ class Connection(BaseConnection):
self.event_dict[msg_id] = event self.event_dict[msg_id] = event
self.em.addIdleEvent(event) self.em.addIdleEvent(event)
def notify(self, packet): def notify(self, packet, msg_id=None):
msg_id = self.getNextId() """ Then a packet with a new ID """
if msg_id is None:
msg_id = self._getNextId()
packet.setId(msg_id) packet.setId(msg_id)
self.addPacket(packet) self._addPacket(packet)
return msg_id return msg_id
def ask(self, packet, timeout=5, additional_timeout=30): def ask(self, packet, timeout=5, additional_timeout=30):
msg_id = self.getNextId() """ Send a packet with a new ID and register the expectation of an answer """
msg_id = self._getNextId()
packet.setId(msg_id) packet.setId(msg_id)
self.expectMessage(msg_id) self.expectMessage(msg_id)
self.addPacket(packet) self._addPacket(packet)
return msg_id return msg_id
def answer(self, packet, answer_to): def answer(self, packet, answered_packet):
msg_id = answer_to.getId() """ Answer to a packet by re-using its ID for the packet answer """
msg_id = answered_packet.getId()
packet.setId(msg_id) packet.setId(msg_id)
self.addPacket(packet) self._addPacket(packet)
def isServerConnection(self): def isServerConnection(self):
raise NotImplementedError raise NotImplementedError
...@@ -418,14 +422,6 @@ class MTClientConnection(ClientConnection): ...@@ -418,14 +422,6 @@ class MTClientConnection(ClientConnection):
def unlock(self): def unlock(self):
self.release() self.release()
@lockCheckWrapper
def recv(self, *args, **kw):
return super(MTClientConnection, self).recv(*args, **kw)
@lockCheckWrapper
def send(self, *args, **kw):
return super(MTClientConnection, self).send(*args, **kw)
@lockCheckWrapper @lockCheckWrapper
def writable(self, *args, **kw): def writable(self, *args, **kw):
return super(MTClientConnection, self).writable(*args, **kw) return super(MTClientConnection, self).writable(*args, **kw)
...@@ -439,16 +435,20 @@ class MTClientConnection(ClientConnection): ...@@ -439,16 +435,20 @@ class MTClientConnection(ClientConnection):
return super(MTClientConnection, self).analyse(*args, **kw) return super(MTClientConnection, self).analyse(*args, **kw)
@lockCheckWrapper @lockCheckWrapper
def addPacket(self, *args, **kw): def expectMessage(self, *args, **kw):
return super(MTClientConnection, self).addPacket(*args, **kw) return super(MTClientConnection, self).expectMessage(*args, **kw)
@lockCheckWrapper
def notify(self, *args, **kw):
return super(MTClientConnection, self).notify(*args, **kw)
@lockCheckWrapper @lockCheckWrapper
def getNextId(self, *args, **kw): def ask(self, *args, **kw):
return super(MTClientConnection, self).getNextId(*args, **kw) return super(MTClientConnection, self).ask(*args, **kw)
@lockCheckWrapper @lockCheckWrapper
def expectMessage(self, *args, **kw): def answer(self, *args, **kw):
return super(MTClientConnection, self).expectMessage(*args, **kw) return super(MTClientConnection, self).answer(*args, **kw)
class MTServerConnection(ServerConnection): class MTServerConnection(ServerConnection):
"""A Multithread-safe version of ServerConnection.""" """A Multithread-safe version of ServerConnection."""
...@@ -469,14 +469,6 @@ class MTServerConnection(ServerConnection): ...@@ -469,14 +469,6 @@ class MTServerConnection(ServerConnection):
def unlock(self): def unlock(self):
self.release() self.release()
@lockCheckWrapper
def recv(self, *args, **kw):
return super(MTServerConnection, self).recv(*args, **kw)
@lockCheckWrapper
def send(self, *args, **kw):
return super(MTServerConnection, self).send(*args, **kw)
@lockCheckWrapper @lockCheckWrapper
def writable(self, *args, **kw): def writable(self, *args, **kw):
return super(MTServerConnection, self).writable(*args, **kw) return super(MTServerConnection, self).writable(*args, **kw)
...@@ -490,14 +482,18 @@ class MTServerConnection(ServerConnection): ...@@ -490,14 +482,18 @@ class MTServerConnection(ServerConnection):
return super(MTServerConnection, self).analyse(*args, **kw) return super(MTServerConnection, self).analyse(*args, **kw)
@lockCheckWrapper @lockCheckWrapper
def addPacket(self, *args, **kw): def expectMessage(self, *args, **kw):
return super(MTServerConnection, self).addPacket(*args, **kw) return super(MTServerConnection, self).expectMessage(*args, **kw)
@lockCheckWrapper
def notify(self, *args, **kw):
return super(MTClientConnection, self).notify(*args, **kw)
@lockCheckWrapper @lockCheckWrapper
def getNextId(self, *args, **kw): def ask(self, *args, **kw):
return super(MTServerConnection, self).getNextId(*args, **kw) return super(MTClientConnection, self).ask(*args, **kw)
@lockCheckWrapper @lockCheckWrapper
def expectMessage(self, *args, **kw): def answer(self, *args, **kw):
return super(MTServerConnection, self).expectMessage(*args, **kw) return super(MTClientConnection, self).answer(*args, **kw)
...@@ -467,10 +467,8 @@ class ServiceEventHandler(MasterEventHandler): ...@@ -467,10 +467,8 @@ class ServiceEventHandler(MasterEventHandler):
node = app.nm.getNodeByUUID(uuid) node = app.nm.getNodeByUUID(uuid)
if node.getNodeType() == CLIENT_NODE_TYPE: if node.getNodeType() == CLIENT_NODE_TYPE:
if c is t.getConnection(): if c is t.getConnection():
# TODO: use connection.notify if possible
p = protocol.notifyTransactionFinished(tid) p = protocol.notifyTransactionFinished(tid)
p.setId(t.getMessageId()) c.notify(p, t.getMessageId())
c.addPacket(p)
else: else:
p = protocol.invalidateObjects(t.getOIDList(), tid) p = protocol.invalidateObjects(t.getOIDList(), tid)
c.notify(p) c.notify(p)
......
...@@ -51,16 +51,16 @@ from neo.node import MasterNode, StorageNode ...@@ -51,16 +51,16 @@ from neo.node import MasterNode, StorageNode
from neo.master.tests.connector import DoNothingConnector from neo.master.tests.connector import DoNothingConnector
from neo.connection import ClientConnection from neo.connection import ClientConnection
# patch connection so that we can register addPacket messages # patch connection so that we can register _addPacket messages
# in mock object # in mock object
def addPacket(self, packet): def _addPacket(self, packet):
if self.connector is not None: if self.connector is not None:
self.connector.addPacket(packet) self.connector._addPacket(packet)
def expectMessage(self, packet): def expectMessage(self, packet):
if self.connector is not None: if self.connector is not None:
self.connector.expectMessage(packet) self.connector.expectMessage(packet)
ClientConnection.addPacket = addPacket ClientConnection._addPacket = _addPacket
ClientConnection.expectMessage = expectMessage ClientConnection.expectMessage = expectMessage
...@@ -182,7 +182,7 @@ server: 127.0.0.1:10023 ...@@ -182,7 +182,7 @@ server: 127.0.0.1:10023
args = (node_type, uuid, ip, port, self.app.name) args = (node_type, uuid, ip, port, self.app.name)
packet = protocol.requestNodeIdentification(*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,
"isServerConnection" : True}) "isServerConnection" : True})
self.election.handleRequestNodeIdentification(conn, self.election.handleRequestNodeIdentification(conn,
packet=packet, packet=packet,
...@@ -207,7 +207,7 @@ server: 127.0.0.1:10023 ...@@ -207,7 +207,7 @@ server: 127.0.0.1:10023
def checkCalledAskPrimaryMaster(self, conn, packet_number=0): def checkCalledAskPrimaryMaster(self, conn, packet_number=0):
""" Check ask primary master has been send""" """ Check ask primary master has been send"""
call = conn.mockGetNamedCalls("addPacket")[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(),ASK_PRIMARY_MASTER) self.assertEquals(packet.getType(),ASK_PRIMARY_MASTER)
...@@ -351,7 +351,7 @@ server: 127.0.0.1:10023 ...@@ -351,7 +351,7 @@ server: 127.0.0.1:10023
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), None) self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), None)
self.assertEqual(conn.getUUID(), None) self.assertEqual(conn.getUUID(), None)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.election.handleAcceptNodeIdentification(conn, p, STORAGE_NODE_TYPE, self.election.handleAcceptNodeIdentification(conn, p, STORAGE_NODE_TYPE,
uuid, "127.0.0.1", self.master_port, uuid, "127.0.0.1", self.master_port,
self.app.num_partitions, self.app.num_partitions,
...@@ -374,7 +374,7 @@ server: 127.0.0.1:10023 ...@@ -374,7 +374,7 @@ server: 127.0.0.1:10023
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), None) self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), None)
self.assertEqual(conn.getUUID(), None) self.assertEqual(conn.getUUID(), None)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.election.handleAcceptNodeIdentification(conn, p, STORAGE_NODE_TYPE, self.election.handleAcceptNodeIdentification(conn, p, STORAGE_NODE_TYPE,
uuid, "127.0.0.2", self.master_port, uuid, "127.0.0.2", self.master_port,
self.app.num_partitions, self.app.num_partitions,
...@@ -394,7 +394,7 @@ server: 127.0.0.1:10023 ...@@ -394,7 +394,7 @@ server: 127.0.0.1:10023
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), None) self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), None)
self.assertEqual(conn.getUUID(), None) self.assertEqual(conn.getUUID(), None)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.election.handleAcceptNodeIdentification(conn, p, MASTER_NODE_TYPE, self.election.handleAcceptNodeIdentification(conn, p, MASTER_NODE_TYPE,
uuid, "127.0.0.1", self.master_port, uuid, "127.0.0.1", self.master_port,
...@@ -403,7 +403,7 @@ server: 127.0.0.1:10023 ...@@ -403,7 +403,7 @@ server: 127.0.0.1:10023
self.app.uuid) self.app.uuid)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), uuid) self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), uuid)
self.assertEqual(conn.getUUID(), uuid) self.assertEqual(conn.getUUID(), uuid)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),2) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),2)
self.checkCalledAskPrimaryMaster(conn.getConnector(), 1) self.checkCalledAskPrimaryMaster(conn.getConnector(), 1)
...@@ -418,10 +418,10 @@ server: 127.0.0.1:10023 ...@@ -418,10 +418,10 @@ server: 127.0.0.1:10023
p = protocol.askPrimaryMaster() p = protocol.askPrimaryMaster()
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1) self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
self.election.handleAnswerPrimaryMaster(conn, p, INVALID_UUID, []) self.election.handleAnswerPrimaryMaster(conn, p, INVALID_UUID, [])
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(self.app.primary, False) self.assertEqual(self.app.primary, False)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1) self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
...@@ -439,10 +439,10 @@ server: 127.0.0.1:10023 ...@@ -439,10 +439,10 @@ server: 127.0.0.1:10023
p = protocol.askPrimaryMaster() p = protocol.askPrimaryMaster()
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1) self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
self.election.handleAnswerPrimaryMaster(conn, p, INVALID_UUID, []) self.election.handleAnswerPrimaryMaster(conn, p, INVALID_UUID, [])
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(self.app.primary, None) self.assertEqual(self.app.primary, None)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1) self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
...@@ -459,11 +459,11 @@ server: 127.0.0.1:10023 ...@@ -459,11 +459,11 @@ server: 127.0.0.1:10023
self.app.nm.add(MasterNode(("127.0.0.1", self.master_port), uuid)) 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.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 2) self.assertEqual(len(self.app.nm.getMasterNodeList()), 2)
self.assertEqual(self.app.primary_master_node, None) self.assertEqual(self.app.primary_master_node, None)
self.election.handleAnswerPrimaryMaster(conn, p, uuid, []) self.election.handleAnswerPrimaryMaster(conn, p, uuid, [])
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 2) self.assertEqual(len(self.app.nm.getMasterNodeList()), 2)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 0) self.assertEqual(len(self.app.negotiating_master_node_set), 0)
...@@ -480,11 +480,11 @@ server: 127.0.0.1:10023 ...@@ -480,11 +480,11 @@ server: 127.0.0.1:10023
p = protocol.askPrimaryMaster() p = protocol.askPrimaryMaster()
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1) self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
self.assertEqual(self.app.primary_master_node, None) self.assertEqual(self.app.primary_master_node, None)
self.election.handleAnswerPrimaryMaster(conn, p, uuid, []) self.election.handleAnswerPrimaryMaster(conn, p, uuid, [])
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1) self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 0) self.assertEqual(len(self.app.negotiating_master_node_set), 0)
...@@ -502,12 +502,12 @@ server: 127.0.0.1:10023 ...@@ -502,12 +502,12 @@ server: 127.0.0.1:10023
self.app.nm.add(MasterNode(("127.0.0.1", self.master_port), uuid)) 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.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 2) self.assertEqual(len(self.app.nm.getMasterNodeList()), 2)
self.assertEqual(self.app.primary_master_node, None) self.assertEqual(self.app.primary_master_node, None)
master_uuid = self.getNewUUID() master_uuid = self.getNewUUID()
self.election.handleAnswerPrimaryMaster(conn, p, master_uuid, [("127.0.0.1", self.master_port+1, master_uuid),]) self.election.handleAnswerPrimaryMaster(conn, p, master_uuid, [("127.0.0.1", self.master_port+1, master_uuid),])
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 3) self.assertEqual(len(self.app.nm.getMasterNodeList()), 3)
self.assertEqual(len(self.app.unconnected_master_node_set), 1) self.assertEqual(len(self.app.unconnected_master_node_set), 1)
self.assertEqual(len(self.app.negotiating_master_node_set), 0) self.assertEqual(len(self.app.negotiating_master_node_set), 0)
...@@ -523,7 +523,7 @@ server: 127.0.0.1:10023 ...@@ -523,7 +523,7 @@ server: 127.0.0.1:10023
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(*args) packet = protocol.requestNodeIdentification(*args)
# test alien cluster # test alien cluster
conn = Mock({"addPacket" : None, "abort" : None, conn = Mock({"_addPacket" : None, "abort" : None,
"isServerConnection" : True}) "isServerConnection" : True})
self.checkProtocolErrorRaised( self.checkProtocolErrorRaised(
election.handleRequestNodeIdentification, election.handleRequestNodeIdentification,
...@@ -535,7 +535,7 @@ server: 127.0.0.1:10023 ...@@ -535,7 +535,7 @@ server: 127.0.0.1:10023
port=self.storage_port, port=self.storage_port,
name="INVALID_NAME",) name="INVALID_NAME",)
# test connection of a storage node # test connection of a storage node
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None, conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None,
"isServerConnection" : True}) "isServerConnection" : True})
self.checkNotReadyErrorRaised( self.checkNotReadyErrorRaised(
election.handleRequestNodeIdentification, election.handleRequestNodeIdentification,
...@@ -548,7 +548,7 @@ server: 127.0.0.1:10023 ...@@ -548,7 +548,7 @@ server: 127.0.0.1:10023
name=self.app.name,) name=self.app.name,)
# known node # known node
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None, conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None,
"isServerConnection" : True}) "isServerConnection" : True})
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1) self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
node = self.app.nm.getMasterNodeList()[0] node = self.app.nm.getMasterNodeList()[0]
...@@ -566,7 +566,7 @@ server: 127.0.0.1:10023 ...@@ -566,7 +566,7 @@ server: 127.0.0.1:10023
self.assertEqual(node.getState(), RUNNING_STATE) self.assertEqual(node.getState(), RUNNING_STATE)
self.checkCalledAcceptNodeIdentification(conn) self.checkCalledAcceptNodeIdentification(conn)
# unknown node # unknown node
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None, conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None,
"isServerConnection" : True}) "isServerConnection" : True})
new_uuid = self.getNewUUID() new_uuid = self.getNewUUID()
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1) self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
...@@ -584,7 +584,7 @@ server: 127.0.0.1:10023 ...@@ -584,7 +584,7 @@ server: 127.0.0.1:10023
self.assertEqual(len(self.app.unconnected_master_node_set), 2) self.assertEqual(len(self.app.unconnected_master_node_set), 2)
self.assertEqual(len(self.app.negotiating_master_node_set), 0) self.assertEqual(len(self.app.negotiating_master_node_set), 0)
# broken node # broken node
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None, conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None,
"isServerConnection" : True}) "isServerConnection" : True})
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port+1)) node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port+1))
self.assertEqual(node.getUUID(), new_uuid) self.assertEqual(node.getUUID(), new_uuid)
...@@ -606,7 +606,7 @@ server: 127.0.0.1:10023 ...@@ -606,7 +606,7 @@ server: 127.0.0.1:10023
election = self.election election = self.election
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = protocol.askPrimaryMaster() packet = protocol.askPrimaryMaster()
conn = Mock({"addPacket" : None, conn = Mock({"_addPacket" : None,
"getUUID" : uuid, "getUUID" : uuid,
"isServerConnection" : True, "isServerConnection" : True,
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
...@@ -621,14 +621,14 @@ server: 127.0.0.1:10023 ...@@ -621,14 +621,14 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(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,
"isServerConnection" : True, "isServerConnection" : True,
"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)
self.checkIdenficationRequired(election.handleAnnouncePrimaryMaster, conn, packet) self.checkIdenficationRequired(election.handleAnnouncePrimaryMaster, conn, packet)
# announce # announce
conn = Mock({"addPacket" : None, conn = Mock({"_addPacket" : None,
"getUUID" : uuid, "getUUID" : uuid,
"isServerConnection" : True, "isServerConnection" : True,
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
...@@ -638,7 +638,7 @@ server: 127.0.0.1:10023 ...@@ -638,7 +638,7 @@ server: 127.0.0.1:10023
self.assertEqual(self.app.primary, False) self.assertEqual(self.app.primary, False)
self.assertNotEqual(self.app.primary_master_node, None) self.assertNotEqual(self.app.primary_master_node, None)
# set current as primary, and announce another, must raise # set current as primary, and announce another, must raise
conn = Mock({"addPacket" : None, conn = Mock({"_addPacket" : None,
"getUUID" : uuid, "getUUID" : uuid,
"isServerConnection" : True, "isServerConnection" : True,
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
...@@ -652,7 +652,7 @@ server: 127.0.0.1:10023 ...@@ -652,7 +652,7 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = protocol.askPrimaryMaster() packet = protocol.askPrimaryMaster()
# No uuid # No uuid
conn = Mock({"addPacket" : None, conn = Mock({"_addPacket" : None,
"getUUID" : None, "getUUID" : None,
"isServerConnection" : True, "isServerConnection" : True,
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
......
...@@ -200,7 +200,7 @@ server: 127.0.0.1:10023 ...@@ -200,7 +200,7 @@ server: 127.0.0.1:10023
def checkCalledNotifyTransactionFinished(self, conn, packet_number=0): def checkCalledNotifyTransactionFinished(self, conn, packet_number=0):
""" Check notifyTransactionFinished message has been send""" """ Check notifyTransactionFinished 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_TRANSACTION_FINISHED) self.assertEquals(packet.getType(), NOTIFY_TRANSACTION_FINISHED)
...@@ -240,7 +240,7 @@ server: 127.0.0.1:10023 ...@@ -240,7 +240,7 @@ server: 127.0.0.1:10023
args = (node_type, uuid, ip, port, self.app.name) args = (node_type, uuid, ip, port, self.app.name)
packet = protocol.requestNodeIdentification(*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.service.handleRequestNodeIdentification(conn, packet, *args) self.service.handleRequestNodeIdentification(conn, packet, *args)
self.checkCalledAcceptNodeIdentification(conn) self.checkCalledAcceptNodeIdentification(conn)
return uuid return uuid
...@@ -252,14 +252,14 @@ server: 127.0.0.1:10023 ...@@ -252,14 +252,14 @@ server: 127.0.0.1:10023
args = (STORAGE_NODE_TYPE, uuid, '127.0.0.1', self.storage_port, 'INVALID_NAME') args = (STORAGE_NODE_TYPE, uuid, '127.0.0.1', self.storage_port, 'INVALID_NAME')
packet = protocol.requestNodeIdentification(*args) packet = protocol.requestNodeIdentification(*args)
# test alien cluster # test alien cluster
conn = Mock({"addPacket" : None, "abort" : None}) conn = Mock({"_addPacket" : None, "abort" : None})
ptid = self.app.lptid ptid = self.app.lptid
self.checkProtocolErrorRaised(service.handleRequestNodeIdentification, conn, packet, *args) self.checkProtocolErrorRaised(service.handleRequestNodeIdentification, conn, packet, *args)
self.assertEquals(len(self.app.nm.getStorageNodeList()), 0) self.assertEquals(len(self.app.nm.getStorageNodeList()), 0)
self.assertEquals(self.app.lptid, ptid) self.assertEquals(self.app.lptid, ptid)
# test connection of a storage node # test connection of a storage node
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None}) conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None})
ptid = self.app.lptid ptid = self.app.lptid
service.handleRequestNodeIdentification(conn, service.handleRequestNodeIdentification(conn,
packet=packet, packet=packet,
...@@ -277,7 +277,7 @@ server: 127.0.0.1:10023 ...@@ -277,7 +277,7 @@ server: 127.0.0.1:10023
self.failUnless(self.app.lptid > ptid) self.failUnless(self.app.lptid > ptid)
# send message again for the same storage node, MN must recognize it # send message again for the same storage node, MN must recognize it
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None}) conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None})
ptid = self.app.lptid ptid = self.app.lptid
service.handleRequestNodeIdentification(conn, service.handleRequestNodeIdentification(conn,
packet=packet, packet=packet,
...@@ -296,7 +296,7 @@ server: 127.0.0.1:10023 ...@@ -296,7 +296,7 @@ server: 127.0.0.1:10023
# send message again for the same storage node but different uuid # send message again for the same storage node but different uuid
# must be rejected as SN is considered as running # must be rejected as SN is considered as running
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None}) conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None})
ptid = self.app.lptid ptid = self.app.lptid
new_uuid = self.getNewUUID() new_uuid = self.getNewUUID()
...@@ -318,7 +318,7 @@ server: 127.0.0.1:10023 ...@@ -318,7 +318,7 @@ server: 127.0.0.1:10023
# same test, but set SN as not running before # same test, but set SN as not running before
# this new node must replaced the old one # this new node must replaced the old one
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None}) conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None})
ptid = self.app.lptid ptid = self.app.lptid
sn = self.app.nm.getStorageNodeList()[0] sn = self.app.nm.getStorageNodeList()[0]
self.assertEquals(sn.getState(), RUNNING_STATE) self.assertEquals(sn.getState(), RUNNING_STATE)
...@@ -344,7 +344,7 @@ server: 127.0.0.1:10023 ...@@ -344,7 +344,7 @@ server: 127.0.0.1:10023
# send message again for the same storage node but different address # send message again for the same storage node but different address
# A new UUID should be send and the node is added to the storage node list # A new UUID should be send and the node is added to the storage node list
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None}) conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None})
ptid = self.app.lptid ptid = self.app.lptid
service.handleRequestNodeIdentification(conn, service.handleRequestNodeIdentification(conn,
packet=packet, packet=packet,
...@@ -370,7 +370,7 @@ server: 127.0.0.1:10023 ...@@ -370,7 +370,7 @@ server: 127.0.0.1:10023
self.failUnless(self.app.lptid > ptid) self.failUnless(self.app.lptid > ptid)
# mark the node as broken and request identification, this must be forbidden # mark the node as broken and request identification, this must be forbidden
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None}) conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None})
ptid = self.app.lptid ptid = self.app.lptid
sn = self.app.nm.getStorageNodeList()[0] sn = self.app.nm.getStorageNodeList()[0]
self.assertEquals(sn.getState(), RUNNING_STATE) self.assertEquals(sn.getState(), RUNNING_STATE)
...@@ -400,7 +400,7 @@ server: 127.0.0.1:10023 ...@@ -400,7 +400,7 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = protocol.askPrimaryMaster() packet = protocol.askPrimaryMaster()
# test answer to a storage node # test answer to a storage node
conn = Mock({"addPacket" : None, conn = Mock({"_addPacket" : None,
"answerPrimaryMaster" : None, "answerPrimaryMaster" : None,
"notifyNodeInformation" : None, "notifyNodeInformation" : None,
"sendPartitionTable" : None, "sendPartitionTable" : None,
...@@ -417,7 +417,7 @@ server: 127.0.0.1:10023 ...@@ -417,7 +417,7 @@ server: 127.0.0.1:10023
# Same but identify as a client node, must not get start operation message # Same but identify as a client node, must not get start operation message
uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=11021) uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=11021)
packet = protocol.askPrimaryMaster() packet = protocol.askPrimaryMaster()
conn = Mock({"addPacket" : None, "abort" : None, "answerPrimaryMaster" : None, conn = Mock({"_addPacket" : None, "abort" : None, "answerPrimaryMaster" : None,
"notifyNodeInformation" : None, "sendPartitionTable" : None, "notifyNodeInformation" : None, "sendPartitionTable" : None,
"getUUID" : uuid, "getAddress" : ("127.0.0.1", 11021)}) "getUUID" : uuid, "getAddress" : ("127.0.0.1", 11021)})
service.handleAskPrimaryMaster(conn, packet) service.handleAskPrimaryMaster(conn, packet)
...@@ -736,7 +736,6 @@ server: 127.0.0.1:10023 ...@@ -736,7 +736,6 @@ server: 127.0.0.1:10023
self.assertEquals(len(storage_conn_1.mockGetNamedCalls("notify")), 1) self.assertEquals(len(storage_conn_1.mockGetNamedCalls("notify")), 1)
self.assertEquals(len(storage_conn_2.mockGetNamedCalls("ask")), 1) self.assertEquals(len(storage_conn_2.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(storage_conn_2.mockGetNamedCalls("notify")), 1) self.assertEquals(len(storage_conn_2.mockGetNamedCalls("notify")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
self.checkCalledLockInformation(storage_conn_1) self.checkCalledLockInformation(storage_conn_1)
self.checkCalledLockInformation(storage_conn_2) self.checkCalledLockInformation(storage_conn_2)
......
...@@ -63,8 +63,8 @@ class StorageEventHandler(EventHandler): ...@@ -63,8 +63,8 @@ class StorageEventHandler(EventHandler):
info = n.getServer() + (n.getUUID() or INVALID_UUID,) info = n.getServer() + (n.getUUID() or INVALID_UUID,)
known_master_list.append(info) known_master_list.append(info)
p = protocol.answerPrimaryMaster(packet.getId(), primary_uuid, known_master_list) p = protocol.answerPrimaryMaster(primary_uuid, known_master_list)
conn.addPacket(p) conn.answer(p, packet)
def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid, def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid,
known_master_list): known_master_list):
......
...@@ -172,15 +172,15 @@ class testConnection(unittest.TestCase): ...@@ -172,15 +172,15 @@ class testConnection(unittest.TestCase):
self.assertEqual(bc.getUUID(), uuid) self.assertEqual(bc.getUUID(), uuid)
# test next id # test next id
cur_id = bc.cur_id cur_id = bc.cur_id
next_id = bc.getNextId() next_id = bc._getNextId()
self.assertEqual(next_id, cur_id) self.assertEqual(next_id, cur_id)
next_id = bc.getNextId() next_id = bc._getNextId()
self.failUnless(next_id > cur_id) self.failUnless(next_id > cur_id)
# test overflow of next id # test overflow of next id
bc.cur_id = 0xffffffff bc.cur_id = 0xffffffff
next_id = bc.getNextId() next_id = bc._getNextId()
self.assertEqual(next_id, 0xffffffff) self.assertEqual(next_id, 0xffffffff)
next_id = bc.getNextId() next_id = bc._getNextId()
self.assertEqual(next_id, 0) self.assertEqual(next_id, 0)
# test abort # test abort
bc.abort() bc.abort()
...@@ -224,7 +224,7 @@ class testConnection(unittest.TestCase): ...@@ -224,7 +224,7 @@ class testConnection(unittest.TestCase):
self.assertEqual(bc.read_buf, '') self.assertEqual(bc.read_buf, '')
self.assertNotEqual(bc.getConnector(), None) self.assertNotEqual(bc.getConnector(), None)
bc.recv() bc._recv()
self.assertEqual(bc.read_buf, "testdata") self.assertEqual(bc.read_buf, "testdata")
# patch receive method to raise try again # patch receive method to raise try again
...@@ -236,7 +236,7 @@ class testConnection(unittest.TestCase): ...@@ -236,7 +236,7 @@ class testConnection(unittest.TestCase):
connector=connector, addr=("127.0.0.7", 93413)) connector=connector, addr=("127.0.0.7", 93413))
self.assertEqual(bc.read_buf, '') self.assertEqual(bc.read_buf, '')
self.assertNotEqual(bc.getConnector(), None) self.assertNotEqual(bc.getConnector(), None)
bc.recv() bc._recv()
self.assertEqual(bc.read_buf, '') self.assertEqual(bc.read_buf, '')
self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0) self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0) self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0)
...@@ -251,7 +251,7 @@ class testConnection(unittest.TestCase): ...@@ -251,7 +251,7 @@ class testConnection(unittest.TestCase):
self.assertNotEqual(bc.getConnector(), None) self.assertNotEqual(bc.getConnector(), None)
# fake client connection instance with connecting attribute # fake client connection instance with connecting attribute
bc.connecting = True bc.connecting = True
bc.recv() bc._recv()
self.assertEqual(bc.read_buf, '') self.assertEqual(bc.read_buf, '')
self.assertEquals(len(handler.mockGetNamedCalls("connectionFailed")), 1) self.assertEquals(len(handler.mockGetNamedCalls("connectionFailed")), 1)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 1) self.assertEquals(len(em.mockGetNamedCalls("unregister")), 1)
...@@ -264,7 +264,7 @@ class testConnection(unittest.TestCase): ...@@ -264,7 +264,7 @@ class testConnection(unittest.TestCase):
connector=connector, addr=("127.0.0.7", 93413)) connector=connector, addr=("127.0.0.7", 93413))
self.assertEqual(bc.read_buf, '') self.assertEqual(bc.read_buf, '')
self.assertNotEqual(bc.getConnector(), None) self.assertNotEqual(bc.getConnector(), None)
self.assertRaises(ConnectorException, bc.recv) self.assertRaises(ConnectorException, bc._recv)
self.assertEqual(bc.read_buf, '') self.assertEqual(bc.read_buf, '')
self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 1) self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 1)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 2) self.assertEquals(len(em.mockGetNamedCalls("unregister")), 2)
...@@ -280,7 +280,7 @@ class testConnection(unittest.TestCase): ...@@ -280,7 +280,7 @@ class testConnection(unittest.TestCase):
connector=connector, addr=("127.0.0.7", 93413)) connector=connector, addr=("127.0.0.7", 93413))
self.assertEqual(bc.write_buf, '') self.assertEqual(bc.write_buf, '')
self.assertNotEqual(bc.getConnector(), None) self.assertNotEqual(bc.getConnector(), None)
bc.send() bc._send()
self.assertEquals(len(connector.mockGetNamedCalls("send")), 0) self.assertEquals(len(connector.mockGetNamedCalls("send")), 0)
self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0) self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0) self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0)
...@@ -295,7 +295,7 @@ class testConnection(unittest.TestCase): ...@@ -295,7 +295,7 @@ class testConnection(unittest.TestCase):
self.assertEqual(bc.write_buf, '') self.assertEqual(bc.write_buf, '')
bc.write_buf = "testdata" bc.write_buf = "testdata"
self.assertNotEqual(bc.getConnector(), None) self.assertNotEqual(bc.getConnector(), None)
bc.send() bc._send()
self.assertEquals(len(connector.mockGetNamedCalls("send")), 1) self.assertEquals(len(connector.mockGetNamedCalls("send")), 1)
call = connector.mockGetNamedCalls("send")[0] call = connector.mockGetNamedCalls("send")[0]
data = call.getParam(0) data = call.getParam(0)
...@@ -314,7 +314,7 @@ class testConnection(unittest.TestCase): ...@@ -314,7 +314,7 @@ class testConnection(unittest.TestCase):
self.assertEqual(bc.write_buf, '') self.assertEqual(bc.write_buf, '')
bc.write_buf = "testdata" bc.write_buf = "testdata"
self.assertNotEqual(bc.getConnector(), None) self.assertNotEqual(bc.getConnector(), None)
bc.send() bc._send()
self.assertEquals(len(connector.mockGetNamedCalls("send")), 1) self.assertEquals(len(connector.mockGetNamedCalls("send")), 1)
call = connector.mockGetNamedCalls("send")[0] call = connector.mockGetNamedCalls("send")[0]
data = call.getParam(0) data = call.getParam(0)
...@@ -333,7 +333,7 @@ class testConnection(unittest.TestCase): ...@@ -333,7 +333,7 @@ class testConnection(unittest.TestCase):
self.assertEqual(bc.write_buf, '') self.assertEqual(bc.write_buf, '')
bc.write_buf = "testdata" + "second" + "third" bc.write_buf = "testdata" + "second" + "third"
self.assertNotEqual(bc.getConnector(), None) self.assertNotEqual(bc.getConnector(), None)
bc.send() bc._send()
self.assertEquals(len(connector.mockGetNamedCalls("send")), 1) self.assertEquals(len(connector.mockGetNamedCalls("send")), 1)
call = connector.mockGetNamedCalls("send")[0] call = connector.mockGetNamedCalls("send")[0]
data = call.getParam(0) data = call.getParam(0)
...@@ -352,7 +352,7 @@ class testConnection(unittest.TestCase): ...@@ -352,7 +352,7 @@ class testConnection(unittest.TestCase):
self.assertEqual(bc.write_buf, '') self.assertEqual(bc.write_buf, '')
bc.write_buf = "testdata" + "second" + "third" bc.write_buf = "testdata" + "second" + "third"
self.assertNotEqual(bc.getConnector(), None) self.assertNotEqual(bc.getConnector(), None)
bc.send() bc._send()
self.assertEquals(len(connector.mockGetNamedCalls("send")), 1) self.assertEquals(len(connector.mockGetNamedCalls("send")), 1)
call = connector.mockGetNamedCalls("send")[0] call = connector.mockGetNamedCalls("send")[0]
data = call.getParam(0) data = call.getParam(0)
...@@ -371,7 +371,7 @@ class testConnection(unittest.TestCase): ...@@ -371,7 +371,7 @@ class testConnection(unittest.TestCase):
self.assertEqual(bc.write_buf, '') self.assertEqual(bc.write_buf, '')
bc.write_buf = "testdata" + "second" + "third" bc.write_buf = "testdata" + "second" + "third"
self.assertNotEqual(bc.getConnector(), None) self.assertNotEqual(bc.getConnector(), None)
bc.send() bc._send()
self.assertEquals(len(connector.mockGetNamedCalls("send")), 1) self.assertEquals(len(connector.mockGetNamedCalls("send")), 1)
call = connector.mockGetNamedCalls("send")[0] call = connector.mockGetNamedCalls("send")[0]
data = call.getParam(0) data = call.getParam(0)
...@@ -390,7 +390,7 @@ class testConnection(unittest.TestCase): ...@@ -390,7 +390,7 @@ class testConnection(unittest.TestCase):
self.assertEqual(bc.write_buf, '') self.assertEqual(bc.write_buf, '')
bc.write_buf = "testdata" + "second" + "third" bc.write_buf = "testdata" + "second" + "third"
self.assertNotEqual(bc.getConnector(), None) self.assertNotEqual(bc.getConnector(), None)
self.assertRaises(ConnectorException, bc.send) self.assertRaises(ConnectorException, bc._send)
self.assertEquals(len(connector.mockGetNamedCalls("send")), 1) self.assertEquals(len(connector.mockGetNamedCalls("send")), 1)
call = connector.mockGetNamedCalls("send")[0] call = connector.mockGetNamedCalls("send")[0]
data = call.getParam(0) data = call.getParam(0)
...@@ -410,7 +410,7 @@ class testConnection(unittest.TestCase): ...@@ -410,7 +410,7 @@ class testConnection(unittest.TestCase):
connector=None, addr=("127.0.0.7", 93413)) connector=None, addr=("127.0.0.7", 93413))
self.assertEqual(bc.getConnector(), None) self.assertEqual(bc.getConnector(), None)
self.assertEqual(bc.write_buf, '') self.assertEqual(bc.write_buf, '')
bc.addPacket(p) bc._addPacket(p)
self.assertEqual(bc.write_buf, '') self.assertEqual(bc.write_buf, '')
self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 0) self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 0)
...@@ -420,7 +420,7 @@ class testConnection(unittest.TestCase): ...@@ -420,7 +420,7 @@ class testConnection(unittest.TestCase):
connector=connector, addr=("127.0.0.7", 93413)) connector=connector, addr=("127.0.0.7", 93413))
self.assertEqual(bc.write_buf, '') self.assertEqual(bc.write_buf, '')
self.assertNotEqual(bc.getConnector(), None) self.assertNotEqual(bc.getConnector(), None)
bc.addPacket(p) bc._addPacket(p)
self.assertEqual(bc.write_buf, "testdata") self.assertEqual(bc.write_buf, "testdata")
self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 1) self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 1)
...@@ -959,15 +959,15 @@ class testConnection(unittest.TestCase): ...@@ -959,15 +959,15 @@ class testConnection(unittest.TestCase):
self.assertEqual(bc.getUUID(), uuid) self.assertEqual(bc.getUUID(), uuid)
# test next id # test next id
cur_id = bc.cur_id cur_id = bc.cur_id
next_id = bc.getNextId() next_id = bc._getNextId()
self.assertEqual(next_id, cur_id) self.assertEqual(next_id, cur_id)
next_id = bc.getNextId() next_id = bc._getNextId()
self.failUnless(next_id > cur_id) self.failUnless(next_id > cur_id)
# test overflow of next id # test overflow of next id
bc.cur_id = 0xffffffff bc.cur_id = 0xffffffff
next_id = bc.getNextId() next_id = bc._getNextId()
self.assertEqual(next_id, 0xffffffff) self.assertEqual(next_id, 0xffffffff)
next_id = bc.getNextId() next_id = bc._getNextId()
self.assertEqual(next_id, 0) self.assertEqual(next_id, 0)
# test abort # test abort
bc.abort() bc.abort()
...@@ -1074,15 +1074,15 @@ class testConnection(unittest.TestCase): ...@@ -1074,15 +1074,15 @@ class testConnection(unittest.TestCase):
# test next id # test next id
bc._lock = Mock({'_is_owned': True}) bc._lock = Mock({'_is_owned': True})
cur_id = bc.cur_id cur_id = bc.cur_id
next_id = bc.getNextId() next_id = bc._getNextId()
self.assertEqual(next_id, cur_id) self.assertEqual(next_id, cur_id)
next_id = bc.getNextId() next_id = bc._getNextId()
self.failUnless(next_id > cur_id) self.failUnless(next_id > cur_id)
# test overflow of next id # test overflow of next id
bc.cur_id = 0xffffffff bc.cur_id = 0xffffffff
next_id = bc.getNextId() next_id = bc._getNextId()
self.assertEqual(next_id, 0xffffffff) self.assertEqual(next_id, 0xffffffff)
next_id = bc.getNextId() next_id = bc._getNextId()
self.assertEqual(next_id, 0) self.assertEqual(next_id, 0)
# test abort # test abort
bc.abort() bc.abort()
......
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