Commit 858cbdc6 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Rename isListeningConnection to isServerConnection.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@426 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 8197473f
......@@ -315,7 +315,7 @@ class Connection(BaseConnection):
self.event_dict[msg_id] = event
self.em.addIdleEvent(event)
def isListeningConnection(self):
def isServerConnection(self):
raise NotImplementedError
class ClientConnection(Connection):
......@@ -358,12 +358,12 @@ class ClientConnection(Connection):
else:
Connection.writable(self)
def isListeningConnection(self):
def isServerConnection(self):
return False
class ServerConnection(Connection):
"""A connection from a remote node to this node."""
def isListeningConnection(self):
def isServerConnection(self):
return True
class MTClientConnection(ClientConnection):
......
......@@ -59,12 +59,12 @@ class ElectionEventHandler(MasterEventHandler):
MasterEventHandler.connectionFailed(self, conn)
def connectionClosed(self, conn):
if not conn.isListeningConnection():
if not conn.isServerConnection():
self.connectionFailed(conn)
MasterEventHandler.connectionClosed(self, conn)
def timeoutExpired(self, conn):
if not conn.isListeningConnection():
if not conn.isServerConnection():
self.connectionFailed(conn)
MasterEventHandler.timeoutExpired(self, conn)
......@@ -72,7 +72,7 @@ class ElectionEventHandler(MasterEventHandler):
app = self.app
addr = conn.getAddress()
node = app.nm.getNodeByServer(addr)
if not conn.isListeningConnection():
if not conn.isServerConnection():
if node is not None:
node.setState(DOWN_STATE)
app.negotiating_master_node_set.discard(addr)
......@@ -82,7 +82,7 @@ class ElectionEventHandler(MasterEventHandler):
MasterEventHandler.peerBroken(self, conn)
def packetReceived(self, conn, packet):
if not conn.isListeningConnection():
if not conn.isServerConnection():
node = self.app.nm.getNodeByServer(conn.getAddress())
if node.getState() != BROKEN_STATE:
node.setState(RUNNING_STATE)
......@@ -91,7 +91,7 @@ class ElectionEventHandler(MasterEventHandler):
def handleAcceptNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, num_partitions,
num_replicas, your_uuid):
if not conn.isListeningConnection():
if not conn.isServerConnection():
app = self.app
node = app.nm.getNodeByServer(conn.getAddress())
if node_type != MASTER_NODE_TYPE:
......@@ -127,7 +127,7 @@ class ElectionEventHandler(MasterEventHandler):
self.handleUnexpectedPacket(conn, packet)
def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid, known_master_list):
if not conn.isListeningConnection():
if not conn.isServerConnection():
app = self.app
# Register new master nodes.
for ip_address, port, uuid in known_master_list:
......@@ -176,7 +176,7 @@ class ElectionEventHandler(MasterEventHandler):
def handleRequestNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, name):
if not conn.isListeningConnection():
if not conn.isServerConnection():
self.handleUnexpectedPacket(conn, packet)
else:
app = self.app
......@@ -225,7 +225,7 @@ class ElectionEventHandler(MasterEventHandler):
conn.expectMessage()
def handleAskPrimaryMaster(self, conn, packet):
if not conn.isListeningConnection():
if not conn.isServerConnection():
self.handleUnexpectedPacket(conn, packet)
else:
uuid = conn.getUUID()
......@@ -252,7 +252,7 @@ class ElectionEventHandler(MasterEventHandler):
conn.addPacket(p)
def handleAnnouncePrimaryMaster(self, conn, packet):
if not conn.isListeningConnection():
if not conn.isServerConnection():
self.handleUnexpectedPacket(conn, packet)
else:
uuid = conn.getUUID()
......
......@@ -162,7 +162,7 @@ server: 127.0.0.1:10023
uuid = self.getNewUUID()
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None,
"isListeningConnection" : True})
"isServerConnection" : True})
self.election.handleRequestNodeIdentification(conn,
packet=packet,
node_type=node_type,
......@@ -284,7 +284,7 @@ server: 127.0.0.1:10023
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port)
# Without a client connection
conn = Mock({"getUUID" : uuid,
"isListeningConnection" : True,
"isServerConnection" : True,
"getAddress" : ("127.0.0.1", self.master_port),})
self.assertEqual(len(self.app.unconnected_master_node_set), 1)
self.assertEqual(len(self.app.negotiating_master_node_set), 0)
......@@ -499,7 +499,7 @@ server: 127.0.0.1:10023
uuid = self.getNewUUID()
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None,
"isListeningConnection" : True})
"isServerConnection" : True})
election.handleRequestNodeIdentification(conn,
packet=packet,
node_type=MASTER_NODE_TYPE,
......@@ -510,7 +510,7 @@ server: 127.0.0.1:10023
self.checkCalledAbort(conn)
# test connection of a storage node
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None,
"isListeningConnection" : True})
"isServerConnection" : True})
election.handleRequestNodeIdentification(conn,
packet=packet,
node_type=STORAGE_NODE_TYPE,
......@@ -522,7 +522,7 @@ server: 127.0.0.1:10023
# known node
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None,
"isListeningConnection" : True})
"isServerConnection" : True})
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
node = self.app.nm.getMasterNodeList()[0]
self.assertEqual(node.getUUID(), None)
......@@ -540,7 +540,7 @@ server: 127.0.0.1:10023
self.checkCalledAcceptNodeIdentification(conn)
# unknown node
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None,
"isListeningConnection" : True})
"isServerConnection" : True})
new_uuid = self.getNewUUID()
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
self.assertEqual(len(self.app.unconnected_master_node_set), 1)
......@@ -558,7 +558,7 @@ server: 127.0.0.1:10023
self.assertEqual(len(self.app.negotiating_master_node_set), 0)
# broken node
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None,
"isListeningConnection" : True})
"isServerConnection" : True})
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port+1))
self.assertEqual(node.getUUID(), new_uuid)
self.assertEqual(node.getState(), RUNNING_STATE)
......@@ -580,7 +580,7 @@ server: 127.0.0.1:10023
packet = Packet(msg_id=2)
conn = Mock({"addPacket" : None,
"getUUID" : uuid,
"isListeningConnection" : True,
"isServerConnection" : True,
"getAddress" : ("127.0.0.1", self.master_port)})
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
election.handleAskPrimaryMaster(conn, packet)
......@@ -595,7 +595,7 @@ server: 127.0.0.1:10023
# No uuid
conn = Mock({"addPacket" : None,
"getUUID" : None,
"isListeningConnection" : True,
"isServerConnection" : True,
"getAddress" : ("127.0.0.1", self.master_port)})
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
election.handleAnnouncePrimaryMaster(conn, packet)
......@@ -603,7 +603,7 @@ server: 127.0.0.1:10023
# announce
conn = Mock({"addPacket" : None,
"getUUID" : uuid,
"isListeningConnection" : True,
"isServerConnection" : True,
"getAddress" : ("127.0.0.1", self.master_port)})
self.assertEqual(self.app.primary, None)
self.assertEqual(self.app.primary_master_node, None)
......@@ -613,7 +613,7 @@ server: 127.0.0.1:10023
# set current as primary, and announce another, must raise
conn = Mock({"addPacket" : None,
"getUUID" : uuid,
"isListeningConnection" : True,
"isServerConnection" : True,
"getAddress" : ("127.0.0.1", self.master_port)})
self.app.primary = True
self.assertEqual(self.app.primary, True)
......@@ -627,7 +627,7 @@ server: 127.0.0.1:10023
# No uuid
conn = Mock({"addPacket" : None,
"getUUID" : None,
"isListeningConnection" : True,
"isServerConnection" : True,
"getAddress" : ("127.0.0.1", self.master_port)})
self.assertRaises(ElectionFailure, election.handleReelectPrimaryMaster, conn, packet)
......
......@@ -65,7 +65,7 @@ class BootstrapEventHandler(StorageEventHandler):
StorageEventHandler.connectionAccepted(self, conn, s, addr)
def timeoutExpired(self, conn):
if not conn.isListeningConnection():
if not conn.isServerConnection():
app = self.app
if app.trying_master_node is app.primary_master_node:
# If a primary master node timeouts, I should not rely on it.
......@@ -76,7 +76,7 @@ class BootstrapEventHandler(StorageEventHandler):
StorageEventHandler.timeoutExpired(self, conn)
def connectionClosed(self, conn):
if not conn.isListeningConnection():
if not conn.isServerConnection():
app = self.app
if app.trying_master_node is app.primary_master_node:
# If a primary master node closes, I should not rely on it.
......@@ -87,7 +87,7 @@ class BootstrapEventHandler(StorageEventHandler):
StorageEventHandler.connectionClosed(self, conn)
def peerBroken(self, conn):
if not conn.isListeningConnection():
if not conn.isServerConnection():
app = self.app
if app.trying_master_node is app.primary_master_node:
# If a primary master node gets broken, I should not rely
......@@ -99,7 +99,7 @@ class BootstrapEventHandler(StorageEventHandler):
StorageEventHandler.peerBroken(self, conn)
def handleNotReady(self, conn, packet, message):
if not conn.isListeningConnection():
if not conn.isServerConnection():
app = self.app
if app.trying_master_node is not None:
app.trying_master_node = None
......@@ -108,7 +108,7 @@ class BootstrapEventHandler(StorageEventHandler):
def handleRequestNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, name):
if not conn.isListeningConnection():
if not conn.isServerConnection():
self.handleUnexpectedPacket(conn, packet)
else:
app = self.app
......@@ -155,7 +155,7 @@ class BootstrapEventHandler(StorageEventHandler):
def handleAcceptNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port,
num_partitions, num_replicas, your_uuid):
if conn.isListeningConnection():
if conn.isServerConnection():
self.handleUnexpectedPacket(conn, packet)
else:
app = self.app
......@@ -201,7 +201,7 @@ class BootstrapEventHandler(StorageEventHandler):
def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid,
known_master_list):
if conn.isListeningConnection():
if conn.isServerConnection():
self.handleUnexpectedPacket(conn, packet)
else:
app = self.app
......
......@@ -89,7 +89,7 @@ class OperationEventHandler(StorageEventHandler):
app.executeQueuedEvents()
def timeoutExpired(self, conn):
if not conn.isListeningConnection():
if not conn.isServerConnection():
if conn.getUUID() == self.app.primary_master_node.getUUID():
# If a primary master node timeouts, I cannot continue.
logging.critical('the primary master node times out')
......@@ -103,7 +103,7 @@ class OperationEventHandler(StorageEventHandler):
StorageEventHandler.timeoutExpired(self, conn)
def connectionClosed(self, conn):
if not conn.isListeningConnection():
if not conn.isServerConnection():
if conn.getUUID() == self.app.primary_master_node.getUUID():
# If a primary master node closes, I cannot continue.
logging.critical('the primary master node is dead')
......@@ -117,7 +117,7 @@ class OperationEventHandler(StorageEventHandler):
StorageEventHandler.connectionClosed(self, conn)
def peerBroken(self, conn):
if not conn.isListeningConnection():
if not conn.isServerConnection():
if conn.getUUID() == self.app.primary_master_node.getUUID():
# If a primary master node gets broken, I cannot continue.
logging.critical('the primary master node is broken')
......@@ -132,7 +132,7 @@ class OperationEventHandler(StorageEventHandler):
def handleRequestNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, name):
if not conn.isListeningConnection():
if not conn.isServerConnection():
self.handleUnexpectedPacket(conn, packet)
else:
app = self.app
......@@ -186,7 +186,7 @@ class OperationEventHandler(StorageEventHandler):
def handleAcceptNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port,
num_partitions, num_replicas, your_uuid):
if not conn.isListeningConnection():
if not conn.isServerConnection():
raise NotImplementedError
else:
self.handleUnexpectedPacket(conn, packet)
......@@ -207,7 +207,7 @@ class OperationEventHandler(StorageEventHandler):
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list):
"""This is very similar to Send Partition Table, except that
the information is only about changes from the previous."""
if not conn.isListeningConnection():
if not conn.isServerConnection():
app = self.app
nm = app.nm
pt = app.pt
......@@ -244,7 +244,7 @@ class OperationEventHandler(StorageEventHandler):
self.handleUnexpectedPacket(conn, packet)
def handleStopOperation(self, conn, packet):
if not conn.isListeningConnection():
if not conn.isServerConnection():
raise OperationFailure('operation stopped')
else:
self.handleUnexpectedPacket(conn, packet)
......@@ -274,7 +274,7 @@ class OperationEventHandler(StorageEventHandler):
self.handleUnexpectedPacket(conn, packet)
def handleLockInformation(self, conn, packet, tid):
if not conn.isListeningConnection():
if not conn.isServerConnection():
app = self.app
try:
t = app.transaction_dict[tid]
......@@ -291,7 +291,7 @@ class OperationEventHandler(StorageEventHandler):
self.handleUnexpectedPacket(conn, packet)
def handleUnlockInformation(self, conn, packet, tid):
if not conn.isListeningConnection():
if not conn.isServerConnection():
app = self.app
try:
t = app.transaction_dict[tid]
......@@ -455,13 +455,13 @@ class OperationEventHandler(StorageEventHandler):
pass
def handleAnswerLastIDs(self, conn, packet, loid, ltid, lptid):
if not conn.isListeningConnection():
if not conn.isServerConnection():
self.app.replicator.setCriticalTID(packet, ltid)
else:
self.handleUnexpectedPacket(conn, packet)
def handleAnswerUnfinishedTransactions(self, conn, packet, tid_list):
if not conn.isListeningConnection():
if not conn.isServerConnection():
self.app.replicator.setUnfinishedTIDList(tid_list)
else:
self.handleUnexpectedPacket(conn, packet)
......
......@@ -185,7 +185,7 @@ server: 127.0.0.1:10020
def test_04_timeoutExpired(self):
conn = Mock({
"isListeningConnection": False,
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
# pmn connection has expired
......@@ -205,7 +205,7 @@ server: 127.0.0.1:10020
def test_05_connectionClosed(self):
conn = Mock({
"isListeningConnection": False,
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
# pmn connection is closed
......@@ -225,7 +225,7 @@ server: 127.0.0.1:10020
def test_06_peerBroken(self):
conn = Mock({
"isListeningConnection": False,
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
# the primary is broken
......@@ -245,7 +245,7 @@ server: 127.0.0.1:10020
def test_07_handleNotReady(self):
conn = Mock({
"isListeningConnection": False,
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
# the primary is not ready
......@@ -268,7 +268,7 @@ server: 127.0.0.1:10020
def test_08_handleRequestNodeIdentification1(self):
# client socket connection -> rejected
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({"isListeningConnection": False,
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
self.app.trying_master_node = self.trying_master_node
self.bootstrap.handleRequestNodeIdentification(
......@@ -285,7 +285,7 @@ server: 127.0.0.1:10020
def test_08_handleRequestNodeIdentification2(self):
# not a master node -> rejected
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({"isListeningConnection": True,
conn = Mock({"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port), })
self.bootstrap.handleRequestNodeIdentification(
conn=conn,
......@@ -301,7 +301,7 @@ server: 127.0.0.1:10020
def test_08_handleRequestNodeIdentification3(self):
# bad app name -> rejected
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({"isListeningConnection": True,
conn = Mock({"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port), })
self.bootstrap.handleRequestNodeIdentification(
conn=conn,
......@@ -317,7 +317,7 @@ server: 127.0.0.1:10020
def test_08_handleRequestNodeIdentification4(self):
# new master
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({"isListeningConnection": True,
conn = Mock({"isServerConnection": True,
"getAddress" : ("192.168.1.1", self.master_port), })
# master not known
mn = self.app.nm.getNodeByServer(('192.168.1.1', self.master_port))
......@@ -347,7 +347,7 @@ server: 127.0.0.1:10020
def test_08_handleRequestNodeIdentification5(self):
# broken node -> rejected
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({"isListeningConnection": True,
conn = Mock({"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port), })
master = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port))
uuid=self.getNewUUID()
......@@ -367,7 +367,7 @@ server: 127.0.0.1:10020
def test_08_handleRequestNodeIdentification6(self):
# master node is already known
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({"isListeningConnection": True,
conn = Mock({"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port), })
# master known
mn = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port))
......@@ -398,7 +398,7 @@ server: 127.0.0.1:10020
def test_09_handleAcceptNodeIdentification1(self):
# server socket connection -> rejected
conn = Mock({"isListeningConnection": True,
conn = Mock({"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_id=1, msg_type=ACCEPT_NODE_IDENTIFICATION)
self.app.trying_master_node = self.trying_master_node
......@@ -416,7 +416,7 @@ server: 127.0.0.1:10020
def test_09_handleAcceptNodeIdentification2(self):
# not a master node -> rejected
conn = Mock({"isListeningConnection": False,
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.storage_port), })
self.app.trying_master_node = self.trying_master_node
packet = Packet(msg_id=1, msg_type=ACCEPT_NODE_IDENTIFICATION)
......@@ -439,7 +439,7 @@ server: 127.0.0.1:10020
def test_09_handleAcceptNodeIdentification3(self):
# bad address -> rejected
conn = Mock({"isListeningConnection": False,
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
self.app.trying_master_node = self.trying_master_node
packet = Packet(msg_id=1, msg_type=ACCEPT_NODE_IDENTIFICATION)
......@@ -459,7 +459,7 @@ server: 127.0.0.1:10020
def test_09_handleAcceptNodeIdentification4(self):
# bad number of replicas/partitions
conn = Mock({"isListeningConnection": False,
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
self.app.trying_master_node = self.trying_master_node
packet = Packet(msg_id=1, msg_type=ACCEPT_NODE_IDENTIFICATION)
......@@ -495,7 +495,7 @@ server: 127.0.0.1:10020
uuid, your_uuid = self.getNewUUID(), self.getNewUUID()
self.app.num_partitions = None
self.app.num_replicas = None
conn = Mock({"isListeningConnection": False,
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
self.app.trying_master_node = self.trying_master_node
self.assertNotEquals(self.app.trying_master_node.getUUID(), uuid)
......@@ -530,7 +530,7 @@ server: 127.0.0.1:10020
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
def test_09_handleAcceptNodeIdentification6(self):
conn = Mock({"isListeningConnection": False,
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
self.app.trying_master_node = self.trying_master_node
packet = Packet(msg_id=1, msg_type=ACCEPT_NODE_IDENTIFICATION)
......@@ -561,7 +561,7 @@ server: 127.0.0.1:10020
def test_10_handleAnswerPrimaryMaster01(self):
# server connection rejected
conn = Mock({"isListeningConnection": True,
conn = Mock({"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_id=1, msg_type=ANSWER_PRIMARY_MASTER)
self.app.trying_master_node = self.trying_master_node
......@@ -581,7 +581,7 @@ server: 127.0.0.1:10020
existing_master = ('127.0.0.1', self.master_port, self.getNewUUID(), )
new_master = ('192.168.0.1', 10001, self.getNewUUID(), )
known_masters = (existing_master, new_master, )
conn = Mock({"isListeningConnection": False,
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_id=1, msg_type=ANSWER_PRIMARY_MASTER)
self.assertTrue(existing_master[:2] in self.app.nm.server_dict)
......@@ -605,7 +605,7 @@ server: 127.0.0.1:10020
def test_10_handleAnswerPrimaryMaster03(self):
# invalid primary master uuid -> close connection
conn = Mock({"isListeningConnection": False,
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_id=1, msg_type=ANSWER_PRIMARY_MASTER)
pmn = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port))
......@@ -625,7 +625,7 @@ server: 127.0.0.1:10020
def test_10_handleAnswerPrimaryMaster04(self):
# trying_master_node is not pmn -> close connection
conn = Mock({"isListeningConnection": False,
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_id=1, msg_type=ANSWER_PRIMARY_MASTER)
pmn = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port))
......@@ -647,7 +647,7 @@ server: 127.0.0.1:10020
def test_10_handleAnswerPrimaryMaster05(self):
# trying_master_node is pmn -> set verification handler
conn = Mock({"isListeningConnection": False,
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_id=1, msg_type=ANSWER_PRIMARY_MASTER)
pmn = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port))
......@@ -671,7 +671,7 @@ server: 127.0.0.1:10020
def test_10_handleAnswerPrimaryMaster06(self):
# primary_uuid not known -> nothing happen
conn = Mock({"isListeningConnection": False,
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_id=1, msg_type=ANSWER_PRIMARY_MASTER)
self.app.primary_master_node = None
......
......@@ -70,7 +70,7 @@ class StorageOperationTests(unittest.TestCase):
def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs):
conn = Mock({
"getAddress" : ("127.0.0.1", self.master_port),
"isListeningConnection": _listening,
"isServerConnection": _listening,
})
packet = Packet(msg_id=1, msg_type=_msg_type)
# hook
......@@ -219,42 +219,42 @@ server: 127.0.0.1:10020
def test_06_timeoutExpired(self):
# server connection
conn = Mock({
"isListeningConnection": True,
"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port),
})
self.operation.timeoutExpired(conn)
self.assertEquals(len(conn.mockGetNamedCalls('isListeningConnection')), 1)
self.assertEquals(len(conn.mockGetNamedCalls('isServerConnection')), 1)
self.assertEquals(len(conn.mockGetNamedCalls('getUUID')), 1)
self.checkNoPacketSent(conn)
# client connection
conn = Mock({
"getUUID": self.master_uuid,
"isListeningConnection": False,
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
self.assertRaises(PrimaryFailure, self.operation.timeoutExpired, conn)
self.assertEquals(len(conn.mockGetNamedCalls('isListeningConnection')), 1)
self.assertEquals(len(conn.mockGetNamedCalls('isServerConnection')), 1)
self.assertEquals(len(conn.mockGetNamedCalls('getUUID')), 1)
self.checkNoPacketSent(conn)
# connection with another storage node
conn = Mock({
"getUUID": self.getNewUUID(),
"isListeningConnection": False,
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
self.assertRaises(NotImplementedError, self.operation.timeoutExpired, conn)
self.assertEquals(len(conn.mockGetNamedCalls('isListeningConnection')), 1)
self.assertEquals(len(conn.mockGetNamedCalls('isServerConnection')), 1)
self.assertEquals(len(conn.mockGetNamedCalls('getUUID')), 1)
self.checkNoPacketSent(conn)
def test_07_connectionClosed1(self):
# server connection
conn = Mock({
"isListeningConnection": True,
"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port),
})
self.operation.connectionClosed(conn)
self.assertEquals(len(conn.mockGetNamedCalls('isListeningConnection')), 1)
self.assertEquals(len(conn.mockGetNamedCalls('isServerConnection')), 1)
self.assertEquals(len(conn.mockGetNamedCalls('getUUID')), 1)
self.checkNoPacketSent(conn)
......@@ -262,12 +262,12 @@ server: 127.0.0.1:10020
# primary has closed the connection
conn = Mock({
"getUUID": self.master_uuid,
"isListeningConnection": False,
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
self.assertRaises(PrimaryFailure,
self.operation.connectionClosed, conn)
self.assertEquals(len(conn.mockGetNamedCalls('isListeningConnection')), 1)
self.assertEquals(len(conn.mockGetNamedCalls('isServerConnection')), 1)
self.assertEquals(len(conn.mockGetNamedCalls('getUUID')), 1)
self.checkNoPacketSent(conn)
......@@ -275,43 +275,43 @@ server: 127.0.0.1:10020
# listening connection with a storage node
conn = Mock({
"getUUID": self.getNewUUID(),
"isListeningConnection": False,
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
self.assertRaises(NotImplementedError, self.operation.connectionClosed, conn)
self.assertEquals(len(conn.mockGetNamedCalls('isListeningConnection')), 1)
self.assertEquals(len(conn.mockGetNamedCalls('isServerConnection')), 1)
self.assertEquals(len(conn.mockGetNamedCalls('getUUID')), 1)
self.checkNoPacketSent(conn)
def test_08_peerBroken(self):
# server connection
conn = Mock({
"isListeningConnection": True,
"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port),
})
self.operation.peerBroken(conn)
self.assertEquals(len(conn.mockGetNamedCalls('isListeningConnection')), 1)
self.assertEquals(len(conn.mockGetNamedCalls('isServerConnection')), 1)
self.assertEquals(len(conn.mockGetNamedCalls('getUUID')), 1)
self.checkNoPacketSent(conn)
# client connection
conn = Mock({
"getUUID": self.master_uuid,
"isListeningConnection": False,
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
self.assertRaises(PrimaryFailure,
self.operation.peerBroken, conn)
self.assertEquals(len(conn.mockGetNamedCalls('isListeningConnection')), 1)
self.assertEquals(len(conn.mockGetNamedCalls('isServerConnection')), 1)
self.assertEquals(len(conn.mockGetNamedCalls('getUUID')), 1)
self.checkNoPacketSent(conn)
# connection with another storage node
conn = Mock({
"getUUID": self.getNewUUID(),
"isListeningConnection": False,
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
self.assertRaises(NotImplementedError, self.operation.peerBroken, conn)
self.assertEquals(len(conn.mockGetNamedCalls('isListeningConnection')), 1)
self.assertEquals(len(conn.mockGetNamedCalls('isServerConnection')), 1)
self.assertEquals(len(conn.mockGetNamedCalls('getUUID')), 1)
self.checkNoPacketSent(conn)
......@@ -335,7 +335,7 @@ server: 127.0.0.1:10020
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({
"getUUID": uuid,
"isListeningConnection": True,
"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port),
})
count = len(self.app.nm.getNodeList())
......@@ -357,7 +357,7 @@ server: 127.0.0.1:10020
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({
"getUUID": uuid,
"isListeningConnection": True,
"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port),
})
count = len(self.app.nm.getNodeList())
......@@ -376,7 +376,7 @@ server: 127.0.0.1:10020
# new non-master, rejected
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({
"isListeningConnection": True,
"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port),
})
count = len(self.app.nm.getNodeList())
......@@ -396,7 +396,7 @@ server: 127.0.0.1:10020
uuid = self.getNewUUID()
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({
"isListeningConnection": True,
"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port),
})
count = len(self.app.nm.getNodeList())
......@@ -425,7 +425,7 @@ server: 127.0.0.1:10020
# not new & accepted
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({
"isListeningConnection": True,
"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port),
})
mn = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port))
......@@ -454,7 +454,7 @@ server: 127.0.0.1:10020
def test_10_handleAcceptNodeIdentification1(self):
# client connection not implemented
conn = Mock({
"isListeningConnection": False,
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
packet = Packet(msg_id=1, msg_type=ACCEPT_NODE_IDENTIFICATION)
......@@ -530,7 +530,7 @@ server: 127.0.0.1:10020
# old partition change -> do nothing
app = self.app
conn = Mock({
"isListeningConnection": False,
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
app.replicator = Mock({})
......@@ -555,7 +555,7 @@ server: 127.0.0.1:10020
)
# context
conn = Mock({
"isListeningConnection": False,
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
packet = Packet(msg_id=1, msg_type=NOTIFY_PARTITION_CHANGES)
......@@ -608,7 +608,7 @@ server: 127.0.0.1:10020
def test_16_handleStopOperation1(self):
# OperationFailure
conn = Mock({ 'isListeningConnection': False })
conn = Mock({ 'isServerConnection': False })
packet = Packet(msg_id=1, msg_type=STOP_OPERATION)
self.assertRaises(OperationFailure, self.operation.handleStopOperation, conn, packet)
......@@ -680,7 +680,7 @@ server: 127.0.0.1:10020
def test_22_handleLockInformation2(self):
# load transaction informations
conn = Mock({ 'isListeningConnection': False, })
conn = Mock({ 'isServerConnection': False, })
self.app.dm = Mock({ })
packet = Packet(msg_id=1, msg_type=LOCK_INFORMATION)
transaction = Mock({ 'getObjectList': ((0, ), ), })
......@@ -692,7 +692,7 @@ server: 127.0.0.1:10020
self.checkPacket(conn, packet_type=NOTIFY_INFORMATION_LOCKED)
# transaction not in transaction_dict -> KeyError
transaction = Mock({ 'getObjectList': ((0, ), ), })
conn = Mock({ 'isListeningConnection': False, })
conn = Mock({ 'isServerConnection': False, })
self.operation.handleLockInformation(conn, packet, '\x01' * 8)
self.checkPacket(conn, packet_type=NOTIFY_INFORMATION_LOCKED)
......@@ -709,7 +709,7 @@ server: 127.0.0.1:10020
def test_23_handleUnlockInformation2(self):
# delete transaction informations
conn = Mock({ 'isListeningConnection': False, })
conn = Mock({ 'isServerConnection': False, })
self.app.dm = Mock({ })
packet = Packet(msg_id=1, msg_type=LOCK_INFORMATION)
transaction = Mock({ 'getObjectList': ((0, ), ), })
......@@ -725,7 +725,7 @@ server: 127.0.0.1:10020
self.assertEquals(calls[0].getParam(0), INVALID_TID)
# transaction not in transaction_dict -> KeyError
transaction = Mock({ 'getObjectList': ((0, ), ), })
conn = Mock({ 'isListeningConnection': False, })
conn = Mock({ 'isServerConnection': False, })
self.operation.handleLockInformation(conn, packet, '\x01' * 8)
self.checkPacket(conn, packet_type=NOTIFY_INFORMATION_LOCKED)
......
......@@ -150,7 +150,7 @@ server: 127.0.0.1:10020
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : True})
"isServerConnection" : True})
self.verification.timeoutExpired(conn)
# nothing happens
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 0)
......@@ -159,7 +159,7 @@ server: 127.0.0.1:10020
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : False})
"isServerConnection" : False})
self.assertRaises(PrimaryFailure, self.verification.timeoutExpired, conn,)
# nothing happens
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 0)
......@@ -169,7 +169,7 @@ server: 127.0.0.1:10020
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : True})
"isServerConnection" : True})
self.verification.connectionClosed(conn)
# nothing happens
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 0)
......@@ -178,7 +178,7 @@ server: 127.0.0.1:10020
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : False})
"isServerConnection" : False})
self.assertRaises(PrimaryFailure, self.verification.connectionClosed, conn,)
# nothing happens
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 0)
......@@ -189,7 +189,7 @@ server: 127.0.0.1:10020
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : True})
"isServerConnection" : True})
self.verification.peerBroken(conn)
# nothing happens
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 0)
......@@ -198,7 +198,7 @@ server: 127.0.0.1:10020
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : False})
"isServerConnection" : False})
self.assertRaises(PrimaryFailure, self.verification.peerBroken, conn,)
# nothing happens
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 0)
......@@ -209,7 +209,7 @@ server: 127.0.0.1:10020
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : True})
"isServerConnection" : True})
p = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
self.verification.handleRequestNodeIdentification(conn, p, CLIENT_NODE_TYPE,
uuid, "127.0.0.1", self.client_port, "zatt")
......@@ -219,7 +219,7 @@ server: 127.0.0.1:10020
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : True})
"isServerConnection" : True})
p = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
self.verification.handleRequestNodeIdentification(conn, p, CLIENT_NODE_TYPE,
uuid, "127.0.0.1", self.client_port, "zatt")
......@@ -229,7 +229,7 @@ server: 127.0.0.1:10020
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port),
"isListeningConnection" : True})
"isServerConnection" : True})
p = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
self.verification.handleRequestNodeIdentification(conn, p, MASTER_NODE_TYPE,
uuid, "127.0.0.1", self.client_port, "zatt")
......@@ -239,7 +239,7 @@ server: 127.0.0.1:10020
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port),
"isListeningConnection" : True})
"isServerConnection" : True})
p = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
self.verification.handleRequestNodeIdentification(conn, p, MASTER_NODE_TYPE,
......@@ -258,7 +258,7 @@ server: 127.0.0.1:10020
# notify a node declared as broken
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port),
"isListeningConnection" : True})
"isServerConnection" : True})
node = self.app.nm.getNodeByServer(conn.getAddress())
node.setState(BROKEN_STATE)
self.assertEqual(node.getUUID(), uuid)
......@@ -275,7 +275,7 @@ server: 127.0.0.1:10020
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port),
"isListeningConnection" : True})
"isServerConnection" : True})
node = self.app.nm.getNodeByServer(conn.getAddress())
node.setState(RUNNING_STATE)
self.assertNotEqual(node.getUUID(), uuid)
......@@ -297,7 +297,7 @@ server: 127.0.0.1:10020
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : True})
"isServerConnection" : True})
p = Packet(msg_id=1, msg_type=ACCEPT_NODE_IDENTIFICATION)
self.verification.handleAcceptNodeIdentification(conn, p, CLIENT_NODE_TYPE,
self.getNewUUID(),"127.0.0.1", self.client_port,
......@@ -310,14 +310,14 @@ server: 127.0.0.1:10020
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : True})
"isServerConnection" : True})
self.verification.handleAnswerPrimaryMaster(conn, packet,self.getNewUUID(), ())
self.checkCalledAbort(conn)
# raise id uuid is different
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : False})
"isServerConnection" : False})
self.app.primary_master_node = MasterNode(uuid=self.getNewUUID())
self.assertNotEqual(uuid, self.app.primary_master_node.getUUID())
self.assertRaises(PrimaryFailure, self.verification.handleAnswerPrimaryMaster, conn, packet,uuid, ())
......@@ -326,7 +326,7 @@ server: 127.0.0.1:10020
uuid = self.app.primary_master_node.getUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : False})
"isServerConnection" : False})
self.assertEqual(uuid, self.app.primary_master_node.getUUID())
self.verification.handleAnswerPrimaryMaster(conn, packet,uuid, ())
......@@ -336,14 +336,14 @@ server: 127.0.0.1:10020
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : True})
"isServerConnection" : True})
self.verification.handleAskLastIDs(conn, packet)
self.checkCalledAbort(conn)
# return invalid if db store nothing
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : False})
"isServerConnection" : False})
self.verification.handleAskLastIDs(conn, packet)
call = conn.mockGetNamedCalls("addPacket")[0]
packet = call.getParam(0)
......@@ -358,7 +358,7 @@ server: 127.0.0.1:10020
# insert some oid
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : False})
"isServerConnection" : False})
self.app.dm.begin()
self.app.dm.query("""insert into obj (oid, serial, compression,
checksum, value) values (3, 'A', 0, 0, '')""")
......@@ -395,7 +395,7 @@ server: 127.0.0.1:10020
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : True})
"isServerConnection" : True})
self.verification.handleAskPartitionTable(conn, packet, [1,])
self.checkCalledAbort(conn)
......@@ -405,7 +405,7 @@ server: 127.0.0.1:10020
self.assertEqual(len(self.app.pt.getCellList(1)), 0)
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : False})
"isServerConnection" : False})
self.verification.handleAskPartitionTable(conn, packet, [1,])
call = conn.mockGetNamedCalls("addPacket")[0]
packet = call.getParam(0)
......@@ -423,7 +423,7 @@ server: 127.0.0.1:10020
self.assertTrue(self.app.pt.hasOffset(1))
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : False})
"isServerConnection" : False})
self.verification.handleAskPartitionTable(conn, packet, [1,])
call = conn.mockGetNamedCalls("addPacket")[0]
packet = call.getParam(0)
......@@ -441,7 +441,7 @@ server: 127.0.0.1:10020
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : True})
"isServerConnection" : True})
self.app.ptid = 1
self.verification.handleSendPartitionTable(conn, packet, 0, ())
self.assertEquals(self.app.ptid, 1)
......@@ -450,7 +450,7 @@ server: 127.0.0.1:10020
# send a table
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : False})
"isServerConnection" : False})
self.app.pt = PartitionTable(3, 2)
node_1 = self.getNewUUID()
......@@ -488,7 +488,7 @@ server: 127.0.0.1:10020
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isListeningConnection" : True})
"isServerConnection" : True})
self.app.ptid = 1
self.verification.handleNotifyPartitionChanges(conn, packet, 0, ())
self.assertEquals(self.app.ptid, 1)
......@@ -496,7 +496,7 @@ server: 127.0.0.1:10020
# old partition change
conn = Mock({
"isListeningConnection": False,
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
packet = Packet(msg_id=1, msg_type=NOTIFY_PARTITION_CHANGES)
......@@ -506,7 +506,7 @@ server: 127.0.0.1:10020
# new node
conn = Mock({
"isListeningConnection": False,
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
packet = Packet(msg_id=1, msg_type=NOTIFY_PARTITION_CHANGES)
......@@ -526,12 +526,12 @@ server: 127.0.0.1:10020
def test_11_handleStartOperation(self):
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': True })
'isServerConnection': True })
packet = Packet(msg_id=1, msg_type=STOP_OPERATION)
self.verification.handleStartOperation(conn, packet)
self.checkCalledAbort(conn)
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': False })
'isServerConnection': False })
self.assertFalse(self.app.operational)
packet = Packet(msg_id=1, msg_type=STOP_OPERATION)
self.verification.handleStartOperation(conn, packet)
......@@ -539,25 +539,25 @@ server: 127.0.0.1:10020
def test_12_handleStopOperation(self):
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': True })
'isServerConnection': True })
packet = Packet(msg_id=1, msg_type=STOP_OPERATION)
self.verification.handleStopOperation(conn, packet)
self.checkCalledAbort(conn)
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': False })
'isServerConnection': False })
packet = Packet(msg_id=1, msg_type=STOP_OPERATION)
self.assertRaises(OperationFailure, self.verification.handleStopOperation, conn, packet)
def test_13_handleAskUnfinishedTransactions(self):
# server connection
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': True })
'isServerConnection': True })
packet = Packet(msg_id=1, msg_type=ASK_UNFINISHED_TRANSACTIONS)
self.verification.handleAskUnfinishedTransactions(conn, packet)
self.checkCalledAbort(conn)
# client connection with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': False})
'isServerConnection': False})
packet = Packet(msg_id=1, msg_type=ASK_UNFINISHED_TRANSACTIONS)
self.verification.handleAskUnfinishedTransactions(conn, packet)
call = conn.mockGetNamedCalls("addPacket")[0]
......@@ -573,7 +573,7 @@ server: 127.0.0.1:10020
checksum, value) values (0, 4, 0, 0, '')""")
self.app.dm.commit()
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': False})
'isServerConnection': False})
packet = Packet(msg_id=1, msg_type=ASK_UNFINISHED_TRANSACTIONS)
self.verification.handleAskUnfinishedTransactions(conn, packet)
call = conn.mockGetNamedCalls("addPacket")[0]
......@@ -587,7 +587,7 @@ server: 127.0.0.1:10020
def test_14_handleAskTransactionInformation(self):
# ask from server with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': True })
'isServerConnection': True })
packet = Packet(msg_id=1, msg_type=ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(1))
call = conn.mockGetNamedCalls("addPacket")[0]
......@@ -598,7 +598,7 @@ server: 127.0.0.1:10020
self.assertEqual(code, TID_NOT_FOUND_CODE)
# ask from client conn with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': False })
'isServerConnection': False })
packet = Packet(msg_id=1, msg_type=ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(1))
call = conn.mockGetNamedCalls("addPacket")[0]
......@@ -617,7 +617,7 @@ server: 127.0.0.1:10020
self.app.dm.commit()
# object from trans
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': False })
'isServerConnection': False })
packet = Packet(msg_id=1, msg_type=ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(1))
call = conn.mockGetNamedCalls("addPacket")[0]
......@@ -633,7 +633,7 @@ server: 127.0.0.1:10020
self.assertEqual(u64(oid_list[0]), 2)
# object from ttrans
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': False })
'isServerConnection': False })
packet = Packet(msg_id=1, msg_type=ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(3))
call = conn.mockGetNamedCalls("addPacket")[0]
......@@ -650,7 +650,7 @@ server: 127.0.0.1:10020
# input some tmp data and ask from server, must find one transaction
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': True })
'isServerConnection': True })
# find the one in trans
packet = Packet(msg_id=1, msg_type=ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(1))
......@@ -667,7 +667,7 @@ server: 127.0.0.1:10020
self.assertEqual(u64(oid_list[0]), 2)
# do not find the one in ttrans
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': True })
'isServerConnection': True })
packet = Packet(msg_id=1, msg_type=ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(3))
call = conn.mockGetNamedCalls("addPacket")[0]
......@@ -680,13 +680,13 @@ server: 127.0.0.1:10020
def test_15_handleAskObjectPresent(self):
# server connection
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': True })
'isServerConnection': True })
packet = Packet(msg_id=1, msg_type=ASK_OBJECT_PRESENT)
self.verification.handleAskObjectPresent(conn, packet, p64(1), p64(2))
self.checkCalledAbort(conn)
# client connection with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': False})
'isServerConnection': False})
packet = Packet(msg_id=1, msg_type=ASK_OBJECT_PRESENT)
self.verification.handleAskObjectPresent(conn, packet, p64(1), p64(2))
call = conn.mockGetNamedCalls("addPacket")[0]
......@@ -702,7 +702,7 @@ server: 127.0.0.1:10020
checksum, value) values (1, 2, 0, 0, '')""")
self.app.dm.commit()
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': False})
'isServerConnection': False})
packet = Packet(msg_id=1, msg_type=ASK_OBJECT_PRESENT)
self.verification.handleAskObjectPresent(conn, packet, p64(1), p64(2))
call = conn.mockGetNamedCalls("addPacket")[0]
......@@ -716,13 +716,13 @@ server: 127.0.0.1:10020
def test_16_handleDeleteTransaction(self):
# server connection
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': True })
'isServerConnection': True })
packet = Packet(msg_id=1, msg_type=ASK_OBJECT_PRESENT)
self.verification.handleDeleteTransaction(conn, packet, p64(1))
self.checkCalledAbort(conn)
# client connection with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': False})
'isServerConnection': False})
packet = Packet(msg_id=1, msg_type=ASK_OBJECT_PRESENT)
self.verification.handleDeleteTransaction(conn, packet, p64(1))
# client connection with data
......@@ -737,7 +737,7 @@ server: 127.0.0.1:10020
def test_17_handleCommitTransaction(self):
# server connection
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': True })
'isServerConnection': True })
dm = Mock()
self.app.dm = dm
packet = Packet(msg_id=1, msg_type=COMMIT_TRANSACTION)
......@@ -746,7 +746,7 @@ server: 127.0.0.1:10020
self.assertEqual(len(dm.mockGetNamedCalls("finishTransaction")), 0)
# commit a transaction
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': False })
'isServerConnection': False })
dm = Mock()
self.app.dm = dm
packet = Packet(msg_id=1, msg_type=COMMIT_TRANSACTION)
......@@ -758,7 +758,7 @@ server: 127.0.0.1:10020
def test_18_handleLockInformation(self):
conn = Mock({"getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': False})
'isServerConnection': False})
packet = Packet(msg_id=1, msg_type=LOCK_INFORMATION)
self.assertEquals(len(self.app.load_lock_dict), 0)
self.verification.handleLockInformation(conn, packet, p64(1))
......@@ -766,7 +766,7 @@ server: 127.0.0.1:10020
def test_19_handleUnlockInformation(self):
conn = Mock({"getAddress" : ("127.0.0.1", self.master_port),
'isListeningConnection': False})
'isServerConnection': False})
self.app.load_lock_dict[p64(1)] = Mock()
packet = Packet(msg_id=1, msg_type=UNLOCK_INFORMATION)
self.verification.handleUnlockInformation(conn, packet, p64(1))
......
......@@ -37,7 +37,7 @@ class VerificationEventHandler(StorageEventHandler):
StorageEventHandler.connectionAccepted(self, conn, s, addr)
def timeoutExpired(self, conn):
if not conn.isListeningConnection():
if not conn.isServerConnection():
# If a primary master node timeouts, I cannot continue.
logging.critical('the primary master node times out')
raise PrimaryFailure('the primary master node times out')
......@@ -45,7 +45,7 @@ class VerificationEventHandler(StorageEventHandler):
StorageEventHandler.timeoutExpired(self, conn)
def connectionClosed(self, conn):
if not conn.isListeningConnection():
if not conn.isServerConnection():
# If a primary master node closes, I cannot continue.
logging.critical('the primary master node is dead')
raise PrimaryFailure('the primary master node is dead')
......@@ -53,7 +53,7 @@ class VerificationEventHandler(StorageEventHandler):
StorageEventHandler.connectionClosed(self, conn)
def peerBroken(self, conn):
if not conn.isListeningConnection():
if not conn.isServerConnection():
# If a primary master node gets broken, I cannot continue.
logging.critical('the primary master node is broken')
raise PrimaryFailure('the primary master node is broken')
......@@ -62,7 +62,7 @@ class VerificationEventHandler(StorageEventHandler):
def handleRequestNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, name):
if not conn.isListeningConnection():
if not conn.isServerConnection():
self.handleUnexpectedPacket(conn, packet)
else:
app = self.app
......@@ -114,7 +114,7 @@ class VerificationEventHandler(StorageEventHandler):
def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid,
known_master_list):
if not conn.isListeningConnection():
if not conn.isServerConnection():
app = self.app
if app.primary_master_node.getUUID() != primary_uuid:
raise PrimaryFailure('the primary master node seems to have changed')
......@@ -125,7 +125,7 @@ class VerificationEventHandler(StorageEventHandler):
self.handleUnexpectedPacket(conn, packet)
def handleAskLastIDs(self, conn, packet):
if not conn.isListeningConnection():
if not conn.isServerConnection():
app = self.app
p = Packet()
oid = app.dm.getLastOID() or INVALID_OID
......@@ -136,7 +136,7 @@ class VerificationEventHandler(StorageEventHandler):
self.handleUnexpectedPacket(conn, packet)
def handleAskPartitionTable(self, conn, packet, offset_list):
if not conn.isListeningConnection():
if not conn.isServerConnection():
app = self.app
row_list = []
try:
......@@ -164,7 +164,7 @@ class VerificationEventHandler(StorageEventHandler):
def handleSendPartitionTable(self, conn, packet, ptid, row_list):
"""A primary master node sends this packet to synchronize a partition
table. Note that the message can be split into multiple packets."""
if not conn.isListeningConnection():
if not conn.isServerConnection():
app = self.app
nm = app.nm
pt = app.pt
......@@ -198,7 +198,7 @@ class VerificationEventHandler(StorageEventHandler):
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list):
"""This is very similar to Send Partition Table, except that
the information is only about changes from the previous."""
if not conn.isListeningConnection():
if not conn.isServerConnection():
app = self.app
nm = app.nm
pt = app.pt
......@@ -225,19 +225,19 @@ class VerificationEventHandler(StorageEventHandler):
self.handleUnexpectedPacket(conn, packet)
def handleStartOperation(self, conn, packet):
if not conn.isListeningConnection():
if not conn.isServerConnection():
self.app.operational = True
else:
self.handleUnexpectedPacket(conn, packet)
def handleStopOperation(self, conn, packet):
if not conn.isListeningConnection():
if not conn.isServerConnection():
raise OperationFailure('operation stopped')
else:
self.handleUnexpectedPacket(conn, packet)
def handleAskUnfinishedTransactions(self, conn, packet):
if not conn.isListeningConnection():
if not conn.isServerConnection():
app = self.app
tid_list = app.dm.getUnfinishedTIDList()
p = Packet()
......@@ -248,7 +248,7 @@ class VerificationEventHandler(StorageEventHandler):
def handleAskTransactionInformation(self, conn, packet, tid):
app = self.app
if not conn.isListeningConnection():
if not conn.isServerConnection():
# If this is from a primary master node, assume that it wants
# to obtain information about the transaction, even if it has
# not been finished.
......@@ -265,7 +265,7 @@ class VerificationEventHandler(StorageEventHandler):
conn.addPacket(p)
def handleAskObjectPresent(self, conn, packet, oid, tid):
if not conn.isListeningConnection():
if not conn.isServerConnection():
app = self.app
p = Packet()
if app.dm.objectPresent(oid, tid):
......@@ -278,14 +278,14 @@ class VerificationEventHandler(StorageEventHandler):
self.handleUnexpectedPacket(conn, packet)
def handleDeleteTransaction(self, conn, packet, tid):
if not conn.isListeningConnection():
if not conn.isServerConnection():
app = self.app
app.dm.deleteTransaction(tid, all = True)
else:
self.handleUnexpectedPacket(conn, packet)
def handleCommitTransaction(self, conn, packet, tid):
if not conn.isListeningConnection():
if not conn.isServerConnection():
app = self.app
app.dm.finishTransaction(tid)
else:
......
......@@ -182,7 +182,7 @@ class testConnection(unittest.TestCase):
# test abort
bc.abort()
self.assertEqual(bc.aborted, True)
self.assertRaises(NotImplementedError, bc.isListeningConnection)
self.assertRaises(NotImplementedError, bc.isServerConnection)
def test_04_Connection_pending(self):
em = Mock()
......@@ -732,7 +732,7 @@ class testConnection(unittest.TestCase):
addr=("127.0.0.7", 93413))
# check connector created and connection initialize
self.assertFalse(bc.connecting)
self.assertFalse(bc.isListeningConnection())
self.assertFalse(bc.isServerConnection())
self.assertNotEqual(bc.getConnector(), None)
conn = bc.getConnector()
self.assertEquals(len(conn.mockGetNamedCalls("makeClientConnection")), 1)
......@@ -760,7 +760,7 @@ class testConnection(unittest.TestCase):
addr=("127.0.0.7", 93413))
# check connector created and connection initialize
self.assertTrue(bc.connecting)
self.assertFalse(bc.isListeningConnection())
self.assertFalse(bc.isServerConnection())
self.assertNotEqual(bc.getConnector(), None)
conn = bc.getConnector()
self.assertEquals(len(conn.mockGetNamedCalls("makeClientConnection")), 1)
......@@ -788,7 +788,7 @@ class testConnection(unittest.TestCase):
addr=("127.0.0.7", 93413))
# check connector created and connection initialize
self.assertTrue(bc.connecting)
self.assertFalse(bc.isListeningConnection())
self.assertFalse(bc.isServerConnection())
self.assertEqual(bc.getConnector(), None)
call = conn.mockGetNamedCalls("makeClientConnection")[0]
data = call.getParam(0)
......@@ -955,7 +955,7 @@ class testConnection(unittest.TestCase):
# test abort
bc.abort()
self.assertEqual(bc.aborted, True)
self.assertTrue(bc.isListeningConnection())
self.assertTrue(bc.isServerConnection())
def test_15_MTClientConnection(self):
......@@ -968,7 +968,7 @@ class testConnection(unittest.TestCase):
addr=("127.0.0.7", 93413))
# check connector created and connection initialize
self.assertFalse(bc.connecting)
self.assertFalse(bc.isListeningConnection())
self.assertFalse(bc.isServerConnection())
self.assertNotEqual(bc.getConnector(), None)
conn = bc.getConnector()
self.assertEquals(len(conn.mockGetNamedCalls("makeClientConnection")), 1)
......@@ -995,7 +995,7 @@ class testConnection(unittest.TestCase):
addr=("127.0.0.7", 93413))
# check connector created and connection initialize
self.assertTrue(bc.connecting)
self.assertFalse(bc.isListeningConnection())
self.assertFalse(bc.isServerConnection())
self.assertNotEqual(bc.getConnector(), None)
conn = bc.getConnector()
self.assertEquals(len(conn.mockGetNamedCalls("makeClientConnection")), 1)
......@@ -1023,7 +1023,7 @@ class testConnection(unittest.TestCase):
addr=("127.0.0.7", 93413))
# check connector created and connection initialize
self.assertTrue(bc.connecting)
self.assertFalse(bc.isListeningConnection())
self.assertFalse(bc.isServerConnection())
self.assertEqual(bc.getConnector(), None)
call = conn.mockGetNamedCalls("makeClientConnection")[0]
data = call.getParam(0)
......@@ -1075,7 +1075,7 @@ class testConnection(unittest.TestCase):
# test abort
bc.abort()
self.assertEqual(bc.aborted, True)
self.assertTrue(bc.isListeningConnection())
self.assertTrue(bc.isServerConnection())
# XXX check locking ???
......
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