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

Use new Enum class for packet types. Drop the old Enum, this job is done.


git-svn-id: https://svn.erp5.org/repos/neo/trunk@1343 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent cf37fdd3
...@@ -19,7 +19,7 @@ from neo import logging ...@@ -19,7 +19,7 @@ from neo import logging
from neo.locking import RLock from neo.locking import RLock
from neo import protocol from neo import protocol
from neo.protocol import PacketMalformedError from neo.protocol import PacketMalformedError, PacketTypes
from neo.event import IdleEvent from neo.event import IdleEvent
from neo.connector import ConnectorException, ConnectorTryAgainException, \ from neo.connector import ConnectorException, ConnectorTryAgainException, \
ConnectorInProgressException, ConnectorConnectionRefusedException, \ ConnectorInProgressException, ConnectorConnectionRefusedException, \
...@@ -256,10 +256,10 @@ class Connection(BaseConnection): ...@@ -256,10 +256,10 @@ class Connection(BaseConnection):
try: try:
packet_type = packet.getType() packet_type = packet.getType()
if packet_type == protocol.PING: if packet_type == PacketTypes.PING:
# Send a pong notification # Send a pong notification
self.answer(protocol.pong(), packet.getId()) self.answer(protocol.pong(), packet.getId())
elif packet_type != protocol.PONG: elif packet_type != PacketTypes.PONG:
# Skip PONG packets, its only purpose is to drop IdleEvent # Skip PONG packets, its only purpose is to drop IdleEvent
# generated upong ping. # generated upong ping.
self._queue.append(packet) self._queue.append(packet)
......
This diff is collapsed.
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from neo import logging from neo import logging
from neo import protocol from neo.protocol import PacketTypes
from neo.util import dump from neo.util import dump
class PacketLogger(object): class PacketLogger(object):
...@@ -243,68 +243,68 @@ class PacketLogger(object): ...@@ -243,68 +243,68 @@ class PacketLogger(object):
# Fetch tables initialization # Fetch tables initialization
def initFetchTable(self): def initFetchTable(self):
d = {} d = {}
d[protocol.ERROR] = self.error d[PacketTypes.ERROR] = self.error
d[protocol.REQUEST_NODE_IDENTIFICATION] = self.requestNodeIdentification d[PacketTypes.REQUEST_NODE_IDENTIFICATION] = self.requestNodeIdentification
d[protocol.ACCEPT_NODE_IDENTIFICATION] = self.acceptNodeIdentification d[PacketTypes.ACCEPT_NODE_IDENTIFICATION] = self.acceptNodeIdentification
d[protocol.ASK_PRIMARY_MASTER] = self.askPrimaryMaster d[PacketTypes.ASK_PRIMARY_MASTER] = self.askPrimaryMaster
d[protocol.ANSWER_PRIMARY_MASTER] = self.answerPrimaryMaster d[PacketTypes.ANSWER_PRIMARY_MASTER] = self.answerPrimaryMaster
d[protocol.ANNOUNCE_PRIMARY_MASTER] = self.announcePrimaryMaster d[PacketTypes.ANNOUNCE_PRIMARY_MASTER] = self.announcePrimaryMaster
d[protocol.REELECT_PRIMARY_MASTER] = self.reelectPrimaryMaster d[PacketTypes.REELECT_PRIMARY_MASTER] = self.reelectPrimaryMaster
d[protocol.NOTIFY_NODE_INFORMATION] = self.notifyNodeInformation d[PacketTypes.NOTIFY_NODE_INFORMATION] = self.notifyNodeInformation
d[protocol.ASK_LAST_IDS] = self.askLastIDs d[PacketTypes.ASK_LAST_IDS] = self.askLastIDs
d[protocol.ANSWER_LAST_IDS] = self.answerLastIDs d[PacketTypes.ANSWER_LAST_IDS] = self.answerLastIDs
d[protocol.ASK_PARTITION_TABLE] = self.askPartitionTable d[PacketTypes.ASK_PARTITION_TABLE] = self.askPartitionTable
d[protocol.ANSWER_PARTITION_TABLE] = self.answerPartitionTable d[PacketTypes.ANSWER_PARTITION_TABLE] = self.answerPartitionTable
d[protocol.SEND_PARTITION_TABLE] = self.sendPartitionTable d[PacketTypes.SEND_PARTITION_TABLE] = self.sendPartitionTable
d[protocol.NOTIFY_PARTITION_CHANGES] = self.notifyPartitionChanges d[PacketTypes.NOTIFY_PARTITION_CHANGES] = self.notifyPartitionChanges
d[protocol.START_OPERATION] = self.startOperation d[PacketTypes.START_OPERATION] = self.startOperation
d[protocol.STOP_OPERATION] = self.stopOperation d[PacketTypes.STOP_OPERATION] = self.stopOperation
d[protocol.ASK_UNFINISHED_TRANSACTIONS] = self.askUnfinishedTransactions d[PacketTypes.ASK_UNFINISHED_TRANSACTIONS] = self.askUnfinishedTransactions
d[protocol.ANSWER_UNFINISHED_TRANSACTIONS] = self.answerUnfinishedTransactions d[PacketTypes.ANSWER_UNFINISHED_TRANSACTIONS] = self.answerUnfinishedTransactions
d[protocol.ASK_OBJECT_PRESENT] = self.askObjectPresent d[PacketTypes.ASK_OBJECT_PRESENT] = self.askObjectPresent
d[protocol.ANSWER_OBJECT_PRESENT] = self.answerObjectPresent d[PacketTypes.ANSWER_OBJECT_PRESENT] = self.answerObjectPresent
d[protocol.DELETE_TRANSACTION] = self.deleteTransaction d[PacketTypes.DELETE_TRANSACTION] = self.deleteTransaction
d[protocol.COMMIT_TRANSACTION] = self.commitTransaction d[PacketTypes.COMMIT_TRANSACTION] = self.commitTransaction
d[protocol.ASK_BEGIN_TRANSACTION] = self.askBeginTransaction d[PacketTypes.ASK_BEGIN_TRANSACTION] = self.askBeginTransaction
d[protocol.ANSWER_BEGIN_TRANSACTION] = self.answerBeginTransaction d[PacketTypes.ANSWER_BEGIN_TRANSACTION] = self.answerBeginTransaction
d[protocol.FINISH_TRANSACTION] = self.finishTransaction d[PacketTypes.FINISH_TRANSACTION] = self.finishTransaction
d[protocol.NOTIFY_TRANSACTION_FINISHED] = self.notifyTransactionFinished d[PacketTypes.NOTIFY_TRANSACTION_FINISHED] = self.notifyTransactionFinished
d[protocol.LOCK_INFORMATION] = self.lockInformation d[PacketTypes.LOCK_INFORMATION] = self.lockInformation
d[protocol.NOTIFY_INFORMATION_LOCKED] = self.notifyInformationLocked d[PacketTypes.NOTIFY_INFORMATION_LOCKED] = self.notifyInformationLocked
d[protocol.INVALIDATE_OBJECTS] = self.invalidateObjects d[PacketTypes.INVALIDATE_OBJECTS] = self.invalidateObjects
d[protocol.UNLOCK_INFORMATION] = self.unlockInformation d[PacketTypes.UNLOCK_INFORMATION] = self.unlockInformation
d[protocol.ASK_NEW_OIDS] = self.askNewOIDs d[PacketTypes.ASK_NEW_OIDS] = self.askNewOIDs
d[protocol.ANSWER_NEW_OIDS] = self.answerNewOIDs d[PacketTypes.ANSWER_NEW_OIDS] = self.answerNewOIDs
d[protocol.ASK_STORE_OBJECT] = self.askStoreObject d[PacketTypes.ASK_STORE_OBJECT] = self.askStoreObject
d[protocol.ANSWER_STORE_OBJECT] = self.answerStoreObject d[PacketTypes.ANSWER_STORE_OBJECT] = self.answerStoreObject
d[protocol.ABORT_TRANSACTION] = self.abortTransaction d[PacketTypes.ABORT_TRANSACTION] = self.abortTransaction
d[protocol.ASK_STORE_TRANSACTION] = self.askStoreTransaction d[PacketTypes.ASK_STORE_TRANSACTION] = self.askStoreTransaction
d[protocol.ANSWER_STORE_TRANSACTION] = self.answerStoreTransaction d[PacketTypes.ANSWER_STORE_TRANSACTION] = self.answerStoreTransaction
d[protocol.ASK_OBJECT] = self.askObject d[PacketTypes.ASK_OBJECT] = self.askObject
d[protocol.ANSWER_OBJECT] = self.answerObject d[PacketTypes.ANSWER_OBJECT] = self.answerObject
d[protocol.ASK_TIDS] = self.askTIDs d[PacketTypes.ASK_TIDS] = self.askTIDs
d[protocol.ANSWER_TIDS] = self.answerTIDs d[PacketTypes.ANSWER_TIDS] = self.answerTIDs
d[protocol.ASK_TRANSACTION_INFORMATION] = self.askTransactionInformation d[PacketTypes.ASK_TRANSACTION_INFORMATION] = self.askTransactionInformation
d[protocol.ANSWER_TRANSACTION_INFORMATION] = self.answerTransactionInformation d[PacketTypes.ANSWER_TRANSACTION_INFORMATION] = self.answerTransactionInformation
d[protocol.ASK_OBJECT_HISTORY] = self.askObjectHistory d[PacketTypes.ASK_OBJECT_HISTORY] = self.askObjectHistory
d[protocol.ANSWER_OBJECT_HISTORY] = self.answerObjectHistory d[PacketTypes.ANSWER_OBJECT_HISTORY] = self.answerObjectHistory
d[protocol.ASK_OIDS] = self.askOIDs d[PacketTypes.ASK_OIDS] = self.askOIDs
d[protocol.ANSWER_OIDS] = self.answerOIDs d[PacketTypes.ANSWER_OIDS] = self.answerOIDs
d[protocol.ASK_PARTITION_LIST] = self.askPartitionList d[PacketTypes.ASK_PARTITION_LIST] = self.askPartitionList
d[protocol.ANSWER_PARTITION_LIST] = self.answerPartitionList d[PacketTypes.ANSWER_PARTITION_LIST] = self.answerPartitionList
d[protocol.ASK_NODE_LIST] = self.askNodeList d[PacketTypes.ASK_NODE_LIST] = self.askNodeList
d[protocol.ANSWER_NODE_LIST] = self.answerNodeList d[PacketTypes.ANSWER_NODE_LIST] = self.answerNodeList
d[protocol.SET_NODE_STATE] = self.setNodeState d[PacketTypes.SET_NODE_STATE] = self.setNodeState
d[protocol.ANSWER_NODE_STATE] = self.answerNodeState d[PacketTypes.ANSWER_NODE_STATE] = self.answerNodeState
d[protocol.SET_CLUSTER_STATE] = self.setClusterState d[PacketTypes.SET_CLUSTER_STATE] = self.setClusterState
d[protocol.ADD_PENDING_NODES] = self.addPendingNodes d[PacketTypes.ADD_PENDING_NODES] = self.addPendingNodes
d[protocol.ANSWER_NEW_NODES] = self.answerNewNodes d[PacketTypes.ANSWER_NEW_NODES] = self.answerNewNodes
d[protocol.ASK_NODE_INFORMATION] = self.askNodeInformation d[PacketTypes.ASK_NODE_INFORMATION] = self.askNodeInformation
d[protocol.ANSWER_NODE_INFORMATION] = self.answerNodeInformation d[PacketTypes.ANSWER_NODE_INFORMATION] = self.answerNodeInformation
d[protocol.ASK_CLUSTER_STATE] = self.askClusterState d[PacketTypes.ASK_CLUSTER_STATE] = self.askClusterState
d[protocol.ANSWER_CLUSTER_STATE] = self.answerClusterState d[PacketTypes.ANSWER_CLUSTER_STATE] = self.answerClusterState
d[protocol.NOTIFY_CLUSTER_INFORMATION] = self.notifyClusterInformation d[PacketTypes.NOTIFY_CLUSTER_INFORMATION] = self.notifyClusterInformation
d[protocol.NOTIFY_LAST_OID] = self.notifyLastOID d[PacketTypes.NOTIFY_LAST_OID] = self.notifyLastOID
return d return d
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
from neo.handler import EventHandler from neo.handler import EventHandler
from neo.protocol import ErrorCodes from neo.protocol import ErrorCodes
from neo import protocol
class CommandEventHandler(EventHandler): class CommandEventHandler(EventHandler):
""" Base handler for command """ """ Base handler for command """
......
...@@ -20,7 +20,7 @@ from neo.connection import ClientConnection ...@@ -20,7 +20,7 @@ from neo.connection import ClientConnection
from neo.event import EventManager from neo.event import EventManager
from neo.neoctl.handler import CommandEventHandler from neo.neoctl.handler import CommandEventHandler
from neo import protocol from neo import protocol
from neo.protocol import ClusterStates, NodeStates, ErrorCodes from neo.protocol import ClusterStates, NodeStates, ErrorCodes, PacketTypes
class NotReadyException(Exception): class NotReadyException(Exception):
pass pass
...@@ -59,7 +59,7 @@ class NeoCTL(object): ...@@ -59,7 +59,7 @@ class NeoCTL(object):
if not self.connected: if not self.connected:
raise NotReadyException, 'Connection closed' raise NotReadyException, 'Connection closed'
response = response_queue.pop() response = response_queue.pop()
if response[0] == protocol.ERROR and \ if response[0] == PacketTypes.ERROR and \
response[1] == ErrorCodes.NOT_READY: response[1] == ErrorCodes.NOT_READY:
raise NotReadyException(response[2]) raise NotReadyException(response[2])
return response return response
...@@ -70,7 +70,7 @@ class NeoCTL(object): ...@@ -70,7 +70,7 @@ class NeoCTL(object):
""" """
packet = protocol.addPendingNodes(uuid_list) packet = protocol.addPendingNodes(uuid_list)
response = self.__ask(packet) response = self.__ask(packet)
assert response[0] == protocol.ERROR assert response[0] == PacketTypes.ERROR
assert response[1] == ErrorCodes.NO_ERROR assert response[1] == ErrorCodes.NO_ERROR
def setClusterState(self, state): def setClusterState(self, state):
...@@ -79,7 +79,7 @@ class NeoCTL(object): ...@@ -79,7 +79,7 @@ class NeoCTL(object):
""" """
packet = protocol.setClusterState(state) packet = protocol.setClusterState(state)
response = self.__ask(packet) response = self.__ask(packet)
assert response[0] == protocol.ERROR assert response[0] == PacketTypes.ERROR
assert response[1] == ErrorCodes.NO_ERROR assert response[1] == ErrorCodes.NO_ERROR
def setNodeState(self, node, state, update_partition_table=False): def setNodeState(self, node, state, update_partition_table=False):
...@@ -92,7 +92,7 @@ class NeoCTL(object): ...@@ -92,7 +92,7 @@ class NeoCTL(object):
update_partition_table = 0 update_partition_table = 0
packet = protocol.setNodeState(node, state, update_partition_table) packet = protocol.setNodeState(node, state, update_partition_table)
response = self.__ask(packet) response = self.__ask(packet)
assert response[0] == protocol.ERROR assert response[0] == PacketTypes.ERROR
assert response[1] == ErrorCodes.NO_ERROR assert response[1] == ErrorCodes.NO_ERROR
def getClusterState(self): def getClusterState(self):
...@@ -101,7 +101,7 @@ class NeoCTL(object): ...@@ -101,7 +101,7 @@ class NeoCTL(object):
""" """
packet = protocol.askClusterState() packet = protocol.askClusterState()
response = self.__ask(packet) response = self.__ask(packet)
assert response[0] == protocol.ANSWER_CLUSTER_STATE assert response[0] == PacketTypes.ANSWER_CLUSTER_STATE
return response[1] return response[1]
def getNodeList(self, node_type=None): def getNodeList(self, node_type=None):
...@@ -110,7 +110,7 @@ class NeoCTL(object): ...@@ -110,7 +110,7 @@ class NeoCTL(object):
""" """
packet = protocol.askNodeList(node_type) packet = protocol.askNodeList(node_type)
response = self.__ask(packet) response = self.__ask(packet)
assert response[0] == protocol.ANSWER_NODE_LIST assert response[0] == PacketTypes.ANSWER_NODE_LIST
return response[1] return response[1]
def getPartitionRowList(self, min_offset=0, max_offset=0, node=None): def getPartitionRowList(self, min_offset=0, max_offset=0, node=None):
...@@ -120,7 +120,7 @@ class NeoCTL(object): ...@@ -120,7 +120,7 @@ class NeoCTL(object):
""" """
packet = protocol.askPartitionList(min_offset, max_offset, node) packet = protocol.askPartitionList(min_offset, max_offset, node)
response = self.__ask(packet) response = self.__ask(packet)
assert response[0] == protocol.ANSWER_PARTITION_LIST assert response[0] == PacketTypes.ANSWER_PARTITION_LIST
return (response[1], response[2]) return (response[1], response[2])
def startCluster(self): def startCluster(self):
...@@ -141,6 +141,6 @@ class NeoCTL(object): ...@@ -141,6 +141,6 @@ class NeoCTL(object):
""" """
packet = protocol.askPrimaryMaster() packet = protocol.askPrimaryMaster()
response = self.__ask(packet) response = self.__ask(packet)
assert response[0] == protocol.ANSWER_PRIMARY_MASTER assert response[0] == PacketTypes.ANSWER_PRIMARY_MASTER
return response[1] return response[1]
This diff is collapsed.
...@@ -22,6 +22,7 @@ import MySQLdb ...@@ -22,6 +22,7 @@ import MySQLdb
from neo import logging from neo import logging
from mock import Mock from mock import Mock
from neo import protocol from neo import protocol
from neo.protocol import PacketTypes
DB_PREFIX = 'test_neo_' DB_PREFIX = 'test_neo_'
DB_ADMIN = 'root' DB_ADMIN = 'root'
...@@ -168,7 +169,7 @@ class NeoTestBase(unittest.TestCase): ...@@ -168,7 +169,7 @@ class NeoTestBase(unittest.TestCase):
self.assertEquals(len(calls), 1) self.assertEquals(len(calls), 1)
packet = calls[0].getParam(0) packet = calls[0].getParam(0)
self.assertTrue(isinstance(packet, protocol.Packet)) self.assertTrue(isinstance(packet, protocol.Packet))
self.assertEquals(packet.getType(), protocol.ERROR) self.assertEquals(packet.getType(), PacketTypes.ERROR)
if decode: if decode:
return protocol.decode_table[packet.getType()](packet._body) return protocol.decode_table[packet.getType()](packet._body)
return packet return packet
...@@ -210,97 +211,97 @@ class NeoTestBase(unittest.TestCase): ...@@ -210,97 +211,97 @@ class NeoTestBase(unittest.TestCase):
return packet return packet
def checkNotifyNodeInformation(self, conn, **kw): def checkNotifyNodeInformation(self, conn, **kw):
return self.checkNotifyPacket(conn, protocol.NOTIFY_NODE_INFORMATION, **kw) return self.checkNotifyPacket(conn, PacketTypes.NOTIFY_NODE_INFORMATION, **kw)
def checkSendPartitionTable(self, conn, **kw): def checkSendPartitionTable(self, conn, **kw):
return self.checkNotifyPacket(conn, protocol.SEND_PARTITION_TABLE, **kw) return self.checkNotifyPacket(conn, PacketTypes.SEND_PARTITION_TABLE, **kw)
def checkStartOperation(self, conn, **kw): def checkStartOperation(self, conn, **kw):
return self.checkNotifyPacket(conn, protocol.START_OPERATION, **kw) return self.checkNotifyPacket(conn, PacketTypes.START_OPERATION, **kw)
def checkNotifyTransactionFinished(self, conn, **kw): def checkNotifyTransactionFinished(self, conn, **kw):
return self.checkNotifyPacket(conn, protocol.NOTIFY_TRANSACTION_FINISHED, **kw) return self.checkNotifyPacket(conn, PacketTypes.NOTIFY_TRANSACTION_FINISHED, **kw)
def checkNotifyInformationLocked(self, conn, **kw): def checkNotifyInformationLocked(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.NOTIFY_INFORMATION_LOCKED, **kw) return self.checkAnswerPacket(conn, PacketTypes.NOTIFY_INFORMATION_LOCKED, **kw)
def checkLockInformation(self, conn, **kw): def checkLockInformation(self, conn, **kw):
return self.checkAskPacket(conn, protocol.LOCK_INFORMATION, **kw) return self.checkAskPacket(conn, PacketTypes.LOCK_INFORMATION, **kw)
def checkUnlockInformation(self, conn, **kw): def checkUnlockInformation(self, conn, **kw):
return self.checkAskPacket(conn, protocol.UNLOCK_INFORMATION, **kw) return self.checkAskPacket(conn, PacketTypes.UNLOCK_INFORMATION, **kw)
def checkRequestNodeIdentification(self, conn, **kw): def checkRequestNodeIdentification(self, conn, **kw):
return self.checkAskPacket(conn, protocol.REQUEST_NODE_IDENTIFICATION, **kw) return self.checkAskPacket(conn, PacketTypes.REQUEST_NODE_IDENTIFICATION, **kw)
def checkAskPrimaryMaster(self, conn, **kw): def checkAskPrimaryMaster(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_PRIMARY_MASTER) return self.checkAskPacket(conn, PacketTypes.ASK_PRIMARY_MASTER)
def checkAskUnfinishedTransactions(self, conn, **kw): def checkAskUnfinishedTransactions(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_UNFINISHED_TRANSACTIONS) return self.checkAskPacket(conn, PacketTypes.ASK_UNFINISHED_TRANSACTIONS)
def checkAskTransactionInformation(self, conn, **kw): def checkAskTransactionInformation(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_TRANSACTION_INFORMATION, **kw) return self.checkAskPacket(conn, PacketTypes.ASK_TRANSACTION_INFORMATION, **kw)
def checkAskObjectPresent(self, conn, **kw): def checkAskObjectPresent(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_OBJECT_PRESENT, **kw) return self.checkAskPacket(conn, PacketTypes.ASK_OBJECT_PRESENT, **kw)
def checkAskObject(self, conn, **kw): def checkAskObject(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_OBJECT, **kw) return self.checkAskPacket(conn, PacketTypes.ASK_OBJECT, **kw)
def checkAskStoreObject(self, conn, **kw): def checkAskStoreObject(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_STORE_OBJECT, **kw) return self.checkAskPacket(conn, PacketTypes.ASK_STORE_OBJECT, **kw)
def checkAskStoreTransaction(self, conn, **kw): def checkAskStoreTransaction(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_STORE_TRANSACTION, **kw) return self.checkAskPacket(conn, PacketTypes.ASK_STORE_TRANSACTION, **kw)
def checkFinishTransaction(self, conn, **kw): def checkFinishTransaction(self, conn, **kw):
return self.checkAskPacket(conn, protocol.FINISH_TRANSACTION, **kw) return self.checkAskPacket(conn, PacketTypes.FINISH_TRANSACTION, **kw)
def checkAskNewTid(self, conn, **kw): def checkAskNewTid(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_BEGIN_TRANSACTION, **kw) return self.checkAskPacket(conn, PacketTypes.ASK_BEGIN_TRANSACTION, **kw)
def checkAskLastIDs(self, conn, **kw): def checkAskLastIDs(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_LAST_IDS, **kw) return self.checkAskPacket(conn, PacketTypes.ASK_LAST_IDS, **kw)
def checkAcceptNodeIdentification(self, conn, **kw): def checkAcceptNodeIdentification(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ACCEPT_NODE_IDENTIFICATION, **kw) return self.checkAnswerPacket(conn, PacketTypes.ACCEPT_NODE_IDENTIFICATION, **kw)
def checkAnswerPrimaryMaster(self, conn, **kw): def checkAnswerPrimaryMaster(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_PRIMARY_MASTER, **kw) return self.checkAnswerPacket(conn, PacketTypes.ANSWER_PRIMARY_MASTER, **kw)
def checkAnswerLastIDs(self, conn, **kw): def checkAnswerLastIDs(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_LAST_IDS, **kw) return self.checkAnswerPacket(conn, PacketTypes.ANSWER_LAST_IDS, **kw)
def checkAnswerUnfinishedTransactions(self, conn, **kw): def checkAnswerUnfinishedTransactions(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_UNFINISHED_TRANSACTIONS, **kw) return self.checkAnswerPacket(conn, PacketTypes.ANSWER_UNFINISHED_TRANSACTIONS, **kw)
def checkAnswerObject(self, conn, **kw): def checkAnswerObject(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_OBJECT, **kw) return self.checkAnswerPacket(conn, PacketTypes.ANSWER_OBJECT, **kw)
def checkAnswerTransactionInformation(self, conn, **kw): def checkAnswerTransactionInformation(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_TRANSACTION_INFORMATION, **kw) return self.checkAnswerPacket(conn, PacketTypes.ANSWER_TRANSACTION_INFORMATION, **kw)
def checkAnswerTids(self, conn, **kw): def checkAnswerTids(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_TIDS, **kw) return self.checkAnswerPacket(conn, PacketTypes.ANSWER_TIDS, **kw)
def checkAnswerObjectHistory(self, conn, **kw): def checkAnswerObjectHistory(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_OBJECT_HISTORY, **kw) return self.checkAnswerPacket(conn, PacketTypes.ANSWER_OBJECT_HISTORY, **kw)
def checkAnswerStoreTransaction(self, conn, **kw): def checkAnswerStoreTransaction(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_STORE_TRANSACTION, **kw) return self.checkAnswerPacket(conn, PacketTypes.ANSWER_STORE_TRANSACTION, **kw)
def checkAnswerStoreObject(self, conn, **kw): def checkAnswerStoreObject(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_STORE_OBJECT, **kw) return self.checkAnswerPacket(conn, PacketTypes.ANSWER_STORE_OBJECT, **kw)
def checkAnswerOids(self, conn, **kw): def checkAnswerOids(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_OIDS, **kw) return self.checkAnswerPacket(conn, PacketTypes.ANSWER_OIDS, **kw)
def checkAnswerPartitionTable(self, conn, **kw): def checkAnswerPartitionTable(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_PARTITION_TABLE, **kw) return self.checkAnswerPacket(conn, PacketTypes.ANSWER_PARTITION_TABLE, **kw)
def checkAnswerObjectPresent(self, conn, **kw): def checkAnswerObjectPresent(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_OBJECT_PRESENT, **kw) return self.checkAnswerPacket(conn, PacketTypes.ANSWER_OBJECT_PRESENT, **kw)
# XXX: imported from neo.master.test.connector since it's used at many places # XXX: imported from neo.master.test.connector since it's used at many places
......
...@@ -23,14 +23,9 @@ from struct import pack, unpack ...@@ -23,14 +23,9 @@ from struct import pack, unpack
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
import neo.master import neo.master
from neo import protocol from neo import protocol
from neo.protocol import Packet, NodeTypes, NodeStates, INVALID_UUID from neo.protocol import Packet, PacketTypes, NodeTypes, NodeStates
from neo.master.handlers.client import ClientServiceHandler from neo.master.handlers.client import ClientServiceHandler
from neo.master.app import Application from neo.master.app import Application
from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \
REELECT_PRIMARY_MASTER, NOTIFY_NODE_INFORMATION, \
ASK_LAST_IDS, ANSWER_LAST_IDS, NOTIFY_PARTITION_CHANGES, \
ASK_UNFINISHED_TRANSACTIONS, ASK_BEGIN_TRANSACTION, FINISH_TRANSACTION, \
NOTIFY_INFORMATION_LOCKED, ASK_NEW_OIDS, ABORT_TRANSACTION
from neo.exception import OperationFailure, ElectionFailure from neo.exception import OperationFailure, ElectionFailure
class MasterClientHandlerTests(NeoTestBase): class MasterClientHandlerTests(NeoTestBase):
...@@ -82,7 +77,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -82,7 +77,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_05_handleNotifyNodeInformation(self): def test_05_handleNotifyNodeInformation(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION) packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION)
# tell the master node that is not running any longer, it must raises # tell the master node that is not running any longer, it must raises
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),
...@@ -153,7 +148,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -153,7 +148,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_06_handleAnswerLastIDs(self): def test_06_handleAnswerLastIDs(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ANSWER_LAST_IDS) packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
loid = self.app.loid loid = self.app.loid
ltid = self.app.ltid ltid = self.app.ltid
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
...@@ -180,7 +175,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -180,7 +175,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_07_handleAskBeginTransaction(self): def test_07_handleAskBeginTransaction(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ASK_BEGIN_TRANSACTION) packet = Packet(msg_type=PacketTypes.ASK_BEGIN_TRANSACTION)
ltid = self.app.ltid ltid = self.app.ltid
# 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)
...@@ -195,7 +190,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -195,7 +190,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_08_handleAskNewOIDs(self): def test_08_handleAskNewOIDs(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ASK_NEW_OIDS) packet = Packet(msg_type=PacketTypes.ASK_NEW_OIDS)
loid = self.app.loid loid = self.app.loid
# 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)
...@@ -206,7 +201,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -206,7 +201,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_09_handleFinishTransaction(self): def test_09_handleFinishTransaction(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=FINISH_TRANSACTION) packet = Packet(msg_type=PacketTypes.FINISH_TRANSACTION)
packet.setId(9) packet.setId(9)
# give an older tid than the PMN known, must abort # give an older tid than the PMN known, must abort
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port) client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
...@@ -244,7 +239,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -244,7 +239,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_11_handleAbortTransaction(self): def test_11_handleAbortTransaction(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ABORT_TRANSACTION) packet = Packet(msg_type=PacketTypes.ABORT_TRANSACTION)
# give a bad tid, must not failed, just ignored it # give a bad tid, must not failed, just ignored 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)
...@@ -263,7 +258,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -263,7 +258,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_12_handleAskLastIDs(self): def test_12_handleAskLastIDs(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ASK_LAST_IDS) packet = Packet(msg_type=PacketTypes.ASK_LAST_IDS)
# give a uuid # give a uuid
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
ptid = self.app.pt.getID() ptid = self.app.pt.getID()
...@@ -280,7 +275,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -280,7 +275,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_13_handleAskUnfinishedTransactions(self): def test_13_handleAskUnfinishedTransactions(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=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.handleAskUnfinishedTransactions(conn, packet)
......
...@@ -22,24 +22,9 @@ from mock import Mock ...@@ -22,24 +22,9 @@ from mock import Mock
from struct import pack, unpack from struct import pack, unpack
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo import protocol from neo import protocol
from neo.protocol import Packet, NodeTypes, NodeStates, INVALID_UUID from neo.protocol import Packet, PacketTypes, NodeTypes, NodeStates, INVALID_UUID
from neo.master.handlers.election import ClientElectionHandler, ServerElectionHandler from neo.master.handlers.election import ClientElectionHandler, ServerElectionHandler
from neo.master.app import Application from neo.master.app import Application
from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \
PING, PONG, ASK_PRIMARY_MASTER, ANSWER_PRIMARY_MASTER, ANNOUNCE_PRIMARY_MASTER, \
REELECT_PRIMARY_MASTER, NOTIFY_NODE_INFORMATION, START_OPERATION, \
STOP_OPERATION, ASK_LAST_IDS, ANSWER_LAST_IDS, ASK_PARTITION_TABLE, \
ANSWER_PARTITION_TABLE, SEND_PARTITION_TABLE, NOTIFY_PARTITION_CHANGES, \
ASK_UNFINISHED_TRANSACTIONS, ANSWER_UNFINISHED_TRANSACTIONS, \
ASK_OBJECT_PRESENT, ANSWER_OBJECT_PRESENT, \
DELETE_TRANSACTION, COMMIT_TRANSACTION, ASK_BEGIN_TRANSACTION, ANSWER_BEGIN_TRANSACTION, \
FINISH_TRANSACTION, NOTIFY_TRANSACTION_FINISHED, LOCK_INFORMATION, \
NOTIFY_INFORMATION_LOCKED, INVALIDATE_OBJECTS, UNLOCK_INFORMATION, \
ASK_NEW_OIDS, ANSWER_NEW_OIDS, ASK_STORE_OBJECT, ANSWER_STORE_OBJECT, \
ABORT_TRANSACTION, ASK_STORE_TRANSACTION, ANSWER_STORE_TRANSACTION, \
ASK_OBJECT, ANSWER_OBJECT, ASK_TIDS, ANSWER_TIDS, ASK_TRANSACTION_INFORMATION, \
ANSWER_TRANSACTION_INFORMATION, ASK_OBJECT_HISTORY, ANSWER_OBJECT_HISTORY, \
ASK_OIDS, ANSWER_OIDS
from neo.exception import OperationFailure, ElectionFailure from neo.exception import OperationFailure, ElectionFailure
from neo.tests import DoNothingConnector from neo.tests import DoNothingConnector
from neo.connection import ClientConnection from neo.connection import ClientConnection
...@@ -541,7 +526,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -541,7 +526,7 @@ class MasterServerElectionTests(NeoTestBase):
def test_12_handleAnnouncePrimaryMaster(self): def test_12_handleAnnouncePrimaryMaster(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=ANNOUNCE_PRIMARY_MASTER) packet = Packet(msg_type=PacketTypes.ANNOUNCE_PRIMARY_MASTER)
# No uuid # No uuid
conn = Mock({"_addPacket" : None, conn = Mock({"_addPacket" : None,
"getUUID" : None, "getUUID" : None,
...@@ -583,7 +568,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -583,7 +568,7 @@ class MasterServerElectionTests(NeoTestBase):
def test_14_handleNotifyNodeInformation(self): def test_14_handleNotifyNodeInformation(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=NOTIFY_NODE_INFORMATION) packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION)
# do not answer if no uuid # do not answer if no uuid
conn = Mock({"getUUID" : None, conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
......
...@@ -20,7 +20,7 @@ from mock import Mock ...@@ -20,7 +20,7 @@ from mock import Mock
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.master.app import Application from neo.master.app import Application
from neo.protocol import INVALID_PTID, INVALID_OID, INVALID_TID, \ from neo.protocol import INVALID_PTID, INVALID_OID, INVALID_TID, \
INVALID_UUID, Packet, NOTIFY_NODE_INFORMATION INVALID_UUID, Packet
from neo.storage.mysqldb import p64, u64 from neo.storage.mysqldb import p64, u64
class MasterAppTests(NeoTestBase): class MasterAppTests(NeoTestBase):
......
...@@ -21,25 +21,10 @@ from neo import logging ...@@ -21,25 +21,10 @@ from neo import logging
from mock import Mock from mock import Mock
from struct import pack, unpack from struct import pack, unpack
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo import protocol from neo.protocol import Packet, PacketTypes
from neo.protocol import Packet, NodeTypes, NodeStates, CellStates, INVALID_UUID from neo.protocol import NodeTypes, NodeStates, CellStates
from neo.master.handlers.recovery import RecoveryHandler from neo.master.handlers.recovery import RecoveryHandler
from neo.master.app import Application from neo.master.app import Application
from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \
PING, PONG, ASK_PRIMARY_MASTER, ANSWER_PRIMARY_MASTER, ANNOUNCE_PRIMARY_MASTER, \
REELECT_PRIMARY_MASTER, NOTIFY_NODE_INFORMATION, START_OPERATION, \
STOP_OPERATION, ASK_LAST_IDS, ANSWER_LAST_IDS, ASK_PARTITION_TABLE, \
ANSWER_PARTITION_TABLE, SEND_PARTITION_TABLE, NOTIFY_PARTITION_CHANGES, \
ASK_UNFINISHED_TRANSACTIONS, ANSWER_UNFINISHED_TRANSACTIONS, \
ASK_OBJECT_PRESENT, ANSWER_OBJECT_PRESENT, \
DELETE_TRANSACTION, COMMIT_TRANSACTION, ASK_BEGIN_TRANSACTION, ANSWER_BEGIN_TRANSACTION, \
FINISH_TRANSACTION, NOTIFY_TRANSACTION_FINISHED, LOCK_INFORMATION, \
NOTIFY_INFORMATION_LOCKED, INVALIDATE_OBJECTS, UNLOCK_INFORMATION, \
ASK_NEW_OIDS, ANSWER_NEW_OIDS, ASK_STORE_OBJECT, ANSWER_STORE_OBJECT, \
ABORT_TRANSACTION, ASK_STORE_TRANSACTION, ANSWER_STORE_TRANSACTION, \
ASK_OBJECT, ANSWER_OBJECT, ASK_TIDS, ANSWER_TIDS, ASK_TRANSACTION_INFORMATION, \
ANSWER_TRANSACTION_INFORMATION, ASK_OBJECT_HISTORY, ANSWER_OBJECT_HISTORY, \
ASK_OIDS, ANSWER_OIDS
from neo.exception import OperationFailure, ElectionFailure from neo.exception import OperationFailure, ElectionFailure
from neo.tests import DoNothingConnector from neo.tests import DoNothingConnector
from neo.connection import ClientConnection from neo.connection import ClientConnection
...@@ -114,7 +99,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -114,7 +99,7 @@ class MasterRecoveryTests(NeoTestBase):
def test_08_handleNotifyNodeInformation(self): def test_08_handleNotifyNodeInformation(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=NOTIFY_NODE_INFORMATION) packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION)
# tell about a client node, do nothing # tell about a client node, do nothing
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(NodeTypes.CLIENT, '127.0.0.1', self.client_port, node_list = [(NodeTypes.CLIENT, '127.0.0.1', self.client_port,
...@@ -172,7 +157,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -172,7 +157,7 @@ class MasterRecoveryTests(NeoTestBase):
def test_09_handleAnswerLastIDs(self): def test_09_handleAnswerLastIDs(self):
recovery = self.recovery recovery = self.recovery
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ANSWER_LAST_IDS) packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
loid = self.app.loid loid = self.app.loid
ltid = self.app.ltid ltid = self.app.ltid
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
...@@ -199,7 +184,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -199,7 +184,7 @@ class MasterRecoveryTests(NeoTestBase):
def test_10_handleAnswerPartitionTable(self): def test_10_handleAnswerPartitionTable(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=ANSWER_PARTITION_TABLE) packet = Packet(msg_type=PacketTypes.ANSWER_PARTITION_TABLE)
# not from target node, ignore # not from target node, ignore
uuid = self.identifyToMasterNode(NodeTypes.STORAGE, port=self.storage_port) uuid = self.identifyToMasterNode(NodeTypes.STORAGE, port=self.storage_port)
conn = self.getFakeConnection(uuid, self.storage_port) conn = self.getFakeConnection(uuid, self.storage_port)
......
...@@ -23,14 +23,10 @@ from struct import pack, unpack ...@@ -23,14 +23,10 @@ from struct import pack, unpack
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
import neo.master import neo.master
from neo import protocol from neo import protocol
from neo.protocol import Packet, NodeTypes, NodeStates, CellStates, INVALID_UUID from neo.protocol import Packet, PacketTypes
from neo.protocol import NodeTypes, NodeStates, CellStates
from neo.master.handlers.storage import StorageServiceHandler from neo.master.handlers.storage import StorageServiceHandler
from neo.master.app import Application from neo.master.app import Application
from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \
REELECT_PRIMARY_MASTER, NOTIFY_NODE_INFORMATION, \
ASK_LAST_IDS, ANSWER_LAST_IDS, NOTIFY_PARTITION_CHANGES, \
ASK_UNFINISHED_TRANSACTIONS, ASK_BEGIN_TRANSACTION, FINISH_TRANSACTION, \
NOTIFY_INFORMATION_LOCKED, ASK_NEW_OIDS, ABORT_TRANSACTION
from neo.exception import OperationFailure, ElectionFailure from neo.exception import OperationFailure, ElectionFailure
class MasterStorageHandlerTests(NeoTestBase): class MasterStorageHandlerTests(NeoTestBase):
...@@ -72,7 +68,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -72,7 +68,7 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_05_handleNotifyNodeInformation(self): def test_05_handleNotifyNodeInformation(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION) packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION)
# tell the master node that is not running any longer, it must raises # tell the master node that is not running any longer, it must raises
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,
...@@ -142,7 +138,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -142,7 +138,7 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_06_handleAnswerLastIDs(self): def test_06_handleAnswerLastIDs(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ANSWER_LAST_IDS) packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
loid = self.app.loid loid = self.app.loid
ltid = self.app.ltid ltid = self.app.ltid
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
...@@ -160,7 +156,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -160,7 +156,7 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_10_handleNotifyInformationLocked(self): def test_10_handleNotifyInformationLocked(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode(port=10020) uuid = self.identifyToMasterNode(port=10020)
packet = Packet(msg_type=NOTIFY_INFORMATION_LOCKED) packet = Packet(msg_type=PacketTypes.NOTIFY_INFORMATION_LOCKED)
# give an older tid than the PMN known, must abort # give an older tid than the PMN known, must abort
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
oid_list = [] oid_list = []
...@@ -203,7 +199,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -203,7 +199,7 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_12_handleAskLastIDs(self): def test_12_handleAskLastIDs(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ASK_LAST_IDS) packet = Packet(msg_type=PacketTypes.ASK_LAST_IDS)
# give a uuid # give a uuid
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
ptid = self.app.pt.getID() ptid = self.app.pt.getID()
...@@ -220,7 +216,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -220,7 +216,7 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_13_handleAskUnfinishedTransactions(self): def test_13_handleAskUnfinishedTransactions(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=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.handleAskUnfinishedTransactions(conn, packet)
...@@ -244,7 +240,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -244,7 +240,7 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_14_handleNotifyPartitionChanges(self): def test_14_handleNotifyPartitionChanges(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES) packet = Packet(msg_type=PacketTypes.NOTIFY_PARTITION_CHANGES)
# do not answer if not a storage node # do not answer if not a storage node
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
port=self.client_port) port=self.client_port)
......
...@@ -22,14 +22,10 @@ from mock import Mock ...@@ -22,14 +22,10 @@ from mock import Mock
from struct import pack, unpack from struct import pack, unpack
import neo import neo
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.protocol import Packet, NodeTypes, NodeStates, CellStates, ErrorCodes from neo.protocol import Packet, PacketTypes
from neo.protocol import NodeTypes, NodeStates, CellStates, ErrorCodes
from neo.master.handlers.verification import VerificationHandler from neo.master.handlers.verification import VerificationHandler
from neo.master.app import Application from neo.master.app import Application
from neo import protocol
from neo.protocol import ERROR, ANNOUNCE_PRIMARY_MASTER, INVALID_UUID, \
NOTIFY_NODE_INFORMATION, ANSWER_LAST_IDS, ANSWER_PARTITION_TABLE, \
ANSWER_UNFINISHED_TRANSACTIONS, ANSWER_OBJECT_PRESENT, \
ANSWER_TRANSACTION_INFORMATION
from neo.exception import OperationFailure, ElectionFailure, VerificationFailure from neo.exception import OperationFailure, ElectionFailure, VerificationFailure
from neo.tests import DoNothingConnector from neo.tests import DoNothingConnector
from neo.connection import ClientConnection from neo.connection import ClientConnection
...@@ -137,7 +133,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -137,7 +133,7 @@ class MasterVerificationTests(NeoTestBase):
def test_09_handleAnswerLastIDs(self): def test_09_handleAnswerLastIDs(self):
verification = self.verification verification = self.verification
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ANSWER_LAST_IDS) packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
loid = self.app.loid loid = self.app.loid
ltid = self.app.ltid ltid = self.app.ltid
lptid = '\0' * 8 lptid = '\0' * 8
...@@ -161,7 +157,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -161,7 +157,7 @@ class MasterVerificationTests(NeoTestBase):
def test_11_handleAnswerUnfinishedTransactions(self): def test_11_handleAnswerUnfinishedTransactions(self):
verification = self.verification verification = self.verification
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ANSWER_UNFINISHED_TRANSACTIONS) packet = Packet(msg_type=PacketTypes.ANSWER_UNFINISHED_TRANSACTIONS)
# do nothing # do nothing
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 0) self.assertEquals(len(self.app.asking_uuid_dict), 0)
...@@ -188,7 +184,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -188,7 +184,7 @@ class MasterVerificationTests(NeoTestBase):
def test_12_handleAnswerTransactionInformation(self): def test_12_handleAnswerTransactionInformation(self):
verification = self.verification verification = self.verification
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ANSWER_TRANSACTION_INFORMATION) packet = Packet(msg_type=PacketTypes.ANSWER_TRANSACTION_INFORMATION)
# do nothing, as unfinished_oid_set is None # do nothing, as unfinished_oid_set is None
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 0) self.assertEquals(len(self.app.asking_uuid_dict), 0)
...@@ -260,7 +256,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -260,7 +256,7 @@ class MasterVerificationTests(NeoTestBase):
def test_14_handleAnswerObjectPresent(self): def test_14_handleAnswerObjectPresent(self):
verification = self.verification verification = self.verification
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ANSWER_OBJECT_PRESENT) packet = Packet(msg_type=PacketTypes.ANSWER_OBJECT_PRESENT)
# do nothing as asking_uuid_dict is True # do nothing as asking_uuid_dict is True
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)
......
...@@ -27,8 +27,8 @@ from neo.storage.handlers.client import TransactionInformation ...@@ -27,8 +27,8 @@ from neo.storage.handlers.client import TransactionInformation
from neo.storage.handlers.client import ClientOperationHandler from neo.storage.handlers.client import ClientOperationHandler
from neo.exception import PrimaryFailure, OperationFailure from neo.exception import PrimaryFailure, OperationFailure
from neo.pt import PartitionTable from neo.pt import PartitionTable
from neo import protocol
from neo.protocol import * from neo.protocol import *
from neo.protocol import PacketTypes
class StorageClientHandlerTests(NeoTestBase): class StorageClientHandlerTests(NeoTestBase):
...@@ -107,14 +107,14 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -107,14 +107,14 @@ class StorageClientHandlerTests(NeoTestBase):
def test_18_handleAskTransactionInformation1(self): def test_18_handleAskTransactionInformation1(self):
# transaction does not exists # transaction does not exists
conn = Mock({ }) conn = Mock({ })
packet = Packet(msg_type=ASK_TRANSACTION_INFORMATION) packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
self.operation.handleAskTransactionInformation(conn, packet, INVALID_TID) self.operation.handleAskTransactionInformation(conn, packet, INVALID_TID)
self.checkErrorPacket(conn) self.checkErrorPacket(conn)
def test_18_handleAskTransactionInformation2(self): def test_18_handleAskTransactionInformation2(self):
# answer # answer
conn = Mock({ }) conn = Mock({ })
packet = Packet(msg_type=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.handleAskTransactionInformation(conn, packet, INVALID_TID)
...@@ -124,7 +124,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -124,7 +124,7 @@ class StorageClientHandlerTests(NeoTestBase):
# delayed response # delayed response
conn = Mock({}) conn = Mock({})
self.app.dm = Mock() self.app.dm = Mock()
packet = Packet(msg_type=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.handleAskObject(conn, packet,
...@@ -139,7 +139,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -139,7 +139,7 @@ class StorageClientHandlerTests(NeoTestBase):
# 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=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.handleAskObject(conn, packet,
oid=INVALID_OID, oid=INVALID_OID,
...@@ -155,7 +155,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -155,7 +155,7 @@ class StorageClientHandlerTests(NeoTestBase):
# 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=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.handleAskObject(conn, packet,
oid=INVALID_OID, oid=INVALID_OID,
...@@ -170,7 +170,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -170,7 +170,7 @@ class StorageClientHandlerTests(NeoTestBase):
app.pt = Mock() app.pt = Mock()
app.dm = Mock() app.dm = Mock()
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=ASK_TIDS) packet = Packet(msg_type=PacketTypes.ASK_TIDS)
self.checkProtocolErrorRaised(self.operation.handleAskTIDs, conn, packet, 1, 1, None) self.checkProtocolErrorRaised(self.operation.handleAskTIDs, 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)
...@@ -178,7 +178,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -178,7 +178,7 @@ class StorageClientHandlerTests(NeoTestBase):
def test_25_handleAskTIDs2(self): def test_25_handleAskTIDs2(self):
# well case => answer # well case => answer
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=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.handleAskTIDs(conn, packet, 1, 2, 1)
...@@ -190,7 +190,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -190,7 +190,7 @@ class StorageClientHandlerTests(NeoTestBase):
def test_25_handleAskTIDs3(self): def test_25_handleAskTIDs3(self):
# invalid partition => answer usable partitions # invalid partition => answer usable partitions
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=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})
...@@ -206,13 +206,13 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -206,13 +206,13 @@ class StorageClientHandlerTests(NeoTestBase):
app = self.app app = self.app
app.dm = Mock() app.dm = Mock()
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=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.handleAskObjectHistory, 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_handleAskObjectHistory2(self):
# first case: empty history # first case: empty history
packet = Packet(msg_type=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.handleAskObjectHistory(conn, packet, INVALID_OID, 1, 2)
...@@ -225,7 +225,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -225,7 +225,7 @@ class StorageClientHandlerTests(NeoTestBase):
def test_27_handleAskStoreTransaction2(self): def test_27_handleAskStoreTransaction2(self):
# add transaction entry # add transaction entry
packet = Packet(msg_type=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.handleAskStoreTransaction(conn, packet,
INVALID_TID, '', '', '', ()) INVALID_TID, '', '', '', ())
...@@ -237,7 +237,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -237,7 +237,7 @@ class StorageClientHandlerTests(NeoTestBase):
def test_28_handleAskStoreObject2(self): def test_28_handleAskStoreObject2(self):
# locked => delayed response # locked => delayed response
packet = Packet(msg_type=ASK_STORE_OBJECT) packet = Packet(msg_type=PacketTypes.ASK_STORE_OBJECT)
conn = Mock({'getUUID': self.app.uuid}) conn = Mock({'getUUID': self.app.uuid})
oid = '\x02' * 8 oid = '\x02' * 8
tid1, tid2 = self.getTwoIDs() tid1, tid2 = self.getTwoIDs()
...@@ -254,7 +254,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -254,7 +254,7 @@ class StorageClientHandlerTests(NeoTestBase):
def test_28_handleAskStoreObject3(self): def test_28_handleAskStoreObject3(self):
# locked => unresolvable conflict => answer # locked => unresolvable conflict => answer
packet = Packet(msg_type=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
...@@ -268,7 +268,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -268,7 +268,7 @@ class StorageClientHandlerTests(NeoTestBase):
def test_28_handleAskStoreObject4(self): def test_28_handleAskStoreObject4(self):
# resolvable conflict => answer # resolvable conflict => answer
packet = Packet(msg_type=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)
...@@ -282,7 +282,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -282,7 +282,7 @@ class StorageClientHandlerTests(NeoTestBase):
def test_28_handleAskStoreObject5(self): def test_28_handleAskStoreObject5(self):
# no conflict => answer # no conflict => answer
packet = Packet(msg_type=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.handleAskStoreObject(conn, packet, INVALID_OID,
INVALID_SERIAL, 0, 0, '', INVALID_TID) INVALID_SERIAL, 0, 0, '', INVALID_TID)
...@@ -297,7 +297,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -297,7 +297,7 @@ class StorageClientHandlerTests(NeoTestBase):
def test_29_handleAbortTransaction(self): def test_29_handleAbortTransaction(self):
# remove transaction # remove transaction
packet = Packet(msg_type=ABORT_TRANSACTION) packet = Packet(msg_type=PacketTypes.ABORT_TRANSACTION)
conn = Mock({'getUUID': self.app.uuid}) conn = Mock({'getUUID': self.app.uuid})
transaction = Mock({ 'getObjectList': ((0, ), ), }) transaction = Mock({ 'getObjectList': ((0, ), ), })
self.called = False self.called = False
......
...@@ -24,14 +24,7 @@ from neo import protocol ...@@ -24,14 +24,7 @@ from neo import protocol
from neo.pt import PartitionTable from neo.pt import PartitionTable
from neo.storage.app import Application from neo.storage.app import Application
from neo.storage.handlers.initialization import InitializationHandler from neo.storage.handlers.initialization import InitializationHandler
from neo.protocol import Packet, CellStates, INVALID_UUID, INVALID_TID from neo.protocol import Packet, PacketTypes, CellStates
from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION, \
NOTIFY_PARTITION_CHANGES, STOP_OPERATION, ASK_LAST_IDS, ASK_PARTITION_TABLE, \
ANSWER_OBJECT_PRESENT, ASK_OBJECT_PRESENT, LOCK_INFORMATION, \
UNLOCK_INFORMATION, ASK_TRANSACTION_INFORMATION, \
COMMIT_TRANSACTION, ASK_UNFINISHED_TRANSACTIONS, SEND_PARTITION_TABLE
from neo.protocol import ERROR, ASK_PRIMARY_MASTER
from neo.protocol import ANSWER_PRIMARY_MASTER
from neo.exception import PrimaryFailure, OperationFailure from neo.exception import PrimaryFailure, OperationFailure
from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64 from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64
...@@ -91,7 +84,7 @@ class StorageInitializationHandlerTests(NeoTestBase): ...@@ -91,7 +84,7 @@ class StorageInitializationHandlerTests(NeoTestBase):
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
def test_09_handleSendPartitionTable(self): def test_09_handleSendPartitionTable(self):
packet = Packet(msg_type=SEND_PARTITION_TABLE) packet = Packet(msg_type=PacketTypes.SEND_PARTITION_TABLE)
uuid = self.getNewUUID() uuid = self.getNewUUID()
# send a table # send a table
conn = Mock({"getUUID" : uuid, conn = Mock({"getUUID" : uuid,
......
...@@ -26,7 +26,7 @@ from neo.storage.app import Application ...@@ -26,7 +26,7 @@ from neo.storage.app import Application
from neo.storage.handlers.master import MasterOperationHandler from neo.storage.handlers.master import MasterOperationHandler
from neo.exception import PrimaryFailure, OperationFailure from neo.exception import PrimaryFailure, OperationFailure
from neo.pt import PartitionTable from neo.pt import PartitionTable
from neo.protocol import CellStates from neo.protocol import CellStates, PacketTypes
from neo.protocol import * from neo.protocol import *
class StorageMasterHandlerTests(NeoTestBase): class StorageMasterHandlerTests(NeoTestBase):
...@@ -100,7 +100,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -100,7 +100,7 @@ class StorageMasterHandlerTests(NeoTestBase):
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
}) })
app.replicator = Mock({}) app.replicator = Mock({})
packet = Packet(msg_type=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.handleNotifyPartitionChanges(conn, packet, 0, ())
...@@ -124,7 +124,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -124,7 +124,7 @@ class StorageMasterHandlerTests(NeoTestBase):
"isServer": False, "isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
}) })
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES) packet = Packet(msg_type=PacketTypes.NOTIFY_PARTITION_CHANGES)
app = self.app app = self.app
# register nodes # register nodes
app.nm.createStorage(uuid=uuid1) app.nm.createStorage(uuid=uuid1)
...@@ -147,14 +147,14 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -147,14 +147,14 @@ class StorageMasterHandlerTests(NeoTestBase):
def test_16_handleStopOperation1(self): def test_16_handleStopOperation1(self):
# OperationFailure # OperationFailure
conn = Mock({ 'isServer': False }) conn = Mock({ 'isServer': False })
packet = Packet(msg_type=STOP_OPERATION) packet = Packet(msg_type=PacketTypes.STOP_OPERATION)
self.assertRaises(OperationFailure, self.operation.handleStopOperation, conn, packet) self.assertRaises(OperationFailure, self.operation.handleStopOperation, conn, packet)
def test_22_handleLockInformation2(self): def test_22_handleLockInformation2(self):
# load transaction informations # load transaction informations
conn = Mock({ 'isServer': False, }) conn = Mock({ 'isServer': False, })
self.app.dm = Mock({ }) self.app.dm = Mock({ })
packet = Packet(msg_type=LOCK_INFORMATION) packet = Packet(msg_type=PacketTypes.LOCK_INFORMATION)
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
...@@ -173,7 +173,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -173,7 +173,7 @@ class StorageMasterHandlerTests(NeoTestBase):
# delete transaction informations # delete transaction informations
conn = Mock({ 'isServer': False, }) conn = Mock({ 'isServer': False, })
self.app.dm = Mock({ }) self.app.dm = Mock({ })
packet = Packet(msg_type=LOCK_INFORMATION) packet = Packet(msg_type=PacketTypes.LOCK_INFORMATION)
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
...@@ -195,7 +195,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -195,7 +195,7 @@ class StorageMasterHandlerTests(NeoTestBase):
def test_30_handleAnswerLastIDs(self): def test_30_handleAnswerLastIDs(self):
# set critical TID on replicator # set critical TID on replicator
conn = Mock() conn = Mock()
packet = Packet(msg_type=ANSWER_LAST_IDS) packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
self.app.replicator = Mock() self.app.replicator = Mock()
self.operation.handleAnswerLastIDs( self.operation.handleAnswerLastIDs(
conn=conn, conn=conn,
...@@ -211,7 +211,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -211,7 +211,7 @@ class StorageMasterHandlerTests(NeoTestBase):
def test_31_handleAnswerUnfinishedTransactions(self): def test_31_handleAnswerUnfinishedTransactions(self):
# set unfinished TID on replicator # set unfinished TID on replicator
conn = Mock() conn = Mock()
packet = Packet(msg_type=ANSWER_UNFINISHED_TRANSACTIONS) packet = Packet(msg_type=PacketTypes.ANSWER_UNFINISHED_TRANSACTIONS)
self.app.replicator = Mock() self.app.replicator = Mock()
self.operation.handleAnswerUnfinishedTransactions( self.operation.handleAnswerUnfinishedTransactions(
conn=conn, conn=conn,
......
...@@ -19,8 +19,8 @@ import unittest, logging, os ...@@ -19,8 +19,8 @@ import unittest, logging, os
from mock import Mock from mock import Mock
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.storage.app import Application from neo.storage.app import Application
from neo.protocol import CellStates, INVALID_PTID, INVALID_TID, \ from neo.protocol import Packet, CellStates, PacketTypes, \
INVALID_UUID, Packet, NOTIFY_NODE_INFORMATION INVALID_PTID, INVALID_TID, INVALID_UUID
from neo.storage.mysqldb import p64, u64, MySQLDatabaseManager from neo.storage.mysqldb import p64, u64, MySQLDatabaseManager
from collections import deque from collections import deque
from neo.pt import PartitionTable from neo.pt import PartitionTable
......
...@@ -24,8 +24,8 @@ from collections import deque ...@@ -24,8 +24,8 @@ from collections import deque
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.storage.app import Application from neo.storage.app import Application
from neo.storage.handlers.storage import StorageOperationHandler from neo.storage.handlers.storage import StorageOperationHandler
from neo import protocol
from neo.protocol import * from neo.protocol import *
from neo.protocol import PacketTypes
class StorageStorageHandlerTests(NeoTestBase): class StorageStorageHandlerTests(NeoTestBase):
...@@ -65,14 +65,14 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -65,14 +65,14 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_18_handleAskTransactionInformation1(self): def test_18_handleAskTransactionInformation1(self):
# transaction does not exists # transaction does not exists
conn = Mock({ }) conn = Mock({ })
packet = Packet(msg_type=ASK_TRANSACTION_INFORMATION) packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
self.operation.handleAskTransactionInformation(conn, packet, INVALID_TID) self.operation.handleAskTransactionInformation(conn, packet, INVALID_TID)
self.checkErrorPacket(conn) self.checkErrorPacket(conn)
def test_18_handleAskTransactionInformation2(self): def test_18_handleAskTransactionInformation2(self):
# answer # answer
conn = Mock({ }) conn = Mock({ })
packet = Packet(msg_type=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.handleAskTransactionInformation(conn, packet, INVALID_TID)
...@@ -82,7 +82,7 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -82,7 +82,7 @@ class StorageStorageHandlerTests(NeoTestBase):
# delayed response # delayed response
conn = Mock({}) conn = Mock({})
self.app.dm = Mock() self.app.dm = Mock()
packet = Packet(msg_type=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.handleAskObject(conn, packet,
...@@ -97,7 +97,7 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -97,7 +97,7 @@ class StorageStorageHandlerTests(NeoTestBase):
# 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=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.handleAskObject(conn, packet,
oid=INVALID_OID, oid=INVALID_OID,
...@@ -113,7 +113,7 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -113,7 +113,7 @@ class StorageStorageHandlerTests(NeoTestBase):
# 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=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.handleAskObject(conn, packet,
oid=INVALID_OID, oid=INVALID_OID,
...@@ -128,7 +128,7 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -128,7 +128,7 @@ class StorageStorageHandlerTests(NeoTestBase):
app.pt = Mock() app.pt = Mock()
app.dm = Mock() app.dm = Mock()
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=ASK_TIDS) packet = Packet(msg_type=PacketTypes.ASK_TIDS)
self.checkProtocolErrorRaised(self.operation.handleAskTIDs, conn, packet, 1, 1, None) self.checkProtocolErrorRaised(self.operation.handleAskTIDs, 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)
...@@ -136,7 +136,7 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -136,7 +136,7 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_25_handleAskTIDs2(self): def test_25_handleAskTIDs2(self):
# well case => answer # well case => answer
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=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.handleAskTIDs(conn, packet, 1, 2, 1)
...@@ -148,7 +148,7 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -148,7 +148,7 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_25_handleAskTIDs3(self): def test_25_handleAskTIDs3(self):
# invalid partition => answer usable partitions # invalid partition => answer usable partitions
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=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})
...@@ -164,13 +164,13 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -164,13 +164,13 @@ class StorageStorageHandlerTests(NeoTestBase):
app = self.app app = self.app
app.dm = Mock() app.dm = Mock()
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=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.handleAskObjectHistory, 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_handleAskObjectHistory2(self):
# first case: empty history # first case: empty history
packet = Packet(msg_type=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.handleAskObjectHistory(conn, packet, INVALID_OID, 1, 2)
...@@ -187,7 +187,7 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -187,7 +187,7 @@ class StorageStorageHandlerTests(NeoTestBase):
app.pt = Mock() app.pt = Mock()
app.dm = Mock() app.dm = Mock()
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=ASK_OIDS) packet = Packet(msg_type=PacketTypes.ASK_OIDS)
self.checkProtocolErrorRaised(self.operation.handleAskOIDs, conn, packet, 1, 1, None) self.checkProtocolErrorRaised(self.operation.handleAskOIDs, 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)
...@@ -195,7 +195,7 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -195,7 +195,7 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_25_handleAskOIDs2(self): def test_25_handleAskOIDs2(self):
# well case > answer OIDs # well case > answer OIDs
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=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.handleAskOIDs(conn, packet, 1, 2, 1)
...@@ -207,7 +207,7 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -207,7 +207,7 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_25_handleAskOIDs3(self): def test_25_handleAskOIDs3(self):
# invalid partition => answer usable partitions # invalid partition => answer usable partitions
conn = Mock({}) conn = Mock({})
packet = Packet(msg_type=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})
......
...@@ -20,14 +20,11 @@ import unittest ...@@ -20,14 +20,11 @@ import unittest
from neo import logging from neo import logging
from mock import Mock from mock import Mock
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo import protocol
from neo.pt import PartitionTable from neo.pt import PartitionTable
from neo.storage.app import Application from neo.storage.app import Application
from neo.storage.handlers.verification import VerificationHandler from neo.storage.handlers.verification import VerificationHandler
from neo.protocol import Packet, CellStates, NodeTypes, ErrorCodes from neo.protocol import Packet, PacketTypes, CellStates, NodeTypes, ErrorCodes
from neo.protocol import NOTIFY_PARTITION_CHANGES, STOP_OPERATION, \ from neo.protocol import INVALID_OID, INVALID_TID
ASK_OBJECT_PRESENT, ASK_TRANSACTION_INFORMATION, COMMIT_TRANSACTION, \
ASK_UNFINISHED_TRANSACTIONS, INVALID_OID, INVALID_TID
from neo.exception import PrimaryFailure, OperationFailure from neo.exception import PrimaryFailure, OperationFailure
from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64 from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64
...@@ -177,7 +174,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -177,7 +174,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
"isServer": False, "isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
}) })
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES) packet = Packet(msg_type=PacketTypes.NOTIFY_PARTITION_CHANGES)
self.verification.handleNotifyPartitionChanges(conn, packet, 1, ()) self.verification.handleNotifyPartitionChanges(conn, packet, 1, ())
self.verification.handleNotifyPartitionChanges(conn, packet, 0, ()) self.verification.handleNotifyPartitionChanges(conn, packet, 0, ())
self.assertEqual(self.app.pt.getID(), 1) self.assertEqual(self.app.pt.getID(), 1)
...@@ -187,7 +184,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -187,7 +184,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
"isServer": False, "isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
}) })
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES) packet = Packet(msg_type=PacketTypes.NOTIFY_PARTITION_CHANGES)
new_uuid = self.getNewUUID() new_uuid = self.getNewUUID()
cell = (0, new_uuid, CellStates.UP_TO_DATE) cell = (0, new_uuid, CellStates.UP_TO_DATE)
self.app.nm.createStorage(uuid=new_uuid) self.app.nm.createStorage(uuid=new_uuid)
...@@ -206,21 +203,21 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -206,21 +203,21 @@ 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 })
self.assertFalse(self.app.operational) self.assertFalse(self.app.operational)
packet = Packet(msg_type=STOP_OPERATION) packet = Packet(msg_type=PacketTypes.STOP_OPERATION)
self.verification.handleStartOperation(conn, packet) self.verification.handleStartOperation(conn, packet)
self.assertTrue(self.app.operational) self.assertTrue(self.app.operational)
def test_12_handleStopOperation(self): def test_12_handleStopOperation(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=STOP_OPERATION) packet = Packet(msg_type=PacketTypes.STOP_OPERATION)
self.assertRaises(OperationFailure, self.verification.handleStopOperation, conn, packet) self.assertRaises(OperationFailure, self.verification.handleStopOperation, conn, packet)
def test_13_handleAskUnfinishedTransactions(self): def test_13_handleAskUnfinishedTransactions(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=ASK_UNFINISHED_TRANSACTIONS) packet = Packet(msg_type=PacketTypes.ASK_UNFINISHED_TRANSACTIONS)
self.verification.handleAskUnfinishedTransactions(conn, packet) self.verification.handleAskUnfinishedTransactions(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)
...@@ -232,7 +229,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -232,7 +229,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
self.app.dm.commit() self.app.dm.commit()
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=ASK_UNFINISHED_TRANSACTIONS) packet = Packet(msg_type=PacketTypes.ASK_UNFINISHED_TRANSACTIONS)
self.verification.handleAskUnfinishedTransactions(conn, packet) self.verification.handleAskUnfinishedTransactions(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)
...@@ -242,7 +239,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -242,7 +239,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
# 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=ASK_TRANSACTION_INFORMATION) packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(1)) self.verification.handleAskTransactionInformation(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)
...@@ -257,7 +254,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -257,7 +254,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
# object from trans # object from trans
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=ASK_TRANSACTION_INFORMATION) packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(1)) self.verification.handleAskTransactionInformation(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)
...@@ -269,7 +266,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -269,7 +266,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
# object from ttrans # object from ttrans
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=ASK_TRANSACTION_INFORMATION) packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(3)) self.verification.handleAskTransactionInformation(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)
...@@ -283,7 +280,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -283,7 +280,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': True }) 'isServer': True })
# find the one in trans # find the one in trans
packet = Packet(msg_type=ASK_TRANSACTION_INFORMATION) packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(1)) self.verification.handleAskTransactionInformation(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)
...@@ -295,7 +292,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -295,7 +292,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
# do not find the one in ttrans # do not find the one in ttrans
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=ASK_TRANSACTION_INFORMATION) packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(2)) self.verification.handleAskTransactionInformation(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)
...@@ -304,7 +301,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -304,7 +301,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
# 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=ASK_OBJECT_PRESENT) packet = Packet(msg_type=PacketTypes.ASK_OBJECT_PRESENT)
self.verification.handleAskObjectPresent(conn, packet, p64(1), p64(2)) self.verification.handleAskObjectPresent(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)
...@@ -316,7 +313,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -316,7 +313,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
self.app.dm.commit() self.app.dm.commit()
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=ASK_OBJECT_PRESENT) packet = Packet(msg_type=PacketTypes.ASK_OBJECT_PRESENT)
self.verification.handleAskObjectPresent(conn, packet, p64(1), p64(2)) self.verification.handleAskObjectPresent(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)
...@@ -326,7 +323,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -326,7 +323,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
# 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=ASK_OBJECT_PRESENT) packet = Packet(msg_type=PacketTypes.ASK_OBJECT_PRESENT)
self.verification.handleDeleteTransaction(conn, packet, p64(1)) self.verification.handleDeleteTransaction(conn, packet, p64(1))
# client connection with data # client connection with data
self.app.dm.begin() self.app.dm.begin()
...@@ -343,7 +340,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -343,7 +340,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
'isServer': False }) 'isServer': False })
dm = Mock() dm = Mock()
self.app.dm = dm self.app.dm = dm
packet = Packet(msg_type=COMMIT_TRANSACTION) packet = Packet(msg_type=PacketTypes.COMMIT_TRANSACTION)
self.verification.handleCommitTransaction(conn, packet, p64(1)) self.verification.handleCommitTransaction(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]
......
...@@ -25,7 +25,7 @@ from neo.handler import EventHandler ...@@ -25,7 +25,7 @@ from neo.handler import EventHandler
from neo.tests import DoNothingConnector from neo.tests import DoNothingConnector
from neo.connector import ConnectorException, ConnectorTryAgainException, \ from neo.connector import ConnectorException, ConnectorTryAgainException, \
ConnectorInProgressException, ConnectorConnectionRefusedException ConnectorInProgressException, ConnectorConnectionRefusedException
from neo.protocol import Packet, ProtocolError, ANSWER_PRIMARY_MASTER from neo.protocol import Packet, ProtocolError, PacketTypes
from neo import protocol from neo import protocol
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
...@@ -721,7 +721,7 @@ class ConnectionTests(NeoTestBase): ...@@ -721,7 +721,7 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(bc._queue.mockGetNamedCalls("append")), 1) self.assertEquals(len(bc._queue.mockGetNamedCalls("append")), 1)
call = bc._queue.mockGetNamedCalls("append")[0] call = bc._queue.mockGetNamedCalls("append")[0]
data = call.getParam(0) data = call.getParam(0)
self.assertEqual(data.getType(), ANSWER_PRIMARY_MASTER) self.assertEqual(data.getType(), PacketTypes.ANSWER_PRIMARY_MASTER)
self.assertEqual(data.getId(), 1) self.assertEqual(data.getId(), 1)
self.assertEqual(len(bc.event_dict), 0) self.assertEqual(len(bc.event_dict), 0)
self.assertEqual(bc.read_buf, '') self.assertEqual(bc.read_buf, '')
......
...@@ -20,7 +20,6 @@ from time import time ...@@ -20,7 +20,6 @@ from time import time
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.epoll import Epoll from neo.epoll import Epoll
from neo.event import EpollEventManager, IdleEvent from neo.event import EpollEventManager, IdleEvent
from neo.protocol import Packet, PING
class EventTests(NeoTestBase): class EventTests(NeoTestBase):
......
...@@ -19,7 +19,8 @@ import unittest, os ...@@ -19,7 +19,8 @@ import unittest, os
from mock import Mock from mock import Mock
from neo import protocol from neo import protocol
from neo.protocol import * from neo.protocol import *
from neo.protocol import NodeTypes, NodeStates, CellStates, ErrorCodes from neo.protocol import NodeTypes, NodeStates, CellStates
from neo.protocol import ErrorCodes, PacketTypes
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.util import getNextTID from neo.util import getNextTID
from time import time, gmtime from time import time, gmtime
...@@ -37,8 +38,8 @@ class ProtocolTests(NeoTestBase): ...@@ -37,8 +38,8 @@ class ProtocolTests(NeoTestBase):
return self.ltid return self.ltid
def test_01_Packet_init(self): def test_01_Packet_init(self):
p = Packet(msg_type=ASK_PRIMARY_MASTER, body=None) p = Packet(msg_type=PacketTypes.ASK_PRIMARY_MASTER, body=None)
self.assertEqual(p.getType(), ASK_PRIMARY_MASTER) self.assertEqual(p.getType(), PacketTypes.ASK_PRIMARY_MASTER)
self.assertEqual(len(p), PACKET_HEADER_SIZE) self.assertEqual(len(p), PACKET_HEADER_SIZE)
def test_02_error(self): def test_02_error(self):
...@@ -252,7 +253,7 @@ class ProtocolTests(NeoTestBase): ...@@ -252,7 +253,7 @@ class ProtocolTests(NeoTestBase):
def test_30_deleteTransaction(self): def test_30_deleteTransaction(self):
tid = self.getNextTID() tid = self.getNextTID()
p = protocol.deleteTransaction(tid) p = protocol.deleteTransaction(tid)
self.assertEqual(p.getType(), DELETE_TRANSACTION) self.assertEqual(p.getType(), PacketTypes.DELETE_TRANSACTION)
ptid = p.decode()[0] ptid = p.decode()[0]
self.assertEqual(ptid, tid) self.assertEqual(ptid, tid)
......
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