Commit 3593c1aa authored by Vincent Pelletier's avatar Vincent Pelletier

Remove all "isinstance(conn, MTClientConnection)" tests from client handler to...

Remove all "isinstance(conn, MTClientConnection)" tests from client handler to make it unit-test-friendly: Client node does not have any listening socket, so there cannot be any (MT)ServerConnection instance used to reach handler. Also, Multi-Thread safety is not a runtime but a static criterion (ie, it is most likely a bug to use non-multi-thread-safe Connection subclasses in client). So this test is an always-true check, and can be removed.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@307 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 241b4eb2
......@@ -158,16 +158,12 @@ class ClientEventHandler(EventHandler):
def handleNotReady(self, conn, packet, message):
if isinstance(conn, MTClientConnection):
app = self.app
app.local_var.node_not_ready = 1
else:
self.handleUnexpectedPacket(conn, packet)
def handleAcceptNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port,
num_partitions, num_replicas):
if isinstance(conn, MTClientConnection):
app = self.app
node = app.nm.getNodeByServer(conn.getAddress())
# It can be eiter a master node or a storage node
......@@ -207,13 +203,10 @@ class ClientEventHandler(EventHandler):
conn.unlock()
elif node_type == STORAGE_NODE_TYPE:
app.storage_node = node
else:
self.handleUnexpectedPacket(conn, packet)
# Master node handler
def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid, known_master_list):
if isinstance(conn, MTClientConnection):
uuid = conn.getUUID()
if uuid is None:
self.handleUnexpectedPacket(conn, packet)
......@@ -253,11 +246,8 @@ class ClientEventHandler(EventHandler):
if primary_node.getUUID() == primary_uuid:
# Whatever the situation is, I trust this master.
app.primary_master_node = primary_node
else:
self.handleUnexpectedPacket(conn, packet)
def handleSendPartitionTable(self, conn, packet, ptid, row_list):
if isinstance(conn, MTClientConnection):
uuid = conn.getUUID()
if uuid is None:
self.handleUnexpectedPacket(conn, packet)
......@@ -282,11 +272,8 @@ class ClientEventHandler(EventHandler):
node.setState(TEMPORARILY_DOWN_STATE)
nm.add(node)
pt.setCell(offset, node, state)
else:
self.handleUnexpectedPacket(conn, packet)
def handleNotifyNodeInformation(self, conn, packet, node_list):
if isinstance(conn, MTClientConnection):
uuid = conn.getUUID()
if uuid is None:
self.handleUnexpectedPacket(conn, packet)
......@@ -330,11 +317,8 @@ class ClientEventHandler(EventHandler):
continue
n.setState(state)
else:
self.handleUnexpectedPacket(conn, packet)
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list):
if isinstance(conn, MTClientConnection):
app = self.app
nm = app.nm
pt = app.pt
......@@ -365,28 +349,19 @@ class ClientEventHandler(EventHandler):
nm.add(node)
pt.setCell(offset, node, state)
else:
self.handleUnexpectedPacket(conn, packet)
def handleAnswerNewTID(self, conn, packet, tid):
if isinstance(conn, MTClientConnection):
app = self.app
app.tid = tid
else:
self.handleUnexpectedPacket(conn, packet)
def handleNotifyTransactionFinished(self, conn, packet, tid):
if isinstance(conn, MTClientConnection):
app = self.app
if tid != app.tid:
app.txn_finished = -1
else:
app.txn_finished = 1
else:
self.handleUnexpectedPacket(conn, packet)
def handleInvalidateObjects(self, conn, packet, oid_list, tid):
if isinstance(conn, MTClientConnection):
app = self.app
app._cache_lock_acquire()
try:
......@@ -402,54 +377,36 @@ class ClientEventHandler(EventHandler):
app._db.invalidate(tid, oids)
finally:
app._cache_lock_release()
else:
self.handleUnexpectedPacket(conn, packet)
def handleAnswerNewOIDs(self, conn, packet, oid_list):
if isinstance(conn, MTClientConnection):
app = self.app
app.new_oid_list = oid_list
app.new_oid_list.reverse()
else:
self.handleUnexpectedPacket(conn, packet)
def handleStopOperation(self, conn, packet):
if isinstance(conn, MTClientConnection):
logging.critical("master node ask to stop operation")
else:
self.handleUnexpectedPacket(conn, packet)
# Storage node handler
def handleAnswerObject(self, conn, packet, oid, start_serial, end_serial, compression,
checksum, data):
if isinstance(conn, MTClientConnection):
app = self.app
app.local_var.asked_object = (oid, start_serial, end_serial, compression,
checksum, data)
else:
self.handleUnexpectedPacket(conn, packet)
def handleAnswerStoreObject(self, conn, packet, conflicting, oid, serial):
if isinstance(conn, MTClientConnection):
app = self.app
if conflicting:
app.txn_object_stored = -1, serial
else:
app.txn_object_stored = oid, serial
else:
self.handleUnexpectedPacket(conn, packet)
def handleAnswerStoreTransaction(self, conn, packet, tid):
if isinstance(conn, MTClientConnection):
app = self.app
app.txn_voted = 1
else:
self.handleUnexpectedPacket(conn, packet)
def handleAnswerTransactionInformation(self, conn, packet, tid,
user, desc, ext, oid_list):
if isinstance(conn, MTClientConnection):
app = self.app
# transaction information are returned as a dict
info = {}
......@@ -459,39 +416,25 @@ class ClientEventHandler(EventHandler):
info['id'] = tid
info['oids'] = oid_list
app.local_var.txn_info = info
else:
self.handleUnexpectedPacket(conn, packet)
def handleAnswerObjectHistory(self, conn, packet, oid, history_list):
if isinstance(conn, MTClientConnection):
app = self.app
# history_list is a list of tuple (serial, size)
app.local_var.history = oid, history_list
else:
self.handleUnexpectedPacket(conn, packet)
def handleOidNotFound(self, conn, packet, message):
if isinstance(conn, MTClientConnection):
app = self.app
# This can happen either when :
# - loading an object
# - asking for history
app.local_var.asked_object = -1
app.local_var.history = -1
else:
self.handleUnexpectedPacket(conn, packet)
def handleTidNotFound(self, conn, packet, message):
if isinstance(conn, MTClientConnection):
app = self.app
# This can happen when requiring txn informations
app.local_var.txn_info = -1
else:
self.handleUnexpectedPacket(conn, packet)
def handleAnswerTIDs(self, conn, packet, tid_list):
if isinstance(conn, MTClientConnection):
app = self.app
app.local_var.node_tids[conn.getUUID()] = tid_list
else:
self.handleUnexpectedPacket(conn, packet)
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