Commit d8a1d43d authored by Grégory Wisniewski's avatar Grégory Wisniewski

Rename is(Server|Client|Listening)Connection without the 'Connection' suffix,

because there are Connection class atttributes.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1093 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent f532bbbc
...@@ -120,13 +120,13 @@ class BaseConnection(object): ...@@ -120,13 +120,13 @@ class BaseConnection(object):
def getUUID(self): def getUUID(self):
return None return None
def isListeningConnection(self): def isListening(self):
return False return False
def isServerConnection(self): def isServer(self):
return False return False
def isClientConnection(self): def isClient(self):
return False return False
def hasPendingMessages(self): def hasPendingMessages(self):
...@@ -157,7 +157,7 @@ class ListeningConnection(BaseConnection): ...@@ -157,7 +157,7 @@ class ListeningConnection(BaseConnection):
def writable(self): def writable(self):
return False return False
def isListeningConnection(self): def isListening(self):
return True return True
...@@ -468,14 +468,14 @@ class ClientConnection(Connection): ...@@ -468,14 +468,14 @@ class ClientConnection(Connection):
else: else:
Connection.writable(self) Connection.writable(self)
def isClientConnection(self): def isClient(self):
return True return True
class ServerConnection(Connection): class ServerConnection(Connection):
"""A connection from a remote node to this node.""" """A connection from a remote node to this node."""
def isServerConnection(self): def isServer(self):
return True return True
......
...@@ -52,7 +52,7 @@ def restrict_node_types(*node_types): ...@@ -52,7 +52,7 @@ def restrict_node_types(*node_types):
def client_connection_required(handler): def client_connection_required(handler):
""" Raise UnexpectedPacketError if the packet comes from a client connection """ """ Raise UnexpectedPacketError if the packet comes from a client connection """
def wrapper(self, conn, packet, *args, **kwargs): def wrapper(self, conn, packet, *args, **kwargs):
if conn.isServerConnection(): if conn.isServer():
raise protocol.UnexpectedPacketError raise protocol.UnexpectedPacketError
# it's a client connection, call the handler # it's a client connection, call the handler
handler(self, conn, packet, *args, **kwargs) handler(self, conn, packet, *args, **kwargs)
...@@ -61,7 +61,7 @@ def client_connection_required(handler): ...@@ -61,7 +61,7 @@ def client_connection_required(handler):
def server_connection_required(handler): def server_connection_required(handler):
""" Raise UnexpectedPacketError if the packet comes from a server connection """ """ Raise UnexpectedPacketError if the packet comes from a server connection """
def wrapper(self, conn, packet, *args, **kwargs): def wrapper(self, conn, packet, *args, **kwargs):
if not conn.isServerConnection(): if not conn.isServer():
raise protocol.UnexpectedPacketError raise protocol.UnexpectedPacketError
# it's a server connection, call the handler # it's a server connection, call the handler
handler(self, conn, packet, *args, **kwargs) handler(self, conn, packet, *args, **kwargs)
......
...@@ -122,7 +122,7 @@ class Application(object): ...@@ -122,7 +122,7 @@ class Application(object):
except (ElectionFailure, PrimaryFailure): except (ElectionFailure, PrimaryFailure):
# Forget all connections. # Forget all connections.
for conn in self.em.getConnectionList(): for conn in self.em.getConnectionList():
if not conn.isListeningConnection(): if not conn.isListening():
conn.close() conn.close()
# Reelect a new primary master. # Reelect a new primary master.
self.electPrimary(bootstrap = False) self.electPrimary(bootstrap = False)
...@@ -197,7 +197,7 @@ class Application(object): ...@@ -197,7 +197,7 @@ class Application(object):
self.primary = True self.primary = True
logging.debug('I am the primary, so sending an announcement') logging.debug('I am the primary, so sending an announcement')
for conn in em.getConnectionList(): for conn in em.getConnectionList():
if conn.isClientConnection(): if conn.isClient():
conn.notify(protocol.announcePrimaryMaster()) conn.notify(protocol.announcePrimaryMaster())
conn.abort() conn.abort()
closed = False closed = False
...@@ -206,12 +206,12 @@ class Application(object): ...@@ -206,12 +206,12 @@ class Application(object):
em.poll(1) em.poll(1)
closed = True closed = True
for conn in em.getConnectionList(): for conn in em.getConnectionList():
if conn.isClientConnection(): if conn.isClient():
closed = False closed = False
break break
if t + 10 < time(): if t + 10 < time():
for conn in em.getConnectionList(): for conn in em.getConnectionList():
if conn.isClientConnection(): if conn.isClient():
conn.close() conn.close()
closed = True closed = True
else: else:
...@@ -227,13 +227,13 @@ class Application(object): ...@@ -227,13 +227,13 @@ class Application(object):
primary = self.primary_master_node primary = self.primary_master_node
addr = primary.getServer() addr = primary.getServer()
for conn in em.getConnectionList(): for conn in em.getConnectionList():
if conn.isServerConnection() or conn.isClientConnection() \ if conn.isServer() or conn.isClient() \
and addr != conn.getAddress(): and addr != conn.getAddress():
conn.close() conn.close()
# But if there is no such connection, something wrong happened. # But if there is no such connection, something wrong happened.
for conn in em.getConnectionList(): for conn in em.getConnectionList():
if conn.isClientConnection() and addr == conn.getAddress(): if conn.isClient() and addr == conn.getAddress():
break break
else: else:
raise ElectionFailure, 'no connection remains to the primary' raise ElectionFailure, 'no connection remains to the primary'
...@@ -244,7 +244,7 @@ class Application(object): ...@@ -244,7 +244,7 @@ class Application(object):
# Ask all connected nodes to reelect a single primary master. # Ask all connected nodes to reelect a single primary master.
for conn in em.getConnectionList(): for conn in em.getConnectionList():
if conn.isClientConnection(): if conn.isClient():
conn.notify(protocol.reelectPrimaryMaster()) conn.notify(protocol.reelectPrimaryMaster())
conn.abort() conn.abort()
...@@ -261,7 +261,7 @@ class Application(object): ...@@ -261,7 +261,7 @@ class Application(object):
closed = True closed = True
for conn in em.getConnectionList(): for conn in em.getConnectionList():
if conn.isClientConnection(): if conn.isClient():
# Still not closed. # Still not closed.
closed = False closed = False
break break
...@@ -272,7 +272,7 @@ class Application(object): ...@@ -272,7 +272,7 @@ class Application(object):
# Close all connections. # Close all connections.
for conn in em.getConnectionList(): for conn in em.getConnectionList():
if not conn.isListeningConnection(): if not conn.isListening():
conn.close() conn.close()
bootstrap = False bootstrap = False
...@@ -666,7 +666,7 @@ class Application(object): ...@@ -666,7 +666,7 @@ class Application(object):
notification_packet = protocol.notifyClusterInformation(state) notification_packet = protocol.notifyClusterInformation(state)
for conn in em.getConnectionList(): for conn in em.getConnectionList():
node = nm.getNodeByUUID(conn.getUUID()) node = nm.getNodeByUUID(conn.getUUID())
if conn.isListeningConnection() or node is None: if conn.isListening() or node is None:
# not identified or listening, keep the identification handler # not identified or listening, keep the identification handler
continue continue
conn.notify(notification_packet) conn.notify(notification_packet)
......
...@@ -49,7 +49,7 @@ class PrimaryMasterHandler(MasterHandler): ...@@ -49,7 +49,7 @@ class PrimaryMasterHandler(MasterHandler):
raise PrimaryFailure, 'primary master is dead' raise PrimaryFailure, 'primary master is dead'
def packetReceived(self, conn, packet): def packetReceived(self, conn, packet):
if not conn.isServerConnection(): if not conn.isServer():
node = self.app.nm.getNodeByServer(conn.getAddress()) node = self.app.nm.getNodeByServer(conn.getAddress())
if node.getState() != BROKEN_STATE: if node.getState() != BROKEN_STATE:
node.setState(RUNNING_STATE) node.setState(RUNNING_STATE)
......
...@@ -178,7 +178,7 @@ class Application(object): ...@@ -178,7 +178,7 @@ class Application(object):
# First of all, make sure that I have no connection. # First of all, make sure that I have no connection.
for conn in self.em.getConnectionList(): for conn in self.em.getConnectionList():
if not conn.isListeningConnection(): if not conn.isListening():
conn.close() conn.close()
# search, find, connect and identify to the primary master # search, find, connect and identify to the primary master
...@@ -296,6 +296,6 @@ class Application(object): ...@@ -296,6 +296,6 @@ class Application(object):
def shutdown(self): def shutdown(self):
"""Close all connections and exit""" """Close all connections and exit"""
for c in self.em.getConnectionList(): for c in self.em.getConnectionList():
if not c.isListeningConnection(): if not c.isListening():
c.close() c.close()
sys.exit("Application has been asked to shut down") sys.exit("Application has been asked to shut down")
...@@ -247,7 +247,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -247,7 +247,7 @@ class MasterServerElectionTests(NeoTestBase):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port)
# Without a client connection # Without a client connection
conn = Mock({"getUUID" : uuid, conn = Mock({"getUUID" : uuid,
"isServerConnection" : True, "isServer" : True,
"getAddress" : ("127.0.0.1", self.master_port),}) "getAddress" : ("127.0.0.1", self.master_port),})
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)
...@@ -462,7 +462,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -462,7 +462,7 @@ class MasterServerElectionTests(NeoTestBase):
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}) "isServer" : True})
self.checkProtocolErrorRaised( self.checkProtocolErrorRaised(
election.handleRequestNodeIdentification, election.handleRequestNodeIdentification,
conn, conn,
...@@ -474,7 +474,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -474,7 +474,7 @@ class MasterServerElectionTests(NeoTestBase):
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}) "isServer" : True})
self.checkNotReadyErrorRaised( self.checkNotReadyErrorRaised(
election.handleRequestNodeIdentification, election.handleRequestNodeIdentification,
conn, conn,
...@@ -487,7 +487,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -487,7 +487,7 @@ class MasterServerElectionTests(NeoTestBase):
# known node # known node
conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None, conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None,
"isServerConnection" : True}) "isServer" : 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]
self.assertEqual(node.getUUID(), None) self.assertEqual(node.getUUID(), None)
...@@ -505,7 +505,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -505,7 +505,7 @@ class MasterServerElectionTests(NeoTestBase):
self.checkAcceptNodeIdentification(conn, answered_packet=packet) self.checkAcceptNodeIdentification(conn, answered_packet=packet)
# unknown node # unknown node
conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None, conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None,
"isServerConnection" : True}) "isServer" : 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)
self.assertEqual(len(self.app.unconnected_master_node_set), 1) self.assertEqual(len(self.app.unconnected_master_node_set), 1)
...@@ -523,7 +523,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -523,7 +523,7 @@ class MasterServerElectionTests(NeoTestBase):
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}) "isServer" : 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)
self.assertEqual(node.getState(), RUNNING_STATE) self.assertEqual(node.getState(), RUNNING_STATE)
...@@ -546,7 +546,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -546,7 +546,7 @@ class MasterServerElectionTests(NeoTestBase):
packet = protocol.askPrimaryMaster() packet = protocol.askPrimaryMaster()
conn = Mock({"_addPacket" : None, conn = Mock({"_addPacket" : None,
"getUUID" : uuid, "getUUID" : uuid,
"isServerConnection" : True, "isServer" : 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)
election.handleAskPrimaryMaster(conn, packet) election.handleAskPrimaryMaster(conn, packet)
...@@ -561,14 +561,14 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -561,14 +561,14 @@ class MasterServerElectionTests(NeoTestBase):
# No uuid # No uuid
conn = Mock({"_addPacket" : None, conn = Mock({"_addPacket" : None,
"getUUID" : None, "getUUID" : None,
"isServerConnection" : True, "isServer" : 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, "isServer" : True,
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
self.assertEqual(self.app.primary, None) self.assertEqual(self.app.primary, None)
self.assertEqual(self.app.primary_master_node, None) self.assertEqual(self.app.primary_master_node, None)
...@@ -578,7 +578,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -578,7 +578,7 @@ class MasterServerElectionTests(NeoTestBase):
# 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, "isServer" : True,
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
self.app.primary = True self.app.primary = True
self.assertEqual(self.app.primary, True) self.assertEqual(self.app.primary, True)
...@@ -592,7 +592,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -592,7 +592,7 @@ class MasterServerElectionTests(NeoTestBase):
# No uuid # No uuid
conn = Mock({"_addPacket" : None, conn = Mock({"_addPacket" : None,
"getUUID" : None, "getUUID" : None,
"isServerConnection" : True, "isServer" : True,
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
self.assertRaises(ElectionFailure, election.handleReelectPrimaryMaster, conn, packet) self.assertRaises(ElectionFailure, election.handleReelectPrimaryMaster, conn, packet)
......
...@@ -36,7 +36,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -36,7 +36,7 @@ class StorageClientHandlerTests(NeoTestBase):
def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs): def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs):
conn = Mock({ conn = Mock({
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
"isServerConnection": _listening, "isServer": _listening,
}) })
packet = Packet(msg_type=_msg_type) packet = Packet(msg_type=_msg_type)
# hook # hook
......
...@@ -70,7 +70,7 @@ class StorageInitializationHandlerTests(NeoTestBase): ...@@ -70,7 +70,7 @@ class StorageInitializationHandlerTests(NeoTestBase):
uuid = self.getNewUUID() uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid, conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port), "getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : False}) "isServer" : False})
self.assertRaises(PrimaryFailure, self.verification.timeoutExpired, conn,) self.assertRaises(PrimaryFailure, self.verification.timeoutExpired, conn,)
# nothing happens # nothing happens
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
...@@ -80,7 +80,7 @@ class StorageInitializationHandlerTests(NeoTestBase): ...@@ -80,7 +80,7 @@ class StorageInitializationHandlerTests(NeoTestBase):
uuid = self.getNewUUID() uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid, conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port), "getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : False}) "isServer" : False})
self.assertRaises(PrimaryFailure, self.verification.connectionClosed, conn,) self.assertRaises(PrimaryFailure, self.verification.connectionClosed, conn,)
# nothing happens # nothing happens
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
...@@ -90,7 +90,7 @@ class StorageInitializationHandlerTests(NeoTestBase): ...@@ -90,7 +90,7 @@ class StorageInitializationHandlerTests(NeoTestBase):
uuid = self.getNewUUID() uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid, conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port), "getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : False}) "isServer" : False})
self.assertRaises(PrimaryFailure, self.verification.peerBroken, conn,) self.assertRaises(PrimaryFailure, self.verification.peerBroken, conn,)
# nothing happens # nothing happens
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
...@@ -101,7 +101,7 @@ class StorageInitializationHandlerTests(NeoTestBase): ...@@ -101,7 +101,7 @@ class StorageInitializationHandlerTests(NeoTestBase):
# send a table # send a table
conn = Mock({"getUUID" : uuid, conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port), "getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : False}) "isServer" : False})
self.app.pt = PartitionTable(3, 2) self.app.pt = PartitionTable(3, 2)
node_1 = self.getNewUUID() node_1 = self.getNewUUID()
......
...@@ -35,7 +35,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -35,7 +35,7 @@ class StorageMasterHandlerTests(NeoTestBase):
def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs): def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs):
conn = Mock({ conn = Mock({
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
"isServerConnection": _listening, "isServer": _listening,
}) })
packet = Packet(msg_type=_msg_type) packet = Packet(msg_type=_msg_type)
# hook # hook
...@@ -100,7 +100,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -100,7 +100,7 @@ class StorageMasterHandlerTests(NeoTestBase):
# old partition change -> do nothing # old partition change -> do nothing
app = self.app app = self.app
conn = Mock({ conn = Mock({
"isServerConnection": False, "isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
}) })
app.replicator = Mock({}) app.replicator = Mock({})
...@@ -125,7 +125,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -125,7 +125,7 @@ class StorageMasterHandlerTests(NeoTestBase):
) )
# context # context
conn = Mock({ conn = Mock({
"isServerConnection": False, "isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
}) })
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES) packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES)
...@@ -163,13 +163,13 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -163,13 +163,13 @@ class StorageMasterHandlerTests(NeoTestBase):
def test_16_handleStopOperation1(self): def test_16_handleStopOperation1(self):
# OperationFailure # OperationFailure
conn = Mock({ 'isServerConnection': False }) conn = Mock({ 'isServer': False })
packet = Packet(msg_type=STOP_OPERATION) packet = Packet(msg_type=STOP_OPERATION)
self.assertRaises(OperationFailure, self.operation.handleStopOperation, conn, packet) self.assertRaises(OperationFailure, self.operation.handleStopOperation, conn, packet)
def test_22_handleLockInformation2(self): def test_22_handleLockInformation2(self):
# load transaction informations # load transaction informations
conn = Mock({ 'isServerConnection': False, }) conn = Mock({ 'isServer': False, })
self.app.dm = Mock({ }) self.app.dm = Mock({ })
packet = Packet(msg_type=LOCK_INFORMATION) packet = Packet(msg_type=LOCK_INFORMATION)
transaction = Mock({ 'getObjectList': ((0, ), ), }) transaction = Mock({ 'getObjectList': ((0, ), ), })
...@@ -181,13 +181,13 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -181,13 +181,13 @@ class StorageMasterHandlerTests(NeoTestBase):
self.checkNotifyInformationLocked(conn, answered_packet=packet) self.checkNotifyInformationLocked(conn, answered_packet=packet)
# transaction not in transaction_dict -> KeyError # transaction not in transaction_dict -> KeyError
transaction = Mock({ 'getObjectList': ((0, ), ), }) transaction = Mock({ 'getObjectList': ((0, ), ), })
conn = Mock({ 'isServerConnection': False, }) conn = Mock({ 'isServer': False, })
self.operation.handleLockInformation(conn, packet, '\x01' * 8) self.operation.handleLockInformation(conn, packet, '\x01' * 8)
self.checkNotifyInformationLocked(conn, answered_packet=packet) self.checkNotifyInformationLocked(conn, answered_packet=packet)
def test_23_handleUnlockInformation2(self): def test_23_handleUnlockInformation2(self):
# delete transaction informations # delete transaction informations
conn = Mock({ 'isServerConnection': False, }) conn = Mock({ 'isServer': False, })
self.app.dm = Mock({ }) self.app.dm = Mock({ })
packet = Packet(msg_type=LOCK_INFORMATION) packet = Packet(msg_type=LOCK_INFORMATION)
transaction = Mock({ 'getObjectList': ((0, ), ), }) transaction = Mock({ 'getObjectList': ((0, ), ), })
...@@ -203,7 +203,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -203,7 +203,7 @@ class StorageMasterHandlerTests(NeoTestBase):
calls[0].checkArgs(INVALID_TID) calls[0].checkArgs(INVALID_TID)
# transaction not in transaction_dict -> KeyError # transaction not in transaction_dict -> KeyError
transaction = Mock({ 'getObjectList': ((0, ), ), }) transaction = Mock({ 'getObjectList': ((0, ), ), })
conn = Mock({ 'isServerConnection': False, }) conn = Mock({ 'isServer': False, })
self.operation.handleLockInformation(conn, packet, '\x01' * 8) self.operation.handleLockInformation(conn, packet, '\x01' * 8)
self.checkNotifyInformationLocked(conn, answered_packet=packet) self.checkNotifyInformationLocked(conn, answered_packet=packet)
......
...@@ -33,7 +33,7 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -33,7 +33,7 @@ class StorageStorageHandlerTests(NeoTestBase):
def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs): def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs):
conn = Mock({ conn = Mock({
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
"isServerConnection": _listening, "isServer": _listening,
}) })
packet = Packet(msg_type=_msg_type) packet = Packet(msg_type=_msg_type)
# hook # hook
......
...@@ -100,7 +100,7 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -100,7 +100,7 @@ class BootstrapManagerTests(NeoTestBase):
def test_04_timeoutExpired(self): def test_04_timeoutExpired(self):
conn = Mock({ conn = Mock({
"isServerConnection": False, "isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
}) })
# pmn connection has expired # pmn connection has expired
...@@ -120,7 +120,7 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -120,7 +120,7 @@ class BootstrapManagerTests(NeoTestBase):
def test_05_connectionClosed(self): def test_05_connectionClosed(self):
conn = Mock({ conn = Mock({
"isServerConnection": False, "isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
}) })
# pmn connection is closed # pmn connection is closed
...@@ -140,7 +140,7 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -140,7 +140,7 @@ class BootstrapManagerTests(NeoTestBase):
def test_06_peerBroken(self): def test_06_peerBroken(self):
conn = Mock({ conn = Mock({
"isServerConnection": False, "isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
}) })
# the primary is broken # the primary is broken
...@@ -161,7 +161,7 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -161,7 +161,7 @@ class BootstrapManagerTests(NeoTestBase):
def test_07_handleNotReady(self): def test_07_handleNotReady(self):
# the primary is not ready # the primary is not ready
conn = Mock({ conn = Mock({
"isServerConnection": False, "isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
}) })
self.app.trying_master_node = self.trying_master_node self.app.trying_master_node = self.trying_master_node
...@@ -172,7 +172,7 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -172,7 +172,7 @@ class BootstrapManagerTests(NeoTestBase):
self.checkClosed(conn) self.checkClosed(conn)
# another master is not ready # another master is not ready
conn = Mock({ conn = Mock({
"isServerConnection": False, "isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
}) })
self.app.trying_master_node = self.trying_master_node self.app.trying_master_node = self.trying_master_node
...@@ -186,7 +186,7 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -186,7 +186,7 @@ class BootstrapManagerTests(NeoTestBase):
def test_09_handleAcceptNodeIdentification2(self): def test_09_handleAcceptNodeIdentification2(self):
# not a master node -> rejected # not a master node -> rejected
conn = Mock({"isServerConnection": False, conn = Mock({"isServer": False,
"getAddress" : ("127.0.0.1", self.storage_port), }) "getAddress" : ("127.0.0.1", self.storage_port), })
self.app.trying_master_node = self.trying_master_node self.app.trying_master_node = self.trying_master_node
packet = Packet(msg_type=ACCEPT_NODE_IDENTIFICATION) packet = Packet(msg_type=ACCEPT_NODE_IDENTIFICATION)
...@@ -209,7 +209,7 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -209,7 +209,7 @@ class BootstrapManagerTests(NeoTestBase):
def test_09_handleAcceptNodeIdentification3(self): def test_09_handleAcceptNodeIdentification3(self):
# bad address -> rejected # bad address -> rejected
conn = Mock({"isServerConnection": False, conn = Mock({"isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), }) "getAddress" : ("127.0.0.1", self.master_port), })
self.app.trying_master_node = self.trying_master_node self.app.trying_master_node = self.trying_master_node
packet = Packet(msg_type=ACCEPT_NODE_IDENTIFICATION) packet = Packet(msg_type=ACCEPT_NODE_IDENTIFICATION)
...@@ -229,7 +229,7 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -229,7 +229,7 @@ class BootstrapManagerTests(NeoTestBase):
def test_09_handleAcceptNodeIdentification4(self): def test_09_handleAcceptNodeIdentification4(self):
# bad number of replicas/partitions # bad number of replicas/partitions
conn = Mock({"isServerConnection": False, conn = Mock({"isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), }) "getAddress" : ("127.0.0.1", self.master_port), })
self.app.trying_master_node = self.trying_master_node self.app.trying_master_node = self.trying_master_node
packet = Packet(msg_type=ACCEPT_NODE_IDENTIFICATION) packet = Packet(msg_type=ACCEPT_NODE_IDENTIFICATION)
...@@ -261,7 +261,7 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -261,7 +261,7 @@ class BootstrapManagerTests(NeoTestBase):
self.assertNotEquals(uuid, your_uuid) self.assertNotEquals(uuid, your_uuid)
self.app.num_partitions = None # will create a partition table self.app.num_partitions = None # will create a partition table
self.app.num_replicas = None self.app.num_replicas = None
conn = Mock({"isServerConnection": False, conn = Mock({"isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), }) "getAddress" : ("127.0.0.1", self.master_port), })
self.app.trying_master_node = self.trying_master_node self.app.trying_master_node = self.trying_master_node
self.assertNotEquals(self.app.trying_master_node.getUUID(), uuid) self.assertNotEquals(self.app.trying_master_node.getUUID(), uuid)
...@@ -295,7 +295,7 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -295,7 +295,7 @@ class BootstrapManagerTests(NeoTestBase):
existing_master = ('127.0.0.1', self.master_port, self.getNewUUID(), ) existing_master = ('127.0.0.1', self.master_port, self.getNewUUID(), )
new_master = ('192.168.0.1', 10001, self.getNewUUID(), ) new_master = ('192.168.0.1', 10001, self.getNewUUID(), )
known_masters = (existing_master, new_master, ) known_masters = (existing_master, new_master, )
conn = Mock({"isServerConnection": False, conn = Mock({"isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), }) "getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_type=ANSWER_PRIMARY_MASTER) packet = Packet(msg_type=ANSWER_PRIMARY_MASTER)
self.assertTrue(existing_master[:2] in self.app.nm.server_dict) self.assertTrue(existing_master[:2] in self.app.nm.server_dict)
...@@ -318,7 +318,7 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -318,7 +318,7 @@ class BootstrapManagerTests(NeoTestBase):
def test_10_handleAnswerPrimaryMaster03(self): def test_10_handleAnswerPrimaryMaster03(self):
# invalid primary master uuid -> close connection # invalid primary master uuid -> close connection
conn = Mock({"isServerConnection": False, conn = Mock({"isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), }) "getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_type=ANSWER_PRIMARY_MASTER) packet = Packet(msg_type=ANSWER_PRIMARY_MASTER)
pmn = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port)) pmn = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port))
...@@ -338,7 +338,7 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -338,7 +338,7 @@ class BootstrapManagerTests(NeoTestBase):
def test_10_handleAnswerPrimaryMaster04(self): def test_10_handleAnswerPrimaryMaster04(self):
# trying_master_node is not pmn -> close connection # trying_master_node is not pmn -> close connection
conn = Mock({"isServerConnection": False, conn = Mock({"isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), }) "getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_type=ANSWER_PRIMARY_MASTER) packet = Packet(msg_type=ANSWER_PRIMARY_MASTER)
pmn = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port)) pmn = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port))
...@@ -360,7 +360,7 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -360,7 +360,7 @@ class BootstrapManagerTests(NeoTestBase):
def test_10_handleAnswerPrimaryMaster05(self): def test_10_handleAnswerPrimaryMaster05(self):
# trying_master_node is pmn -> set verification handler # trying_master_node is pmn -> set verification handler
conn = Mock({"isServerConnection": False, conn = Mock({"isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), }) "getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_type=ANSWER_PRIMARY_MASTER) packet = Packet(msg_type=ANSWER_PRIMARY_MASTER)
pmn = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port)) pmn = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port))
...@@ -380,7 +380,7 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -380,7 +380,7 @@ class BootstrapManagerTests(NeoTestBase):
def test_10_handleAnswerPrimaryMaster06(self): def test_10_handleAnswerPrimaryMaster06(self):
# primary_uuid not known -> nothing happen # primary_uuid not known -> nothing happen
conn = Mock({"isServerConnection": False, conn = Mock({"isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), }) "getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_type=ANSWER_PRIMARY_MASTER) packet = Packet(msg_type=ANSWER_PRIMARY_MASTER)
self.app.primary_master_node = None self.app.primary_master_node = None
......
...@@ -186,7 +186,7 @@ class ConnectionTests(unittest.TestCase): ...@@ -186,7 +186,7 @@ class ConnectionTests(unittest.TestCase):
# test abort # test abort
bc.abort() bc.abort()
self.assertEqual(bc.aborted, True) self.assertEqual(bc.aborted, True)
self.assertRaises(NotImplementedError, bc.isServerConnection) self.assertRaises(NotImplementedError, bc.isServer)
def test_04_Connection_pending(self): def test_04_Connection_pending(self):
em = Mock() em = Mock()
...@@ -763,7 +763,7 @@ class ConnectionTests(unittest.TestCase): ...@@ -763,7 +763,7 @@ class ConnectionTests(unittest.TestCase):
addr=("127.0.0.7", 93413)) addr=("127.0.0.7", 93413))
# check connector created and connection initialize # check connector created and connection initialize
self.assertFalse(bc.connecting) self.assertFalse(bc.connecting)
self.assertFalse(bc.isServerConnection()) self.assertFalse(bc.isServer())
self.assertNotEqual(bc.getConnector(), None) self.assertNotEqual(bc.getConnector(), None)
conn = bc.getConnector() conn = bc.getConnector()
self.assertEquals(len(conn.mockGetNamedCalls("makeClientConnection")), 1) self.assertEquals(len(conn.mockGetNamedCalls("makeClientConnection")), 1)
...@@ -794,7 +794,7 @@ class ConnectionTests(unittest.TestCase): ...@@ -794,7 +794,7 @@ class ConnectionTests(unittest.TestCase):
DoNothingConnector.makeClientConnection = makeClientConnection_org DoNothingConnector.makeClientConnection = makeClientConnection_org
# check connector created and connection initialize # check connector created and connection initialize
self.assertTrue(bc.connecting) self.assertTrue(bc.connecting)
self.assertFalse(bc.isServerConnection()) self.assertFalse(bc.isServer())
self.assertNotEqual(bc.getConnector(), None) self.assertNotEqual(bc.getConnector(), None)
conn = bc.getConnector() conn = bc.getConnector()
self.assertEquals(len(conn.mockGetNamedCalls("makeClientConnection")), 1) self.assertEquals(len(conn.mockGetNamedCalls("makeClientConnection")), 1)
...@@ -992,7 +992,7 @@ class ConnectionTests(unittest.TestCase): ...@@ -992,7 +992,7 @@ class ConnectionTests(unittest.TestCase):
# test abort # test abort
bc.abort() bc.abort()
self.assertEqual(bc.aborted, True) self.assertEqual(bc.aborted, True)
self.assertTrue(bc.isServerConnection()) self.assertTrue(bc.isServer())
def test_15_MTClientConnection(self): def test_15_MTClientConnection(self):
...@@ -1007,7 +1007,7 @@ class ConnectionTests(unittest.TestCase): ...@@ -1007,7 +1007,7 @@ class ConnectionTests(unittest.TestCase):
addr=("127.0.0.7", 93413), dispatcher=dispatcher) addr=("127.0.0.7", 93413), dispatcher=dispatcher)
# check connector created and connection initialize # check connector created and connection initialize
self.assertFalse(bc.connecting) self.assertFalse(bc.connecting)
self.assertFalse(bc.isServerConnection()) self.assertFalse(bc.isServer())
self.assertNotEqual(bc.getConnector(), None) self.assertNotEqual(bc.getConnector(), None)
conn = bc.getConnector() conn = bc.getConnector()
self.assertEquals(len(conn.mockGetNamedCalls("makeClientConnection")), 1) self.assertEquals(len(conn.mockGetNamedCalls("makeClientConnection")), 1)
...@@ -1037,7 +1037,7 @@ class ConnectionTests(unittest.TestCase): ...@@ -1037,7 +1037,7 @@ class ConnectionTests(unittest.TestCase):
DoNothingConnector.makeClientConnection = makeClientConnection_org DoNothingConnector.makeClientConnection = makeClientConnection_org
# check connector created and connection initialize # check connector created and connection initialize
self.assertTrue(bc.connecting) self.assertTrue(bc.connecting)
self.assertFalse(bc.isServerConnection()) self.assertFalse(bc.isServer())
self.assertNotEqual(bc.getConnector(), None) self.assertNotEqual(bc.getConnector(), None)
conn = bc.getConnector() conn = bc.getConnector()
self.assertEquals(len(conn.mockGetNamedCalls("makeClientConnection")), 1) self.assertEquals(len(conn.mockGetNamedCalls("makeClientConnection")), 1)
...@@ -1116,7 +1116,7 @@ class ConnectionTests(unittest.TestCase): ...@@ -1116,7 +1116,7 @@ class ConnectionTests(unittest.TestCase):
# test abort # test abort
bc.abort() bc.abort()
self.assertEqual(bc.aborted, True) self.assertEqual(bc.aborted, True)
self.assertTrue(bc.isServerConnection()) self.assertTrue(bc.isServer())
# XXX check locking ??? # XXX check locking ???
......
...@@ -118,11 +118,11 @@ class HandlerDecoratorsTests(NeoTestBase): ...@@ -118,11 +118,11 @@ class HandlerDecoratorsTests(NeoTestBase):
handler = Mock({}) handler = Mock({})
wrapped = decorators.client_connection_required(handler) wrapped = decorators.client_connection_required(handler)
# server connection -> fail # server connection -> fail
conn = Mock({ 'isServerConnection': True, }) conn = Mock({ 'isServer': True, })
self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet) self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet)
self.checkHandlerNotCalled(handler) self.checkHandlerNotCalled(handler)
# client connection -> ok # client connection -> ok
conn = Mock({ 'isServerConnection': False, }) conn = Mock({ 'isServer': False, })
wrapped(self, conn, packet) wrapped(self, conn, packet)
self.checkHandlerCalled(handler) self.checkHandlerCalled(handler)
...@@ -131,11 +131,11 @@ class HandlerDecoratorsTests(NeoTestBase): ...@@ -131,11 +131,11 @@ class HandlerDecoratorsTests(NeoTestBase):
handler = Mock({}) handler = Mock({})
wrapped = decorators.server_connection_required(handler) wrapped = decorators.server_connection_required(handler)
# client connection -> fail # client connection -> fail
conn = Mock({ 'isServerConnection': False, }) conn = Mock({ 'isServer': False, })
self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet) self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet)
self.checkHandlerNotCalled(handler) self.checkHandlerNotCalled(handler)
# server connection -> ok # server connection -> ok
conn = Mock({ 'isServerConnection': True, }) conn = Mock({ 'isServer': True, })
wrapped(self, conn, packet) wrapped(self, conn, packet)
self.checkHandlerCalled(handler) self.checkHandlerCalled(handler)
......
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