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

Because the purpose of an handler is to *handle* (packets), remove the 'handle'

prefix from everywhere.


git-svn-id: https://svn.erp5.org/repos/neo/trunk@1350 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent a53b51dd
...@@ -25,7 +25,7 @@ from neo.util import dump ...@@ -25,7 +25,7 @@ from neo.util import dump
class AdminEventHandler(EventHandler): class AdminEventHandler(EventHandler):
"""This class deals with events for administrating cluster.""" """This class deals with events for administrating cluster."""
def handleAskPartitionList(self, conn, packet, min_offset, max_offset, uuid): def askPartitionList(self, conn, packet, min_offset, max_offset, uuid):
logging.info("ask partition list from %s to %s for %s" %(min_offset, max_offset, dump(uuid))) logging.info("ask partition list from %s to %s for %s" %(min_offset, max_offset, dump(uuid)))
app = self.app app = self.app
# check we have one pt otherwise ask it to PMN # check we have one pt otherwise ask it to PMN
...@@ -43,7 +43,7 @@ class AdminEventHandler(EventHandler): ...@@ -43,7 +43,7 @@ class AdminEventHandler(EventHandler):
app.sendPartitionTable(conn, min_offset, max_offset, uuid, packet.getId()) app.sendPartitionTable(conn, min_offset, max_offset, uuid, packet.getId())
def handleAskNodeList(self, conn, packet, node_type): def askNodeList(self, conn, packet, node_type):
logging.info("ask node list for %s" %(node_type)) logging.info("ask node list for %s" %(node_type))
def node_filter(n): def node_filter(n):
return n.getType() is node_type return n.getType() is node_type
...@@ -52,7 +52,7 @@ class AdminEventHandler(EventHandler): ...@@ -52,7 +52,7 @@ class AdminEventHandler(EventHandler):
p = protocol.answerNodeList(node_information_list) p = protocol.answerNodeList(node_information_list)
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
def handleSetNodeState(self, conn, packet, uuid, state, modify_partition_table): def setNodeState(self, conn, packet, uuid, state, modify_partition_table):
logging.info("set node state for %s-%s" %(dump(uuid), state)) logging.info("set node state for %s-%s" %(dump(uuid), state))
node = self.app.nm.getByUUID(uuid) node = self.app.nm.getByUUID(uuid)
if node is None: if node is None:
...@@ -69,7 +69,7 @@ class AdminEventHandler(EventHandler): ...@@ -69,7 +69,7 @@ class AdminEventHandler(EventHandler):
msg_id = self.app.master_conn.ask(p) msg_id = self.app.master_conn.ask(p)
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()}) self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()})
def handleSetClusterState(self, conn, packet, state): def setClusterState(self, conn, packet, state):
# forward to primary # forward to primary
if self.app.master_conn is None: if self.app.master_conn is None:
raise protocol.NotReadyError('Not connected to a primary master.') raise protocol.NotReadyError('Not connected to a primary master.')
...@@ -77,7 +77,7 @@ class AdminEventHandler(EventHandler): ...@@ -77,7 +77,7 @@ class AdminEventHandler(EventHandler):
msg_id = self.app.master_conn.ask(p) msg_id = self.app.master_conn.ask(p)
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()}) self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()})
def handleAddPendingNodes(self, conn, packet, uuid_list): def addPendingNodes(self, conn, packet, uuid_list):
if self.app.master_conn is None: if self.app.master_conn is None:
raise protocol.NotReadyError('Not connected to a primary master.') raise protocol.NotReadyError('Not connected to a primary master.')
logging.info('Add nodes %s' % [dump(uuid) for uuid in uuid_list]) logging.info('Add nodes %s' % [dump(uuid) for uuid in uuid_list])
...@@ -85,7 +85,7 @@ class AdminEventHandler(EventHandler): ...@@ -85,7 +85,7 @@ class AdminEventHandler(EventHandler):
msg_id = self.app.master_conn.ask(protocol.addPendingNodes(uuid_list)) msg_id = self.app.master_conn.ask(protocol.addPendingNodes(uuid_list))
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()}) self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()})
def handleAskClusterState(self, conn, packet): def askClusterState(self, conn, packet):
if self.app.cluster_state is None: if self.app.cluster_state is None:
if self.app.master_conn is None: if self.app.master_conn is None:
raise protocol.NotReadyError('Not connected to a primary master.') raise protocol.NotReadyError('Not connected to a primary master.')
...@@ -96,7 +96,7 @@ class AdminEventHandler(EventHandler): ...@@ -96,7 +96,7 @@ class AdminEventHandler(EventHandler):
conn.answer(protocol.answerClusterState(self.app.cluster_state), conn.answer(protocol.answerClusterState(self.app.cluster_state),
packet.getId()) packet.getId())
def handleAskPrimaryMaster(self, conn, packet): def askPrimaryMaster(self, conn, packet):
if self.app.master_conn is None: if self.app.master_conn is None:
raise protocol.NotReadyError('Not connected to a primary master.') raise protocol.NotReadyError('Not connected to a primary master.')
master_node = self.app.master_node master_node = self.app.master_node
...@@ -135,17 +135,17 @@ class MasterEventHandler(EventHandler): ...@@ -135,17 +135,17 @@ class MasterEventHandler(EventHandler):
# unexpectexd answers and notifications # unexpectexd answers and notifications
super(MasterEventHandler, self).dispatch(conn, packet) super(MasterEventHandler, self).dispatch(conn, packet)
def handleAnswerNodeInformation(self, conn, packet, node_list): def answerNodeInformation(self, conn, packet, node_list):
# XXX: This will no more exists when the initialization module will be # XXX: This will no more exists when the initialization module will be
# implemented for factorize code (as done for bootstrap) # implemented for factorize code (as done for bootstrap)
logging.debug("handleAnswerNodeInformation") logging.debug("answerNodeInformation")
def handleAnswerPartitionTable(self, conn, packet, ptid, row_list): def answerPartitionTable(self, conn, packet, ptid, row_list):
# XXX: This will no more exists when the initialization module will be # XXX: This will no more exists when the initialization module will be
# implemented for factorize code (as done for bootstrap) # implemented for factorize code (as done for bootstrap)
logging.debug("handleAnswerPartitionTable") logging.debug("answerPartitionTable")
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list): def notifyPartitionChanges(self, conn, packet, ptid, cell_list):
app = self.app app = self.app
if ptid < app.ptid: if ptid < app.ptid:
# Ignore this packet. # Ignore this packet.
...@@ -153,7 +153,7 @@ class MasterEventHandler(EventHandler): ...@@ -153,7 +153,7 @@ class MasterEventHandler(EventHandler):
app.ptid = ptid app.ptid = ptid
app.pt.update(ptid, cell_list, app.nm) app.pt.update(ptid, cell_list, app.nm)
def handleSendPartitionTable(self, conn, packet, ptid, row_list): def sendPartitionTable(self, conn, packet, ptid, row_list):
uuid = conn.getUUID() uuid = conn.getUUID()
app = self.app app = self.app
nm = app.nm nm = app.nm
...@@ -170,10 +170,10 @@ class MasterEventHandler(EventHandler): ...@@ -170,10 +170,10 @@ class MasterEventHandler(EventHandler):
pt.setCell(offset, node, state) pt.setCell(offset, node, state)
pt.log() pt.log()
def handleNotifyClusterInformation(self, conn, packet, cluster_state): def notifyClusterInformation(self, conn, packet, cluster_state):
self.app.cluster_state = cluster_state self.app.cluster_state = cluster_state
def handleNotifyNodeInformation(self, conn, packet, node_list): def notifyNodeInformation(self, conn, packet, node_list):
app = self.app app = self.app
app.nm.update(node_list) app.nm.update(node_list)
if not app.pt.filled(): if not app.pt.filled():
...@@ -189,30 +189,30 @@ class MasterRequestEventHandler(EventHandler): ...@@ -189,30 +189,30 @@ class MasterRequestEventHandler(EventHandler):
client_conn, kw = self.app.dispatcher.pop(msg_id) client_conn, kw = self.app.dispatcher.pop(msg_id)
client_conn.answer(packet, kw['msg_id']) client_conn.answer(packet, kw['msg_id'])
def handleAnswerClusterState(self, conn, packet, state): def answerClusterState(self, conn, packet, state):
logging.info("handleAnswerClusterState for a conn") logging.info("answerClusterState for a conn")
self.app.cluster_state = state self.app.cluster_state = state
self.__answerNeoCTL(packet.getId(), self.__answerNeoCTL(packet.getId(),
protocol.answerClusterState(state)) protocol.answerClusterState(state))
def handleAnswerNewNodes(self, conn, packet, uuid_list): def answerNewNodes(self, conn, packet, uuid_list):
logging.info("handleAnswerNewNodes for a conn") logging.info("answerNewNodes for a conn")
self.__answerNeoCTL(packet.getId(), self.__answerNeoCTL(packet.getId(),
protocol.answerNewNodes(uuid_list)) protocol.answerNewNodes(uuid_list))
def handleAnswerPartitionTable(self, conn, packet, ptid, row_list): def answerPartitionTable(self, conn, packet, ptid, row_list):
logging.info("handleAnswerPartitionTable for a conn") logging.info("answerPartitionTable for a conn")
client_conn, kw = self.app.dispatcher.pop(packet.getId()) client_conn, kw = self.app.dispatcher.pop(packet.getId())
# sent client the partition table # sent client the partition table
self.app.sendPartitionTable(client_conn, **kw) self.app.sendPartitionTable(client_conn, **kw)
def handleAnswerNodeState(self, conn, packet, uuid, state): def answerNodeState(self, conn, packet, uuid, state):
self.__answerNeoCTL(packet.getId(), self.__answerNeoCTL(packet.getId(),
protocol.answerNodeState(uuid, state)) protocol.answerNodeState(uuid, state))
def handleNoError(self, conn, packet, msg): def noError(self, conn, packet, msg):
self.__answerNeoCTL(packet.getId(), protocol.noError(msg)) self.__answerNeoCTL(packet.getId(), protocol.noError(msg))
def handleProtocolError(self, conn, packet, msg): def protocolError(self, conn, packet, msg):
self.__answerNeoCTL(packet.getId(), protocol.protocolError(msg)) self.__answerNeoCTL(packet.getId(), protocol.protocolError(msg))
...@@ -52,12 +52,12 @@ class BootstrapManager(EventHandler): ...@@ -52,12 +52,12 @@ class BootstrapManager(EventHandler):
def connectionLost(self, conn, new_state): def connectionLost(self, conn, new_state):
self.current = None self.current = None
def handleNotReady(self, conn, packet, message): def notReady(self, conn, packet, message):
# master are still electing on of them # master are still electing on of them
self.current = None self.current = None
conn.close() conn.close()
def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid, known_master_list): def answerPrimaryMaster(self, conn, packet, primary_uuid, known_master_list):
nm = self.app.nm nm = self.app.nm
# Register new master nodes. # Register new master nodes.
...@@ -81,7 +81,7 @@ class BootstrapManager(EventHandler): ...@@ -81,7 +81,7 @@ class BootstrapManager(EventHandler):
conn.ask(protocol.requestNodeIdentification(self.node_type, conn.ask(protocol.requestNodeIdentification(self.node_type,
self.uuid, self.server, self.name)) self.uuid, self.server, self.name))
def handleAcceptNodeIdentification(self, conn, packet, node_type, def acceptNodeIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid): uuid, address, num_partitions, num_replicas, your_uuid):
self.num_partitions = num_partitions self.num_partitions = num_partitions
self.num_replicas = num_replicas self.num_replicas = num_replicas
......
...@@ -25,12 +25,12 @@ from neo.util import dump ...@@ -25,12 +25,12 @@ from neo.util import dump
class PrimaryBootstrapHandler(AnswerBaseHandler): class PrimaryBootstrapHandler(AnswerBaseHandler):
""" Bootstrap handler used when looking for the primary master """ """ Bootstrap handler used when looking for the primary master """
def handleNotReady(self, conn, packet, message): def notReady(self, conn, packet, message):
app = self.app app = self.app
app.trying_master_node = None app.trying_master_node = None
app.setNodeNotReady() app.setNodeNotReady()
def handleAcceptNodeIdentification(self, conn, packet, node_type, def acceptNodeIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid): uuid, address, num_partitions, num_replicas, your_uuid):
app = self.app app = self.app
node = app.nm.getByAddress(conn.getAddress()) node = app.nm.getByAddress(conn.getAddress())
...@@ -57,7 +57,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler): ...@@ -57,7 +57,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
# Always create partition table # Always create partition table
app.pt = PartitionTable(num_partitions, num_replicas) app.pt = PartitionTable(num_partitions, num_replicas)
def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid, def answerPrimaryMaster(self, conn, packet, primary_uuid,
known_master_list): known_master_list):
app = self.app app = self.app
# Register new master nodes. # Register new master nodes.
...@@ -92,10 +92,10 @@ class PrimaryBootstrapHandler(AnswerBaseHandler): ...@@ -92,10 +92,10 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
app.trying_master_node = None app.trying_master_node = None
conn.close() conn.close()
def handleAnswerPartitionTable(self, conn, packet, ptid, row_list): def answerPartitionTable(self, conn, packet, ptid, row_list):
pass pass
def handleAnswerNodeInformation(self, conn, packet, node_list): def answerNodeInformation(self, conn, packet, node_list):
pass pass
class PrimaryNotificationsHandler(BaseHandler): class PrimaryNotificationsHandler(BaseHandler):
...@@ -126,10 +126,10 @@ class PrimaryNotificationsHandler(BaseHandler): ...@@ -126,10 +126,10 @@ class PrimaryNotificationsHandler(BaseHandler):
logging.critical("primary master node is broken") logging.critical("primary master node is broken")
BaseHandler.peerBroken(self, conn) BaseHandler.peerBroken(self, conn)
def handleStopOperation(self, conn, packet): def stopOperation(self, conn, packet):
logging.critical("master node ask to stop operation") logging.critical("master node ask to stop operation")
def handleInvalidateObjects(self, conn, packet, oid_list, tid): def invalidateObjects(self, conn, packet, oid_list, tid):
app = self.app app = self.app
app._cache_lock_acquire() app._cache_lock_acquire()
try: try:
...@@ -151,15 +151,15 @@ class PrimaryNotificationsHandler(BaseHandler): ...@@ -151,15 +151,15 @@ class PrimaryNotificationsHandler(BaseHandler):
# to avoid a dead lock. It is safe to not check the master connection # to avoid a dead lock. It is safe to not check the master connection
# because it's in the master handler, so the connection is already # because it's in the master handler, so the connection is already
# established. # established.
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list): def notifyPartitionChanges(self, conn, packet, ptid, cell_list):
pt = self.app.pt pt = self.app.pt
if pt.filled(): if pt.filled():
pt.update(ptid, cell_list, self.app.nm) pt.update(ptid, cell_list, self.app.nm)
def handleSendPartitionTable(self, conn, packet, ptid, row_list): def sendPartitionTable(self, conn, packet, ptid, row_list):
self.app.pt.load(ptid, row_list, self.app.nm) self.app.pt.load(ptid, row_list, self.app.nm)
def handleNotifyNodeInformation(self, conn, packet, node_list): def notifyNodeInformation(self, conn, packet, node_list):
app = self.app app = self.app
self.app.nm.update(node_list) self.app.nm.update(node_list)
for node_type, addr, uuid, state in node_list: for node_type, addr, uuid, state in node_list:
...@@ -178,16 +178,16 @@ class PrimaryNotificationsHandler(BaseHandler): ...@@ -178,16 +178,16 @@ class PrimaryNotificationsHandler(BaseHandler):
class PrimaryAnswersHandler(AnswerBaseHandler): class PrimaryAnswersHandler(AnswerBaseHandler):
""" Handle that process expected packets from the primary master """ """ Handle that process expected packets from the primary master """
def handleAnswerBeginTransaction(self, conn, packet, tid): def answerBeginTransaction(self, conn, packet, tid):
app = self.app app = self.app
app.setTID(tid) app.setTID(tid)
def handleAnswerNewOIDs(self, conn, packet, oid_list): def answerNewOIDs(self, conn, packet, oid_list):
app = self.app app = self.app
app.new_oid_list = oid_list app.new_oid_list = oid_list
app.new_oid_list.reverse() app.new_oid_list.reverse()
def handleNotifyTransactionFinished(self, conn, packet, tid): def notifyTransactionFinished(self, conn, packet, tid):
app = self.app app = self.app
if tid == app.getTID(): if tid == app.getTID():
app.setTransactionFinished() app.setTransactionFinished()
......
...@@ -48,11 +48,11 @@ class StorageEventHandler(BaseHandler): ...@@ -48,11 +48,11 @@ class StorageEventHandler(BaseHandler):
class StorageBootstrapHandler(AnswerBaseHandler): class StorageBootstrapHandler(AnswerBaseHandler):
""" Handler used when connecting to a storage node """ """ Handler used when connecting to a storage node """
def handleNotReady(self, conn, packet, message): def notReady(self, conn, packet, message):
app = self.app app = self.app
app.setNodeNotReady() app.setNodeNotReady()
def handleAcceptNodeIdentification(self, conn, packet, node_type, def acceptNodeIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid): uuid, address, num_partitions, num_replicas, your_uuid):
app = self.app app = self.app
node = app.nm.getByAddress(conn.getAddress()) node = app.nm.getByAddress(conn.getAddress())
...@@ -75,24 +75,24 @@ class StorageBootstrapHandler(AnswerBaseHandler): ...@@ -75,24 +75,24 @@ class StorageBootstrapHandler(AnswerBaseHandler):
class StorageAnswersHandler(AnswerBaseHandler): class StorageAnswersHandler(AnswerBaseHandler):
""" Handle all messages related to ZODB operations """ """ Handle all messages related to ZODB operations """
def handleAnswerObject(self, conn, packet, oid, start_serial, end_serial, def answerObject(self, conn, packet, oid, start_serial, end_serial,
compression, checksum, data): compression, checksum, data):
app = self.app app = self.app
app.local_var.asked_object = (oid, start_serial, end_serial, compression, app.local_var.asked_object = (oid, start_serial, end_serial, compression,
checksum, data) checksum, data)
def handleAnswerStoreObject(self, conn, packet, conflicting, oid, serial): def answerStoreObject(self, conn, packet, conflicting, oid, serial):
app = self.app app = self.app
if conflicting: if conflicting:
app.local_var.object_stored = -1, serial app.local_var.object_stored = -1, serial
else: else:
app.local_var.object_stored = oid, serial app.local_var.object_stored = oid, serial
def handleAnswerStoreTransaction(self, conn, packet, tid): def answerStoreTransaction(self, conn, packet, tid):
app = self.app app = self.app
app.setTransactionVoted() app.setTransactionVoted()
def handleAnswerTransactionInformation(self, conn, packet, tid, def answerTransactionInformation(self, conn, packet, tid,
user, desc, ext, oid_list): user, desc, ext, oid_list):
app = self.app app = self.app
# transaction information are returned as a dict # transaction information are returned as a dict
...@@ -104,12 +104,12 @@ class StorageAnswersHandler(AnswerBaseHandler): ...@@ -104,12 +104,12 @@ class StorageAnswersHandler(AnswerBaseHandler):
info['oids'] = oid_list info['oids'] = oid_list
app.local_var.txn_info = info app.local_var.txn_info = info
def handleAnswerObjectHistory(self, conn, packet, oid, history_list): def answerObjectHistory(self, conn, packet, oid, history_list):
app = self.app app = self.app
# history_list is a list of tuple (serial, size) # history_list is a list of tuple (serial, size)
app.local_var.history = oid, history_list app.local_var.history = oid, history_list
def handleOidNotFound(self, conn, packet, message): def oidNotFound(self, conn, packet, message):
app = self.app app = self.app
# This can happen either when : # This can happen either when :
# - loading an object # - loading an object
...@@ -117,12 +117,12 @@ class StorageAnswersHandler(AnswerBaseHandler): ...@@ -117,12 +117,12 @@ class StorageAnswersHandler(AnswerBaseHandler):
app.local_var.asked_object = -1 app.local_var.asked_object = -1
app.local_var.history = -1 app.local_var.history = -1
def handleTidNotFound(self, conn, packet, message): def tidNotFound(self, conn, packet, message):
app = self.app app = self.app
# This can happen when requiring txn informations # This can happen when requiring txn informations
app.local_var.txn_info = -1 app.local_var.txn_info = -1
def handleAnswerTIDs(self, conn, packet, tid_list): def answerTIDs(self, conn, packet, tid_list):
app = self.app app = self.app
app.local_var.node_tids[conn.getUUID()] = tid_list app.local_var.node_tids[conn.getUUID()] = tid_list
...@@ -140,226 +140,226 @@ class EventHandler(object): ...@@ -140,226 +140,226 @@ class EventHandler(object):
# Packet handlers. # Packet handlers.
def handleRequestNodeIdentification(self, conn, packet, node_type, def requestNodeIdentification(self, conn, packet, node_type,
uuid, address, name): uuid, address, name):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAcceptNodeIdentification(self, conn, packet, node_type, def acceptNodeIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid): uuid, address, num_partitions, num_replicas, your_uuid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskPrimaryMaster(self, conn, packet): def askPrimaryMaster(self, conn, packet):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid, def answerPrimaryMaster(self, conn, packet, primary_uuid,
known_master_list): known_master_list):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnnouncePrimaryMaster(self, conn, packet): def announcePrimaryMaster(self, conn, packet):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleReelectPrimaryMaster(self, conn, packet): def reelectPrimaryMaster(self, conn, packet):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleNotifyNodeInformation(self, conn, packet, node_list): def notifyNodeInformation(self, conn, packet, node_list):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskLastIDs(self, conn, packet): def askLastIDs(self, conn, packet):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerLastIDs(self, conn, packet, loid, ltid, lptid): def answerLastIDs(self, conn, packet, loid, ltid, lptid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskPartitionTable(self, conn, packet, offset_list): def askPartitionTable(self, conn, packet, offset_list):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerPartitionTable(self, conn, packet, ptid, row_list): def answerPartitionTable(self, conn, packet, ptid, row_list):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleSendPartitionTable(self, conn, packet, ptid, row_list): def sendPartitionTable(self, conn, packet, ptid, row_list):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list): def notifyPartitionChanges(self, conn, packet, ptid, cell_list):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleStartOperation(self, conn, packet): def startOperation(self, conn, packet):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleStopOperation(self, conn, packet): def stopOperation(self, conn, packet):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskUnfinishedTransactions(self, conn, packet): def askUnfinishedTransactions(self, conn, packet):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerUnfinishedTransactions(self, conn, packet, tid_list): def answerUnfinishedTransactions(self, conn, packet, tid_list):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskObjectPresent(self, conn, packet, oid, tid): def askObjectPresent(self, conn, packet, oid, tid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerObjectPresent(self, conn, packet, oid, tid): def answerObjectPresent(self, conn, packet, oid, tid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleDeleteTransaction(self, conn, packet, tid): def deleteTransaction(self, conn, packet, tid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleCommitTransaction(self, conn, packet, tid): def commitTransaction(self, conn, packet, tid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskBeginTransaction(self, conn, packet, tid): def askBeginTransaction(self, conn, packet, tid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerBeginTransaction(self, conn, packet, tid): def answerBeginTransaction(self, conn, packet, tid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskNewOIDs(self, conn, packet, num_oids): def askNewOIDs(self, conn, packet, num_oids):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerNewOIDs(self, conn, packet, num_oids): def answerNewOIDs(self, conn, packet, num_oids):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleFinishTransaction(self, conn, packet, oid_list, tid): def finishTransaction(self, conn, packet, oid_list, tid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleNotifyTransactionFinished(self, conn, packet, tid): def notifyTransactionFinished(self, conn, packet, tid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleLockInformation(self, conn, packet, tid): def lockInformation(self, conn, packet, tid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleNotifyInformationLocked(self, conn, packet, tid): def notifyInformationLocked(self, conn, packet, tid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleInvalidateObjects(self, conn, packet, oid_list, tid): def invalidateObjects(self, conn, packet, oid_list, tid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleUnlockInformation(self, conn, packet, tid): def unlockInformation(self, conn, packet, tid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskStoreObject(self, conn, packet, oid, serial, def askStoreObject(self, conn, packet, oid, serial,
compression, checksum, data, tid): compression, checksum, data, tid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerStoreObject(self, conn, packet, conflicting, oid, serial): def answerStoreObject(self, conn, packet, conflicting, oid, serial):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAbortTransaction(self, conn, packet, tid): def abortTransaction(self, conn, packet, tid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskStoreTransaction(self, conn, packet, tid, user, desc, def askStoreTransaction(self, conn, packet, tid, user, desc,
ext, oid_list): ext, oid_list):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerStoreTransaction(self, conn, packet, tid): def answerStoreTransaction(self, conn, packet, tid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskObject(self, conn, packet, oid, serial, tid): def askObject(self, conn, packet, oid, serial, tid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerObject(self, conn, packet, oid, serial_start, def answerObject(self, conn, packet, oid, serial_start,
serial_end, compression, checksum, data): serial_end, compression, checksum, data):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskTIDs(self, conn, packet, first, last, partition): def askTIDs(self, conn, packet, first, last, partition):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerTIDs(self, conn, packet, tid_list): def answerTIDs(self, conn, packet, tid_list):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskTransactionInformation(self, conn, packet, tid): def askTransactionInformation(self, conn, packet, tid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerTransactionInformation(self, conn, packet, tid, def answerTransactionInformation(self, conn, packet, tid,
user, desc, ext, oid_list): user, desc, ext, oid_list):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskObjectHistory(self, conn, packet, oid, first, last): def askObjectHistory(self, conn, packet, oid, first, last):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerObjectHistory(self, conn, packet, oid, history_list): def answerObjectHistory(self, conn, packet, oid, history_list):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskOIDs(self, conn, packet, first, last, partition): def askOIDs(self, conn, packet, first, last, partition):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerOIDs(self, conn, packet, oid_list): def answerOIDs(self, conn, packet, oid_list):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskPartitionList(self, conn, packet, min_offset, max_offset, uuid): def askPartitionList(self, conn, packet, min_offset, max_offset, uuid):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerPartitionList(self, conn, packet, ptid, row_list): def answerPartitionList(self, conn, packet, ptid, row_list):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskNodeList(self, conn, packet, offset_list): def askNodeList(self, conn, packet, offset_list):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerNodeList(self, conn, packet, node_list): def answerNodeList(self, conn, packet, node_list):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleSetNodeState(self, conn, packet, uuid, state, modify_partition_table): def setNodeState(self, conn, packet, uuid, state, modify_partition_table):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerNodeState(self, conn, packet, uuid, state): def answerNodeState(self, conn, packet, uuid, state):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAddPendingNodes(self, conn, packet, uuid_list): def addPendingNodes(self, conn, packet, uuid_list):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerNewNodes(self, conn, packet, uuid_list): def answerNewNodes(self, conn, packet, uuid_list):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskNodeInformation(self, conn, packet): def askNodeInformation(self, conn, packet):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerNodeInformation(self, conn, packet, node_list): def answerNodeInformation(self, conn, packet, node_list):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskClusterState(self, conn, packet): def askClusterState(self, conn, packet):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAnswerClusterState(self, conn, packet, state): def answerClusterState(self, conn, packet, state):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleSetClusterState(self, conn, packet, state): def setClusterState(self, conn, packet, state):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleNotifyClusterInformation(self, conn, packet, state): def notifyClusterInformation(self, conn, packet, state):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleNotifyLastOID(self, conn, packet, oid): def notifyLastOID(self, conn, packet, oid):
raise UnexpectedPacketError raise UnexpectedPacketError
# Error packet handlers. # Error packet handlers.
def handleError(self, conn, packet, code, message): def error(self, conn, packet, code, message):
try: try:
method = self.error_dispatch_table[code] method = self.error_dispatch_table[code]
method(conn, packet, message) method(conn, packet, message)
except ValueError: except ValueError:
raise UnexpectedPacketError(message) raise UnexpectedPacketError(message)
def handleNotReady(self, conn, packet, message): def notReady(self, conn, packet, message):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleOidNotFound(self, conn, packet, message): def oidNotFound(self, conn, packet, message):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleTidNotFound(self, conn, packet, message): def tidNotFound(self, conn, packet, message):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleProtocolError(self, conn, packet, message): def protocolError(self, conn, packet, message):
# the connection should have been closed by the remote peer # the connection should have been closed by the remote peer
logging.error('protocol error: %s' % (message,)) logging.error('protocol error: %s' % (message,))
def handleTimeoutError(self, conn, packet, message): def timeoutError(self, conn, packet, message):
logging.error('timeout error: %s' % (message,)) logging.error('timeout error: %s' % (message,))
def handleBrokenNodeDisallowedError(self, conn, packet, message): def brokenNodeDisallowedError(self, conn, packet, message):
raise RuntimeError, 'broken node disallowed error: %s' % (message,) raise RuntimeError, 'broken node disallowed error: %s' % (message,)
def handleNoError(self, conn, packet, message): def noError(self, conn, packet, message):
logging.debug("no error message : %s" % (message)) logging.debug("no error message : %s" % (message))
...@@ -368,80 +368,80 @@ class EventHandler(object): ...@@ -368,80 +368,80 @@ class EventHandler(object):
def __initPacketDispatchTable(self): def __initPacketDispatchTable(self):
d = {} d = {}
d[PacketTypes.ERROR] = self.handleError d[PacketTypes.ERROR] = self.error
d[PacketTypes.REQUEST_NODE_IDENTIFICATION] = self.handleRequestNodeIdentification d[PacketTypes.REQUEST_NODE_IDENTIFICATION] = self.requestNodeIdentification
d[PacketTypes.ACCEPT_NODE_IDENTIFICATION] = self.handleAcceptNodeIdentification d[PacketTypes.ACCEPT_NODE_IDENTIFICATION] = self.acceptNodeIdentification
d[PacketTypes.ASK_PRIMARY_MASTER] = self.handleAskPrimaryMaster d[PacketTypes.ASK_PRIMARY_MASTER] = self.askPrimaryMaster
d[PacketTypes.ANSWER_PRIMARY_MASTER] = self.handleAnswerPrimaryMaster d[PacketTypes.ANSWER_PRIMARY_MASTER] = self.answerPrimaryMaster
d[PacketTypes.ANNOUNCE_PRIMARY_MASTER] = self.handleAnnouncePrimaryMaster d[PacketTypes.ANNOUNCE_PRIMARY_MASTER] = self.announcePrimaryMaster
d[PacketTypes.REELECT_PRIMARY_MASTER] = self.handleReelectPrimaryMaster d[PacketTypes.REELECT_PRIMARY_MASTER] = self.reelectPrimaryMaster
d[PacketTypes.NOTIFY_NODE_INFORMATION] = self.handleNotifyNodeInformation d[PacketTypes.NOTIFY_NODE_INFORMATION] = self.notifyNodeInformation
d[PacketTypes.ASK_LAST_IDS] = self.handleAskLastIDs d[PacketTypes.ASK_LAST_IDS] = self.askLastIDs
d[PacketTypes.ANSWER_LAST_IDS] = self.handleAnswerLastIDs d[PacketTypes.ANSWER_LAST_IDS] = self.answerLastIDs
d[PacketTypes.ASK_PARTITION_TABLE] = self.handleAskPartitionTable d[PacketTypes.ASK_PARTITION_TABLE] = self.askPartitionTable
d[PacketTypes.ANSWER_PARTITION_TABLE] = self.handleAnswerPartitionTable d[PacketTypes.ANSWER_PARTITION_TABLE] = self.answerPartitionTable
d[PacketTypes.SEND_PARTITION_TABLE] = self.handleSendPartitionTable d[PacketTypes.SEND_PARTITION_TABLE] = self.sendPartitionTable
d[PacketTypes.NOTIFY_PARTITION_CHANGES] = self.handleNotifyPartitionChanges d[PacketTypes.NOTIFY_PARTITION_CHANGES] = self.notifyPartitionChanges
d[PacketTypes.START_OPERATION] = self.handleStartOperation d[PacketTypes.START_OPERATION] = self.startOperation
d[PacketTypes.STOP_OPERATION] = self.handleStopOperation d[PacketTypes.STOP_OPERATION] = self.stopOperation
d[PacketTypes.ASK_UNFINISHED_TRANSACTIONS] = self.handleAskUnfinishedTransactions d[PacketTypes.ASK_UNFINISHED_TRANSACTIONS] = self.askUnfinishedTransactions
d[PacketTypes.ANSWER_UNFINISHED_TRANSACTIONS] = self.handleAnswerUnfinishedTransactions d[PacketTypes.ANSWER_UNFINISHED_TRANSACTIONS] = self.answerUnfinishedTransactions
d[PacketTypes.ASK_OBJECT_PRESENT] = self.handleAskObjectPresent d[PacketTypes.ASK_OBJECT_PRESENT] = self.askObjectPresent
d[PacketTypes.ANSWER_OBJECT_PRESENT] = self.handleAnswerObjectPresent d[PacketTypes.ANSWER_OBJECT_PRESENT] = self.answerObjectPresent
d[PacketTypes.DELETE_TRANSACTION] = self.handleDeleteTransaction d[PacketTypes.DELETE_TRANSACTION] = self.deleteTransaction
d[PacketTypes.COMMIT_TRANSACTION] = self.handleCommitTransaction d[PacketTypes.COMMIT_TRANSACTION] = self.commitTransaction
d[PacketTypes.ASK_BEGIN_TRANSACTION] = self.handleAskBeginTransaction d[PacketTypes.ASK_BEGIN_TRANSACTION] = self.askBeginTransaction
d[PacketTypes.ANSWER_BEGIN_TRANSACTION] = self.handleAnswerBeginTransaction d[PacketTypes.ANSWER_BEGIN_TRANSACTION] = self.answerBeginTransaction
d[PacketTypes.FINISH_TRANSACTION] = self.handleFinishTransaction d[PacketTypes.FINISH_TRANSACTION] = self.finishTransaction
d[PacketTypes.NOTIFY_TRANSACTION_FINISHED] = self.handleNotifyTransactionFinished d[PacketTypes.NOTIFY_TRANSACTION_FINISHED] = self.notifyTransactionFinished
d[PacketTypes.LOCK_INFORMATION] = self.handleLockInformation d[PacketTypes.LOCK_INFORMATION] = self.lockInformation
d[PacketTypes.NOTIFY_INFORMATION_LOCKED] = self.handleNotifyInformationLocked d[PacketTypes.NOTIFY_INFORMATION_LOCKED] = self.notifyInformationLocked
d[PacketTypes.INVALIDATE_OBJECTS] = self.handleInvalidateObjects d[PacketTypes.INVALIDATE_OBJECTS] = self.invalidateObjects
d[PacketTypes.UNLOCK_INFORMATION] = self.handleUnlockInformation d[PacketTypes.UNLOCK_INFORMATION] = self.unlockInformation
d[PacketTypes.ASK_NEW_OIDS] = self.handleAskNewOIDs d[PacketTypes.ASK_NEW_OIDS] = self.askNewOIDs
d[PacketTypes.ANSWER_NEW_OIDS] = self.handleAnswerNewOIDs d[PacketTypes.ANSWER_NEW_OIDS] = self.answerNewOIDs
d[PacketTypes.ASK_STORE_OBJECT] = self.handleAskStoreObject d[PacketTypes.ASK_STORE_OBJECT] = self.askStoreObject
d[PacketTypes.ANSWER_STORE_OBJECT] = self.handleAnswerStoreObject d[PacketTypes.ANSWER_STORE_OBJECT] = self.answerStoreObject
d[PacketTypes.ABORT_TRANSACTION] = self.handleAbortTransaction d[PacketTypes.ABORT_TRANSACTION] = self.abortTransaction
d[PacketTypes.ASK_STORE_TRANSACTION] = self.handleAskStoreTransaction d[PacketTypes.ASK_STORE_TRANSACTION] = self.askStoreTransaction
d[PacketTypes.ANSWER_STORE_TRANSACTION] = self.handleAnswerStoreTransaction d[PacketTypes.ANSWER_STORE_TRANSACTION] = self.answerStoreTransaction
d[PacketTypes.ASK_OBJECT] = self.handleAskObject d[PacketTypes.ASK_OBJECT] = self.askObject
d[PacketTypes.ANSWER_OBJECT] = self.handleAnswerObject d[PacketTypes.ANSWER_OBJECT] = self.answerObject
d[PacketTypes.ASK_TIDS] = self.handleAskTIDs d[PacketTypes.ASK_TIDS] = self.askTIDs
d[PacketTypes.ANSWER_TIDS] = self.handleAnswerTIDs d[PacketTypes.ANSWER_TIDS] = self.answerTIDs
d[PacketTypes.ASK_TRANSACTION_INFORMATION] = self.handleAskTransactionInformation d[PacketTypes.ASK_TRANSACTION_INFORMATION] = self.askTransactionInformation
d[PacketTypes.ANSWER_TRANSACTION_INFORMATION] = self.handleAnswerTransactionInformation d[PacketTypes.ANSWER_TRANSACTION_INFORMATION] = self.answerTransactionInformation
d[PacketTypes.ASK_OBJECT_HISTORY] = self.handleAskObjectHistory d[PacketTypes.ASK_OBJECT_HISTORY] = self.askObjectHistory
d[PacketTypes.ANSWER_OBJECT_HISTORY] = self.handleAnswerObjectHistory d[PacketTypes.ANSWER_OBJECT_HISTORY] = self.answerObjectHistory
d[PacketTypes.ASK_OIDS] = self.handleAskOIDs d[PacketTypes.ASK_OIDS] = self.askOIDs
d[PacketTypes.ANSWER_OIDS] = self.handleAnswerOIDs d[PacketTypes.ANSWER_OIDS] = self.answerOIDs
d[PacketTypes.ASK_PARTITION_LIST] = self.handleAskPartitionList d[PacketTypes.ASK_PARTITION_LIST] = self.askPartitionList
d[PacketTypes.ANSWER_PARTITION_LIST] = self.handleAnswerPartitionList d[PacketTypes.ANSWER_PARTITION_LIST] = self.answerPartitionList
d[PacketTypes.ASK_NODE_LIST] = self.handleAskNodeList d[PacketTypes.ASK_NODE_LIST] = self.askNodeList
d[PacketTypes.ANSWER_NODE_LIST] = self.handleAnswerNodeList d[PacketTypes.ANSWER_NODE_LIST] = self.answerNodeList
d[PacketTypes.SET_NODE_STATE] = self.handleSetNodeState d[PacketTypes.SET_NODE_STATE] = self.setNodeState
d[PacketTypes.ANSWER_NODE_STATE] = self.handleAnswerNodeState d[PacketTypes.ANSWER_NODE_STATE] = self.answerNodeState
d[PacketTypes.SET_CLUSTER_STATE] = self.handleSetClusterState d[PacketTypes.SET_CLUSTER_STATE] = self.setClusterState
d[PacketTypes.ADD_PENDING_NODES] = self.handleAddPendingNodes d[PacketTypes.ADD_PENDING_NODES] = self.addPendingNodes
d[PacketTypes.ANSWER_NEW_NODES] = self.handleAnswerNewNodes d[PacketTypes.ANSWER_NEW_NODES] = self.answerNewNodes
d[PacketTypes.ASK_NODE_INFORMATION] = self.handleAskNodeInformation d[PacketTypes.ASK_NODE_INFORMATION] = self.askNodeInformation
d[PacketTypes.ANSWER_NODE_INFORMATION] = self.handleAnswerNodeInformation d[PacketTypes.ANSWER_NODE_INFORMATION] = self.answerNodeInformation
d[PacketTypes.ASK_CLUSTER_STATE] = self.handleAskClusterState d[PacketTypes.ASK_CLUSTER_STATE] = self.askClusterState
d[PacketTypes.ANSWER_CLUSTER_STATE] = self.handleAnswerClusterState d[PacketTypes.ANSWER_CLUSTER_STATE] = self.answerClusterState
d[PacketTypes.NOTIFY_CLUSTER_INFORMATION] = self.handleNotifyClusterInformation d[PacketTypes.NOTIFY_CLUSTER_INFORMATION] = self.notifyClusterInformation
d[PacketTypes.NOTIFY_LAST_OID] = self.handleNotifyLastOID d[PacketTypes.NOTIFY_LAST_OID] = self.notifyLastOID
return d return d
def __initErrorDispatchTable(self): def __initErrorDispatchTable(self):
d = {} d = {}
d[ErrorCodes.NO_ERROR] = self.handleNoError d[ErrorCodes.NO_ERROR] = self.noError
d[ErrorCodes.NOT_READY] = self.handleNotReady d[ErrorCodes.NOT_READY] = self.notReady
d[ErrorCodes.OID_NOT_FOUND] = self.handleOidNotFound d[ErrorCodes.OID_NOT_FOUND] = self.oidNotFound
d[ErrorCodes.TID_NOT_FOUND] = self.handleTidNotFound d[ErrorCodes.TID_NOT_FOUND] = self.tidNotFound
d[ErrorCodes.PROTOCOL_ERROR] = self.handleProtocolError d[ErrorCodes.PROTOCOL_ERROR] = self.protocolError
d[ErrorCodes.BROKEN_NODE] = self.handleBrokenNodeDisallowedError d[ErrorCodes.BROKEN_NODE] = self.brokenNodeDisallowedError
return d return d
...@@ -24,10 +24,10 @@ from neo.protocol import NodeTypes, NodeStates ...@@ -24,10 +24,10 @@ from neo.protocol import NodeTypes, NodeStates
class MasterHandler(EventHandler): class MasterHandler(EventHandler):
"""This class implements a generic part of the event handlers.""" """This class implements a generic part of the event handlers."""
def handleProtocolError(self, conn, packet, message): def protocolError(self, conn, packet, message):
logging.error('Protocol error %s %s' % (message, conn.getAddress())) logging.error('Protocol error %s %s' % (message, conn.getAddress()))
def handleAskPrimaryMaster(self, conn, packet): def askPrimaryMaster(self, conn, packet):
if conn.getConnector() is None: if conn.getConnector() is None:
# Connection can be closed by peer after he sent AskPrimaryMaster # Connection can be closed by peer after he sent AskPrimaryMaster
# if he finds the primary master before we answer him. # if he finds the primary master before we answer him.
...@@ -54,16 +54,16 @@ class MasterHandler(EventHandler): ...@@ -54,16 +54,16 @@ class MasterHandler(EventHandler):
packet.getId(), packet.getId(),
) )
def handleAskClusterState(self, conn, packet): def askClusterState(self, conn, packet):
assert conn.getUUID() is not None assert conn.getUUID() is not None
state = self.app.getClusterState() state = self.app.getClusterState()
conn.answer(protocol.answerClusterState(state), packet.getId()) conn.answer(protocol.answerClusterState(state), packet.getId())
def handleAskNodeInformation(self, conn, packet): def askNodeInformation(self, conn, packet):
self.app.sendNodesInformations(conn) self.app.sendNodesInformations(conn)
conn.answer(protocol.answerNodeInformation([]), packet.getId()) conn.answer(protocol.answerNodeInformation([]), packet.getId())
def handleAskPartitionTable(self, conn, packet, offset_list): def askPartitionTable(self, conn, packet, offset_list):
assert len(offset_list) == 0 assert len(offset_list) == 0
app = self.app app = self.app
app.sendPartitionTable(conn) app.sendPartitionTable(conn)
...@@ -78,7 +78,7 @@ DISCONNECTED_STATE_DICT = { ...@@ -78,7 +78,7 @@ DISCONNECTED_STATE_DICT = {
class BaseServiceHandler(MasterHandler): class BaseServiceHandler(MasterHandler):
"""This class deals with events for a service phase.""" """This class deals with events for a service phase."""
def handleNodeLost(self, conn, node): def nodeLost(self, conn, node):
# This method provides a hook point overridable by service classes. # This method provides a hook point overridable by service classes.
# It is triggered when a connection to a node gets lost. # It is triggered when a connection to a node gets lost.
pass pass
...@@ -98,13 +98,13 @@ class BaseServiceHandler(MasterHandler): ...@@ -98,13 +98,13 @@ class BaseServiceHandler(MasterHandler):
node.setState(new_state) node.setState(new_state)
self.app.broadcastNodeInformation(node) self.app.broadcastNodeInformation(node)
# clean node related data in specialized handlers # clean node related data in specialized handlers
self.handleNodeLost(conn, node) self.nodeLost(conn, node)
def handleAskLastIDs(self, conn, packet): def askLastIDs(self, conn, packet):
app = self.app app = self.app
conn.answer(protocol.answerLastIDs(app.loid, app.ltid, app.pt.getID()), packet.getId()) conn.answer(protocol.answerLastIDs(app.loid, app.ltid, app.pt.getID()), packet.getId())
def handleAskUnfinishedTransactions(self, conn, packet): def askUnfinishedTransactions(self, conn, packet):
app = self.app app = self.app
p = protocol.answerUnfinishedTransactions(app.finishing_transaction_dict.keys()) p = protocol.answerUnfinishedTransactions(app.finishing_transaction_dict.keys())
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
......
...@@ -29,12 +29,12 @@ class AdministrationHandler(MasterHandler): ...@@ -29,12 +29,12 @@ class AdministrationHandler(MasterHandler):
node = self.app.nm.getByUUID(conn.getUUID()) node = self.app.nm.getByUUID(conn.getUUID())
self.app.nm.remove(node) self.app.nm.remove(node)
def handleAskPrimaryMaster(self, conn, packet): def askPrimaryMaster(self, conn, packet):
app = self.app app = self.app
# I'm the primary # I'm the primary
conn.answer(protocol.answerPrimaryMaster(app.uuid, []), packet.getId()) conn.answer(protocol.answerPrimaryMaster(app.uuid, []), packet.getId())
def handleSetClusterState(self, conn, packet, state): def setClusterState(self, conn, packet, state):
self.app.changeClusterState(state) self.app.changeClusterState(state)
p = protocol.noError('cluster state changed') p = protocol.noError('cluster state changed')
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
...@@ -42,7 +42,7 @@ class AdministrationHandler(MasterHandler): ...@@ -42,7 +42,7 @@ class AdministrationHandler(MasterHandler):
self.app.cluster_state = state self.app.cluster_state = state
self.app.shutdown() self.app.shutdown()
def handleSetNodeState(self, conn, packet, uuid, state, modify_partition_table): def setNodeState(self, conn, packet, uuid, state, modify_partition_table):
logging.info("set node state for %s-%s : %s" % (dump(uuid), state, modify_partition_table)) logging.info("set node state for %s-%s : %s" % (dump(uuid), state, modify_partition_table))
app = self.app app = self.app
node = app.nm.getByUUID(uuid) node = app.nm.getByUUID(uuid)
...@@ -92,7 +92,7 @@ class AdministrationHandler(MasterHandler): ...@@ -92,7 +92,7 @@ class AdministrationHandler(MasterHandler):
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
app.broadcastNodeInformation(node) app.broadcastNodeInformation(node)
def handleAddPendingNodes(self, conn, packet, uuid_list): def addPendingNodes(self, conn, packet, uuid_list):
uuids = ', '.join([dump(uuid) for uuid in uuid_list]) uuids = ', '.join([dump(uuid) for uuid in uuid_list])
logging.debug('Add nodes %s' % uuids) logging.debug('Add nodes %s' % uuids)
app, nm, em, pt = self.app, self.app.nm, self.app.em, self.app.pt app, nm, em, pt = self.app, self.app.nm, self.app.em, self.app.pt
......
...@@ -68,19 +68,19 @@ class ClientServiceHandler(BaseServiceHandler): ...@@ -68,19 +68,19 @@ class ClientServiceHandler(BaseServiceHandler):
def connectionCompleted(self, conn): def connectionCompleted(self, conn):
pass pass
def handleNodeLost(self, conn, node): def nodeLost(self, conn, node):
app = self.app app = self.app
for tid, t in app.finishing_transaction_dict.items(): for tid, t in app.finishing_transaction_dict.items():
if t.getConnection() is conn: if t.getConnection() is conn:
del app.finishing_transaction_dict[tid] del app.finishing_transaction_dict[tid]
def handleAbortTransaction(self, conn, packet, tid): def abortTransaction(self, conn, packet, tid):
try: try:
del self.app.finishing_transaction_dict[tid] del self.app.finishing_transaction_dict[tid]
except KeyError: except KeyError:
logging.warn('aborting transaction %s does not exist', dump(tid)) logging.warn('aborting transaction %s does not exist', dump(tid))
def handleAskBeginTransaction(self, conn, packet, tid): def askBeginTransaction(self, conn, packet, tid):
app = self.app app = self.app
if tid is not None and tid < app.ltid: if tid is not None and tid < app.ltid:
# supplied TID is in the past # supplied TID is in the past
...@@ -92,11 +92,11 @@ class ClientServiceHandler(BaseServiceHandler): ...@@ -92,11 +92,11 @@ class ClientServiceHandler(BaseServiceHandler):
app.finishing_transaction_dict[tid] = FinishingTransaction(conn) app.finishing_transaction_dict[tid] = FinishingTransaction(conn)
conn.answer(protocol.answerBeginTransaction(tid), packet.getId()) conn.answer(protocol.answerBeginTransaction(tid), packet.getId())
def handleAskNewOIDs(self, conn, packet, num_oids): def askNewOIDs(self, conn, packet, num_oids):
oid_list = self.app.getNewOIDList(num_oids) oid_list = self.app.getNewOIDList(num_oids)
conn.answer(protocol.answerNewOIDs(oid_list), packet.getId()) conn.answer(protocol.answerNewOIDs(oid_list), packet.getId())
def handleFinishTransaction(self, conn, packet, oid_list, tid): def finishTransaction(self, conn, packet, oid_list, tid):
app = self.app app = self.app
# If the given transaction ID is later than the last TID, the peer # If the given transaction ID is later than the last TID, the peer
# is crazy. # is crazy.
......
...@@ -25,7 +25,7 @@ from neo.exception import ElectionFailure ...@@ -25,7 +25,7 @@ from neo.exception import ElectionFailure
class ElectionHandler(MasterHandler): class ElectionHandler(MasterHandler):
"""This class deals with events for a primary master election.""" """This class deals with events for a primary master election."""
def handleNotifyNodeInformation(self, conn, packet, node_list): def notifyNodeInformation(self, conn, packet, node_list):
uuid = conn.getUUID() uuid = conn.getUUID()
if uuid is None: if uuid is None:
raise protocol.UnexpectedPacketError raise protocol.UnexpectedPacketError
...@@ -110,7 +110,7 @@ class ClientElectionHandler(ElectionHandler): ...@@ -110,7 +110,7 @@ class ClientElectionHandler(ElectionHandler):
app.negotiating_master_node_set.discard(addr) app.negotiating_master_node_set.discard(addr)
MasterHandler.peerBroken(self, conn) MasterHandler.peerBroken(self, conn)
def handleAcceptNodeIdentification(self, conn, packet, node_type, def acceptNodeIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, uuid, address, num_partitions,
num_replicas, your_uuid): num_replicas, your_uuid):
app = self.app app = self.app
...@@ -146,7 +146,7 @@ class ClientElectionHandler(ElectionHandler): ...@@ -146,7 +146,7 @@ class ClientElectionHandler(ElectionHandler):
app.negotiating_master_node_set.discard(conn.getAddress()) app.negotiating_master_node_set.discard(conn.getAddress())
def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid, known_master_list): def answerPrimaryMaster(self, conn, packet, primary_uuid, known_master_list):
if conn.getConnector() is None: if conn.getConnector() is None:
# Connection can be closed by peer after he sent # Connection can be closed by peer after he sent
# AnswerPrimaryMaster if he finds the primary master before we # AnswerPrimaryMaster if he finds the primary master before we
...@@ -208,7 +208,7 @@ class ClientElectionHandler(ElectionHandler): ...@@ -208,7 +208,7 @@ class ClientElectionHandler(ElectionHandler):
class ServerElectionHandler(ElectionHandler): class ServerElectionHandler(ElectionHandler):
def handleReelectPrimaryMaster(self, conn, packet): def reelectPrimaryMaster(self, conn, packet):
raise ElectionFailure, 'reelection requested' raise ElectionFailure, 'reelection requested'
def peerBroken(self, conn): def peerBroken(self, conn):
...@@ -219,7 +219,7 @@ class ServerElectionHandler(ElectionHandler): ...@@ -219,7 +219,7 @@ class ServerElectionHandler(ElectionHandler):
node.setBroken() node.setBroken()
MasterHandler.peerBroken(self, conn) MasterHandler.peerBroken(self, conn)
def handleRequestNodeIdentification(self, conn, packet, node_type, def requestNodeIdentification(self, conn, packet, node_type,
uuid, address, name): uuid, address, name):
if conn.getConnector() is None: if conn.getConnector() is None:
# Connection can be closed by peer after he sent # Connection can be closed by peer after he sent
...@@ -260,7 +260,7 @@ class ServerElectionHandler(ElectionHandler): ...@@ -260,7 +260,7 @@ class ServerElectionHandler(ElectionHandler):
) )
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
def handleAnnouncePrimaryMaster(self, conn, packet): def announcePrimaryMaster(self, conn, packet):
uuid = conn.getUUID() uuid = conn.getUUID()
if uuid is None: if uuid is None:
raise protocol.UnexpectedPacketError raise protocol.UnexpectedPacketError
......
...@@ -24,10 +24,10 @@ from neo.master.handlers import MasterHandler ...@@ -24,10 +24,10 @@ from neo.master.handlers import MasterHandler
class IdentificationHandler(MasterHandler): class IdentificationHandler(MasterHandler):
"""This class deals with messages from the admin node only""" """This class deals with messages from the admin node only"""
def handleNodeLost(self, conn, node): def nodeLost(self, conn, node):
logging.warning('lost a node in IdentificationHandler : %s' % node) logging.warning('lost a node in IdentificationHandler : %s' % node)
def handleRequestNodeIdentification(self, conn, packet, node_type, def requestNodeIdentification(self, conn, packet, node_type,
uuid, address, name): uuid, address, name):
self.checkClusterName(name) self.checkClusterName(name)
......
...@@ -28,7 +28,7 @@ class RecoveryHandler(MasterHandler): ...@@ -28,7 +28,7 @@ class RecoveryHandler(MasterHandler):
# ask the last IDs to perform the recovery # ask the last IDs to perform the recovery
conn.ask(protocol.askLastIDs()) conn.ask(protocol.askLastIDs())
def handleAnswerLastIDs(self, conn, packet, loid, ltid, lptid): def answerLastIDs(self, conn, packet, loid, ltid, lptid):
app = self.app app = self.app
pt = app.pt pt = app.pt
...@@ -41,7 +41,7 @@ class RecoveryHandler(MasterHandler): ...@@ -41,7 +41,7 @@ class RecoveryHandler(MasterHandler):
app.pt.setID(lptid) app.pt.setID(lptid)
conn.ask(protocol.askPartitionTable([])) conn.ask(protocol.askPartitionTable([]))
def handleAnswerPartitionTable(self, conn, packet, ptid, row_list): def answerPartitionTable(self, conn, packet, ptid, row_list):
uuid = conn.getUUID() uuid = conn.getUUID()
app = self.app app = self.app
if uuid != app.target_uuid: if uuid != app.target_uuid:
......
...@@ -34,13 +34,13 @@ class SecondaryMasterHandler(MasterHandler): ...@@ -34,13 +34,13 @@ class SecondaryMasterHandler(MasterHandler):
def connectionCompleted(self, conn): def connectionCompleted(self, conn):
pass pass
def handleAnnouncePrimaryMaster(self, conn, packet): def announcePrimaryMaster(self, conn, packet):
raise ElectionFailure, 'another primary arises' raise ElectionFailure, 'another primary arises'
def handleReelectPrimaryMaster(self, conn, packet): def reelectPrimaryMaster(self, conn, packet):
raise ElectionFailure, 'reelection requested' raise ElectionFailure, 'reelection requested'
def handleNotifyNodeInformation(self, conn, packet, node_list): def notifyNodeInformation(self, conn, packet, node_list):
logging.error('/!\ NotifyNodeInformation packet from secondary master') logging.error('/!\ NotifyNodeInformation packet from secondary master')
...@@ -58,13 +58,13 @@ class PrimaryMasterHandler(MasterHandler): ...@@ -58,13 +58,13 @@ class PrimaryMasterHandler(MasterHandler):
self.app.primary_master_node.setDown() self.app.primary_master_node.setDown()
raise PrimaryFailure, 'primary master is dead' raise PrimaryFailure, 'primary master is dead'
def handleAnnouncePrimaryMaster(self, conn, packet): def announcePrimaryMaster(self, conn, packet):
raise protocol.UnexpectedPacketError raise protocol.UnexpectedPacketError
def handleReelectPrimaryMaster(self, conn, packet): def reelectPrimaryMaster(self, conn, packet):
raise ElectionFailure, 'reelection requested' raise ElectionFailure, 'reelection requested'
def handleNotifyNodeInformation(self, conn, packet, node_list): def notifyNodeInformation(self, conn, packet, node_list):
app = self.app app = self.app
for node_type, addr, uuid, state in node_list: for node_type, addr, uuid, state in node_list:
if node_type != NodeTypes.MASTER: if node_type != NodeTypes.MASTER:
...@@ -86,7 +86,7 @@ class PrimaryMasterHandler(MasterHandler): ...@@ -86,7 +86,7 @@ class PrimaryMasterHandler(MasterHandler):
if n.getUUID() is None: if n.getUUID() is None:
n.setUUID(uuid) n.setUUID(uuid)
def handleAcceptNodeIdentification(self, conn, packet, node_type, def acceptNodeIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, uuid, address, num_partitions,
num_replicas, your_uuid): num_replicas, your_uuid):
app = self.app app = self.app
...@@ -101,8 +101,8 @@ class PrimaryMasterHandler(MasterHandler): ...@@ -101,8 +101,8 @@ class PrimaryMasterHandler(MasterHandler):
conn.setUUID(uuid) conn.setUUID(uuid)
node.setUUID(uuid) node.setUUID(uuid)
def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid, known_master_list): def answerPrimaryMaster(self, conn, packet, primary_uuid, known_master_list):
pass pass
def handleNotifyClusterInformation(self, conn, packet, state): def notifyClusterInformation(self, conn, packet, state):
pass pass
...@@ -22,20 +22,20 @@ from neo.master.handlers import BaseServiceHandler ...@@ -22,20 +22,20 @@ from neo.master.handlers import BaseServiceHandler
class ShutdownHandler(BaseServiceHandler): class ShutdownHandler(BaseServiceHandler):
"""This class deals with events for a shutting down phase.""" """This class deals with events for a shutting down phase."""
def handleRequestNodeIdentification(self, conn, packet, node_type, def requestNodeIdentification(self, conn, packet, node_type,
uuid, address, name): uuid, address, name):
logging.error('reject any new connection') logging.error('reject any new connection')
raise protocol.ProtocolError('cluster is shutting down') raise protocol.ProtocolError('cluster is shutting down')
def handleAskPrimaryMaster(self, conn, packet): def askPrimaryMaster(self, conn, packet):
logging.error('reject any new demand for primary master') logging.error('reject any new demand for primary master')
raise protocol.ProtocolError('cluster is shutting down') raise protocol.ProtocolError('cluster is shutting down')
def handleAskBeginTransaction(self, conn, packet, tid): def askBeginTransaction(self, conn, packet, tid):
logging.error('reject any new demand for new tid') logging.error('reject any new demand for new tid')
raise protocol.ProtocolError('cluster is shutting down') raise protocol.ProtocolError('cluster is shutting down')
def handleNotifyNodeInformation(self, conn, packet, node_list): def notifyNodeInformation(self, conn, packet, node_list):
# don't care about notifications since we are shutdowning # don't care about notifications since we are shutdowning
pass pass
...@@ -34,7 +34,7 @@ class StorageServiceHandler(BaseServiceHandler): ...@@ -34,7 +34,7 @@ class StorageServiceHandler(BaseServiceHandler):
conn.notify(protocol.notifyLastOID(self.app.loid)) conn.notify(protocol.notifyLastOID(self.app.loid))
conn.notify(protocol.startOperation()) conn.notify(protocol.startOperation())
def handleNodeLost(self, conn, node): def nodeLost(self, conn, node):
logging.info('storage node lost') logging.info('storage node lost')
if not self.app.pt.operational(): if not self.app.pt.operational():
raise OperationFailure, 'cannot continue operation' raise OperationFailure, 'cannot continue operation'
...@@ -42,7 +42,7 @@ class StorageServiceHandler(BaseServiceHandler): ...@@ -42,7 +42,7 @@ class StorageServiceHandler(BaseServiceHandler):
# partition must not oudated to allows a cluster restart. # partition must not oudated to allows a cluster restart.
self.app.outdateAndBroadcastPartition() self.app.outdateAndBroadcastPartition()
def handleNotifyInformationLocked(self, conn, packet, tid): def notifyInformationLocked(self, conn, packet, tid):
uuid = conn.getUUID() uuid = conn.getUUID()
app = self.app app = self.app
node = app.nm.getByUUID(uuid) node = app.nm.getByUUID(uuid)
...@@ -80,7 +80,7 @@ class StorageServiceHandler(BaseServiceHandler): ...@@ -80,7 +80,7 @@ class StorageServiceHandler(BaseServiceHandler):
# What is this? # What is this?
pass pass
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list): def notifyPartitionChanges(self, conn, packet, ptid, cell_list):
# This should be sent when a cell becomes up-to-date because # This should be sent when a cell becomes up-to-date because
# a replication has finished. # a replication has finished.
uuid = conn.getUUID() uuid = conn.getUUID()
......
...@@ -27,18 +27,18 @@ class VerificationHandler(MasterHandler): ...@@ -27,18 +27,18 @@ class VerificationHandler(MasterHandler):
def connectionCompleted(self, conn): def connectionCompleted(self, conn):
pass pass
def handleNodeLost(self, conn, node): def nodeLost(self, conn, node):
if not self.app.pt.operational(): if not self.app.pt.operational():
raise VerificationFailure, 'cannot continue verification' raise VerificationFailure, 'cannot continue verification'
def handleAnswerLastIDs(self, conn, packet, loid, ltid, lptid): def answerLastIDs(self, conn, packet, loid, ltid, lptid):
app = self.app app = self.app
# If I get a bigger value here, it is dangerous. # If I get a bigger value here, it is dangerous.
if app.loid < loid or app.ltid < ltid or app.pt.getID() < lptid: if app.loid < loid or app.ltid < ltid or app.pt.getID() < lptid:
logging.critical('got later information in verification') logging.critical('got later information in verification')
raise VerificationFailure raise VerificationFailure
def handleAnswerUnfinishedTransactions(self, conn, packet, tid_list): def answerUnfinishedTransactions(self, conn, packet, tid_list):
uuid = conn.getUUID() uuid = conn.getUUID()
logging.info('got unfinished transactions %s from %s:%d', logging.info('got unfinished transactions %s from %s:%d',
tid_list, *(conn.getAddress())) tid_list, *(conn.getAddress()))
...@@ -49,7 +49,7 @@ class VerificationHandler(MasterHandler): ...@@ -49,7 +49,7 @@ class VerificationHandler(MasterHandler):
app.unfinished_tid_set.update(tid_list) app.unfinished_tid_set.update(tid_list)
app.asking_uuid_dict[uuid] = True app.asking_uuid_dict[uuid] = True
def handleAnswerTransactionInformation(self, conn, packet, tid, def answerTransactionInformation(self, conn, packet, tid,
user, desc, ext, oid_list): user, desc, ext, oid_list):
uuid = conn.getUUID() uuid = conn.getUUID()
app = self.app app = self.app
...@@ -67,7 +67,7 @@ class VerificationHandler(MasterHandler): ...@@ -67,7 +67,7 @@ class VerificationHandler(MasterHandler):
app.unfinished_oid_set = None app.unfinished_oid_set = None
app.asking_uuid_dict[uuid] = True app.asking_uuid_dict[uuid] = True
def handleTidNotFound(self, conn, packet, message): def tidNotFound(self, conn, packet, message):
uuid = conn.getUUID() uuid = conn.getUUID()
logging.info('TID not found: %s', message) logging.info('TID not found: %s', message)
app = self.app app = self.app
...@@ -77,7 +77,7 @@ class VerificationHandler(MasterHandler): ...@@ -77,7 +77,7 @@ class VerificationHandler(MasterHandler):
app.unfinished_oid_set = None app.unfinished_oid_set = None
app.asking_uuid_dict[uuid] = True app.asking_uuid_dict[uuid] = True
def handleAnswerObjectPresent(self, conn, packet, oid, tid): def answerObjectPresent(self, conn, packet, oid, tid):
uuid = conn.getUUID() uuid = conn.getUUID()
logging.info('object %s:%s found', dump(oid), dump(tid)) logging.info('object %s:%s found', dump(oid), dump(tid))
app = self.app app = self.app
...@@ -86,7 +86,7 @@ class VerificationHandler(MasterHandler): ...@@ -86,7 +86,7 @@ class VerificationHandler(MasterHandler):
return return
app.asking_uuid_dict[uuid] = True app.asking_uuid_dict[uuid] = True
def handleOidNotFound(self, conn, packet, message): def oidNotFound(self, conn, packet, message):
uuid = conn.getUUID() uuid = conn.getUUID()
logging.info('OID not found: %s', message) logging.info('OID not found: %s', message)
app = self.app app = self.app
......
...@@ -50,18 +50,18 @@ class CommandEventHandler(EventHandler): ...@@ -50,18 +50,18 @@ class CommandEventHandler(EventHandler):
super(CommandEventHandler, self).peerBroken(conn) super(CommandEventHandler, self).peerBroken(conn)
self.__disconnected() self.__disconnected()
def __handleAnswer(self, conn, packet, *args): def __answer(self, conn, packet, *args):
self.__respond((packet.getType(), ) + args) self.__respond((packet.getType(), ) + args)
def handleNoError(self, conn, packet, msg): def noError(self, conn, packet, msg):
self.__respond((packet.getType(), ErrorCodes.NO_ERROR, msg)) self.__respond((packet.getType(), ErrorCodes.NO_ERROR, msg))
def handleNotReady(self, conn, packet, msg): def notReady(self, conn, packet, msg):
self.__respond((packet.getType(), ErrorCodes.NOT_READY, msg)) self.__respond((packet.getType(), ErrorCodes.NOT_READY, msg))
handleAnswerPartitionList = __handleAnswer answerPartitionList = __answer
handleAnswerNodeList = __handleAnswer answerNodeList = __answer
handleAnswerNodeState = __handleAnswer answerNodeState = __answer
handleAnswerClusterState = __handleAnswer answerClusterState = __answer
handleAnswerNewNodes = __handleAnswer answerNewNodes = __answer
handleAnswerPrimaryMaster = __handleAnswer answerPrimaryMaster = __answer
...@@ -33,17 +33,17 @@ class BaseMasterHandler(BaseStorageHandler): ...@@ -33,17 +33,17 @@ class BaseMasterHandler(BaseStorageHandler):
def connectionLost(self, conn, new_state): def connectionLost(self, conn, new_state):
raise PrimaryFailure('connection lost') raise PrimaryFailure('connection lost')
def handleReelectPrimaryMaster(self, conn, packet): def reelectPrimaryMaster(self, conn, packet):
raise PrimaryFailure('re-election occurs') raise PrimaryFailure('re-election occurs')
def handleNotifyClusterInformation(self, conn, packet, state): def notifyClusterInformation(self, conn, packet, state):
logging.error('ignoring notify cluster information in %s' % self.__class__.__name__) logging.error('ignoring notify cluster information in %s' % self.__class__.__name__)
def handleNotifyLastOID(self, conn, packet, oid): def notifyLastOID(self, conn, packet, oid):
self.app.loid = oid self.app.loid = oid
self.app.dm.setLastOID(oid) self.app.dm.setLastOID(oid)
def handleNotifyNodeInformation(self, conn, packet, node_list): def notifyNodeInformation(self, conn, packet, node_list):
"""Store information on nodes, only if this is sent by a primary """Store information on nodes, only if this is sent by a primary
master node.""" master node."""
self.app.nm.update(node_list) self.app.nm.update(node_list)
...@@ -63,7 +63,7 @@ class BaseMasterHandler(BaseStorageHandler): ...@@ -63,7 +63,7 @@ class BaseMasterHandler(BaseStorageHandler):
class BaseClientAndStorageOperationHandler(BaseStorageHandler): class BaseClientAndStorageOperationHandler(BaseStorageHandler):
""" Accept requests common to client and storage nodes """ """ Accept requests common to client and storage nodes """
def handleAskTIDs(self, conn, packet, first, last, partition): def askTIDs(self, conn, packet, first, last, partition):
# This method is complicated, because I must return TIDs only # This method is complicated, because I must return TIDs only
# about usable partitions assigned to me. # about usable partitions assigned to me.
if first >= last: if first >= last:
...@@ -87,7 +87,7 @@ class BaseClientAndStorageOperationHandler(BaseStorageHandler): ...@@ -87,7 +87,7 @@ class BaseClientAndStorageOperationHandler(BaseStorageHandler):
app.pt.getPartitions(), partition_list) app.pt.getPartitions(), partition_list)
conn.answer(protocol.answerTIDs(tid_list), packet.getId()) conn.answer(protocol.answerTIDs(tid_list), packet.getId())
def handleAskObjectHistory(self, conn, packet, oid, first, last): def askObjectHistory(self, conn, packet, oid, first, last):
if first >= last: if first >= last:
raise protocol.ProtocolError( 'invalid offsets') raise protocol.ProtocolError( 'invalid offsets')
...@@ -98,7 +98,7 @@ class BaseClientAndStorageOperationHandler(BaseStorageHandler): ...@@ -98,7 +98,7 @@ class BaseClientAndStorageOperationHandler(BaseStorageHandler):
p = protocol.answerObjectHistory(oid, history_list) p = protocol.answerObjectHistory(oid, history_list)
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
def handleAskTransactionInformation(self, conn, packet, tid): def askTransactionInformation(self, conn, packet, tid):
app = self.app app = self.app
t = app.dm.getTransaction(tid) t = app.dm.getTransaction(tid)
if t is None: if t is None:
...@@ -107,11 +107,11 @@ class BaseClientAndStorageOperationHandler(BaseStorageHandler): ...@@ -107,11 +107,11 @@ class BaseClientAndStorageOperationHandler(BaseStorageHandler):
p = protocol.answerTransactionInformation(tid, t[1], t[2], t[3], t[0]) p = protocol.answerTransactionInformation(tid, t[1], t[2], t[3], t[0])
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
def handleAskObject(self, conn, packet, oid, serial, tid): def askObject(self, conn, packet, oid, serial, tid):
app = self.app app = self.app
if oid in app.load_lock_dict: if oid in app.load_lock_dict:
# Delay the response. # Delay the response.
app.queueEvent(self.handleAskObject, conn, packet, oid, app.queueEvent(self.askObject, conn, packet, oid,
serial, tid) serial, tid)
return return
o = app.dm.getObject(oid, serial, tid) o = app.dm.getObject(oid, serial, tid)
......
...@@ -84,7 +84,7 @@ class ClientOperationHandler(BaseClientAndStorageOperationHandler): ...@@ -84,7 +84,7 @@ class ClientOperationHandler(BaseClientAndStorageOperationHandler):
def connectionCompleted(self, conn): def connectionCompleted(self, conn):
BaseClientAndStorageOperationHandler.connectionCompleted(self, conn) BaseClientAndStorageOperationHandler.connectionCompleted(self, conn)
def handleAbortTransaction(self, conn, packet, tid): def abortTransaction(self, conn, packet, tid):
app = self.app app = self.app
try: try:
t = app.transaction_dict[tid] t = app.transaction_dict[tid]
...@@ -104,7 +104,7 @@ class ClientOperationHandler(BaseClientAndStorageOperationHandler): ...@@ -104,7 +104,7 @@ class ClientOperationHandler(BaseClientAndStorageOperationHandler):
except KeyError: except KeyError:
pass pass
def handleAskStoreTransaction(self, conn, packet, tid, user, desc, def askStoreTransaction(self, conn, packet, tid, user, desc,
ext, oid_list): ext, oid_list):
uuid = conn.getUUID() uuid = conn.getUUID()
app = self.app app = self.app
...@@ -114,7 +114,7 @@ class ClientOperationHandler(BaseClientAndStorageOperationHandler): ...@@ -114,7 +114,7 @@ class ClientOperationHandler(BaseClientAndStorageOperationHandler):
t.addTransaction(oid_list, user, desc, ext) t.addTransaction(oid_list, user, desc, ext)
conn.answer(protocol.answerStoreTransaction(tid), packet.getId()) conn.answer(protocol.answerStoreTransaction(tid), packet.getId())
def handleAskStoreObject(self, conn, packet, oid, serial, def askStoreObject(self, conn, packet, oid, serial,
compression, checksum, data, tid): compression, checksum, data, tid):
uuid = conn.getUUID() uuid = conn.getUUID()
# First, check for the locking state. # First, check for the locking state.
...@@ -123,7 +123,7 @@ class ClientOperationHandler(BaseClientAndStorageOperationHandler): ...@@ -123,7 +123,7 @@ class ClientOperationHandler(BaseClientAndStorageOperationHandler):
if locking_tid is not None: if locking_tid is not None:
if locking_tid < tid: if locking_tid < tid:
# Delay the response. # Delay the response.
app.queueEvent(self.handleAskStoreObject, conn, packet, app.queueEvent(self.askStoreObject, conn, packet,
oid, serial, compression, checksum, oid, serial, compression, checksum,
data, tid) data, tid)
else: else:
......
...@@ -27,7 +27,7 @@ class HiddenHandler(BaseMasterHandler): ...@@ -27,7 +27,7 @@ class HiddenHandler(BaseMasterHandler):
self.app = app self.app = app
BaseMasterHandler.__init__(self, app) BaseMasterHandler.__init__(self, app)
def handleNotifyNodeInformation(self, conn, packet, node_list): def notifyNodeInformation(self, conn, packet, node_list):
"""Store information on nodes, only if this is sent by a primary """Store information on nodes, only if this is sent by a primary
master node.""" master node."""
app = self.app app = self.app
...@@ -42,28 +42,28 @@ class HiddenHandler(BaseMasterHandler): ...@@ -42,28 +42,28 @@ class HiddenHandler(BaseMasterHandler):
erase_db = state == NodeStates.DOWN erase_db = state == NodeStates.DOWN
self.app.shutdown(erase=erase_db) self.app.shutdown(erase=erase_db)
def handleRequestNodeIdentification(self, conn, packet, node_type, def requestNodeIdentification(self, conn, packet, node_type,
uuid, address, name): uuid, address, name):
pass pass
def handleAcceptNodeIdentification(self, conn, packet, node_type, def acceptNodeIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid): uuid, address, num_partitions, num_replicas, your_uuid):
pass pass
def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid, def answerPrimaryMaster(self, conn, packet, primary_uuid,
known_master_list): known_master_list):
pass pass
def handleAskLastIDs(self, conn, packet): def askLastIDs(self, conn, packet):
pass pass
def handleAskPartitionTable(self, conn, packet, offset_list): def askPartitionTable(self, conn, packet, offset_list):
pass pass
def handleSendPartitionTable(self, conn, packet, ptid, row_list): def sendPartitionTable(self, conn, packet, ptid, row_list):
pass pass
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list): def notifyPartitionChanges(self, conn, packet, ptid, cell_list):
"""This is very similar to Send Partition Table, except that """This is very similar to Send Partition Table, except that
the information is only about changes from the previous.""" the information is only about changes from the previous."""
app = self.app app = self.app
...@@ -85,59 +85,59 @@ class HiddenHandler(BaseMasterHandler): ...@@ -85,59 +85,59 @@ class HiddenHandler(BaseMasterHandler):
elif state == CellStates.OUT_OF_DATE: elif state == CellStates.OUT_OF_DATE:
app.replicator.addPartition(offset) app.replicator.addPartition(offset)
def handleStartOperation(self, conn, packet): def startOperation(self, conn, packet):
self.app.operational = True self.app.operational = True
def handleStopOperation(self, conn, packet): def stopOperation(self, conn, packet):
pass pass
def handleAskUnfinishedTransactions(self, conn, packet): def askUnfinishedTransactions(self, conn, packet):
pass pass
def handleAskTransactionInformation(self, conn, packet, tid): def askTransactionInformation(self, conn, packet, tid):
pass pass
def handleAskObjectPresent(self, conn, packet, oid, tid): def askObjectPresent(self, conn, packet, oid, tid):
pass pass
def handleDeleteTransaction(self, conn, packet, tid): def deleteTransaction(self, conn, packet, tid):
pass pass
def handleCommitTransaction(self, conn, packet, tid): def commitTransaction(self, conn, packet, tid):
pass pass
def handleLockInformation(self, conn, packet, tid): def lockInformation(self, conn, packet, tid):
pass pass
def handleUnlockInformation(self, conn, packet, tid): def unlockInformation(self, conn, packet, tid):
pass pass
def handleAskObject(self, conn, packet, oid, serial, tid): def askObject(self, conn, packet, oid, serial, tid):
pass pass
def handleAskTIDs(self, conn, packet, first, last, partition): def askTIDs(self, conn, packet, first, last, partition):
pass pass
def handleAskObjectHistory(self, conn, packet, oid, first, last): def askObjectHistory(self, conn, packet, oid, first, last):
pass pass
def handleAskStoreTransaction(self, conn, packet, tid, user, desc, def askStoreTransaction(self, conn, packet, tid, user, desc,
ext, oid_list): ext, oid_list):
pass pass
def handleAskStoreObject(self, conn, packet, oid, serial, def askStoreObject(self, conn, packet, oid, serial,
compression, checksum, data, tid): compression, checksum, data, tid):
pass pass
def handleAbortTransaction(self, conn, packet, tid): def abortTransaction(self, conn, packet, tid):
logging.debug('ignoring abort transaction') logging.debug('ignoring abort transaction')
def handleAnswerLastIDs(self, conn, packet, loid, ltid, lptid): def answerLastIDs(self, conn, packet, loid, ltid, lptid):
logging.debug('ignoring answer last ids') logging.debug('ignoring answer last ids')
def handleAnswerUnfinishedTransactions(self, conn, packet, tid_list): def answerUnfinishedTransactions(self, conn, packet, tid_list):
logging.debug('ignoring answer unfinished transactions') logging.debug('ignoring answer unfinished transactions')
def handleAskOIDs(self, conn, packet, first, last, partition): def askOIDs(self, conn, packet, first, last, partition):
logging.debug('ignoring ask oids') logging.debug('ignoring ask oids')
...@@ -28,7 +28,7 @@ class IdentificationHandler(BaseStorageHandler): ...@@ -28,7 +28,7 @@ class IdentificationHandler(BaseStorageHandler):
def connectionLost(self, conn, new_state): def connectionLost(self, conn, new_state):
logging.warning('A connection was lost during identification') logging.warning('A connection was lost during identification')
def handleRequestNodeIdentification(self, conn, packet, node_type, def requestNodeIdentification(self, conn, packet, node_type,
uuid, address, name): uuid, address, name):
self.checkClusterName(name) self.checkClusterName(name)
# reject any incoming connections if not ready # reject any incoming connections if not ready
......
...@@ -22,20 +22,20 @@ from neo import protocol ...@@ -22,20 +22,20 @@ from neo import protocol
class InitializationHandler(BaseMasterHandler): class InitializationHandler(BaseMasterHandler):
def handleAnswerNodeInformation(self, conn, packet, node_list): def answerNodeInformation(self, conn, packet, node_list):
assert not node_list assert not node_list
self.app.has_node_information = True self.app.has_node_information = True
def handleNotifyNodeInformation(self, conn, packet, node_list): def notifyNodeInformation(self, conn, packet, node_list):
# the whole node list is received here # the whole node list is received here
BaseMasterHandler.handleNotifyNodeInformation(self, conn, packet, node_list) BaseMasterHandler.notifyNodeInformation(self, conn, packet, node_list)
def handleSendPartitionTable(self, conn, packet, ptid, row_list): def sendPartitionTable(self, conn, packet, ptid, row_list):
"""A primary master node sends this packet to synchronize a partition """A primary master node sends this packet to synchronize a partition
table. Note that the message can be split into multiple packets.""" table. Note that the message can be split into multiple packets."""
self.app.pt.load(ptid, row_list, self.app.nm) self.app.pt.load(ptid, row_list, self.app.nm)
def handleAnswerPartitionTable(self, conn, packet, ptid, row_list): def answerPartitionTable(self, conn, packet, ptid, row_list):
app = self.app app = self.app
pt = app.pt pt = app.pt
assert not row_list assert not row_list
...@@ -59,7 +59,7 @@ class InitializationHandler(BaseMasterHandler): ...@@ -59,7 +59,7 @@ class InitializationHandler(BaseMasterHandler):
app.dm.setPartitionTable(ptid, cell_list) app.dm.setPartitionTable(ptid, cell_list)
self.app.has_partition_table = True self.app.has_partition_table = True
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list): def notifyPartitionChanges(self, conn, packet, ptid, cell_list):
# XXX: Currently it safe to ignore those packets because the master is # XXX: Currently it safe to ignore those packets because the master is
# single threaded, it send the partition table without any changes at # single threaded, it send the partition table without any changes at
# the same time. Latter it should be needed to put in queue any changes # the same time. Latter it should be needed to put in queue any changes
......
...@@ -26,16 +26,16 @@ from neo.exception import OperationFailure ...@@ -26,16 +26,16 @@ from neo.exception import OperationFailure
class MasterOperationHandler(BaseMasterHandler): class MasterOperationHandler(BaseMasterHandler):
""" This handler is used for the primary master """ """ This handler is used for the primary master """
def handleStopOperation(self, conn, packet): def stopOperation(self, conn, packet):
raise OperationFailure('operation stopped') raise OperationFailure('operation stopped')
def handleAnswerLastIDs(self, conn, packet, loid, ltid, lptid): def answerLastIDs(self, conn, packet, loid, ltid, lptid):
self.app.replicator.setCriticalTID(packet, ltid) self.app.replicator.setCriticalTID(packet, ltid)
def handleAnswerUnfinishedTransactions(self, conn, packet, tid_list): def answerUnfinishedTransactions(self, conn, packet, tid_list):
self.app.replicator.setUnfinishedTIDList(tid_list) self.app.replicator.setUnfinishedTIDList(tid_list)
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list): def notifyPartitionChanges(self, conn, packet, ptid, cell_list):
"""This is very similar to Send Partition Table, except that """This is very similar to Send Partition Table, except that
the information is only about changes from the previous.""" the information is only about changes from the previous."""
app = self.app app = self.app
...@@ -57,7 +57,7 @@ class MasterOperationHandler(BaseMasterHandler): ...@@ -57,7 +57,7 @@ class MasterOperationHandler(BaseMasterHandler):
elif state == CellStates.OUT_OF_DATE: elif state == CellStates.OUT_OF_DATE:
app.replicator.addPartition(offset) app.replicator.addPartition(offset)
def handleLockInformation(self, conn, packet, tid): def lockInformation(self, conn, packet, tid):
app = self.app app = self.app
try: try:
t = app.transaction_dict[tid] t = app.transaction_dict[tid]
...@@ -70,7 +70,7 @@ class MasterOperationHandler(BaseMasterHandler): ...@@ -70,7 +70,7 @@ class MasterOperationHandler(BaseMasterHandler):
pass pass
conn.answer(protocol.notifyInformationLocked(tid), packet.getId()) conn.answer(protocol.notifyInformationLocked(tid), packet.getId())
def handleUnlockInformation(self, conn, packet, tid): def unlockInformation(self, conn, packet, tid):
app = self.app app = self.app
try: try:
t = app.transaction_dict[tid] t = app.transaction_dict[tid]
......
...@@ -36,12 +36,12 @@ class ReplicationHandler(BaseStorageHandler): ...@@ -36,12 +36,12 @@ class ReplicationHandler(BaseStorageHandler):
logging.error('replication is stopped due to connection failure') logging.error('replication is stopped due to connection failure')
self.app.replicator.reset() self.app.replicator.reset()
def handleAcceptNodeIdentification(self, conn, packet, node_type, def acceptNodeIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid): uuid, address, num_partitions, num_replicas, your_uuid):
# set the UUID on the connection # set the UUID on the connection
conn.setUUID(uuid) conn.setUUID(uuid)
def handleAnswerTIDs(self, conn, packet, tid_list): def answerTIDs(self, conn, packet, tid_list):
app = self.app app = self.app
if app.replicator.current_connection is not conn: if app.replicator.current_connection is not conn:
return return
...@@ -68,7 +68,7 @@ class ReplicationHandler(BaseStorageHandler): ...@@ -68,7 +68,7 @@ class ReplicationHandler(BaseStorageHandler):
conn.ask(p, timeout=300) conn.ask(p, timeout=300)
app.replicator.oid_offset = 0 app.replicator.oid_offset = 0
def handleAnswerTransactionInformation(self, conn, packet, tid, def answerTransactionInformation(self, conn, packet, tid,
user, desc, ext, oid_list): user, desc, ext, oid_list):
app = self.app app = self.app
if app.replicator.current_connection is not conn: if app.replicator.current_connection is not conn:
...@@ -77,7 +77,7 @@ class ReplicationHandler(BaseStorageHandler): ...@@ -77,7 +77,7 @@ class ReplicationHandler(BaseStorageHandler):
# Directly store the transaction. # Directly store the transaction.
app.dm.storeTransaction(tid, (), (oid_list, user, desc, ext), False) app.dm.storeTransaction(tid, (), (oid_list, user, desc, ext), False)
def handleAnswerOIDs(self, conn, packet, oid_list): def answerOIDs(self, conn, packet, oid_list):
app = self.app app = self.app
if app.replicator.current_connection is not conn: if app.replicator.current_connection is not conn:
return return
...@@ -93,7 +93,7 @@ class ReplicationHandler(BaseStorageHandler): ...@@ -93,7 +93,7 @@ class ReplicationHandler(BaseStorageHandler):
# finished. # finished.
app.replicator.replication_done = True app.replicator.replication_done = True
def handleAnswerObjectHistory(self, conn, packet, oid, history_list): def answerObjectHistory(self, conn, packet, oid, history_list):
app = self.app app = self.app
if app.replicator.current_connection is not conn: if app.replicator.current_connection is not conn:
return return
...@@ -127,7 +127,7 @@ class ReplicationHandler(BaseStorageHandler): ...@@ -127,7 +127,7 @@ class ReplicationHandler(BaseStorageHandler):
app.replicator.current_partition.getRID()) app.replicator.current_partition.getRID())
conn.ask(p, timeout=300) conn.ask(p, timeout=300)
def handleAnswerObject(self, conn, packet, oid, serial_start, def answerObject(self, conn, packet, oid, serial_start,
serial_end, compression, checksum, data): serial_end, compression, checksum, data):
app = self.app app = self.app
if app.replicator.current_connection is not conn: if app.replicator.current_connection is not conn:
......
...@@ -20,14 +20,14 @@ from neo.storage.handlers import BaseClientAndStorageOperationHandler ...@@ -20,14 +20,14 @@ from neo.storage.handlers import BaseClientAndStorageOperationHandler
class StorageOperationHandler(BaseClientAndStorageOperationHandler): class StorageOperationHandler(BaseClientAndStorageOperationHandler):
def handleAskLastIDs(self, conn, packet): def askLastIDs(self, conn, packet):
app = self.app app = self.app
oid = app.dm.getLastOID() oid = app.dm.getLastOID()
tid = app.dm.getLastTID() tid = app.dm.getLastTID()
p = protocol.answerLastIDs(oid, tid, app.pt.getID()) p = protocol.answerLastIDs(oid, tid, app.pt.getID())
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
def handleAskOIDs(self, conn, packet, first, last, partition): def askOIDs(self, conn, packet, first, last, partition):
# This method is complicated, because I must return OIDs only # This method is complicated, because I must return OIDs only
# about usable partitions assigned to me. # about usable partitions assigned to me.
if first >= last: if first >= last:
......
...@@ -25,14 +25,14 @@ from neo.exception import OperationFailure ...@@ -25,14 +25,14 @@ from neo.exception import OperationFailure
class VerificationHandler(BaseMasterHandler): class VerificationHandler(BaseMasterHandler):
"""This class deals with events for a verification phase.""" """This class deals with events for a verification phase."""
def handleAskLastIDs(self, conn, packet): def askLastIDs(self, conn, packet):
app = self.app app = self.app
oid = app.dm.getLastOID() oid = app.dm.getLastOID()
tid = app.dm.getLastTID() tid = app.dm.getLastTID()
p = protocol.answerLastIDs(oid, tid, app.pt.getID()) p = protocol.answerLastIDs(oid, tid, app.pt.getID())
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
def handleAskPartitionTable(self, conn, packet, offset_list): def askPartitionTable(self, conn, packet, offset_list):
app, pt = self.app, self.app.pt app, pt = self.app, self.app.pt
if not offset_list: if not offset_list:
# all is requested # all is requested
...@@ -53,7 +53,7 @@ class VerificationHandler(BaseMasterHandler): ...@@ -53,7 +53,7 @@ class VerificationHandler(BaseMasterHandler):
p = protocol.answerPartitionTable(app.pt.getID(), row_list) p = protocol.answerPartitionTable(app.pt.getID(), row_list)
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list): def notifyPartitionChanges(self, conn, packet, ptid, cell_list):
"""This is very similar to Send Partition Table, except that """This is very similar to Send Partition Table, except that
the information is only about changes from the previous.""" the information is only about changes from the previous."""
app = self.app app = self.app
...@@ -65,18 +65,18 @@ class VerificationHandler(BaseMasterHandler): ...@@ -65,18 +65,18 @@ class VerificationHandler(BaseMasterHandler):
app.pt.update(ptid, cell_list, app.nm) app.pt.update(ptid, cell_list, app.nm)
app.dm.changePartitionTable(ptid, cell_list) app.dm.changePartitionTable(ptid, cell_list)
def handleStartOperation(self, conn, packet): def startOperation(self, conn, packet):
self.app.operational = True self.app.operational = True
def handleStopOperation(self, conn, packet): def stopOperation(self, conn, packet):
raise OperationFailure('operation stopped') raise OperationFailure('operation stopped')
def handleAskUnfinishedTransactions(self, conn, packet): def askUnfinishedTransactions(self, conn, packet):
tid_list = self.app.dm.getUnfinishedTIDList() tid_list = self.app.dm.getUnfinishedTIDList()
p = protocol.answerUnfinishedTransactions(tid_list) p = protocol.answerUnfinishedTransactions(tid_list)
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
def handleAskTransactionInformation(self, conn, packet, tid): def askTransactionInformation(self, conn, packet, tid):
app = self.app app = self.app
t = app.dm.getTransaction(tid, all=True) t = app.dm.getTransaction(tid, all=True)
if t is None: if t is None:
...@@ -85,7 +85,7 @@ class VerificationHandler(BaseMasterHandler): ...@@ -85,7 +85,7 @@ class VerificationHandler(BaseMasterHandler):
p = protocol.answerTransactionInformation(tid, t[1], t[2], t[3], t[0]) p = protocol.answerTransactionInformation(tid, t[1], t[2], t[3], t[0])
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
def handleAskObjectPresent(self, conn, packet, oid, tid): def askObjectPresent(self, conn, packet, oid, tid):
if self.app.dm.objectPresent(oid, tid): if self.app.dm.objectPresent(oid, tid):
p = protocol.answerObjectPresent(oid, tid) p = protocol.answerObjectPresent(oid, tid)
else: else:
...@@ -93,9 +93,9 @@ class VerificationHandler(BaseMasterHandler): ...@@ -93,9 +93,9 @@ class VerificationHandler(BaseMasterHandler):
'%s:%s do not exist' % (dump(oid), dump(tid))) '%s:%s do not exist' % (dump(oid), dump(tid)))
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
def handleDeleteTransaction(self, conn, packet, tid): def deleteTransaction(self, conn, packet, tid):
self.app.dm.deleteTransaction(tid, all = True) self.app.dm.deleteTransaction(tid, all = True)
def handleCommitTransaction(self, conn, packet, tid): def commitTransaction(self, conn, packet, tid):
self.app.dm.finishTransaction(tid) self.app.dm.finishTransaction(tid)
...@@ -206,7 +206,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -206,7 +206,7 @@ class ClientHandlerTests(NeoTestBase):
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
conn = self.getConnection() conn = self.getConnection()
client_handler = StorageBootstrapHandler(app) client_handler = StorageBootstrapHandler(app)
client_handler.handleNotReady(conn, None, None) client_handler.notReady(conn, None, None)
self.assertEquals(len(app.mockGetNamedCalls('setNodeNotReady')), 1) self.assertEquals(len(app.mockGetNamedCalls('setNodeNotReady')), 1)
def test_clientAcceptNodeIdentification(self): def test_clientAcceptNodeIdentification(self):
...@@ -220,7 +220,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -220,7 +220,7 @@ class ClientHandlerTests(NeoTestBase):
conn = self.getConnection() conn = self.getConnection()
uuid = self.getNewUUID() uuid = self.getNewUUID()
app.uuid = 'C' * 16 app.uuid = 'C' * 16
client_handler.handleAcceptNodeIdentification( client_handler.acceptNodeIdentification(
conn, None, conn, None,
NodeTypes.CLIENT, NodeTypes.CLIENT,
uuid, ('127.0.0.1', 10010), uuid, ('127.0.0.1', 10010),
...@@ -248,7 +248,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -248,7 +248,7 @@ class ClientHandlerTests(NeoTestBase):
uuid = self.getNewUUID() uuid = self.getNewUUID()
your_uuid = 'C' * 16 your_uuid = 'C' * 16
app.uuid = INVALID_UUID app.uuid = INVALID_UUID
client_handler.handleAcceptNodeIdentification(conn, None, client_handler.acceptNodeIdentification(conn, None,
NodeTypes.MASTER, uuid, ('127.0.0.1', 10010), 10, 2, your_uuid) NodeTypes.MASTER, uuid, ('127.0.0.1', 10010), 10, 2, your_uuid)
self.checkNotClosed(conn) self.checkNotClosed(conn)
self.checkUUIDSet(conn, uuid) self.checkUUIDSet(conn, uuid)
...@@ -268,7 +268,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -268,7 +268,7 @@ class ClientHandlerTests(NeoTestBase):
conn = self.getConnection() conn = self.getConnection()
uuid = self.getNewUUID() uuid = self.getNewUUID()
app.uuid = 'C' * 16 app.uuid = 'C' * 16
client_handler.handleAcceptNodeIdentification(conn, None, client_handler.acceptNodeIdentification(conn, None,
NodeTypes.STORAGE, uuid, ('127.0.0.1', 10010), 0, 0, INVALID_UUID) NodeTypes.STORAGE, uuid, ('127.0.0.1', 10010), 0, 0, INVALID_UUID)
self.checkNotClosed(conn) self.checkNotClosed(conn)
self.checkUUIDSet(conn, uuid) self.checkUUIDSet(conn, uuid)
...@@ -288,7 +288,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -288,7 +288,7 @@ class ClientHandlerTests(NeoTestBase):
app = App() app = App()
client_handler = PrimaryBootstrapHandler(app) client_handler = PrimaryBootstrapHandler(app)
conn = self.getConnection() conn = self.getConnection()
client_handler.handleAnswerPrimaryMaster(conn, None, 0, []) client_handler.answerPrimaryMaster(conn, None, 0, [])
# Check that nothing happened # Check that nothing happened
self.assertEqual(len(app.nm.mockGetNamedCalls('getByAddress')), 0) self.assertEqual(len(app.nm.mockGetNamedCalls('getByAddress')), 0)
self.assertEqual(len(app.nm.mockGetNamedCalls('add')), 0) self.assertEqual(len(app.nm.mockGetNamedCalls('add')), 0)
...@@ -302,7 +302,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -302,7 +302,7 @@ class ClientHandlerTests(NeoTestBase):
client_handler = PrimaryBootstrapHandler(app) client_handler = PrimaryBootstrapHandler(app)
conn = self.getConnection() conn = self.getConnection()
test_master_list = [(('127.0.0.1', 10010), self.getNewUUID())] test_master_list = [(('127.0.0.1', 10010), self.getNewUUID())]
client_handler.handleAnswerPrimaryMaster(conn, None, INVALID_UUID, test_master_list) client_handler.answerPrimaryMaster(conn, None, INVALID_UUID, test_master_list)
# Check that yet-unknown master node got added # Check that yet-unknown master node got added
getByAddress_call_list = app.nm.mockGetNamedCalls('getNodeByServer') getByAddress_call_list = app.nm.mockGetNamedCalls('getNodeByServer')
add_call_list = app.nm.mockGetNamedCalls('add') add_call_list = app.nm.mockGetNamedCalls('add')
...@@ -328,7 +328,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -328,7 +328,7 @@ class ClientHandlerTests(NeoTestBase):
conn = self.getConnection() conn = self.getConnection()
test_node_uuid = self.getNewUUID() test_node_uuid = self.getNewUUID()
test_master_list = [(('127.0.0.1', 10010), test_node_uuid)] test_master_list = [(('127.0.0.1', 10010), test_node_uuid)]
client_handler.handleAnswerPrimaryMaster(conn, None, INVALID_UUID, test_master_list) client_handler.answerPrimaryMaster(conn, None, INVALID_UUID, test_master_list)
# Test sanity checks # Test sanity checks
getByAddress_call_list = app.nm.mockGetNamedCalls('getNodeByServer') getByAddress_call_list = app.nm.mockGetNamedCalls('getNodeByServer')
self.assertEqual(len(getByAddress_call_list), 1) self.assertEqual(len(getByAddress_call_list), 1)
...@@ -354,7 +354,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -354,7 +354,7 @@ class ClientHandlerTests(NeoTestBase):
client_handler = PrimaryBootstrapHandler(app) client_handler = PrimaryBootstrapHandler(app)
conn = self.getConnection() conn = self.getConnection()
test_master_list = [(('127.0.0.1', 10010), test_node_uuid)] test_master_list = [(('127.0.0.1', 10010), test_node_uuid)]
client_handler.handleAnswerPrimaryMaster(conn, None, INVALID_UUID, test_master_list) client_handler.answerPrimaryMaster(conn, None, INVALID_UUID, test_master_list)
# Test sanity checks # Test sanity checks
getByAddress_call_list = app.nm.mockGetNamedCalls('getNodeByServer') getByAddress_call_list = app.nm.mockGetNamedCalls('getNodeByServer')
self.assertEqual(len(getByAddress_call_list), 1) self.assertEqual(len(getByAddress_call_list), 1)
...@@ -391,7 +391,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -391,7 +391,7 @@ class ClientHandlerTests(NeoTestBase):
# If primary master is already set *and* is not given primary master # If primary master is already set *and* is not given primary master
# handle call raises. # handle call raises.
# Check that the call doesn't raise # Check that the call doesn't raise
client_handler.handleAnswerPrimaryMaster(conn, None, test_node_uuid, []) client_handler.answerPrimaryMaster(conn, None, test_node_uuid, [])
# Check that the primary master changed # Check that the primary master changed
self.assertTrue(app.primary_master_node is node) self.assertTrue(app.primary_master_node is node)
# Test sanity checks # Test sanity checks
...@@ -411,7 +411,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -411,7 +411,7 @@ class ClientHandlerTests(NeoTestBase):
app = App() app = App()
client_handler = PrimaryBootstrapHandler(app) client_handler = PrimaryBootstrapHandler(app)
conn = self.getConnection() conn = self.getConnection()
client_handler.handleAnswerPrimaryMaster(conn, None, test_node_uuid, []) client_handler.answerPrimaryMaster(conn, None, test_node_uuid, [])
# Check that primary node is (still) node. # Check that primary node is (still) node.
self.assertTrue(app.primary_master_node is node) self.assertTrue(app.primary_master_node is node)
...@@ -428,7 +428,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -428,7 +428,7 @@ class ClientHandlerTests(NeoTestBase):
app = App() app = App()
client_handler = PrimaryBootstrapHandler(app) client_handler = PrimaryBootstrapHandler(app)
conn = self.getConnection() conn = self.getConnection()
client_handler.handleAnswerPrimaryMaster(conn, None, test_primary_node_uuid, []) client_handler.answerPrimaryMaster(conn, None, test_primary_node_uuid, [])
# Test sanity checks # Test sanity checks
getByUUID_call_list = app.nm.mockGetNamedCalls('getNodeByUUID') getByUUID_call_list = app.nm.mockGetNamedCalls('getNodeByUUID')
self.assertEqual(len(getByUUID_call_list), 1) self.assertEqual(len(getByUUID_call_list), 1)
...@@ -447,7 +447,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -447,7 +447,7 @@ class ClientHandlerTests(NeoTestBase):
client_handler = PrimaryBootstrapHandler(app) client_handler = PrimaryBootstrapHandler(app)
conn = self.getConnection() conn = self.getConnection()
test_master_list = [(('127.0.0.1', 10010), test_node_uuid)] test_master_list = [(('127.0.0.1', 10010), test_node_uuid)]
client_handler.handleAnswerPrimaryMaster(conn, None, test_node_uuid, test_master_list) client_handler.answerPrimaryMaster(conn, None, test_node_uuid, test_master_list)
# Test sanity checks # Test sanity checks
getByUUID_call_list = app.nm.mockGetNamedCalls('getNodeByUUID') getByUUID_call_list = app.nm.mockGetNamedCalls('getNodeByUUID')
self.assertEqual(len(getByUUID_call_list), 1) self.assertEqual(len(getByUUID_call_list), 1)
...@@ -467,7 +467,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -467,7 +467,7 @@ class ClientHandlerTests(NeoTestBase):
app = App() app = App()
client_handler = PrimaryNotificationsHandler(app, Mock()) client_handler = PrimaryNotificationsHandler(app, Mock())
conn = self.getConnection() conn = self.getConnection()
client_handler.handleSendPartitionTable(conn, None, test_ptid + 1, []) client_handler.sendPartitionTable(conn, None, test_ptid + 1, [])
# Check that partition table got cleared and ptid got updated # Check that partition table got cleared and ptid got updated
self.assertEquals(app.pt.getID(), 1) self.assertEquals(app.pt.getID(), 1)
...@@ -484,7 +484,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -484,7 +484,7 @@ class ClientHandlerTests(NeoTestBase):
conn = self.getConnection() conn = self.getConnection()
# TODO: use realistic values # TODO: use realistic values
test_row_list = [(0, [(test_storage_uuid, 0)])] test_row_list = [(0, [(test_storage_uuid, 0)])]
client_handler.handleSendPartitionTable(conn, None, test_ptid, test_row_list) client_handler.sendPartitionTable(conn, None, test_ptid, test_row_list)
# Check that node got created # Check that node got created
add_call_list = app.nm.mockGetNamedCalls('add') add_call_list = app.nm.mockGetNamedCalls('add')
self.assertEquals(len(add_call_list), 1) self.assertEquals(len(add_call_list), 1)
...@@ -509,7 +509,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -509,7 +509,7 @@ class ClientHandlerTests(NeoTestBase):
conn = self.getConnection() conn = self.getConnection()
# TODO: use realistic values # TODO: use realistic values
test_row_list = [(0, [(test_storage_uuid, 0)])] test_row_list = [(0, [(test_storage_uuid, 0)])]
client_handler.handleSendPartitionTable(conn, None, test_ptid, test_row_list) client_handler.sendPartitionTable(conn, None, test_ptid, test_row_list)
# Check that node did not get created # Check that node did not get created
self.assertEquals(len(app.nm.mockGetNamedCalls('add')), 0) self.assertEquals(len(app.nm.mockGetNamedCalls('add')), 0)
# Check that partition table cell got added # Check that partition table cell got added
...@@ -527,7 +527,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -527,7 +527,7 @@ class ClientHandlerTests(NeoTestBase):
app = App() app = App()
client_handler = PrimaryNotificationsHandler(app, self.getDispatcher()) client_handler = PrimaryNotificationsHandler(app, self.getDispatcher())
conn = self.getConnection(uuid=test_master_uuid) conn = self.getConnection(uuid=test_master_uuid)
client_handler.handleNotifyNodeInformation(conn, None, ()) client_handler.notifyNodeInformation(conn, None, ())
def test_nonIterableParameterRaisesNotifyNodeInformation(self): def test_nonIterableParameterRaisesNotifyNodeInformation(self):
# XXX: this test is here for sanity self-check: it verifies the # XXX: this test is here for sanity self-check: it verifies the
...@@ -541,7 +541,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -541,7 +541,7 @@ class ClientHandlerTests(NeoTestBase):
app = App() app = App()
client_handler = PrimaryNotificationsHandler(app, self.getDispatcher()) client_handler = PrimaryNotificationsHandler(app, self.getDispatcher())
conn = self.getConnection(uuid=test_master_uuid) conn = self.getConnection(uuid=test_master_uuid)
self.assertRaises(TypeError, client_handler.handleNotifyNodeInformation, self.assertRaises(TypeError, client_handler.notifyNodeInformation,
conn, None, None) conn, None, None)
def _testNotifyNodeInformation(self, test_node, getByAddress=None, getByUUID=MARKER): def _testNotifyNodeInformation(self, test_node, getByAddress=None, getByUUID=MARKER):
...@@ -560,7 +560,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -560,7 +560,7 @@ class ClientHandlerTests(NeoTestBase):
app = App() app = App()
client_handler = PrimaryBootstrapHandler(app) client_handler = PrimaryBootstrapHandler(app)
conn = self.getConnection(uuid=test_master_uuid) conn = self.getConnection(uuid=test_master_uuid)
client_handler.handleNotifyNodeInformation(conn, None, test_node_list) client_handler.notifyNodeInformation(conn, None, test_node_list)
# Return nm so caller can check handler actions. # Return nm so caller can check handler actions.
return app.nm return app.nm
...@@ -632,7 +632,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -632,7 +632,7 @@ class ClientHandlerTests(NeoTestBase):
client_handler = PrimaryBootstrapHandler(app) client_handler = PrimaryBootstrapHandler(app)
conn = Mock({'getUUID': None}) conn = Mock({'getUUID': None})
self._testHandleUnexpectedPacketCalledWithMedhod( self._testHandleUnexpectedPacketCalledWithMedhod(
client_handler.handleNotifyPartitionChanges, client_handler.notifyPartitionChanges,
args=(conn, None, None, None)) args=(conn, None, None, None))
def test_nonMasterNotifyPartitionChanges(self): def test_nonMasterNotifyPartitionChanges(self):
...@@ -647,7 +647,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -647,7 +647,7 @@ class ClientHandlerTests(NeoTestBase):
app = App() app = App()
client_handler = PrimaryNotificationsHandler(app, self.getDispatcher()) client_handler = PrimaryNotificationsHandler(app, self.getDispatcher())
conn = self.getConnection(uuid=test_master_uuid) conn = self.getConnection(uuid=test_master_uuid)
client_handler.handleNotifyPartitionChanges(conn, None, 0, []) client_handler.notifyPartitionChanges(conn, None, 0, [])
# Check that nothing happened # Check that nothing happened
self.assertEquals(len(app.pt.mockGetNamedCalls('setCell')), 0) self.assertEquals(len(app.pt.mockGetNamedCalls('setCell')), 0)
self.assertEquals(len(app.pt.mockGetNamedCalls('removeCell')), 0) self.assertEquals(len(app.pt.mockGetNamedCalls('removeCell')), 0)
...@@ -662,7 +662,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -662,7 +662,7 @@ class ClientHandlerTests(NeoTestBase):
app = App() app = App()
client_handler = PrimaryNotificationsHandler(app, self.getDispatcher()) client_handler = PrimaryNotificationsHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
client_handler.handleNotifyPartitionChanges(conn, None, 0, []) client_handler.notifyPartitionChanges(conn, None, 0, [])
# Check that nothing happened # Check that nothing happened
self.assertEquals(len(app.pt.mockGetNamedCalls('setCell')), 0) self.assertEquals(len(app.pt.mockGetNamedCalls('setCell')), 0)
self.assertEquals(len(app.pt.mockGetNamedCalls('removeCell')), 0) self.assertEquals(len(app.pt.mockGetNamedCalls('removeCell')), 0)
...@@ -682,7 +682,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -682,7 +682,7 @@ class ClientHandlerTests(NeoTestBase):
app = App() app = App()
client_handler = PrimaryNotificationsHandler(app, self.getDispatcher()) client_handler = PrimaryNotificationsHandler(app, self.getDispatcher())
conn = self.getConnection(uuid=test_sender_uuid) conn = self.getConnection(uuid=test_sender_uuid)
client_handler.handleNotifyPartitionChanges(conn, None, 0, []) client_handler.notifyPartitionChanges(conn, None, 0, [])
# Check that nothing happened # Check that nothing happened
self.assertEquals(len(app.pt.mockGetNamedCalls('setCell')), 0) self.assertEquals(len(app.pt.mockGetNamedCalls('setCell')), 0)
self.assertEquals(len(app.pt.mockGetNamedCalls('removeCell')), 0) self.assertEquals(len(app.pt.mockGetNamedCalls('removeCell')), 0)
...@@ -699,7 +699,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -699,7 +699,7 @@ class ClientHandlerTests(NeoTestBase):
app = App() app = App()
client_handler = PrimaryNotificationsHandler(app, self.getDispatcher()) client_handler = PrimaryNotificationsHandler(app, self.getDispatcher())
conn = self.getConnection(uuid=test_master_uuid) conn = self.getConnection(uuid=test_master_uuid)
client_handler.handleNotifyPartitionChanges(conn, None, test_ptid, []) client_handler.notifyPartitionChanges(conn, None, test_ptid, [])
# Check that nothing happened # Check that nothing happened
self.assertEquals(len(app.pt.mockGetNamedCalls('setCell')), 0) self.assertEquals(len(app.pt.mockGetNamedCalls('setCell')), 0)
self.assertEquals(len(app.pt.mockGetNamedCalls('removeCell')), 0) self.assertEquals(len(app.pt.mockGetNamedCalls('removeCell')), 0)
...@@ -721,7 +721,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -721,7 +721,7 @@ class ClientHandlerTests(NeoTestBase):
test_storage_uuid = self.getNewUUID() test_storage_uuid = self.getNewUUID()
# TODO: use realistic values # TODO: use realistic values
test_cell_list = [(0, test_storage_uuid, CellStates.UP_TO_DATE)] test_cell_list = [(0, test_storage_uuid, CellStates.UP_TO_DATE)]
client_handler.handleNotifyPartitionChanges(conn, None, test_ptid + 1, test_cell_list) client_handler.notifyPartitionChanges(conn, None, test_ptid + 1, test_cell_list)
# Check that a new node got added # Check that a new node got added
add_call_list = app.nm.mockGetNamedCalls('add') add_call_list = app.nm.mockGetNamedCalls('add')
self.assertEqual(len(add_call_list), 1) self.assertEqual(len(add_call_list), 1)
...@@ -754,7 +754,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -754,7 +754,7 @@ class ClientHandlerTests(NeoTestBase):
(0, uuid3, CellStates.FEEDING), (0, uuid3, CellStates.FEEDING),
(0, uuid4, CellStates.UP_TO_DATE), (0, uuid4, CellStates.UP_TO_DATE),
] ]
client_handler.handleNotifyPartitionChanges(conn, None, test_ptid + 1, test_cell_list) client_handler.notifyPartitionChanges(conn, None, test_ptid + 1, test_cell_list)
# Check that the three last node got added # Check that the three last node got added
calls = app.nm.mockGetNamedCalls('add') calls = app.nm.mockGetNamedCalls('add')
self.assertEquals(len(calls), 3) self.assertEquals(len(calls), 3)
...@@ -778,7 +778,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -778,7 +778,7 @@ class ClientHandlerTests(NeoTestBase):
client_handler = PrimaryAnswersHandler(app) client_handler = PrimaryAnswersHandler(app)
conn = self.getConnection() conn = self.getConnection()
test_tid = 1 test_tid = 1
client_handler.handleAnswerBeginTransaction(conn, None, test_tid) client_handler.answerBeginTransaction(conn, None, test_tid)
setTID_call_list = app.mockGetNamedCalls('setTID') setTID_call_list = app.mockGetNamedCalls('setTID')
self.assertEquals(len(setTID_call_list), 1) self.assertEquals(len(setTID_call_list), 1)
self.assertEquals(setTID_call_list[0].getParam(0), test_tid) self.assertEquals(setTID_call_list[0].getParam(0), test_tid)
...@@ -789,7 +789,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -789,7 +789,7 @@ class ClientHandlerTests(NeoTestBase):
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = PrimaryAnswersHandler(app) client_handler = PrimaryAnswersHandler(app)
conn = self.getConnection() conn = self.getConnection()
client_handler.handleNotifyTransactionFinished(conn, None, test_tid) client_handler.notifyTransactionFinished(conn, None, test_tid)
self.assertEquals(len(app.mockGetNamedCalls('setTransactionFinished')), 1) self.assertEquals(len(app.mockGetNamedCalls('setTransactionFinished')), 1)
# TODO: decide what to do when non-current transaction is notified as finished, and test that behaviour # TODO: decide what to do when non-current transaction is notified as finished, and test that behaviour
...@@ -816,7 +816,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -816,7 +816,7 @@ class ClientHandlerTests(NeoTestBase):
test_oid_list = ['\x00\x00\x00\x00\x00\x00\x00\x01', '\x00\x00\x00\x00\x00\x00\x00\x02'] test_oid_list = ['\x00\x00\x00\x00\x00\x00\x00\x01', '\x00\x00\x00\x00\x00\x00\x00\x02']
test_db = Mock({'invalidate': None}) test_db = Mock({'invalidate': None})
app.registerDB(test_db, None) app.registerDB(test_db, None)
client_handler.handleInvalidateObjects(conn, None, test_oid_list[:], test_tid) client_handler.invalidateObjects(conn, None, test_oid_list[:], test_tid)
# 'invalidate' is called just once # 'invalidate' is called just once
db = app.getDB() db = app.getDB()
self.assertTrue(db is test_db) self.assertTrue(db is test_db)
...@@ -843,7 +843,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -843,7 +843,7 @@ class ClientHandlerTests(NeoTestBase):
client_handler = PrimaryAnswersHandler(app) client_handler = PrimaryAnswersHandler(app)
conn = self.getConnection() conn = self.getConnection()
test_oid_list = ['\x00\x00\x00\x00\x00\x00\x00\x01', '\x00\x00\x00\x00\x00\x00\x00\x02'] test_oid_list = ['\x00\x00\x00\x00\x00\x00\x00\x01', '\x00\x00\x00\x00\x00\x00\x00\x02']
client_handler.handleAnswerNewOIDs(conn, None, test_oid_list[:]) client_handler.answerNewOIDs(conn, None, test_oid_list[:])
self.assertEquals(set(app.new_oid_list), set(test_oid_list)) self.assertEquals(set(app.new_oid_list), set(test_oid_list))
def test_StopOperation(self): def test_StopOperation(self):
...@@ -862,14 +862,14 @@ class ClientHandlerTests(NeoTestBase): ...@@ -862,14 +862,14 @@ class ClientHandlerTests(NeoTestBase):
conn = self.getConnection() conn = self.getConnection()
# TODO: use realistic values # TODO: use realistic values
test_object_data = ('\x00\x00\x00\x00\x00\x00\x00\x01', 0, 0, 0, 0, 'test') test_object_data = ('\x00\x00\x00\x00\x00\x00\x00\x01', 0, 0, 0, 0, 'test')
client_handler.handleAnswerObject(conn, None, *test_object_data) client_handler.answerObject(conn, None, *test_object_data)
self.assertEquals(app.local_var.asked_object, test_object_data) self.assertEquals(app.local_var.asked_object, test_object_data)
def _testAnswerStoreObject(self, app, conflicting, oid, serial): def _testAnswerStoreObject(self, app, conflicting, oid, serial):
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = StorageAnswersHandler(app) client_handler = StorageAnswersHandler(app)
conn = self.getConnection() conn = self.getConnection()
client_handler.handleAnswerStoreObject(conn, None, conflicting, oid, serial) client_handler.answerStoreObject(conn, None, conflicting, oid, serial)
def test_conflictingAnswerStoreObject(self): def test_conflictingAnswerStoreObject(self):
class App: class App:
...@@ -897,9 +897,9 @@ class ClientHandlerTests(NeoTestBase): ...@@ -897,9 +897,9 @@ class ClientHandlerTests(NeoTestBase):
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = StorageAnswersHandler(app) client_handler = StorageAnswersHandler(app)
conn = self.getConnection() conn = self.getConnection()
client_handler.handleAnswerStoreTransaction(conn, None, test_tid) client_handler.answerStoreTransaction(conn, None, test_tid)
self.assertEquals(len(app.mockGetNamedCalls('setTransactionVoted')), 1) self.assertEquals(len(app.mockGetNamedCalls('setTransactionVoted')), 1)
# TODO: test handleAnswerObject with test_tid not matching app.tid (not handled in program) # TODO: test answerObject with test_tid not matching app.tid (not handled in program)
def test_AnswerTransactionInformation(self): def test_AnswerTransactionInformation(self):
class FakeLocal: class FakeLocal:
...@@ -915,7 +915,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -915,7 +915,7 @@ class ClientHandlerTests(NeoTestBase):
desc = 'foo' desc = 'foo'
ext = 0 # XXX: unused in implementation ext = 0 # XXX: unused in implementation
oid_list = ['\x00\x00\x00\x00\x00\x00\x00\x01', '\x00\x00\x00\x00\x00\x00\x00\x02'] oid_list = ['\x00\x00\x00\x00\x00\x00\x00\x01', '\x00\x00\x00\x00\x00\x00\x00\x02']
client_handler.handleAnswerTransactionInformation(conn, None, tid, user, desc, ext, oid_list[:]) client_handler.answerTransactionInformation(conn, None, tid, user, desc, ext, oid_list[:])
stored_dict = app.local_var.txn_info stored_dict = app.local_var.txn_info
# TODO: test 'time' value ? # TODO: test 'time' value ?
self.assertEquals(stored_dict['user_name'], user) self.assertEquals(stored_dict['user_name'], user)
...@@ -935,7 +935,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -935,7 +935,7 @@ class ClientHandlerTests(NeoTestBase):
test_oid = '\x00\x00\x00\x00\x00\x00\x00\x01' test_oid = '\x00\x00\x00\x00\x00\x00\x00\x01'
# TODO: use realistic values # TODO: use realistic values
test_history_list = [(1, 2), (3, 4)] test_history_list = [(1, 2), (3, 4)]
client_handler.handleAnswerObjectHistory(conn, None, test_oid, test_history_list[:]) client_handler.answerObjectHistory(conn, None, test_oid, test_history_list[:])
oid, history = app.local_var.history oid, history = app.local_var.history
self.assertEquals(oid, test_oid) self.assertEquals(oid, test_oid)
self.assertEquals(len(history), len(test_history_list)) self.assertEquals(len(history), len(test_history_list))
...@@ -951,7 +951,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -951,7 +951,7 @@ class ClientHandlerTests(NeoTestBase):
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = StorageAnswersHandler(app) client_handler = StorageAnswersHandler(app)
conn = self.getConnection() conn = self.getConnection()
client_handler.handleOidNotFound(conn, None, None) client_handler.oidNotFound(conn, None, None)
self.assertEquals(app.local_var.asked_object, -1) self.assertEquals(app.local_var.asked_object, -1)
self.assertEquals(app.local_var.history, -1) self.assertEquals(app.local_var.history, -1)
...@@ -964,7 +964,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -964,7 +964,7 @@ class ClientHandlerTests(NeoTestBase):
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = StorageAnswersHandler(app) client_handler = StorageAnswersHandler(app)
conn = self.getConnection() conn = self.getConnection()
client_handler.handleTidNotFound(conn, None, None) client_handler.tidNotFound(conn, None, None)
self.assertEquals(app.local_var.txn_info, -1) self.assertEquals(app.local_var.txn_info, -1)
def test_AnswerTIDs(self): def test_AnswerTIDs(self):
...@@ -977,7 +977,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -977,7 +977,7 @@ class ClientHandlerTests(NeoTestBase):
client_handler = StorageAnswersHandler(app) client_handler = StorageAnswersHandler(app)
conn = self.getConnection() conn = self.getConnection()
test_tid_list = ['\x00\x00\x00\x00\x00\x00\x00\x01', '\x00\x00\x00\x00\x00\x00\x00\x02'] test_tid_list = ['\x00\x00\x00\x00\x00\x00\x00\x01', '\x00\x00\x00\x00\x00\x00\x00\x02']
client_handler.handleAnswerTIDs(conn, None, test_tid_list[:]) client_handler.answerTIDs(conn, None, test_tid_list[:])
stored_tid_list = [] stored_tid_list = []
for tid_list in app.local_var.node_tids.itervalues(): for tid_list in app.local_var.node_tids.itervalues():
stored_tid_list.extend(tid_list) stored_tid_list.extend(tid_list)
......
...@@ -71,7 +71,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -71,7 +71,7 @@ class MasterClientHandlerTests(NeoTestBase):
return uuid return uuid
# Tests # Tests
def test_05_handleNotifyNodeInformation(self): def test_05_notifyNodeInformation(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION) packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION)
...@@ -79,12 +79,12 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -79,12 +79,12 @@ class MasterClientHandlerTests(NeoTestBase):
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.MASTER, ('127.0.0.1', self.master_port), node_list = [(NodeTypes.MASTER, ('127.0.0.1', self.master_port),
self.app.uuid, NodeStates.DOWN),] self.app.uuid, NodeStates.DOWN),]
self.assertRaises(RuntimeError, service.handleNotifyNodeInformation, conn, packet, node_list) self.assertRaises(RuntimeError, service.notifyNodeInformation, conn, packet, node_list)
# tell the master node that it's running, nothing change # tell the master node that it's running, nothing change
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.MASTER, ('127.0.0.1', self.master_port), node_list = [(NodeTypes.MASTER, ('127.0.0.1', self.master_port),
self.app.uuid, NodeStates.RUNNING),] self.app.uuid, NodeStates.RUNNING),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.notifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify about a client node, don't care # notify about a client node, don't care
...@@ -92,14 +92,14 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -92,14 +92,14 @@ class MasterClientHandlerTests(NeoTestBase):
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.CLIENT, ('127.0.0.1', self.client_port), node_list = [(NodeTypes.CLIENT, ('127.0.0.1', self.client_port),
new_uuid, NodeStates.BROKEN),] new_uuid, NodeStates.BROKEN),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.notifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify about an unknown node, don't care # notify about an unknown node, don't care
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.STORAGE, ('127.0.0.1', 11010), new_uuid, node_list = [(NodeTypes.STORAGE, ('127.0.0.1', 11010), new_uuid,
NodeStates.BROKEN),] NodeStates.BROKEN),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.notifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify about a known node but with bad address, don't care # notify about a known node but with bad address, don't care
...@@ -109,14 +109,14 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -109,14 +109,14 @@ class MasterClientHandlerTests(NeoTestBase):
) )
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.STORAGE, ('127.0.0.1', 11012), uuid, NodeStates.BROKEN),] node_list = [(NodeTypes.STORAGE, ('127.0.0.1', 11012), uuid, NodeStates.BROKEN),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.notifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify node is running, as PMN already know it, nothing is done # notify node is running, as PMN already know it, nothing is done
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.STORAGE, ('127.0.0.1', self.storage_port), uuid, node_list = [(NodeTypes.STORAGE, ('127.0.0.1', self.storage_port), uuid,
NodeStates.RUNNING),] NodeStates.RUNNING),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.notifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify node is temp down, must be taken into account # notify node is temp down, must be taken into account
...@@ -124,7 +124,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -124,7 +124,7 @@ class MasterClientHandlerTests(NeoTestBase):
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.STORAGE, ('127.0.0.1', self.storage_port), uuid, node_list = [(NodeTypes.STORAGE, ('127.0.0.1', self.storage_port), uuid,
NodeStates.TEMPORARILY_DOWN),] NodeStates.TEMPORARILY_DOWN),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.notifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
sn = self.app.nm.getStorageList()[0] sn = self.app.nm.getStorageList()[0]
...@@ -134,7 +134,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -134,7 +134,7 @@ class MasterClientHandlerTests(NeoTestBase):
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.STORAGE, ('127.0.0.1', self.storage_port), uuid, node_list = [(NodeTypes.STORAGE, ('127.0.0.1', self.storage_port), uuid,
NodeStates.BROKEN),] NodeStates.BROKEN),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.notifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
sn = self.app.nm.getStorageList()[0] sn = self.app.nm.getStorageList()[0]
...@@ -142,7 +142,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -142,7 +142,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.failUnless(ptid < self.app.pt.getID()) self.failUnless(ptid < self.app.pt.getID())
def test_06_handleAnswerLastIDs(self): def test_06_answerLastIDs(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS) packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
...@@ -153,7 +153,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -153,7 +153,7 @@ class MasterClientHandlerTests(NeoTestBase):
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port) client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
node_list = [] node_list = []
self.checkUnexpectedPacketRaised(service.handleAnswerLastIDs, conn, packet, None, None, None) self.checkUnexpectedPacketRaised(service.answerLastIDs, conn, packet, None, None, None)
self.assertEquals(loid, self.app.loid) self.assertEquals(loid, self.app.loid)
self.assertEquals(ltid, self.app.ltid) self.assertEquals(ltid, self.app.ltid)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
...@@ -163,13 +163,13 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -163,13 +163,13 @@ class MasterClientHandlerTests(NeoTestBase):
new_ptid = unpack('!Q', lptid)[0] new_ptid = unpack('!Q', lptid)[0]
new_ptid = pack('!Q', new_ptid + 1) new_ptid = pack('!Q', new_ptid + 1)
self.failUnless(new_ptid > self.app.pt.getID()) self.failUnless(new_ptid > self.app.pt.getID())
self.assertRaises(OperationFailure, service.handleAnswerLastIDs, conn, packet, None, None, new_ptid) self.assertRaises(OperationFailure, service.answerLastIDs, conn, packet, None, None, new_ptid)
self.assertEquals(loid, self.app.loid) self.assertEquals(loid, self.app.loid)
self.assertEquals(ltid, self.app.ltid) self.assertEquals(ltid, self.app.ltid)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
def test_07_handleAskBeginTransaction(self): def test_07_askBeginTransaction(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ASK_BEGIN_TRANSACTION) packet = Packet(msg_type=PacketTypes.ASK_BEGIN_TRANSACTION)
...@@ -177,14 +177,14 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -177,14 +177,14 @@ class MasterClientHandlerTests(NeoTestBase):
# client call it # client call it
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port) client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
service.handleAskBeginTransaction(conn, packet, None) service.askBeginTransaction(conn, packet, None)
self.failUnless(ltid < self.app.ltid) self.failUnless(ltid < self.app.ltid)
self.assertEquals(len(self.app.finishing_transaction_dict), 1) self.assertEquals(len(self.app.finishing_transaction_dict), 1)
tid = self.app.finishing_transaction_dict.keys()[0] tid = self.app.finishing_transaction_dict.keys()[0]
self.assertEquals(tid, self.app.ltid) self.assertEquals(tid, self.app.ltid)
def test_08_handleAskNewOIDs(self): def test_08_askNewOIDs(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ASK_NEW_OIDS) packet = Packet(msg_type=PacketTypes.ASK_NEW_OIDS)
...@@ -192,10 +192,10 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -192,10 +192,10 @@ class MasterClientHandlerTests(NeoTestBase):
# client call it # client call it
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port) client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
service.handleAskNewOIDs(conn, packet, 1) service.askNewOIDs(conn, packet, 1)
self.failUnless(loid < self.app.loid) self.failUnless(loid < self.app.loid)
def test_09_handleFinishTransaction(self): def test_09_finishTransaction(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.FINISH_TRANSACTION) packet = Packet(msg_type=PacketTypes.FINISH_TRANSACTION)
...@@ -206,7 +206,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -206,7 +206,7 @@ class MasterClientHandlerTests(NeoTestBase):
oid_list = [] oid_list = []
upper, lower = unpack('!LL', self.app.ltid) upper, lower = unpack('!LL', self.app.ltid)
new_tid = pack('!LL', upper, lower + 10) new_tid = pack('!LL', upper, lower + 10)
self.checkUnexpectedPacketRaised(service.handleFinishTransaction, conn, packet, oid_list, new_tid) self.checkUnexpectedPacketRaised(service.finishTransaction, conn, packet, oid_list, new_tid)
old_node = self.app.nm.getByUUID(uuid) old_node = self.app.nm.getByUUID(uuid)
self.app.nm.remove(old_node) self.app.nm.remove(old_node)
self.app.pt.dropNode(old_node) self.app.pt.dropNode(old_node)
...@@ -217,12 +217,12 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -217,12 +217,12 @@ class MasterClientHandlerTests(NeoTestBase):
storage_conn = self.getFakeConnection(storage_uuid, self.storage_address) storage_conn = self.getFakeConnection(storage_uuid, self.storage_address)
self.assertNotEquals(uuid, client_uuid) self.assertNotEquals(uuid, client_uuid)
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
service.handleAskBeginTransaction(conn, packet, None) service.askBeginTransaction(conn, packet, None)
oid_list = [] oid_list = []
tid = self.app.ltid tid = self.app.ltid
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
self.app.em = Mock({"getConnectionList" : [conn, storage_conn]}) self.app.em = Mock({"getConnectionList" : [conn, storage_conn]})
service.handleFinishTransaction(conn, packet, oid_list, tid) service.finishTransaction(conn, packet, oid_list, tid)
self.checkLockInformation(storage_conn) self.checkLockInformation(storage_conn)
self.assertEquals(len(self.app.finishing_transaction_dict), 1) self.assertEquals(len(self.app.finishing_transaction_dict), 1)
apptid = self.app.finishing_transaction_dict.keys()[0] apptid = self.app.finishing_transaction_dict.keys()[0]
...@@ -233,7 +233,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -233,7 +233,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEquals(txn.getMessageId(), 9) self.assertEquals(txn.getMessageId(), 9)
def test_11_handleAbortTransaction(self): def test_11_abortTransaction(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ABORT_TRANSACTION) packet = Packet(msg_type=PacketTypes.ABORT_TRANSACTION)
...@@ -241,18 +241,18 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -241,18 +241,18 @@ class MasterClientHandlerTests(NeoTestBase):
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port) client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
self.assertEqual(len(self.app.finishing_transaction_dict.keys()), 0) self.assertEqual(len(self.app.finishing_transaction_dict.keys()), 0)
service.handleAbortTransaction(conn, packet, None) service.abortTransaction(conn, packet, None)
self.assertEqual(len(self.app.finishing_transaction_dict.keys()), 0) self.assertEqual(len(self.app.finishing_transaction_dict.keys()), 0)
# give a known tid # give a known tid
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
tid = self.app.ltid tid = self.app.ltid
self.app.finishing_transaction_dict[tid] = None self.app.finishing_transaction_dict[tid] = None
self.assertEqual(len(self.app.finishing_transaction_dict.keys()), 1) self.assertEqual(len(self.app.finishing_transaction_dict.keys()), 1)
service.handleAbortTransaction(conn, packet, tid) service.abortTransaction(conn, packet, tid)
self.assertEqual(len(self.app.finishing_transaction_dict.keys()), 0) self.assertEqual(len(self.app.finishing_transaction_dict.keys()), 0)
def test_12_handleAskLastIDs(self): def test_12_askLastIDs(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ASK_LAST_IDS) packet = Packet(msg_type=PacketTypes.ASK_LAST_IDS)
...@@ -261,7 +261,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -261,7 +261,7 @@ class MasterClientHandlerTests(NeoTestBase):
ptid = self.app.pt.getID() ptid = self.app.pt.getID()
self.app.ltid = '\1' * 8 self.app.ltid = '\1' * 8
self.app.loid = '\1' * 8 self.app.loid = '\1' * 8
service.handleAskLastIDs(conn, packet) service.askLastIDs(conn, packet)
packet = self.checkAnswerLastIDs(conn, answered_packet=packet) packet = self.checkAnswerLastIDs(conn, answered_packet=packet)
loid, ltid, lptid = protocol._decodeAnswerLastIDs(packet._body) loid, ltid, lptid = protocol._decodeAnswerLastIDs(packet._body)
self.assertEqual(loid, self.app.loid) self.assertEqual(loid, self.app.loid)
...@@ -269,13 +269,13 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -269,13 +269,13 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEqual(lptid, ptid) self.assertEqual(lptid, ptid)
def test_13_handleAskUnfinishedTransactions(self): def test_13_askUnfinishedTransactions(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ASK_UNFINISHED_TRANSACTIONS) packet = Packet(msg_type=PacketTypes.ASK_UNFINISHED_TRANSACTIONS)
# give a uuid # give a uuid
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
service.handleAskUnfinishedTransactions(conn, packet) service.askUnfinishedTransactions(conn, packet)
packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet) packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet)
tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0] tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0]
self.assertEqual(len(tid_list), 0) self.assertEqual(len(tid_list), 0)
...@@ -283,11 +283,11 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -283,11 +283,11 @@ class MasterClientHandlerTests(NeoTestBase):
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
port=self.client_port) port=self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
service.handleAskBeginTransaction(conn, packet, None) service.askBeginTransaction(conn, packet, None)
service.handleAskBeginTransaction(conn, packet, None) service.askBeginTransaction(conn, packet, None)
service.handleAskBeginTransaction(conn, packet, None) service.askBeginTransaction(conn, packet, None)
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
service.handleAskUnfinishedTransactions(conn, packet) service.askUnfinishedTransactions(conn, packet)
packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet) packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet)
tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0] tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0]
self.assertEqual(len(tid_list), 3) self.assertEqual(len(tid_list), 3)
...@@ -324,9 +324,9 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -324,9 +324,9 @@ class MasterClientHandlerTests(NeoTestBase):
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
packet = Packet(msg_type=ASK_BEGIN_TRANSACTION) packet = Packet(msg_type=ASK_BEGIN_TRANSACTION)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(), self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING) NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
...@@ -368,9 +368,9 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -368,9 +368,9 @@ class MasterClientHandlerTests(NeoTestBase):
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
packet = Packet(msg_type=ASK_BEGIN_TRANSACTION) packet = Packet(msg_type=ASK_BEGIN_TRANSACTION)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(), self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING) NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
...@@ -412,9 +412,9 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -412,9 +412,9 @@ class MasterClientHandlerTests(NeoTestBase):
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
packet = Packet(msg_type=ASK_BEGIN_TRANSACTION) packet = Packet(msg_type=ASK_BEGIN_TRANSACTION)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(), self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING) NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
......
...@@ -112,7 +112,7 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -112,7 +112,7 @@ class MasterClientElectionTests(NeoTestBase):
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.TEMPORARILY_DOWN) NodeStates.TEMPORARILY_DOWN)
def test_11_handleAskPrimaryMaster(self): def test_11_askPrimaryMaster(self):
election = self.election election = self.election
uuid = self.identifyToMasterNode(port=self.master_port) uuid = self.identifyToMasterNode(port=self.master_port)
packet = protocol.askPrimaryMaster() packet = protocol.askPrimaryMaster()
...@@ -122,12 +122,12 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -122,12 +122,12 @@ class MasterClientElectionTests(NeoTestBase):
"getConnector": Mock(), "getConnector": Mock(),
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
self.assertEqual(len(self.app.nm.getMasterList()), 2) self.assertEqual(len(self.app.nm.getMasterList()), 2)
election.handleAskPrimaryMaster(conn, packet) election.askPrimaryMaster(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1) self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0) self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.checkAnswerPrimaryMaster(conn) self.checkAnswerPrimaryMaster(conn)
def test_09_handleAnswerPrimaryMaster1(self): def test_09_answerPrimaryMaster1(self):
# test with master node and greater uuid # test with master node and greater uuid
uuid = self.getNewUUID() uuid = self.getNewUUID()
if uuid < self.app.uuid: if uuid < self.app.uuid:
...@@ -140,7 +140,7 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -140,7 +140,7 @@ class MasterClientElectionTests(NeoTestBase):
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(len(self.app.nm.getMasterList()), 1) self.assertEqual(len(self.app.nm.getMasterList()), 1)
self.election.handleAnswerPrimaryMaster(conn, p, INVALID_UUID, []) self.election.answerPrimaryMaster(conn, p, INVALID_UUID, [])
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(self.app.primary, False) self.assertEqual(self.app.primary, False)
self.assertEqual(len(self.app.nm.getMasterList()), 1) self.assertEqual(len(self.app.nm.getMasterList()), 1)
...@@ -148,7 +148,7 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -148,7 +148,7 @@ class MasterClientElectionTests(NeoTestBase):
self.assertEqual(len(self.app.negotiating_master_node_set), 0) self.assertEqual(len(self.app.negotiating_master_node_set), 0)
def test_09_handleAnswerPrimaryMaster2(self): def test_09_answerPrimaryMaster2(self):
# test with master node and lesser uuid # test with master node and lesser uuid
uuid = self.getNewUUID() uuid = self.getNewUUID()
if uuid > self.app.uuid: if uuid > self.app.uuid:
...@@ -161,7 +161,7 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -161,7 +161,7 @@ class MasterClientElectionTests(NeoTestBase):
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(len(self.app.nm.getMasterList()), 1) self.assertEqual(len(self.app.nm.getMasterList()), 1)
self.election.handleAnswerPrimaryMaster(conn, p, INVALID_UUID, []) self.election.answerPrimaryMaster(conn, p, INVALID_UUID, [])
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(self.app.primary, None) self.assertEqual(self.app.primary, None)
self.assertEqual(len(self.app.nm.getMasterList()), 1) self.assertEqual(len(self.app.nm.getMasterList()), 1)
...@@ -169,7 +169,7 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -169,7 +169,7 @@ class MasterClientElectionTests(NeoTestBase):
self.assertEqual(len(self.app.negotiating_master_node_set), 0) self.assertEqual(len(self.app.negotiating_master_node_set), 0)
def test_09_handleAnswerPrimaryMaster3(self): def test_09_answerPrimaryMaster3(self):
# test with master node and given uuid for PMN # test with master node and given uuid for PMN
uuid = self.getNewUUID() uuid = self.getNewUUID()
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
...@@ -182,7 +182,7 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -182,7 +182,7 @@ class MasterClientElectionTests(NeoTestBase):
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(len(self.app.nm.getMasterList()), 2) self.assertEqual(len(self.app.nm.getMasterList()), 2)
self.assertEqual(self.app.primary_master_node, None) self.assertEqual(self.app.primary_master_node, None)
self.election.handleAnswerPrimaryMaster(conn, p, uuid, []) self.election.answerPrimaryMaster(conn, p, uuid, [])
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(len(self.app.nm.getMasterList()), 2) self.assertEqual(len(self.app.nm.getMasterList()), 2)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
...@@ -191,7 +191,7 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -191,7 +191,7 @@ class MasterClientElectionTests(NeoTestBase):
self.assertEqual(self.app.primary, False) self.assertEqual(self.app.primary, False)
def test_09_handleAnswerPrimaryMaster4(self): def test_09_answerPrimaryMaster4(self):
# test with master node and unknown uuid for PMN # test with master node and unknown uuid for PMN
uuid = self.getNewUUID() uuid = self.getNewUUID()
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
...@@ -203,7 +203,7 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -203,7 +203,7 @@ class MasterClientElectionTests(NeoTestBase):
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(len(self.app.nm.getMasterList()), 1) self.assertEqual(len(self.app.nm.getMasterList()), 1)
self.assertEqual(self.app.primary_master_node, None) self.assertEqual(self.app.primary_master_node, None)
self.election.handleAnswerPrimaryMaster(conn, p, uuid, []) self.election.answerPrimaryMaster(conn, p, uuid, [])
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(len(self.app.nm.getMasterList()), 1) self.assertEqual(len(self.app.nm.getMasterList()), 1)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
...@@ -212,7 +212,7 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -212,7 +212,7 @@ class MasterClientElectionTests(NeoTestBase):
self.assertEqual(self.app.primary, None) self.assertEqual(self.app.primary, None)
def test_09_handleAnswerPrimaryMaster5(self): def test_09_answerPrimaryMaster5(self):
# test with master node and new uuid for PMN # test with master node and new uuid for PMN
uuid = self.getNewUUID() uuid = self.getNewUUID()
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
...@@ -226,7 +226,7 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -226,7 +226,7 @@ class MasterClientElectionTests(NeoTestBase):
self.assertEqual(len(self.app.nm.getMasterList()), 2) self.assertEqual(len(self.app.nm.getMasterList()), 2)
self.assertEqual(self.app.primary_master_node, None) self.assertEqual(self.app.primary_master_node, None)
master_uuid = self.getNewUUID() master_uuid = self.getNewUUID()
self.election.handleAnswerPrimaryMaster(conn, p, master_uuid, self.election.answerPrimaryMaster(conn, p, master_uuid,
[(("127.0.0.1", self.master_port+1), master_uuid,)]) [(("127.0.0.1", self.master_port+1), master_uuid,)])
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.assertEqual(len(self.app.nm.getMasterList()), 3) self.assertEqual(len(self.app.nm.getMasterList()), 3)
...@@ -235,7 +235,7 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -235,7 +235,7 @@ class MasterClientElectionTests(NeoTestBase):
self.assertNotEqual(self.app.primary_master_node, None) self.assertNotEqual(self.app.primary_master_node, None)
self.assertEqual(self.app.primary, False) self.assertEqual(self.app.primary, False)
# Now tell it's another node which is primary, it must raise # Now tell it's another node which is primary, it must raise
self.assertRaises(ElectionFailure, self.election.handleAnswerPrimaryMaster, conn, p, uuid, []) self.assertRaises(ElectionFailure, self.election.answerPrimaryMaster, conn, p, uuid, [])
...@@ -369,7 +369,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -369,7 +369,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING) NodeStates.RUNNING)
def test_08_handleAcceptNodeIdentification1(self): def test_08_acceptNodeIdentification1(self):
# test with storage node, must be rejected # test with storage node, must be rejected
uuid = self.getNewUUID() uuid = self.getNewUUID()
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
...@@ -382,7 +382,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -382,7 +382,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getUUID(), None) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getUUID(), None)
self.assertEqual(conn.getUUID(), None) self.assertEqual(conn.getUUID(), None)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.election.handleAcceptNodeIdentification(conn, p, NodeTypes.STORAGE, self.election.acceptNodeIdentification(conn, p, NodeTypes.STORAGE,
uuid, "127.0.0.1", self.master_port, uuid, "127.0.0.1", self.master_port,
self.app.pt.getPartitions(), self.app.pt.getPartitions(),
self.app.pt.getReplicas(), self.app.pt.getReplicas(),
...@@ -392,7 +392,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -392,7 +392,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 0) self.assertEqual(len(self.app.negotiating_master_node_set), 0)
def test_08_handleAcceptNodeIdentification2(self): def test_08_acceptNodeIdentification2(self):
# test with bad address, must be rejected # test with bad address, must be rejected
uuid = self.getNewUUID() uuid = self.getNewUUID()
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
...@@ -405,14 +405,14 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -405,14 +405,14 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getUUID(), None) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getUUID(), None)
self.assertEqual(conn.getUUID(), None) self.assertEqual(conn.getUUID(), None)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.election.handleAcceptNodeIdentification(conn, p, NodeTypes.STORAGE, self.election.acceptNodeIdentification(conn, p, NodeTypes.STORAGE,
uuid, ("127.0.0.2", self.master_port), uuid, ("127.0.0.2", self.master_port),
self.app.pt.getPartitions(), self.app.pt.getPartitions(),
self.app.pt.getReplicas(), self.app.pt.getReplicas(),
self.app.uuid) self.app.uuid)
self.assertEqual(conn.getConnector(), None) self.assertEqual(conn.getConnector(), None)
def test_08_handleAcceptNodeIdentification3(self): def test_08_acceptNodeIdentification3(self):
# test with master node, must be ok # test with master node, must be ok
uuid = self.getNewUUID() uuid = self.getNewUUID()
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
...@@ -426,7 +426,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -426,7 +426,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(conn.getUUID(), None) self.assertEqual(conn.getUUID(), None)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.election.handleAcceptNodeIdentification(conn, p, NodeTypes.MASTER, self.election.acceptNodeIdentification(conn, p, NodeTypes.MASTER,
uuid, ("127.0.0.1", self.master_port), uuid, ("127.0.0.1", self.master_port),
self.app.pt.getPartitions(), self.app.pt.getPartitions(),
self.app.pt.getReplicas(), self.app.pt.getReplicas(),
...@@ -437,7 +437,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -437,7 +437,7 @@ class MasterServerElectionTests(NeoTestBase):
self.checkCalledAskPrimaryMaster(conn.getConnector(), 1) self.checkCalledAskPrimaryMaster(conn.getConnector(), 1)
def test_10_handleRequestNodeIdentification(self): def test_10_requestNodeIdentification(self):
election = self.election election = self.election
uuid = self.getNewUUID() uuid = self.getNewUUID()
args = (NodeTypes.MASTER, uuid, ('127.0.0.1', self.storage_port), args = (NodeTypes.MASTER, uuid, ('127.0.0.1', self.storage_port),
...@@ -447,7 +447,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -447,7 +447,7 @@ class MasterServerElectionTests(NeoTestBase):
conn = Mock({"_addPacket" : None, "abort" : None, conn = Mock({"_addPacket" : None, "abort" : None,
"isServer" : True}) "isServer" : True})
self.checkProtocolErrorRaised( self.checkProtocolErrorRaised(
election.handleRequestNodeIdentification, election.requestNodeIdentification,
conn, conn,
packet=packet, packet=packet,
node_type=NodeTypes.MASTER, node_type=NodeTypes.MASTER,
...@@ -458,7 +458,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -458,7 +458,7 @@ class MasterServerElectionTests(NeoTestBase):
conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None, conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None,
"isServer" : True}) "isServer" : True})
self.checkNotReadyErrorRaised( self.checkNotReadyErrorRaised(
election.handleRequestNodeIdentification, election.requestNodeIdentification,
conn, conn,
packet=packet, packet=packet,
node_type=NodeTypes.STORAGE, node_type=NodeTypes.STORAGE,
...@@ -473,7 +473,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -473,7 +473,7 @@ class MasterServerElectionTests(NeoTestBase):
node = self.app.nm.getMasterList()[0] node = self.app.nm.getMasterList()[0]
self.assertEqual(node.getUUID(), None) self.assertEqual(node.getUUID(), None)
self.assertEqual(node.getState(), NodeStates.RUNNING) self.assertEqual(node.getState(), NodeStates.RUNNING)
election.handleRequestNodeIdentification(conn, election.requestNodeIdentification(conn,
packet=packet, packet=packet,
node_type=NodeTypes.MASTER, node_type=NodeTypes.MASTER,
uuid=uuid, uuid=uuid,
...@@ -490,7 +490,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -490,7 +490,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(len(self.app.nm.getMasterList()), 1) self.assertEqual(len(self.app.nm.getMasterList()), 1)
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)
election.handleRequestNodeIdentification(conn, election.requestNodeIdentification(conn,
packet=packet, packet=packet,
node_type=NodeTypes.MASTER, node_type=NodeTypes.MASTER,
uuid=new_uuid, uuid=new_uuid,
...@@ -510,7 +510,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -510,7 +510,7 @@ class MasterServerElectionTests(NeoTestBase):
node.setState(NodeStates.BROKEN) node.setState(NodeStates.BROKEN)
self.assertEqual(node.getState(), NodeStates.BROKEN) self.assertEqual(node.getState(), NodeStates.BROKEN)
self.checkBrokenNodeDisallowedErrorRaised( self.checkBrokenNodeDisallowedErrorRaised(
election.handleRequestNodeIdentification, election.requestNodeIdentification,
conn, conn,
packet=packet, packet=packet,
node_type=NodeTypes.MASTER, node_type=NodeTypes.MASTER,
...@@ -520,7 +520,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -520,7 +520,7 @@ class MasterServerElectionTests(NeoTestBase):
name=self.app.name,) name=self.app.name,)
def test_12_handleAnnouncePrimaryMaster(self): def test_12_announcePrimaryMaster(self):
election = self.election election = self.election
uuid = self.identifyToMasterNode(port=self.master_port) uuid = self.identifyToMasterNode(port=self.master_port)
packet = Packet(msg_type=PacketTypes.ANNOUNCE_PRIMARY_MASTER) packet = Packet(msg_type=PacketTypes.ANNOUNCE_PRIMARY_MASTER)
...@@ -530,7 +530,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -530,7 +530,7 @@ class MasterServerElectionTests(NeoTestBase):
"isServer" : 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.getMasterList()), 1) self.assertEqual(len(self.app.nm.getMasterList()), 1)
self.checkIdenficationRequired(election.handleAnnouncePrimaryMaster, conn, packet) self.checkIdenficationRequired(election.announcePrimaryMaster, conn, packet)
# announce # announce
conn = Mock({"_addPacket" : None, conn = Mock({"_addPacket" : None,
"getUUID" : uuid, "getUUID" : uuid,
...@@ -538,7 +538,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -538,7 +538,7 @@ class MasterServerElectionTests(NeoTestBase):
"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)
election.handleAnnouncePrimaryMaster(conn, packet) election.announcePrimaryMaster(conn, packet)
self.assertEqual(self.app.primary, False) self.assertEqual(self.app.primary, False)
self.assertNotEqual(self.app.primary_master_node, None) self.assertNotEqual(self.app.primary_master_node, None)
# set current as primary, and announce another, must raise # set current as primary, and announce another, must raise
...@@ -548,10 +548,10 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -548,10 +548,10 @@ class MasterServerElectionTests(NeoTestBase):
"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)
self.assertRaises(ElectionFailure, election.handleAnnouncePrimaryMaster, conn, packet) self.assertRaises(ElectionFailure, election.announcePrimaryMaster, conn, packet)
def test_13_handleReelectPrimaryMaster(self): def test_13_reelectPrimaryMaster(self):
election = self.election election = self.election
uuid = self.identifyToMasterNode(port=self.master_port) uuid = self.identifyToMasterNode(port=self.master_port)
packet = protocol.askPrimaryMaster() packet = protocol.askPrimaryMaster()
...@@ -560,9 +560,9 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -560,9 +560,9 @@ class MasterServerElectionTests(NeoTestBase):
"getUUID" : None, "getUUID" : None,
"isServer" : 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.reelectPrimaryMaster, conn, packet)
def test_14_handleNotifyNodeInformation(self): def test_14_notifyNodeInformation(self):
election = self.election election = self.election
uuid = self.identifyToMasterNode(port=self.master_port) uuid = self.identifyToMasterNode(port=self.master_port)
packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION) packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION)
...@@ -570,7 +570,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -570,7 +570,7 @@ class MasterServerElectionTests(NeoTestBase):
conn = Mock({"getUUID" : None, conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
node_list = [] node_list = []
self.checkIdenficationRequired(election.handleNotifyNodeInformation, conn, packet, node_list) self.checkIdenficationRequired(election.notifyNodeInformation, conn, packet, node_list)
# tell the master node about itself, must do nothing # tell the master node about itself, must do nothing
conn = Mock({"getUUID" : uuid, conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
...@@ -578,7 +578,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -578,7 +578,7 @@ class MasterServerElectionTests(NeoTestBase):
self.app.uuid, NodeStates.DOWN),] self.app.uuid, NodeStates.DOWN),]
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1))
self.assertEqual(node, None) self.assertEqual(node, None)
election.handleNotifyNodeInformation(conn, packet, node_list) election.notifyNodeInformation(conn, packet, node_list)
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1))
self.assertEqual(node, None) self.assertEqual(node, None)
# tell about a storage node, do nothing # tell about a storage node, do nothing
...@@ -587,7 +587,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -587,7 +587,7 @@ class MasterServerElectionTests(NeoTestBase):
node_list = [(NodeTypes.STORAGE, ('127.0.0.1', self.master_port - 1), node_list = [(NodeTypes.STORAGE, ('127.0.0.1', self.master_port - 1),
self.getNewUUID(), NodeStates.DOWN),] self.getNewUUID(), NodeStates.DOWN),]
self.assertEqual(len(self.app.nm.getStorageList()), 0) self.assertEqual(len(self.app.nm.getStorageList()), 0)
election.handleNotifyNodeInformation(conn, packet, node_list) election.notifyNodeInformation(conn, packet, node_list)
self.assertEqual(len(self.app.nm.getStorageList()), 0) self.assertEqual(len(self.app.nm.getStorageList()), 0)
# tell about a client node, do nothing # tell about a client node, do nothing
conn = Mock({"getUUID" : uuid, conn = Mock({"getUUID" : uuid,
...@@ -595,7 +595,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -595,7 +595,7 @@ class MasterServerElectionTests(NeoTestBase):
node_list = [(NodeTypes.CLIENT, ('127.0.0.1', self.master_port - 1), node_list = [(NodeTypes.CLIENT, ('127.0.0.1', self.master_port - 1),
self.getNewUUID(), NodeStates.DOWN),] self.getNewUUID(), NodeStates.DOWN),]
self.assertEqual(len(self.app.nm.getNodeList()), 0) self.assertEqual(len(self.app.nm.getNodeList()), 0)
election.handleNotifyNodeInformation(conn, packet, node_list) election.notifyNodeInformation(conn, packet, node_list)
self.assertEqual(len(self.app.nm.getNodeList()), 0) self.assertEqual(len(self.app.nm.getNodeList()), 0)
# tell about another master node # tell about another master node
conn = Mock({"getUUID" : uuid, conn = Mock({"getUUID" : uuid,
...@@ -604,7 +604,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -604,7 +604,7 @@ class MasterServerElectionTests(NeoTestBase):
self.getNewUUID(), NodeStates.RUNNING),] self.getNewUUID(), NodeStates.RUNNING),]
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port+1)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port+1))
self.assertEqual(node, None) self.assertEqual(node, None)
election.handleNotifyNodeInformation(conn, packet, node_list) election.notifyNodeInformation(conn, packet, node_list)
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port+1)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port+1))
self.assertNotEqual(node, None) self.assertNotEqual(node, None)
self.assertEqual(node.getAddress(), ("127.0.0.1", self.master_port+1)) self.assertEqual(node.getAddress(), ("127.0.0.1", self.master_port+1))
...@@ -612,7 +612,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -612,7 +612,7 @@ class MasterServerElectionTests(NeoTestBase):
# tell that node is down # tell that node is down
node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port + 1, node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port + 1,
self.getNewUUID(), NodeStates.DOWN),] self.getNewUUID(), NodeStates.DOWN),]
election.handleNotifyNodeInformation(conn, packet, node_list) election.notifyNodeInformation(conn, packet, node_list)
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port+1)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port+1))
self.assertNotEqual(node, None) self.assertNotEqual(node, None)
self.assertEqual(node.getAddress(), ("127.0.0.1", self.master_port+1)) self.assertEqual(node.getAddress(), ("127.0.0.1", self.master_port+1))
......
...@@ -90,7 +90,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -90,7 +90,7 @@ class MasterRecoveryTests(NeoTestBase):
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.BROKEN) NodeStates.BROKEN)
def test_08_handleNotifyNodeInformation(self): def test_08_notifyNodeInformation(self):
recovery = self.recovery recovery = self.recovery
uuid = self.identifyToMasterNode(NodeTypes.MASTER, port=self.master_port) uuid = self.identifyToMasterNode(NodeTypes.MASTER, port=self.master_port)
packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION) packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION)
...@@ -99,7 +99,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -99,7 +99,7 @@ class MasterRecoveryTests(NeoTestBase):
node_list = [(NodeTypes.CLIENT, '127.0.0.1', self.client_port, node_list = [(NodeTypes.CLIENT, '127.0.0.1', self.client_port,
self.getNewUUID(), NodeStates.DOWN),] self.getNewUUID(), NodeStates.DOWN),]
self.assertEqual(len(self.app.nm.getList()), 0) self.assertEqual(len(self.app.nm.getList()), 0)
recovery.handleNotifyNodeInformation(conn, packet, node_list) recovery.notifyNodeInformation(conn, packet, node_list)
self.assertEqual(len(self.app.nm.getList()), 0) self.assertEqual(len(self.app.nm.getList()), 0)
# tell the master node about itself, if running must do nothing # tell the master node about itself, if running must do nothing
...@@ -108,7 +108,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -108,7 +108,7 @@ class MasterRecoveryTests(NeoTestBase):
self.app.uuid, NodeStates.RUNNING),] self.app.uuid, NodeStates.RUNNING),]
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1))
self.assertEqual(node, None) self.assertEqual(node, None)
recovery.handleNotifyNodeInformation(conn, packet, node_list) recovery.notifyNodeInformation(conn, packet, node_list)
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1))
# tell the master node about itself, if down must raise # tell the master node about itself, if down must raise
...@@ -117,14 +117,14 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -117,14 +117,14 @@ class MasterRecoveryTests(NeoTestBase):
self.app.uuid, NodeStates.DOWN),] self.app.uuid, NodeStates.DOWN),]
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1))
self.assertEqual(node, None) self.assertEqual(node, None)
self.assertRaises(RuntimeError, recovery.handleNotifyNodeInformation, conn, packet, node_list) self.assertRaises(RuntimeError, recovery.notifyNodeInformation, conn, packet, node_list)
# tell about an unknown storage node, do nothing # tell about an unknown storage node, do nothing
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.master_port - 1, node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.master_port - 1,
self.getNewUUID(), NodeStates.DOWN),] self.getNewUUID(), NodeStates.DOWN),]
self.assertEqual(len(self.app.nm.getStorageList()), 0) self.assertEqual(len(self.app.nm.getStorageList()), 0)
recovery.handleNotifyNodeInformation(conn, packet, node_list) recovery.notifyNodeInformation(conn, packet, node_list)
self.assertEqual(len(self.app.nm.getStorageList()), 0) self.assertEqual(len(self.app.nm.getStorageList()), 0)
# tell about a known node but different address # tell about a known node but different address
...@@ -133,7 +133,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -133,7 +133,7 @@ class MasterRecoveryTests(NeoTestBase):
NodeStates.DOWN),] NodeStates.DOWN),]
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port))
self.assertEqual(node.getState(), NodeStates.RUNNING) self.assertEqual(node.getState(), NodeStates.RUNNING)
recovery.handleNotifyNodeInformation(conn, packet, node_list) recovery.notifyNodeInformation(conn, packet, node_list)
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port))
self.assertEqual(node.getState(), NodeStates.RUNNING) self.assertEqual(node.getState(), NodeStates.RUNNING)
...@@ -143,12 +143,12 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -143,12 +143,12 @@ class MasterRecoveryTests(NeoTestBase):
NodeStates.DOWN),] NodeStates.DOWN),]
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port))
self.assertEqual(node.getState(), NodeStates.RUNNING) self.assertEqual(node.getState(), NodeStates.RUNNING)
recovery.handleNotifyNodeInformation(conn, packet, node_list) recovery.notifyNodeInformation(conn, packet, node_list)
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port))
self.assertEqual(node.getState(), NodeStates.DOWN) self.assertEqual(node.getState(), NodeStates.DOWN)
def test_09_handleAnswerLastIDs(self): def test_09_answerLastIDs(self):
recovery = self.recovery recovery = self.recovery
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS) packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
...@@ -168,14 +168,14 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -168,14 +168,14 @@ class MasterRecoveryTests(NeoTestBase):
self.failUnless(new_oid > self.app.loid) self.failUnless(new_oid > self.app.loid)
self.failUnless(new_tid > self.app.ltid) self.failUnless(new_tid > self.app.ltid)
self.assertEquals(self.app.target_uuid, None) self.assertEquals(self.app.target_uuid, None)
recovery.handleAnswerLastIDs(conn, packet, new_oid, new_tid, new_ptid) recovery.answerLastIDs(conn, packet, new_oid, new_tid, new_ptid)
self.assertEquals(new_oid, self.app.loid) self.assertEquals(new_oid, self.app.loid)
self.assertEquals(new_tid, self.app.ltid) self.assertEquals(new_tid, self.app.ltid)
self.assertEquals(new_ptid, self.app.pt.getID()) self.assertEquals(new_ptid, self.app.pt.getID())
self.assertEquals(self.app.target_uuid,uuid) self.assertEquals(self.app.target_uuid,uuid)
def test_10_handleAnswerPartitionTable(self): def test_10_answerPartitionTable(self):
recovery = self.recovery recovery = self.recovery
uuid = self.identifyToMasterNode(NodeTypes.MASTER, port=self.master_port) uuid = self.identifyToMasterNode(NodeTypes.MASTER, port=self.master_port)
packet = Packet(msg_type=PacketTypes.ANSWER_PARTITION_TABLE) packet = Packet(msg_type=PacketTypes.ANSWER_PARTITION_TABLE)
...@@ -188,7 +188,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -188,7 +188,7 @@ class MasterRecoveryTests(NeoTestBase):
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
self.assertEquals(state, CellStates.OUT_OF_DATE) self.assertEquals(state, CellStates.OUT_OF_DATE)
recovery.handleAnswerPartitionTable(conn, packet, None, cell_list) recovery.answerPartitionTable(conn, packet, None, cell_list)
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
self.assertEquals(state, CellStates.OUT_OF_DATE) self.assertEquals(state, CellStates.OUT_OF_DATE)
...@@ -202,7 +202,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -202,7 +202,7 @@ class MasterRecoveryTests(NeoTestBase):
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
self.assertEquals(state, CellStates.OUT_OF_DATE) self.assertEquals(state, CellStates.OUT_OF_DATE)
recovery.handleAnswerPartitionTable(conn, packet, None, cell_list) recovery.answerPartitionTable(conn, packet, None, cell_list)
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
self.assertEquals(state, CellStates.UP_TO_DATE) self.assertEquals(state, CellStates.UP_TO_DATE)
...@@ -212,7 +212,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -212,7 +212,7 @@ class MasterRecoveryTests(NeoTestBase):
offset = 1000000 offset = 1000000
self.assertFalse(self.app.pt.hasOffset(offset)) self.assertFalse(self.app.pt.hasOffset(offset))
cell_list = [(offset, ((uuid, NodeStates.DOWN,),),)] cell_list = [(offset, ((uuid, NodeStates.DOWN,),),)]
self.checkUnexpectedPacketRaised(recovery.handleAnswerPartitionTable, conn, packet, None, cell_list) self.checkUnexpectedPacketRaised(recovery.answerPartitionTable, conn, packet, None, cell_list)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -63,7 +63,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -63,7 +63,7 @@ class MasterStorageHandlerTests(NeoTestBase):
return uuid return uuid
def test_05_handleNotifyNodeInformation(self): def test_05_notifyNodeInformation(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION) packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION)
...@@ -71,12 +71,12 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -71,12 +71,12 @@ class MasterStorageHandlerTests(NeoTestBase):
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port, node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port,
self.app.uuid, NodeStates.DOWN),] self.app.uuid, NodeStates.DOWN),]
self.assertRaises(RuntimeError, service.handleNotifyNodeInformation, conn, packet, node_list) self.assertRaises(RuntimeError, service.notifyNodeInformation, conn, packet, node_list)
# tell the master node that it's running, nothing change # tell the master node that it's running, nothing change
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port, node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port,
self.app.uuid, NodeStates.RUNNING),] self.app.uuid, NodeStates.RUNNING),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.notifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify about a client node, don't care # notify about a client node, don't care
...@@ -84,14 +84,14 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -84,14 +84,14 @@ class MasterStorageHandlerTests(NeoTestBase):
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.CLIENT, '127.0.0.1', self.client_port, new_uuid, node_list = [(NodeTypes.CLIENT, '127.0.0.1', self.client_port, new_uuid,
NodeStates.BROKEN),] NodeStates.BROKEN),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.notifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify about an unknown node, don't care # notify about an unknown node, don't care
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.STORAGE, '127.0.0.1', 11010, new_uuid, node_list = [(NodeTypes.STORAGE, '127.0.0.1', 11010, new_uuid,
NodeStates.BROKEN),] NodeStates.BROKEN),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.notifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify about a known node but with bad address, don't care # notify about a known node but with bad address, don't care
...@@ -101,14 +101,14 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -101,14 +101,14 @@ class MasterStorageHandlerTests(NeoTestBase):
) )
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.STORAGE, '127.0.0.1', 11012, uuid, NodeStates.BROKEN),] node_list = [(NodeTypes.STORAGE, '127.0.0.1', 11012, uuid, NodeStates.BROKEN),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.notifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify node is running, as PMN already know it, nothing is done # notify node is running, as PMN already know it, nothing is done
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.storage_port, uuid, node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.storage_port, uuid,
NodeStates.RUNNING),] NodeStates.RUNNING),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.notifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify node is temp down, must be taken into account # notify node is temp down, must be taken into account
...@@ -116,7 +116,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -116,7 +116,7 @@ class MasterStorageHandlerTests(NeoTestBase):
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.storage_port, uuid, node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.storage_port, uuid,
NodeStates.TEMPORARILY_DOWN),] NodeStates.TEMPORARILY_DOWN),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.notifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
sn = self.app.nm.getStorageList()[0] sn = self.app.nm.getStorageList()[0]
...@@ -126,14 +126,14 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -126,14 +126,14 @@ class MasterStorageHandlerTests(NeoTestBase):
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.storage_port, uuid, node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.storage_port, uuid,
NodeStates.BROKEN),] NodeStates.BROKEN),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.notifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
sn = self.app.nm.getStorageList()[0] sn = self.app.nm.getStorageList()[0]
self.assertEquals(sn.getState(), CellStates.BROKEN) self.assertEquals(sn.getState(), CellStates.BROKEN)
self.failUnless(ptid < self.app.pt.getID()) self.failUnless(ptid < self.app.pt.getID())
def test_06_handleAnswerLastIDs(self): def test_06_answerLastIDs(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS) packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
...@@ -146,12 +146,12 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -146,12 +146,12 @@ class MasterStorageHandlerTests(NeoTestBase):
new_ptid = unpack('!Q', lptid)[0] new_ptid = unpack('!Q', lptid)[0]
new_ptid = pack('!Q', new_ptid + 1) new_ptid = pack('!Q', new_ptid + 1)
self.failUnless(new_ptid > self.app.pt.getID()) self.failUnless(new_ptid > self.app.pt.getID())
self.assertRaises(OperationFailure, service.handleAnswerLastIDs, conn, packet, None, None, new_ptid) self.assertRaises(OperationFailure, service.answerLastIDs, conn, packet, None, None, new_ptid)
self.assertEquals(loid, self.app.loid) self.assertEquals(loid, self.app.loid)
self.assertEquals(ltid, self.app.ltid) self.assertEquals(ltid, self.app.ltid)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
def test_10_handleNotifyInformationLocked(self): def test_10_notifyInformationLocked(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode(port=10020) uuid = self.identifyToMasterNode(port=10020)
packet = Packet(msg_type=PacketTypes.NOTIFY_INFORMATION_LOCKED) packet = Packet(msg_type=PacketTypes.NOTIFY_INFORMATION_LOCKED)
...@@ -160,7 +160,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -160,7 +160,7 @@ class MasterStorageHandlerTests(NeoTestBase):
oid_list = [] oid_list = []
upper, lower = unpack('!LL', self.app.ltid) upper, lower = unpack('!LL', self.app.ltid)
new_tid = pack('!LL', upper, lower + 10) new_tid = pack('!LL', upper, lower + 10)
self.checkUnexpectedPacketRaised(service.handleNotifyInformationLocked, conn, packet, new_tid) self.checkUnexpectedPacketRaised(service.notifyInformationLocked, conn, packet, new_tid)
old_node = self.app.nm.getByUUID(uuid) old_node = self.app.nm.getByUUID(uuid)
# job done through dispatch -> peerBroken # job done through dispatch -> peerBroken
self.app.nm.remove(old_node) self.app.nm.remove(old_node)
...@@ -173,28 +173,28 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -173,28 +173,28 @@ class MasterStorageHandlerTests(NeoTestBase):
storage_conn_1 = self.getFakeConnection(storage_uuid_1, ("127.0.0.1", self.storage_port)) storage_conn_1 = self.getFakeConnection(storage_uuid_1, ("127.0.0.1", self.storage_port))
storage_conn_2 = self.getFakeConnection(storage_uuid_2, ("127.0.0.1", 10022)) storage_conn_2 = self.getFakeConnection(storage_uuid_2, ("127.0.0.1", 10022))
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
# clean mock object # clean mock object
conn.mockCalledMethods = {} conn.mockCalledMethods = {}
conn.mockAllCalledMethods = [] conn.mockAllCalledMethods = []
self.app.em = Mock({"getConnectionList" : [conn, storage_conn_1, storage_conn_2]}) self.app.em = Mock({"getConnectionList" : [conn, storage_conn_1, storage_conn_2]})
oid_list = [] oid_list = []
tid = self.app.ltid tid = self.app.ltid
service.handleFinishTransaction(conn, packet, oid_list, tid) service.finishTransaction(conn, packet, oid_list, tid)
self.checkLockInformation(storage_conn_1) self.checkLockInformation(storage_conn_1)
self.checkLockInformation(storage_conn_2) self.checkLockInformation(storage_conn_2)
self.assertFalse(self.app.finishing_transaction_dict.values()[0].allLocked()) self.assertFalse(self.app.finishing_transaction_dict.values()[0].allLocked())
service.handleNotifyInformationLocked(storage_conn_1, packet, tid) service.notifyInformationLocked(storage_conn_1, packet, tid)
self.checkLockInformation(storage_conn_1) self.checkLockInformation(storage_conn_1)
self.checkLockInformation(storage_conn_2) self.checkLockInformation(storage_conn_2)
self.assertFalse(self.app.finishing_transaction_dict.values()[0].allLocked()) self.assertFalse(self.app.finishing_transaction_dict.values()[0].allLocked())
service.handleNotifyInformationLocked(storage_conn_2, packet, tid) service.notifyInformationLocked(storage_conn_2, packet, tid)
self.checkNotifyTransactionFinished(conn) self.checkNotifyTransactionFinished(conn)
self.checkLockInformation(storage_conn_1) self.checkLockInformation(storage_conn_1)
self.checkLockInformation(storage_conn_2) self.checkLockInformation(storage_conn_2)
def test_12_handleAskLastIDs(self): def test_12_askLastIDs(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ASK_LAST_IDS) packet = Packet(msg_type=PacketTypes.ASK_LAST_IDS)
...@@ -203,7 +203,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -203,7 +203,7 @@ class MasterStorageHandlerTests(NeoTestBase):
ptid = self.app.pt.getID() ptid = self.app.pt.getID()
tid = self.app.ltid tid = self.app.ltid
oid = self.app.loid oid = self.app.loid
service.handleAskLastIDs(conn, packet) service.askLastIDs(conn, packet)
packet = self.checkAnswerLastIDs(conn, answered_packet=packet) packet = self.checkAnswerLastIDs(conn, answered_packet=packet)
loid, ltid, lptid = protocol._decodeAnswerLastIDs(packet._body) loid, ltid, lptid = protocol._decodeAnswerLastIDs(packet._body)
self.assertEqual(loid, oid) self.assertEqual(loid, oid)
...@@ -211,13 +211,13 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -211,13 +211,13 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEqual(lptid, ptid) self.assertEqual(lptid, ptid)
def test_13_handleAskUnfinishedTransactions(self): def test_13_askUnfinishedTransactions(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ASK_UNFINISHED_TRANSACTIONS) packet = Packet(msg_type=PacketTypes.ASK_UNFINISHED_TRANSACTIONS)
# give a uuid # give a uuid
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
service.handleAskUnfinishedTransactions(conn, packet) service.askUnfinishedTransactions(conn, packet)
packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet) packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet)
tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0] tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0]
self.assertEqual(len(tid_list), 0) self.assertEqual(len(tid_list), 0)
...@@ -225,17 +225,17 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -225,17 +225,17 @@ class MasterStorageHandlerTests(NeoTestBase):
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
port=self.client_port) port=self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
service.handleAskUnfinishedTransactions(conn, packet) service.askUnfinishedTransactions(conn, packet)
packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet) packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet)
tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0] tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0]
self.assertEqual(len(tid_list), 3) self.assertEqual(len(tid_list), 3)
def test_14_handleNotifyPartitionChanges(self): def test_14_notifyPartitionChanges(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.NOTIFY_PARTITION_CHANGES) packet = Packet(msg_type=PacketTypes.NOTIFY_PARTITION_CHANGES)
...@@ -243,7 +243,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -243,7 +243,7 @@ class MasterStorageHandlerTests(NeoTestBase):
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
port=self.client_port) port=self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
self.checkUnexpectedPacketRaised(service.handleNotifyPartitionChanges, self.checkUnexpectedPacketRaised(service.notifyPartitionChanges,
conn, packet, None, None) conn, packet, None, None)
# send a bad state, must not be take into account # send a bad state, must not be take into account
...@@ -254,7 +254,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -254,7 +254,7 @@ class MasterStorageHandlerTests(NeoTestBase):
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
self.assertEquals(state, CellStates.OUT_OF_DATE) self.assertEquals(state, CellStates.OUT_OF_DATE)
service.handleNotifyPartitionChanges(conn, packet, self.app.pt.getID(), cell_list) service.notifyPartitionChanges(conn, packet, self.app.pt.getID(), cell_list)
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
self.assertEquals(state, CellStates.OUT_OF_DATE) self.assertEquals(state, CellStates.OUT_OF_DATE)
...@@ -266,7 +266,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -266,7 +266,7 @@ class MasterStorageHandlerTests(NeoTestBase):
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
self.assertEquals(state, CellStates.OUT_OF_DATE) self.assertEquals(state, CellStates.OUT_OF_DATE)
service.handleNotifyPartitionChanges(conn, packet, self.app.pt.getID(), cell_list) service.notifyPartitionChanges(conn, packet, self.app.pt.getID(), cell_list)
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
self.assertEquals(state, CellStates.OUT_OF_DATE) self.assertEquals(state, CellStates.OUT_OF_DATE)
...@@ -290,7 +290,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -290,7 +290,7 @@ class MasterStorageHandlerTests(NeoTestBase):
else: else:
self.assertEquals(state, CellStates.OUT_OF_DATE) self.assertEquals(state, CellStates.OUT_OF_DATE)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
service.handleNotifyPartitionChanges(conn, packet, self.app.pt.getID(), cell_list) service.notifyPartitionChanges(conn, packet, self.app.pt.getID(), cell_list)
self.failUnless(lptid < self.app.pt.getID()) self.failUnless(lptid < self.app.pt.getID())
cells = self.app.pt.getRow(offset) cells = self.app.pt.getRow(offset)
for cell, state in cells: for cell, state in cells:
...@@ -336,9 +336,9 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -336,9 +336,9 @@ class MasterStorageHandlerTests(NeoTestBase):
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
packet = Packet(msg_type=ASK_BEGIN_TRANSACTION) packet = Packet(msg_type=ASK_BEGIN_TRANSACTION)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(), self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING) NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
...@@ -385,9 +385,9 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -385,9 +385,9 @@ class MasterStorageHandlerTests(NeoTestBase):
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
packet = Packet(msg_type=ASK_BEGIN_TRANSACTION) packet = Packet(msg_type=ASK_BEGIN_TRANSACTION)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(), self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING) NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
...@@ -434,9 +434,9 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -434,9 +434,9 @@ class MasterStorageHandlerTests(NeoTestBase):
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
packet = Packet(msg_type=ASK_BEGIN_TRANSACTION) packet = Packet(msg_type=ASK_BEGIN_TRANSACTION)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.askBeginTransaction(conn, packet)
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(), self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING) NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
......
...@@ -124,7 +124,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -124,7 +124,7 @@ class MasterVerificationTests(NeoTestBase):
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.TEMPORARILY_DOWN) NodeStates.TEMPORARILY_DOWN)
def test_09_handleAnswerLastIDs(self): def test_09_answerLastIDs(self):
verification = self.verification verification = self.verification
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS) packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
...@@ -143,12 +143,12 @@ class MasterVerificationTests(NeoTestBase): ...@@ -143,12 +143,12 @@ class MasterVerificationTests(NeoTestBase):
self.failUnless(new_ptid > self.app.pt.getID()) self.failUnless(new_ptid > self.app.pt.getID())
self.failUnless(new_oid > self.app.loid) self.failUnless(new_oid > self.app.loid)
self.failUnless(new_tid > self.app.ltid) self.failUnless(new_tid > self.app.ltid)
self.assertRaises(VerificationFailure, verification.handleAnswerLastIDs, conn, packet, new_oid, new_tid, new_ptid) self.assertRaises(VerificationFailure, verification.answerLastIDs, conn, packet, new_oid, new_tid, new_ptid)
self.assertNotEquals(new_oid, self.app.loid) self.assertNotEquals(new_oid, self.app.loid)
self.assertNotEquals(new_tid, self.app.ltid) self.assertNotEquals(new_tid, self.app.ltid)
self.assertNotEquals(new_ptid, self.app.pt.getID()) self.assertNotEquals(new_ptid, self.app.pt.getID())
def test_11_handleAnswerUnfinishedTransactions(self): def test_11_answerUnfinishedTransactions(self):
verification = self.verification verification = self.verification
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ANSWER_UNFINISHED_TRANSACTIONS) packet = Packet(msg_type=PacketTypes.ANSWER_UNFINISHED_TRANSACTIONS)
...@@ -160,7 +160,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -160,7 +160,7 @@ class MasterVerificationTests(NeoTestBase):
self.assertEquals(len(self.app.unfinished_tid_set), 0) self.assertEquals(len(self.app.unfinished_tid_set), 0)
upper, lower = unpack('!LL', self.app.ltid) upper, lower = unpack('!LL', self.app.ltid)
new_tid = pack('!LL', upper, lower + 10) new_tid = pack('!LL', upper, lower + 10)
verification.handleAnswerUnfinishedTransactions(conn, packet, [new_tid]) verification.answerUnfinishedTransactions(conn, packet, [new_tid])
self.assertEquals(len(self.app.unfinished_tid_set), 0) self.assertEquals(len(self.app.unfinished_tid_set), 0)
# update dict # update dict
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
...@@ -169,13 +169,13 @@ class MasterVerificationTests(NeoTestBase): ...@@ -169,13 +169,13 @@ class MasterVerificationTests(NeoTestBase):
self.assertEquals(len(self.app.unfinished_tid_set), 0) self.assertEquals(len(self.app.unfinished_tid_set), 0)
upper, lower = unpack('!LL', self.app.ltid) upper, lower = unpack('!LL', self.app.ltid)
new_tid = pack('!LL', upper, lower + 10) new_tid = pack('!LL', upper, lower + 10)
verification.handleAnswerUnfinishedTransactions(conn, packet, [new_tid,]) verification.answerUnfinishedTransactions(conn, packet, [new_tid,])
self.assertTrue(self.app.asking_uuid_dict[uuid]) self.assertTrue(self.app.asking_uuid_dict[uuid])
self.assertEquals(len(self.app.unfinished_tid_set), 1) self.assertEquals(len(self.app.unfinished_tid_set), 1)
self.assertTrue(new_tid in self.app.unfinished_tid_set) self.assertTrue(new_tid in self.app.unfinished_tid_set)
def test_12_handleAnswerTransactionInformation(self): def test_12_answerTransactionInformation(self):
verification = self.verification verification = self.verification
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ANSWER_TRANSACTION_INFORMATION) packet = Packet(msg_type=PacketTypes.ANSWER_TRANSACTION_INFORMATION)
...@@ -189,7 +189,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -189,7 +189,7 @@ class MasterVerificationTests(NeoTestBase):
new_tid = pack('!LL', upper, lower + 10) new_tid = pack('!LL', upper, lower + 10)
oid = unpack('!Q', self.app.loid)[0] oid = unpack('!Q', self.app.loid)[0]
new_oid = pack('!Q', oid + 1) new_oid = pack('!Q', oid + 1)
verification.handleAnswerTransactionInformation(conn, packet, new_tid, verification.answerTransactionInformation(conn, packet, new_tid,
"user", "desc", "ext", [new_oid,]) "user", "desc", "ext", [new_oid,])
self.assertEquals(self.app.unfinished_oid_set, None) self.assertEquals(self.app.unfinished_oid_set, None)
# do nothing as asking_uuid_dict is True # do nothing as asking_uuid_dict is True
...@@ -199,7 +199,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -199,7 +199,7 @@ class MasterVerificationTests(NeoTestBase):
self.app.unfinished_oid_set = set() self.app.unfinished_oid_set = set()
self.assertTrue(self.app.asking_uuid_dict.has_key(uuid)) self.assertTrue(self.app.asking_uuid_dict.has_key(uuid))
self.assertEquals(len(self.app.unfinished_oid_set), 0) self.assertEquals(len(self.app.unfinished_oid_set), 0)
verification.handleAnswerTransactionInformation(conn, packet, new_tid, verification.answerTransactionInformation(conn, packet, new_tid,
"user", "desc", "ext", [new_oid,]) "user", "desc", "ext", [new_oid,])
self.assertEquals(len(self.app.unfinished_oid_set), 0) self.assertEquals(len(self.app.unfinished_oid_set), 0)
# do work # do work
...@@ -208,7 +208,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -208,7 +208,7 @@ class MasterVerificationTests(NeoTestBase):
self.app.asking_uuid_dict[uuid] = False self.app.asking_uuid_dict[uuid] = False
self.assertTrue(self.app.asking_uuid_dict.has_key(uuid)) self.assertTrue(self.app.asking_uuid_dict.has_key(uuid))
self.assertEquals(len(self.app.unfinished_oid_set), 0) self.assertEquals(len(self.app.unfinished_oid_set), 0)
verification.handleAnswerTransactionInformation(conn, packet, new_tid, verification.answerTransactionInformation(conn, packet, new_tid,
"user", "desc", "ext", [new_oid,]) "user", "desc", "ext", [new_oid,])
self.assertEquals(len(self.app.unfinished_oid_set), 1) self.assertEquals(len(self.app.unfinished_oid_set), 1)
self.assertTrue(new_oid in self.app.unfinished_oid_set) self.assertTrue(new_oid in self.app.unfinished_oid_set)
...@@ -222,11 +222,11 @@ class MasterVerificationTests(NeoTestBase): ...@@ -222,11 +222,11 @@ class MasterVerificationTests(NeoTestBase):
oid = unpack('!Q', old_oid)[0] oid = unpack('!Q', old_oid)[0]
new_oid = pack('!Q', oid + 1) new_oid = pack('!Q', oid + 1)
self.assertNotEqual(new_oid, old_oid) self.assertNotEqual(new_oid, old_oid)
verification.handleAnswerTransactionInformation(conn, packet, new_tid, verification.answerTransactionInformation(conn, packet, new_tid,
"user", "desc", "ext", [new_oid,]) "user", "desc", "ext", [new_oid,])
self.assertEquals(self.app.unfinished_oid_set, None) self.assertEquals(self.app.unfinished_oid_set, None)
def test_13_handleTidNotFound(self): def test_13_tidNotFound(self):
verification = self.verification verification = self.verification
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ErrorCodes.TID_NOT_FOUND) packet = Packet(msg_type=ErrorCodes.TID_NOT_FOUND)
...@@ -236,7 +236,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -236,7 +236,7 @@ class MasterVerificationTests(NeoTestBase):
self.app.asking_uuid_dict[uuid] = True self.app.asking_uuid_dict[uuid] = True
self.app.unfinished_oid_set = [] self.app.unfinished_oid_set = []
self.assertTrue(self.app.asking_uuid_dict.has_key(uuid)) self.assertTrue(self.app.asking_uuid_dict.has_key(uuid))
verification.handleTidNotFound(conn, packet, "msg") verification.tidNotFound(conn, packet, "msg")
self.assertNotEqual(self.app.unfinished_oid_set, None) self.assertNotEqual(self.app.unfinished_oid_set, None)
# do work as asking_uuid_dict is False # do work as asking_uuid_dict is False
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
...@@ -244,10 +244,10 @@ class MasterVerificationTests(NeoTestBase): ...@@ -244,10 +244,10 @@ class MasterVerificationTests(NeoTestBase):
self.app.asking_uuid_dict[uuid] = False self.app.asking_uuid_dict[uuid] = False
self.app.unfinished_oid_set = [] self.app.unfinished_oid_set = []
self.assertTrue(self.app.asking_uuid_dict.has_key(uuid)) self.assertTrue(self.app.asking_uuid_dict.has_key(uuid))
verification.handleTidNotFound(conn, packet, "msg") verification.tidNotFound(conn, packet, "msg")
self.assertEqual(self.app.unfinished_oid_set, None) self.assertEqual(self.app.unfinished_oid_set, None)
def test_14_handleAnswerObjectPresent(self): def test_14_answerObjectPresent(self):
verification = self.verification verification = self.verification
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ANSWER_OBJECT_PRESENT) packet = Packet(msg_type=PacketTypes.ANSWER_OBJECT_PRESENT)
...@@ -260,16 +260,16 @@ class MasterVerificationTests(NeoTestBase): ...@@ -260,16 +260,16 @@ class MasterVerificationTests(NeoTestBase):
self.assertEquals(len(self.app.asking_uuid_dict), 0) self.assertEquals(len(self.app.asking_uuid_dict), 0)
self.app.asking_uuid_dict[uuid] = True self.app.asking_uuid_dict[uuid] = True
self.assertTrue(self.app.asking_uuid_dict.has_key(uuid)) self.assertTrue(self.app.asking_uuid_dict.has_key(uuid))
verification.handleAnswerObjectPresent(conn, packet, new_oid, new_tid) verification.answerObjectPresent(conn, packet, new_oid, new_tid)
# do work # do work
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 1) self.assertEquals(len(self.app.asking_uuid_dict), 1)
self.app.asking_uuid_dict[uuid] = False self.app.asking_uuid_dict[uuid] = False
self.assertFalse(self.app.asking_uuid_dict[uuid]) self.assertFalse(self.app.asking_uuid_dict[uuid])
verification.handleAnswerObjectPresent(conn, packet, new_oid, new_tid) verification.answerObjectPresent(conn, packet, new_oid, new_tid)
self.assertTrue(self.app.asking_uuid_dict[uuid]) self.assertTrue(self.app.asking_uuid_dict[uuid])
def test_15_handleOidNotFound(self): def test_15_oidNotFound(self):
verification = self.verification verification = self.verification
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ErrorCodes.OID_NOT_FOUND) packet = Packet(msg_type=ErrorCodes.OID_NOT_FOUND)
...@@ -279,7 +279,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -279,7 +279,7 @@ class MasterVerificationTests(NeoTestBase):
self.app.asking_uuid_dict[uuid] = True self.app.asking_uuid_dict[uuid] = True
self.app.object_present = True self.app.object_present = True
self.assertTrue(self.app.object_present) self.assertTrue(self.app.object_present)
verification.handleOidNotFound(conn, packet, "msg") verification.oidNotFound(conn, packet, "msg")
self.assertTrue(self.app.object_present) self.assertTrue(self.app.object_present)
# do work as asking_uuid_dict is False # do work as asking_uuid_dict is False
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
...@@ -287,7 +287,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -287,7 +287,7 @@ class MasterVerificationTests(NeoTestBase):
self.app.asking_uuid_dict[uuid] = False self.app.asking_uuid_dict[uuid] = False
self.assertFalse(self.app.asking_uuid_dict[uuid ]) self.assertFalse(self.app.asking_uuid_dict[uuid ])
self.assertTrue(self.app.object_present) self.assertTrue(self.app.object_present)
verification.handleOidNotFound(conn, packet, "msg") verification.oidNotFound(conn, packet, "msg")
self.assertFalse(self.app.object_present) self.assertFalse(self.app.object_present)
self.assertTrue(self.app.asking_uuid_dict[uuid ]) self.assertTrue(self.app.asking_uuid_dict[uuid ])
......
...@@ -104,30 +104,30 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -104,30 +104,30 @@ class StorageClientHandlerTests(NeoTestBase):
self.assertTrue(0 not in self.app.store_lock_dict) self.assertTrue(0 not in self.app.store_lock_dict)
self.assertTrue(0 not in self.app.transaction_dict) self.assertTrue(0 not in self.app.transaction_dict)
def test_18_handleAskTransactionInformation1(self): def test_18_askTransactionInformation1(self):
# transaction does not exists # transaction does not exists
conn = Mock({ }) conn = Mock({ })
packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION) packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
self.operation.handleAskTransactionInformation(conn, packet, INVALID_TID) self.operation.askTransactionInformation(conn, packet, INVALID_TID)
self.checkErrorPacket(conn) self.checkErrorPacket(conn)
def test_18_handleAskTransactionInformation2(self): def test_18_askTransactionInformation2(self):
# answer # answer
conn = Mock({ }) conn = Mock({ })
packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION) packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
dm = Mock({ "getTransaction": (INVALID_TID, 'user', 'desc', '', ), }) dm = Mock({ "getTransaction": (INVALID_TID, 'user', 'desc', '', ), })
self.app.dm = dm self.app.dm = dm
self.operation.handleAskTransactionInformation(conn, packet, INVALID_TID) self.operation.askTransactionInformation(conn, packet, INVALID_TID)
self.checkAnswerTransactionInformation(conn) self.checkAnswerTransactionInformation(conn)
def test_24_handleAskObject1(self): def test_24_askObject1(self):
# delayed response # delayed response
conn = Mock({}) conn = Mock({})
self.app.dm = Mock() self.app.dm = Mock()
packet = Packet(msg_type=PacketTypes.ASK_OBJECT) packet = Packet(msg_type=PacketTypes.ASK_OBJECT)
self.app.load_lock_dict[INVALID_OID] = object() self.app.load_lock_dict[INVALID_OID] = object()
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.handleAskObject(conn, packet, self.operation.askObject(conn, packet,
oid=INVALID_OID, oid=INVALID_OID,
serial=INVALID_SERIAL, serial=INVALID_SERIAL,
tid=INVALID_TID) tid=INVALID_TID)
...@@ -135,13 +135,13 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -135,13 +135,13 @@ class StorageClientHandlerTests(NeoTestBase):
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
self.assertEquals(len(self.app.dm.mockGetNamedCalls('getObject')), 0) self.assertEquals(len(self.app.dm.mockGetNamedCalls('getObject')), 0)
def test_24_handleAskObject2(self): def test_24_askObject2(self):
# invalid serial / tid / packet not found # invalid serial / tid / packet not found
self.app.dm = Mock({'getObject': None}) self.app.dm = Mock({'getObject': None})
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_OBJECT) packet = Packet(msg_type=PacketTypes.ASK_OBJECT)
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.handleAskObject(conn, packet, self.operation.askObject(conn, packet,
oid=INVALID_OID, oid=INVALID_OID,
serial=INVALID_SERIAL, serial=INVALID_SERIAL,
tid=INVALID_TID) tid=INVALID_TID)
...@@ -151,83 +151,83 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -151,83 +151,83 @@ class StorageClientHandlerTests(NeoTestBase):
calls[0].checkArgs(INVALID_OID, INVALID_TID, INVALID_TID) calls[0].checkArgs(INVALID_OID, INVALID_TID, INVALID_TID)
self.checkErrorPacket(conn) self.checkErrorPacket(conn)
def test_24_handleAskObject3(self): def test_24_askObject3(self):
# object found => answer # object found => answer
self.app.dm = Mock({'getObject': ('', '', 0, 0, '', )}) self.app.dm = Mock({'getObject': ('', '', 0, 0, '', )})
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_OBJECT) packet = Packet(msg_type=PacketTypes.ASK_OBJECT)
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.handleAskObject(conn, packet, self.operation.askObject(conn, packet,
oid=INVALID_OID, oid=INVALID_OID,
serial=INVALID_SERIAL, serial=INVALID_SERIAL,
tid=INVALID_TID) tid=INVALID_TID)
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.checkAnswerObject(conn) self.checkAnswerObject(conn)
def test_25_handleAskTIDs1(self): def test_25_askTIDs1(self):
# invalid offsets => error # invalid offsets => error
app = self.app app = self.app
app.pt = Mock() app.pt = Mock()
app.dm = Mock() app.dm = Mock()
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_TIDS) packet = Packet(msg_type=PacketTypes.ASK_TIDS)
self.checkProtocolErrorRaised(self.operation.handleAskTIDs, conn, packet, 1, 1, None) self.checkProtocolErrorRaised(self.operation.askTIDs, conn, packet, 1, 1, None)
self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0) self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0)
self.assertEquals(len(app.dm.mockGetNamedCalls('getTIDList')), 0) self.assertEquals(len(app.dm.mockGetNamedCalls('getTIDList')), 0)
def test_25_handleAskTIDs2(self): def test_25_askTIDs2(self):
# well case => answer # well case => answer
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_TIDS) packet = Packet(msg_type=PacketTypes.ASK_TIDS)
self.app.pt = Mock({'getPartitions': 1}) self.app.pt = Mock({'getPartitions': 1})
self.app.dm = Mock({'getTIDList': (INVALID_TID, )}) self.app.dm = Mock({'getTIDList': (INVALID_TID, )})
self.operation.handleAskTIDs(conn, packet, 1, 2, 1) self.operation.askTIDs(conn, packet, 1, 2, 1)
calls = self.app.dm.mockGetNamedCalls('getTIDList') calls = self.app.dm.mockGetNamedCalls('getTIDList')
self.assertEquals(len(calls), 1) self.assertEquals(len(calls), 1)
calls[0].checkArgs(1, 1, 1, [1, ]) calls[0].checkArgs(1, 1, 1, [1, ])
self.checkAnswerTids(conn) self.checkAnswerTids(conn)
def test_25_handleAskTIDs3(self): def test_25_askTIDs3(self):
# invalid partition => answer usable partitions # invalid partition => answer usable partitions
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_TIDS) packet = Packet(msg_type=PacketTypes.ASK_TIDS)
cell = Mock({'getUUID':self.app.uuid}) cell = Mock({'getUUID':self.app.uuid})
self.app.dm = Mock({'getTIDList': (INVALID_TID, )}) self.app.dm = Mock({'getTIDList': (INVALID_TID, )})
self.app.pt = Mock({'getCellList': (cell, ), 'getPartitions': 1}) self.app.pt = Mock({'getCellList': (cell, ), 'getPartitions': 1})
self.operation.handleAskTIDs(conn, packet, 1, 2, INVALID_PARTITION) self.operation.askTIDs(conn, packet, 1, 2, INVALID_PARTITION)
self.assertEquals(len(self.app.pt.mockGetNamedCalls('getCellList')), 1) self.assertEquals(len(self.app.pt.mockGetNamedCalls('getCellList')), 1)
calls = self.app.dm.mockGetNamedCalls('getTIDList') calls = self.app.dm.mockGetNamedCalls('getTIDList')
self.assertEquals(len(calls), 1) self.assertEquals(len(calls), 1)
calls[0].checkArgs(1, 1, 1, [0, ]) calls[0].checkArgs(1, 1, 1, [0, ])
self.checkAnswerTids(conn) self.checkAnswerTids(conn)
def test_26_handleAskObjectHistory1(self): def test_26_askObjectHistory1(self):
# invalid offsets => error # invalid offsets => error
app = self.app app = self.app
app.dm = Mock() app.dm = Mock()
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_OBJECT_HISTORY) packet = Packet(msg_type=PacketTypes.ASK_OBJECT_HISTORY)
self.checkProtocolErrorRaised(self.operation.handleAskObjectHistory, conn, packet, 1, 1, None) self.checkProtocolErrorRaised(self.operation.askObjectHistory, conn, packet, 1, 1, None)
self.assertEquals(len(app.dm.mockGetNamedCalls('getObjectHistory')), 0) self.assertEquals(len(app.dm.mockGetNamedCalls('getObjectHistory')), 0)
def test_26_handleAskObjectHistory2(self): def test_26_askObjectHistory2(self):
# first case: empty history # first case: empty history
packet = Packet(msg_type=PacketTypes.ASK_OBJECT_HISTORY) packet = Packet(msg_type=PacketTypes.ASK_OBJECT_HISTORY)
conn = Mock({}) conn = Mock({})
self.app.dm = Mock({'getObjectHistory': None}) self.app.dm = Mock({'getObjectHistory': None})
self.operation.handleAskObjectHistory(conn, packet, INVALID_OID, 1, 2) self.operation.askObjectHistory(conn, packet, INVALID_OID, 1, 2)
self.checkAnswerObjectHistory(conn) self.checkAnswerObjectHistory(conn)
# second case: not empty history # second case: not empty history
conn = Mock({}) conn = Mock({})
self.app.dm = Mock({'getObjectHistory': [('', 0, ), ]}) self.app.dm = Mock({'getObjectHistory': [('', 0, ), ]})
self.operation.handleAskObjectHistory(conn, packet, INVALID_OID, 1, 2) self.operation.askObjectHistory(conn, packet, INVALID_OID, 1, 2)
self.checkAnswerObjectHistory(conn) self.checkAnswerObjectHistory(conn)
def test_27_handleAskStoreTransaction2(self): def test_27_askStoreTransaction2(self):
# add transaction entry # add transaction entry
packet = Packet(msg_type=PacketTypes.ASK_STORE_TRANSACTION) packet = Packet(msg_type=PacketTypes.ASK_STORE_TRANSACTION)
conn = Mock({'getUUID': self.getNewUUID()}) conn = Mock({'getUUID': self.getNewUUID()})
self.operation.handleAskStoreTransaction(conn, packet, self.operation.askStoreTransaction(conn, packet,
INVALID_TID, '', '', '', ()) INVALID_TID, '', '', '', ())
t = self.app.transaction_dict.get(INVALID_TID, None) t = self.app.transaction_dict.get(INVALID_TID, None)
self.assertNotEquals(t, None) self.assertNotEquals(t, None)
...@@ -235,7 +235,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -235,7 +235,7 @@ class StorageClientHandlerTests(NeoTestBase):
self.assertEquals(t.getTransaction(), ((), '', '', '')) self.assertEquals(t.getTransaction(), ((), '', '', ''))
self.checkAnswerStoreTransaction(conn) self.checkAnswerStoreTransaction(conn)
def test_28_handleAskStoreObject2(self): def test_28_askStoreObject2(self):
# locked => delayed response # locked => delayed response
packet = Packet(msg_type=PacketTypes.ASK_STORE_OBJECT) packet = Packet(msg_type=PacketTypes.ASK_STORE_OBJECT)
conn = Mock({'getUUID': self.app.uuid}) conn = Mock({'getUUID': self.app.uuid})
...@@ -244,7 +244,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -244,7 +244,7 @@ class StorageClientHandlerTests(NeoTestBase):
self.app.store_lock_dict[oid] = tid1 self.app.store_lock_dict[oid] = tid1
self.assertTrue(oid in self.app.store_lock_dict) self.assertTrue(oid in self.app.store_lock_dict)
t_before = self.app.transaction_dict.items()[:] t_before = self.app.transaction_dict.items()[:]
self.operation.handleAskStoreObject(conn, packet, oid, self.operation.askStoreObject(conn, packet, oid,
INVALID_SERIAL, 0, 0, '', tid2) INVALID_SERIAL, 0, 0, '', tid2)
self.assertEquals(len(self.app.event_queue), 1) self.assertEquals(len(self.app.event_queue), 1)
t_after = self.app.transaction_dict.items()[:] t_after = self.app.transaction_dict.items()[:]
...@@ -252,13 +252,13 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -252,13 +252,13 @@ class StorageClientHandlerTests(NeoTestBase):
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
self.assertTrue(oid in self.app.store_lock_dict) self.assertTrue(oid in self.app.store_lock_dict)
def test_28_handleAskStoreObject3(self): def test_28_askStoreObject3(self):
# locked => unresolvable conflict => answer # locked => unresolvable conflict => answer
packet = Packet(msg_type=PacketTypes.ASK_STORE_OBJECT) packet = Packet(msg_type=PacketTypes.ASK_STORE_OBJECT)
conn = Mock({'getUUID': self.app.uuid}) conn = Mock({'getUUID': self.app.uuid})
tid1, tid2 = self.getTwoIDs() tid1, tid2 = self.getTwoIDs()
self.app.store_lock_dict[INVALID_OID] = tid2 self.app.store_lock_dict[INVALID_OID] = tid2
self.operation.handleAskStoreObject(conn, packet, INVALID_OID, self.operation.askStoreObject(conn, packet, INVALID_OID,
INVALID_SERIAL, 0, 0, '', tid1) INVALID_SERIAL, 0, 0, '', tid1)
self.checkAnswerStoreObject(conn) self.checkAnswerStoreObject(conn)
self.assertEquals(self.app.store_lock_dict[INVALID_OID], tid2) self.assertEquals(self.app.store_lock_dict[INVALID_OID], tid2)
...@@ -266,13 +266,13 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -266,13 +266,13 @@ class StorageClientHandlerTests(NeoTestBase):
packet = conn.mockGetNamedCalls('answer')[0].getParam(0) packet = conn.mockGetNamedCalls('answer')[0].getParam(0)
self.assertTrue(unpack('!B8s8s', packet._body)[0]) self.assertTrue(unpack('!B8s8s', packet._body)[0])
def test_28_handleAskStoreObject4(self): def test_28_askStoreObject4(self):
# resolvable conflict => answer # resolvable conflict => answer
packet = Packet(msg_type=PacketTypes.ASK_STORE_OBJECT) packet = Packet(msg_type=PacketTypes.ASK_STORE_OBJECT)
conn = Mock({'getUUID': self.app.uuid}) conn = Mock({'getUUID': self.app.uuid})
self.app.dm = Mock({'getObjectHistory':((self.getNewUUID(), ), )}) self.app.dm = Mock({'getObjectHistory':((self.getNewUUID(), ), )})
self.assertEquals(self.app.store_lock_dict.get(INVALID_OID, None), None) self.assertEquals(self.app.store_lock_dict.get(INVALID_OID, None), None)
self.operation.handleAskStoreObject(conn, packet, INVALID_OID, self.operation.askStoreObject(conn, packet, INVALID_OID,
INVALID_SERIAL, 0, 0, '', INVALID_TID) INVALID_SERIAL, 0, 0, '', INVALID_TID)
self.checkAnswerStoreObject(conn) self.checkAnswerStoreObject(conn)
self.assertEquals(self.app.store_lock_dict.get(INVALID_OID, None), None) self.assertEquals(self.app.store_lock_dict.get(INVALID_OID, None), None)
...@@ -280,11 +280,11 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -280,11 +280,11 @@ class StorageClientHandlerTests(NeoTestBase):
packet = conn.mockGetNamedCalls('answer')[0].getParam(0) packet = conn.mockGetNamedCalls('answer')[0].getParam(0)
self.assertTrue(unpack('!B8s8s', packet._body)[0]) self.assertTrue(unpack('!B8s8s', packet._body)[0])
def test_28_handleAskStoreObject5(self): def test_28_askStoreObject5(self):
# no conflict => answer # no conflict => answer
packet = Packet(msg_type=PacketTypes.ASK_STORE_OBJECT) packet = Packet(msg_type=PacketTypes.ASK_STORE_OBJECT)
conn = Mock({'getUUID': self.app.uuid}) conn = Mock({'getUUID': self.app.uuid})
self.operation.handleAskStoreObject(conn, packet, INVALID_OID, self.operation.askStoreObject(conn, packet, INVALID_OID,
INVALID_SERIAL, 0, 0, '', INVALID_TID) INVALID_SERIAL, 0, 0, '', INVALID_TID)
t = self.app.transaction_dict.get(INVALID_TID, None) t = self.app.transaction_dict.get(INVALID_TID, None)
self.assertNotEquals(t, None) self.assertNotEquals(t, None)
...@@ -295,7 +295,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -295,7 +295,7 @@ class StorageClientHandlerTests(NeoTestBase):
packet = self.checkAnswerStoreObject(conn) packet = self.checkAnswerStoreObject(conn)
self.assertFalse(unpack('!B8s8s', packet._body)[0]) self.assertFalse(unpack('!B8s8s', packet._body)[0])
def test_29_handleAbortTransaction(self): def test_29_abortTransaction(self):
# remove transaction # remove transaction
packet = Packet(msg_type=PacketTypes.ABORT_TRANSACTION) packet = Packet(msg_type=PacketTypes.ABORT_TRANSACTION)
conn = Mock({'getUUID': self.app.uuid}) conn = Mock({'getUUID': self.app.uuid})
...@@ -307,7 +307,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -307,7 +307,7 @@ class StorageClientHandlerTests(NeoTestBase):
self.app.load_lock_dict[0] = object() self.app.load_lock_dict[0] = object()
self.app.store_lock_dict[0] = object() self.app.store_lock_dict[0] = object()
self.app.transaction_dict[INVALID_TID] = transaction self.app.transaction_dict[INVALID_TID] = transaction
self.operation.handleAbortTransaction(conn, packet, INVALID_TID) self.operation.abortTransaction(conn, packet, INVALID_TID)
self.assertTrue(self.called) self.assertTrue(self.called)
self.assertEquals(len(self.app.load_lock_dict), 0) self.assertEquals(len(self.app.load_lock_dict), 0)
self.assertEquals(len(self.app.store_lock_dict), 0) self.assertEquals(len(self.app.store_lock_dict), 0)
......
...@@ -79,7 +79,7 @@ class StorageInitializationHandlerTests(NeoTestBase): ...@@ -79,7 +79,7 @@ class StorageInitializationHandlerTests(NeoTestBase):
# nothing happens # nothing happens
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
def test_09_handleSendPartitionTable(self): def test_09_sendPartitionTable(self):
packet = Packet(msg_type=PacketTypes.SEND_PARTITION_TABLE) packet = Packet(msg_type=PacketTypes.SEND_PARTITION_TABLE)
uuid = self.getNewUUID() uuid = self.getNewUUID()
# send a table # send a table
...@@ -101,19 +101,19 @@ class StorageInitializationHandlerTests(NeoTestBase): ...@@ -101,19 +101,19 @@ class StorageInitializationHandlerTests(NeoTestBase):
(2, ((node_2, CellStates.UP_TO_DATE), (node_3, CellStates.UP_TO_DATE)))] (2, ((node_2, CellStates.UP_TO_DATE), (node_3, CellStates.UP_TO_DATE)))]
self.assertFalse(self.app.pt.filled()) self.assertFalse(self.app.pt.filled())
# send part of the table, won't be filled # send part of the table, won't be filled
self.verification.handleSendPartitionTable(conn, packet, 1, row_list[:1]) self.verification.sendPartitionTable(conn, packet, 1, row_list[:1])
self.assertFalse(self.app.pt.filled()) self.assertFalse(self.app.pt.filled())
self.assertEqual(self.app.pt.getID(), 1) self.assertEqual(self.app.pt.getID(), 1)
self.assertEqual(self.app.dm.getPartitionTable(), []) self.assertEqual(self.app.dm.getPartitionTable(), [])
# send remaining of the table (ack with AnswerPartitionTable) # send remaining of the table (ack with AnswerPartitionTable)
self.verification.handleSendPartitionTable(conn, packet, 1, row_list[1:]) self.verification.sendPartitionTable(conn, packet, 1, row_list[1:])
self.verification.handleAnswerPartitionTable(conn, packet, 1, []) self.verification.answerPartitionTable(conn, packet, 1, [])
self.assertTrue(self.app.pt.filled()) self.assertTrue(self.app.pt.filled())
self.assertEqual(self.app.pt.getID(), 1) self.assertEqual(self.app.pt.getID(), 1)
self.assertNotEqual(self.app.dm.getPartitionTable(), []) self.assertNotEqual(self.app.dm.getPartitionTable(), [])
# send a complete new table and ack # send a complete new table and ack
self.verification.handleSendPartitionTable(conn, packet, 2, row_list) self.verification.sendPartitionTable(conn, packet, 2, row_list)
self.verification.handleAnswerPartitionTable(conn, packet, 2, []) self.verification.answerPartitionTable(conn, packet, 2, [])
self.assertTrue(self.app.pt.filled()) self.assertTrue(self.app.pt.filled())
self.assertEqual(self.app.pt.getID(), 2) self.assertEqual(self.app.pt.getID(), 2)
self.assertNotEqual(self.app.dm.getPartitionTable(), []) self.assertNotEqual(self.app.dm.getPartitionTable(), [])
......
...@@ -92,7 +92,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -92,7 +92,7 @@ class StorageMasterHandlerTests(NeoTestBase):
self.assertRaises(PrimaryFailure, self.operation.peerBroken, conn) self.assertRaises(PrimaryFailure, self.operation.peerBroken, conn)
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
def test_14_handleNotifyPartitionChanges1(self): def test_14_notifyPartitionChanges1(self):
# old partition change -> do nothing # old partition change -> do nothing
app = self.app app = self.app
conn = Mock({ conn = Mock({
...@@ -103,7 +103,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -103,7 +103,7 @@ class StorageMasterHandlerTests(NeoTestBase):
packet = Packet(msg_type=PacketTypes.NOTIFY_PARTITION_CHANGES) packet = Packet(msg_type=PacketTypes.NOTIFY_PARTITION_CHANGES)
self.app.pt = Mock({'getID': 1}) self.app.pt = Mock({'getID': 1})
count = len(self.app.nm.getList()) count = len(self.app.nm.getList())
self.operation.handleNotifyPartitionChanges(conn, packet, 0, ()) self.operation.notifyPartitionChanges(conn, packet, 0, ())
self.assertEquals(self.app.pt.getID(), 1) self.assertEquals(self.app.pt.getID(), 1)
self.assertEquals(len(self.app.nm.getList()), count) self.assertEquals(len(self.app.nm.getList()), count)
calls = self.app.replicator.mockGetNamedCalls('removePartition') calls = self.app.replicator.mockGetNamedCalls('removePartition')
...@@ -111,7 +111,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -111,7 +111,7 @@ class StorageMasterHandlerTests(NeoTestBase):
calls = self.app.replicator.mockGetNamedCalls('addPartition') calls = self.app.replicator.mockGetNamedCalls('addPartition')
self.assertEquals(len(calls), 0) self.assertEquals(len(calls), 0)
def test_14_handleNotifyPartitionChanges2(self): def test_14_notifyPartitionChanges2(self):
# cases : # cases :
uuid1, uuid2, uuid3 = [self.getNewUUID() for i in range(3)] uuid1, uuid2, uuid3 = [self.getNewUUID() for i in range(3)]
cells = ( cells = (
...@@ -136,7 +136,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -136,7 +136,7 @@ class StorageMasterHandlerTests(NeoTestBase):
app.dm = Mock({ }) app.dm = Mock({ })
app.replicator = Mock({}) app.replicator = Mock({})
count = len(app.nm.getList()) count = len(app.nm.getList())
self.operation.handleNotifyPartitionChanges(conn, packet, ptid2, cells) self.operation.notifyPartitionChanges(conn, packet, ptid2, cells)
# ptid set # ptid set
self.assertEquals(app.pt.getID(), ptid2) self.assertEquals(app.pt.getID(), ptid2)
# dm call # dm call
...@@ -144,13 +144,13 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -144,13 +144,13 @@ class StorageMasterHandlerTests(NeoTestBase):
self.assertEquals(len(calls), 1) self.assertEquals(len(calls), 1)
calls[0].checkArgs(ptid2, cells) calls[0].checkArgs(ptid2, cells)
def test_16_handleStopOperation1(self): def test_16_stopOperation1(self):
# OperationFailure # OperationFailure
conn = Mock({ 'isServer': False }) conn = Mock({ 'isServer': False })
packet = Packet(msg_type=PacketTypes.STOP_OPERATION) packet = Packet(msg_type=PacketTypes.STOP_OPERATION)
self.assertRaises(OperationFailure, self.operation.handleStopOperation, conn, packet) self.assertRaises(OperationFailure, self.operation.stopOperation, conn, packet)
def test_22_handleLockInformation2(self): def test_22_lockInformation2(self):
# load transaction informations # load transaction informations
conn = Mock({ 'isServer': False, }) conn = Mock({ 'isServer': False, })
self.app.dm = Mock({ }) self.app.dm = Mock({ })
...@@ -158,7 +158,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -158,7 +158,7 @@ class StorageMasterHandlerTests(NeoTestBase):
packet.setId(1) packet.setId(1)
transaction = Mock({ 'getObjectList': ((0, ), ), }) transaction = Mock({ 'getObjectList': ((0, ), ), })
self.app.transaction_dict[INVALID_TID] = transaction self.app.transaction_dict[INVALID_TID] = transaction
self.operation.handleLockInformation(conn, packet, INVALID_TID) self.operation.lockInformation(conn, packet, INVALID_TID)
self.assertEquals(self.app.load_lock_dict[0], INVALID_TID) self.assertEquals(self.app.load_lock_dict[0], INVALID_TID)
calls = self.app.dm.mockGetNamedCalls('storeTransaction') calls = self.app.dm.mockGetNamedCalls('storeTransaction')
self.assertEquals(len(calls), 1) self.assertEquals(len(calls), 1)
...@@ -166,10 +166,10 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -166,10 +166,10 @@ class StorageMasterHandlerTests(NeoTestBase):
# transaction not in transaction_dict -> KeyError # transaction not in transaction_dict -> KeyError
transaction = Mock({ 'getObjectList': ((0, ), ), }) transaction = Mock({ 'getObjectList': ((0, ), ), })
conn = Mock({ 'isServer': False, }) conn = Mock({ 'isServer': False, })
self.operation.handleLockInformation(conn, packet, '\x01' * 8) self.operation.lockInformation(conn, packet, '\x01' * 8)
self.checkNotifyInformationLocked(conn, answered_packet=packet) self.checkNotifyInformationLocked(conn, answered_packet=packet)
def test_23_handleUnlockInformation2(self): def test_23_unlockInformation2(self):
# delete transaction informations # delete transaction informations
conn = Mock({ 'isServer': False, }) conn = Mock({ 'isServer': False, })
self.app.dm = Mock({ }) self.app.dm = Mock({ })
...@@ -179,7 +179,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -179,7 +179,7 @@ class StorageMasterHandlerTests(NeoTestBase):
self.app.transaction_dict[INVALID_TID] = transaction self.app.transaction_dict[INVALID_TID] = transaction
self.app.load_lock_dict[0] = transaction self.app.load_lock_dict[0] = transaction
self.app.store_lock_dict[0] = transaction self.app.store_lock_dict[0] = transaction
self.operation.handleUnlockInformation(conn, packet, INVALID_TID) self.operation.unlockInformation(conn, packet, INVALID_TID)
self.assertEquals(len(self.app.load_lock_dict), 0) self.assertEquals(len(self.app.load_lock_dict), 0)
self.assertEquals(len(self.app.store_lock_dict), 0) self.assertEquals(len(self.app.store_lock_dict), 0)
self.assertEquals(len(self.app.store_lock_dict), 0) self.assertEquals(len(self.app.store_lock_dict), 0)
...@@ -189,15 +189,15 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -189,15 +189,15 @@ class StorageMasterHandlerTests(NeoTestBase):
# transaction not in transaction_dict -> KeyError # transaction not in transaction_dict -> KeyError
transaction = Mock({ 'getObjectList': ((0, ), ), }) transaction = Mock({ 'getObjectList': ((0, ), ), })
conn = Mock({ 'isServer': False, }) conn = Mock({ 'isServer': False, })
self.operation.handleLockInformation(conn, packet, '\x01' * 8) self.operation.lockInformation(conn, packet, '\x01' * 8)
self.checkNotifyInformationLocked(conn, answered_packet=packet) self.checkNotifyInformationLocked(conn, answered_packet=packet)
def test_30_handleAnswerLastIDs(self): def test_30_answerLastIDs(self):
# set critical TID on replicator # set critical TID on replicator
conn = Mock() conn = Mock()
packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS) packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
self.app.replicator = Mock() self.app.replicator = Mock()
self.operation.handleAnswerLastIDs( self.operation.answerLastIDs(
conn=conn, conn=conn,
packet=packet, packet=packet,
loid=INVALID_OID, loid=INVALID_OID,
...@@ -208,12 +208,12 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -208,12 +208,12 @@ class StorageMasterHandlerTests(NeoTestBase):
self.assertEquals(len(calls), 1) self.assertEquals(len(calls), 1)
calls[0].checkArgs(packet, INVALID_TID) calls[0].checkArgs(packet, INVALID_TID)
def test_31_handleAnswerUnfinishedTransactions(self): def test_31_answerUnfinishedTransactions(self):
# set unfinished TID on replicator # set unfinished TID on replicator
conn = Mock() conn = Mock()
packet = Packet(msg_type=PacketTypes.ANSWER_UNFINISHED_TRANSACTIONS) packet = Packet(msg_type=PacketTypes.ANSWER_UNFINISHED_TRANSACTIONS)
self.app.replicator = Mock() self.app.replicator = Mock()
self.operation.handleAnswerUnfinishedTransactions( self.operation.answerUnfinishedTransactions(
conn=conn, conn=conn,
packet=packet, packet=packet,
tid_list=(INVALID_TID, ), tid_list=(INVALID_TID, ),
......
...@@ -62,30 +62,30 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -62,30 +62,30 @@ class StorageStorageHandlerTests(NeoTestBase):
def tearDown(self): def tearDown(self):
NeoTestBase.tearDown(self) NeoTestBase.tearDown(self)
def test_18_handleAskTransactionInformation1(self): def test_18_askTransactionInformation1(self):
# transaction does not exists # transaction does not exists
conn = Mock({ }) conn = Mock({ })
packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION) packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
self.operation.handleAskTransactionInformation(conn, packet, INVALID_TID) self.operation.askTransactionInformation(conn, packet, INVALID_TID)
self.checkErrorPacket(conn) self.checkErrorPacket(conn)
def test_18_handleAskTransactionInformation2(self): def test_18_askTransactionInformation2(self):
# answer # answer
conn = Mock({ }) conn = Mock({ })
packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION) packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
dm = Mock({ "getTransaction": (INVALID_TID, 'user', 'desc', '', ), }) dm = Mock({ "getTransaction": (INVALID_TID, 'user', 'desc', '', ), })
self.app.dm = dm self.app.dm = dm
self.operation.handleAskTransactionInformation(conn, packet, INVALID_TID) self.operation.askTransactionInformation(conn, packet, INVALID_TID)
self.checkAnswerTransactionInformation(conn) self.checkAnswerTransactionInformation(conn)
def test_24_handleAskObject1(self): def test_24_askObject1(self):
# delayed response # delayed response
conn = Mock({}) conn = Mock({})
self.app.dm = Mock() self.app.dm = Mock()
packet = Packet(msg_type=PacketTypes.ASK_OBJECT) packet = Packet(msg_type=PacketTypes.ASK_OBJECT)
self.app.load_lock_dict[INVALID_OID] = object() self.app.load_lock_dict[INVALID_OID] = object()
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.handleAskObject(conn, packet, self.operation.askObject(conn, packet,
oid=INVALID_OID, oid=INVALID_OID,
serial=INVALID_SERIAL, serial=INVALID_SERIAL,
tid=INVALID_TID) tid=INVALID_TID)
...@@ -93,13 +93,13 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -93,13 +93,13 @@ class StorageStorageHandlerTests(NeoTestBase):
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
self.assertEquals(len(self.app.dm.mockGetNamedCalls('getObject')), 0) self.assertEquals(len(self.app.dm.mockGetNamedCalls('getObject')), 0)
def test_24_handleAskObject2(self): def test_24_askObject2(self):
# invalid serial / tid / packet not found # invalid serial / tid / packet not found
self.app.dm = Mock({'getObject': None}) self.app.dm = Mock({'getObject': None})
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_OBJECT) packet = Packet(msg_type=PacketTypes.ASK_OBJECT)
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.handleAskObject(conn, packet, self.operation.askObject(conn, packet,
oid=INVALID_OID, oid=INVALID_OID,
serial=INVALID_SERIAL, serial=INVALID_SERIAL,
tid=INVALID_TID) tid=INVALID_TID)
...@@ -109,109 +109,109 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -109,109 +109,109 @@ class StorageStorageHandlerTests(NeoTestBase):
calls[0].checkArgs(INVALID_OID, INVALID_TID, INVALID_TID) calls[0].checkArgs(INVALID_OID, INVALID_TID, INVALID_TID)
self.checkErrorPacket(conn) self.checkErrorPacket(conn)
def test_24_handleAskObject3(self): def test_24_askObject3(self):
# object found => answer # object found => answer
self.app.dm = Mock({'getObject': ('', '', 0, 0, '', )}) self.app.dm = Mock({'getObject': ('', '', 0, 0, '', )})
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_OBJECT) packet = Packet(msg_type=PacketTypes.ASK_OBJECT)
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.handleAskObject(conn, packet, self.operation.askObject(conn, packet,
oid=INVALID_OID, oid=INVALID_OID,
serial=INVALID_SERIAL, serial=INVALID_SERIAL,
tid=INVALID_TID) tid=INVALID_TID)
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.checkAnswerObject(conn) self.checkAnswerObject(conn)
def test_25_handleAskTIDs1(self): def test_25_askTIDs1(self):
# invalid offsets => error # invalid offsets => error
app = self.app app = self.app
app.pt = Mock() app.pt = Mock()
app.dm = Mock() app.dm = Mock()
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_TIDS) packet = Packet(msg_type=PacketTypes.ASK_TIDS)
self.checkProtocolErrorRaised(self.operation.handleAskTIDs, conn, packet, 1, 1, None) self.checkProtocolErrorRaised(self.operation.askTIDs, conn, packet, 1, 1, None)
self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0) self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0)
self.assertEquals(len(app.dm.mockGetNamedCalls('getTIDList')), 0) self.assertEquals(len(app.dm.mockGetNamedCalls('getTIDList')), 0)
def test_25_handleAskTIDs2(self): def test_25_askTIDs2(self):
# well case => answer # well case => answer
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_TIDS) packet = Packet(msg_type=PacketTypes.ASK_TIDS)
self.app.dm = Mock({'getTIDList': (INVALID_TID, )}) self.app.dm = Mock({'getTIDList': (INVALID_TID, )})
self.app.pt = Mock({'getPartitions': 1}) self.app.pt = Mock({'getPartitions': 1})
self.operation.handleAskTIDs(conn, packet, 1, 2, 1) self.operation.askTIDs(conn, packet, 1, 2, 1)
calls = self.app.dm.mockGetNamedCalls('getTIDList') calls = self.app.dm.mockGetNamedCalls('getTIDList')
self.assertEquals(len(calls), 1) self.assertEquals(len(calls), 1)
calls[0].checkArgs(1, 1, 1, [1, ]) calls[0].checkArgs(1, 1, 1, [1, ])
self.checkAnswerTids(conn) self.checkAnswerTids(conn)
def test_25_handleAskTIDs3(self): def test_25_askTIDs3(self):
# invalid partition => answer usable partitions # invalid partition => answer usable partitions
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_TIDS) packet = Packet(msg_type=PacketTypes.ASK_TIDS)
cell = Mock({'getUUID':self.app.uuid}) cell = Mock({'getUUID':self.app.uuid})
self.app.dm = Mock({'getTIDList': (INVALID_TID, )}) self.app.dm = Mock({'getTIDList': (INVALID_TID, )})
self.app.pt = Mock({'getCellList': (cell, ), 'getPartitions': 1}) self.app.pt = Mock({'getCellList': (cell, ), 'getPartitions': 1})
self.operation.handleAskTIDs(conn, packet, 1, 2, INVALID_PARTITION) self.operation.askTIDs(conn, packet, 1, 2, INVALID_PARTITION)
self.assertEquals(len(self.app.pt.mockGetNamedCalls('getCellList')), 1) self.assertEquals(len(self.app.pt.mockGetNamedCalls('getCellList')), 1)
calls = self.app.dm.mockGetNamedCalls('getTIDList') calls = self.app.dm.mockGetNamedCalls('getTIDList')
self.assertEquals(len(calls), 1) self.assertEquals(len(calls), 1)
calls[0].checkArgs(1, 1, 1, [0, ]) calls[0].checkArgs(1, 1, 1, [0, ])
self.checkAnswerTids(conn) self.checkAnswerTids(conn)
def test_26_handleAskObjectHistory1(self): def test_26_askObjectHistory1(self):
# invalid offsets => error # invalid offsets => error
app = self.app app = self.app
app.dm = Mock() app.dm = Mock()
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_OBJECT_HISTORY) packet = Packet(msg_type=PacketTypes.ASK_OBJECT_HISTORY)
self.checkProtocolErrorRaised(self.operation.handleAskObjectHistory, conn, packet, 1, 1, None) self.checkProtocolErrorRaised(self.operation.askObjectHistory, conn, packet, 1, 1, None)
self.assertEquals(len(app.dm.mockGetNamedCalls('getObjectHistory')), 0) self.assertEquals(len(app.dm.mockGetNamedCalls('getObjectHistory')), 0)
def test_26_handleAskObjectHistory2(self): def test_26_askObjectHistory2(self):
# first case: empty history # first case: empty history
packet = Packet(msg_type=PacketTypes.ASK_OBJECT_HISTORY) packet = Packet(msg_type=PacketTypes.ASK_OBJECT_HISTORY)
conn = Mock({}) conn = Mock({})
self.app.dm = Mock({'getObjectHistory': None}) self.app.dm = Mock({'getObjectHistory': None})
self.operation.handleAskObjectHistory(conn, packet, INVALID_OID, 1, 2) self.operation.askObjectHistory(conn, packet, INVALID_OID, 1, 2)
self.checkAnswerObjectHistory(conn) self.checkAnswerObjectHistory(conn)
# second case: not empty history # second case: not empty history
conn = Mock({}) conn = Mock({})
self.app.dm = Mock({'getObjectHistory': [('', 0, ), ]}) self.app.dm = Mock({'getObjectHistory': [('', 0, ), ]})
self.operation.handleAskObjectHistory(conn, packet, INVALID_OID, 1, 2) self.operation.askObjectHistory(conn, packet, INVALID_OID, 1, 2)
self.checkAnswerObjectHistory(conn) self.checkAnswerObjectHistory(conn)
def test_25_handleAskOIDs1(self): def test_25_askOIDs1(self):
# invalid offsets => error # invalid offsets => error
app = self.app app = self.app
app.pt = Mock() app.pt = Mock()
app.dm = Mock() app.dm = Mock()
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_OIDS) packet = Packet(msg_type=PacketTypes.ASK_OIDS)
self.checkProtocolErrorRaised(self.operation.handleAskOIDs, conn, packet, 1, 1, None) self.checkProtocolErrorRaised(self.operation.askOIDs, conn, packet, 1, 1, None)
self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0) self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0)
self.assertEquals(len(app.dm.mockGetNamedCalls('getOIDList')), 0) self.assertEquals(len(app.dm.mockGetNamedCalls('getOIDList')), 0)
def test_25_handleAskOIDs2(self): def test_25_askOIDs2(self):
# well case > answer OIDs # well case > answer OIDs
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_OIDS) packet = Packet(msg_type=PacketTypes.ASK_OIDS)
self.app.pt = Mock({'getPartitions': 1}) self.app.pt = Mock({'getPartitions': 1})
self.app.dm = Mock({'getOIDList': (INVALID_OID, )}) self.app.dm = Mock({'getOIDList': (INVALID_OID, )})
self.operation.handleAskOIDs(conn, packet, 1, 2, 1) self.operation.askOIDs(conn, packet, 1, 2, 1)
calls = self.app.dm.mockGetNamedCalls('getOIDList') calls = self.app.dm.mockGetNamedCalls('getOIDList')
self.assertEquals(len(calls), 1) self.assertEquals(len(calls), 1)
calls[0].checkArgs(1, 1, 1, [1, ]) calls[0].checkArgs(1, 1, 1, [1, ])
self.checkAnswerOids(conn) self.checkAnswerOids(conn)
def test_25_handleAskOIDs3(self): def test_25_askOIDs3(self):
# invalid partition => answer usable partitions # invalid partition => answer usable partitions
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_OIDS) packet = Packet(msg_type=PacketTypes.ASK_OIDS)
cell = Mock({'getUUID':self.app.uuid}) cell = Mock({'getUUID':self.app.uuid})
self.app.dm = Mock({'getOIDList': (INVALID_OID, )}) self.app.dm = Mock({'getOIDList': (INVALID_OID, )})
self.app.pt = Mock({'getCellList': (cell, ), 'getPartitions': 1}) self.app.pt = Mock({'getCellList': (cell, ), 'getPartitions': 1})
self.operation.handleAskOIDs(conn, packet, 1, 2, INVALID_PARTITION) self.operation.askOIDs(conn, packet, 1, 2, INVALID_PARTITION)
self.assertEquals(len(self.app.pt.mockGetNamedCalls('getCellList')), 1) self.assertEquals(len(self.app.pt.mockGetNamedCalls('getCellList')), 1)
calls = self.app.dm.mockGetNamedCalls('getOIDList') calls = self.app.dm.mockGetNamedCalls('getOIDList')
self.assertEquals(len(calls), 1) self.assertEquals(len(calls), 1)
......
...@@ -83,7 +83,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -83,7 +83,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
# nothing happens # nothing happens
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
def test_07_handleAskLastIDs(self): def test_07_askLastIDs(self):
uuid = self.getNewUUID() uuid = self.getNewUUID()
packet = Mock() packet = Mock()
# return invalid if db store nothing # return invalid if db store nothing
...@@ -93,7 +93,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -93,7 +93,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
last_ptid = '\x01' * 8 last_ptid = '\x01' * 8
last_oid = '\x02' * 8 last_oid = '\x02' * 8
self.app.pt = Mock({'getID': last_ptid}) self.app.pt = Mock({'getID': last_ptid})
self.verification.handleAskLastIDs(conn, packet) self.verification.askLastIDs(conn, packet)
oid, tid, ptid = self.checkAnswerLastIDs(conn, decode=True) oid, tid, ptid = self.checkAnswerLastIDs(conn, decode=True)
self.assertEqual(oid, INVALID_OID) self.assertEqual(oid, INVALID_OID)
self.assertEqual(tid, INVALID_TID) self.assertEqual(tid, INVALID_TID)
...@@ -125,14 +125,14 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -125,14 +125,14 @@ class StorageVerificationHandlerTests(NeoTestBase):
checksum, value) values (0, 4, 0, 0, '')""") checksum, value) values (0, 4, 0, 0, '')""")
self.app.dm.commit() self.app.dm.commit()
self.app.dm.setLastOID(last_oid) self.app.dm.setLastOID(last_oid)
self.verification.handleAskLastIDs(conn, packet) self.verification.askLastIDs(conn, packet)
self.checkAnswerLastIDs(conn) self.checkAnswerLastIDs(conn)
oid, tid, ptid = self.checkAnswerLastIDs(conn, decode=True) oid, tid, ptid = self.checkAnswerLastIDs(conn, decode=True)
self.assertEqual(oid, last_oid) self.assertEqual(oid, last_oid)
self.assertEqual(u64(tid), 4) self.assertEqual(u64(tid), 4)
self.assertEqual(ptid, self.app.pt.getID()) self.assertEqual(ptid, self.app.pt.getID())
def test_08_handleAskPartitionTable(self): def test_08_askPartitionTable(self):
uuid = self.getNewUUID() uuid = self.getNewUUID()
packet = Mock() packet = Mock()
# try to get unknown offset # try to get unknown offset
...@@ -142,7 +142,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -142,7 +142,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
conn = Mock({"getUUID" : uuid, conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port), "getAddress" : ("127.0.0.1", self.client_port),
"isServer" : False}) "isServer" : False})
self.verification.handleAskPartitionTable(conn, packet, [1,]) self.verification.askPartitionTable(conn, packet, [1,])
ptid, row_list = self.checkAnswerPartitionTable(conn, decode=True) ptid, row_list = self.checkAnswerPartitionTable(conn, decode=True)
self.assertEqual(len(row_list), 1) self.assertEqual(len(row_list), 1)
offset, rows = row_list[0] offset, rows = row_list[0]
...@@ -159,22 +159,22 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -159,22 +159,22 @@ class StorageVerificationHandlerTests(NeoTestBase):
conn = Mock({"getUUID" : uuid, conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port), "getAddress" : ("127.0.0.1", self.client_port),
"isServer" : False}) "isServer" : False})
self.verification.handleAskPartitionTable(conn, packet, [1,]) self.verification.askPartitionTable(conn, packet, [1,])
ptid, row_list = self.checkAnswerPartitionTable(conn, decode=True) ptid, row_list = self.checkAnswerPartitionTable(conn, decode=True)
self.assertEqual(len(row_list), 1) self.assertEqual(len(row_list), 1)
offset, rows = row_list[0] offset, rows = row_list[0]
self.assertEqual(offset, 1) self.assertEqual(offset, 1)
self.assertEqual(len(rows), 1) self.assertEqual(len(rows), 1)
def test_10_handleNotifyPartitionChanges(self): def test_10_notifyPartitionChanges(self):
# old partition change # old partition change
conn = Mock({ conn = Mock({
"isServer": False, "isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
}) })
packet = Packet(msg_type=PacketTypes.NOTIFY_PARTITION_CHANGES) packet = Packet(msg_type=PacketTypes.NOTIFY_PARTITION_CHANGES)
self.verification.handleNotifyPartitionChanges(conn, packet, 1, ()) self.verification.notifyPartitionChanges(conn, packet, 1, ())
self.verification.handleNotifyPartitionChanges(conn, packet, 0, ()) self.verification.notifyPartitionChanges(conn, packet, 0, ())
self.assertEqual(self.app.pt.getID(), 1) self.assertEqual(self.app.pt.getID(), 1)
# new node # new node
...@@ -190,33 +190,33 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -190,33 +190,33 @@ class StorageVerificationHandlerTests(NeoTestBase):
self.app.dm = Mock({ }) self.app.dm = Mock({ })
ptid, self.ptid = self.getTwoIDs() ptid, self.ptid = self.getTwoIDs()
# pt updated # pt updated
self.verification.handleNotifyPartitionChanges(conn, packet, ptid, (cell, )) self.verification.notifyPartitionChanges(conn, packet, ptid, (cell, ))
# check db update # check db update
calls = self.app.dm.mockGetNamedCalls('changePartitionTable') calls = self.app.dm.mockGetNamedCalls('changePartitionTable')
self.assertEquals(len(calls), 1) self.assertEquals(len(calls), 1)
self.assertEquals(calls[0].getParam(0), ptid) self.assertEquals(calls[0].getParam(0), ptid)
self.assertEquals(calls[0].getParam(1), (cell, )) self.assertEquals(calls[0].getParam(1), (cell, ))
def test_11_handleStartOperation(self): def test_11_startOperation(self):
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port), conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False }) 'isServer': False })
self.assertFalse(self.app.operational) self.assertFalse(self.app.operational)
packet = Packet(msg_type=PacketTypes.STOP_OPERATION) packet = Packet(msg_type=PacketTypes.STOP_OPERATION)
self.verification.handleStartOperation(conn, packet) self.verification.startOperation(conn, packet)
self.assertTrue(self.app.operational) self.assertTrue(self.app.operational)
def test_12_handleStopOperation(self): def test_12_stopOperation(self):
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port), conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False }) 'isServer': False })
packet = Packet(msg_type=PacketTypes.STOP_OPERATION) packet = Packet(msg_type=PacketTypes.STOP_OPERATION)
self.assertRaises(OperationFailure, self.verification.handleStopOperation, conn, packet) self.assertRaises(OperationFailure, self.verification.stopOperation, conn, packet)
def test_13_handleAskUnfinishedTransactions(self): def test_13_askUnfinishedTransactions(self):
# client connection with no data # client connection with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port), conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False}) 'isServer': False})
packet = Packet(msg_type=PacketTypes.ASK_UNFINISHED_TRANSACTIONS) packet = Packet(msg_type=PacketTypes.ASK_UNFINISHED_TRANSACTIONS)
self.verification.handleAskUnfinishedTransactions(conn, packet) self.verification.askUnfinishedTransactions(conn, packet)
(tid_list, ) = self.checkAnswerUnfinishedTransactions(conn, decode=True) (tid_list, ) = self.checkAnswerUnfinishedTransactions(conn, decode=True)
self.assertEqual(len(tid_list), 0) self.assertEqual(len(tid_list), 0)
...@@ -228,17 +228,17 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -228,17 +228,17 @@ class StorageVerificationHandlerTests(NeoTestBase):
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port), conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False}) 'isServer': False})
packet = Packet(msg_type=PacketTypes.ASK_UNFINISHED_TRANSACTIONS) packet = Packet(msg_type=PacketTypes.ASK_UNFINISHED_TRANSACTIONS)
self.verification.handleAskUnfinishedTransactions(conn, packet) self.verification.askUnfinishedTransactions(conn, packet)
(tid_list, ) = self.checkAnswerUnfinishedTransactions(conn, decode=True) (tid_list, ) = self.checkAnswerUnfinishedTransactions(conn, decode=True)
self.assertEqual(len(tid_list), 1) self.assertEqual(len(tid_list), 1)
self.assertEqual(u64(tid_list[0]), 4) self.assertEqual(u64(tid_list[0]), 4)
def test_14_handleAskTransactionInformation(self): def test_14_askTransactionInformation(self):
# ask from client conn with no data # ask from client conn with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port), conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False }) 'isServer': False })
packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION) packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(1)) self.verification.askTransactionInformation(conn, packet, p64(1))
code, message = self.checkErrorPacket(conn, decode=True) code, message = self.checkErrorPacket(conn, decode=True)
self.assertEqual(code, ErrorCodes.TID_NOT_FOUND) self.assertEqual(code, ErrorCodes.TID_NOT_FOUND)
...@@ -253,7 +253,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -253,7 +253,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port), conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False }) 'isServer': False })
packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION) packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(1)) self.verification.askTransactionInformation(conn, packet, p64(1))
tid, user, desc, ext, oid_list = self.checkAnswerTransactionInformation(conn, decode=True) tid, user, desc, ext, oid_list = self.checkAnswerTransactionInformation(conn, decode=True)
self.assertEqual(u64(tid), 1) self.assertEqual(u64(tid), 1)
self.assertEqual(user, 'u2') self.assertEqual(user, 'u2')
...@@ -265,7 +265,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -265,7 +265,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port), conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False }) 'isServer': False })
packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION) packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(3)) self.verification.askTransactionInformation(conn, packet, p64(3))
tid, user, desc, ext, oid_list = self.checkAnswerTransactionInformation(conn, decode=True) tid, user, desc, ext, oid_list = self.checkAnswerTransactionInformation(conn, decode=True)
self.assertEqual(u64(tid), 3) self.assertEqual(u64(tid), 3)
self.assertEqual(user, 'u1') self.assertEqual(user, 'u1')
...@@ -279,7 +279,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -279,7 +279,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
'isServer': True }) 'isServer': True })
# find the one in trans # find the one in trans
packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION) packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(1)) self.verification.askTransactionInformation(conn, packet, p64(1))
tid, user, desc, ext, oid_list = self.checkAnswerTransactionInformation(conn, decode=True) tid, user, desc, ext, oid_list = self.checkAnswerTransactionInformation(conn, decode=True)
self.assertEqual(u64(tid), 1) self.assertEqual(u64(tid), 1)
self.assertEqual(user, 'u2') self.assertEqual(user, 'u2')
...@@ -291,16 +291,16 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -291,16 +291,16 @@ class StorageVerificationHandlerTests(NeoTestBase):
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port), conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': True }) 'isServer': True })
packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION) packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(2)) self.verification.askTransactionInformation(conn, packet, p64(2))
code, message = self.checkErrorPacket(conn, decode=True) code, message = self.checkErrorPacket(conn, decode=True)
self.assertEqual(code, ErrorCodes.TID_NOT_FOUND) self.assertEqual(code, ErrorCodes.TID_NOT_FOUND)
def test_15_handleAskObjectPresent(self): def test_15_askObjectPresent(self):
# client connection with no data # client connection with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port), conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False}) 'isServer': False})
packet = Packet(msg_type=PacketTypes.ASK_OBJECT_PRESENT) packet = Packet(msg_type=PacketTypes.ASK_OBJECT_PRESENT)
self.verification.handleAskObjectPresent(conn, packet, p64(1), p64(2)) self.verification.askObjectPresent(conn, packet, p64(1), p64(2))
code, message = self.checkErrorPacket(conn, decode=True) code, message = self.checkErrorPacket(conn, decode=True)
self.assertEqual(code, ErrorCodes.OID_NOT_FOUND) self.assertEqual(code, ErrorCodes.OID_NOT_FOUND)
...@@ -312,34 +312,34 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -312,34 +312,34 @@ class StorageVerificationHandlerTests(NeoTestBase):
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port), conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False}) 'isServer': False})
packet = Packet(msg_type=PacketTypes.ASK_OBJECT_PRESENT) packet = Packet(msg_type=PacketTypes.ASK_OBJECT_PRESENT)
self.verification.handleAskObjectPresent(conn, packet, p64(1), p64(2)) self.verification.askObjectPresent(conn, packet, p64(1), p64(2))
oid, tid = self.checkAnswerObjectPresent(conn, decode=True) oid, tid = self.checkAnswerObjectPresent(conn, decode=True)
self.assertEqual(u64(tid), 2) self.assertEqual(u64(tid), 2)
self.assertEqual(u64(oid), 1) self.assertEqual(u64(oid), 1)
def test_16_handleDeleteTransaction(self): def test_16_deleteTransaction(self):
# client connection with no data # client connection with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port), conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False}) 'isServer': False})
packet = Packet(msg_type=PacketTypes.ASK_OBJECT_PRESENT) packet = Packet(msg_type=PacketTypes.ASK_OBJECT_PRESENT)
self.verification.handleDeleteTransaction(conn, packet, p64(1)) self.verification.deleteTransaction(conn, packet, p64(1))
# client connection with data # client connection with data
self.app.dm.begin() self.app.dm.begin()
self.app.dm.query("""insert into tobj (oid, serial, compression, self.app.dm.query("""insert into tobj (oid, serial, compression,
checksum, value) values (1, 2, 0, 0, '')""") checksum, value) values (1, 2, 0, 0, '')""")
self.app.dm.commit() self.app.dm.commit()
self.verification.handleDeleteTransaction(conn, packet, p64(2)) self.verification.deleteTransaction(conn, packet, p64(2))
result = self.app.dm.query('select * from tobj') result = self.app.dm.query('select * from tobj')
self.assertEquals(len(result), 0) self.assertEquals(len(result), 0)
def test_17_handleCommitTransaction(self): def test_17_commitTransaction(self):
# commit a transaction # commit a transaction
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port), conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False }) 'isServer': False })
dm = Mock() dm = Mock()
self.app.dm = dm self.app.dm = dm
packet = Packet(msg_type=PacketTypes.COMMIT_TRANSACTION) packet = Packet(msg_type=PacketTypes.COMMIT_TRANSACTION)
self.verification.handleCommitTransaction(conn, packet, p64(1)) self.verification.commitTransaction(conn, packet, p64(1))
self.assertEqual(len(dm.mockGetNamedCalls("finishTransaction")), 1) self.assertEqual(len(dm.mockGetNamedCalls("finishTransaction")), 1)
call = dm.mockGetNamedCalls("finishTransaction")[0] call = dm.mockGetNamedCalls("finishTransaction")[0]
tid = call.getParam(0) tid = call.getParam(0)
......
...@@ -57,7 +57,7 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -57,7 +57,7 @@ class BootstrapManagerTests(NeoTestBase):
# the primary is not ready # the primary is not ready
conn = Mock({}) conn = Mock({})
packet = Mock({}) packet = Mock({})
self.bootstrap.handleNotReady(conn, packet, '') self.bootstrap.notReady(conn, packet, '')
self.checkClosed(conn) self.checkClosed(conn)
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
......
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