Commit 802aadb8 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Use Enum class for error codes.


git-svn-id: https://svn.erp5.org/repos/neo/trunk@1341 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 2c361c13
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
from neo import logging from neo import logging
from neo import protocol from neo import protocol
from neo.protocol import NodeStates from neo.protocol import NodeStates, ErrorCodes
from neo.protocol import PacketMalformedError, UnexpectedPacketError, \ from neo.protocol import PacketMalformedError, UnexpectedPacketError, \
BrokenNodeDisallowedError, NotReadyError, ProtocolError BrokenNodeDisallowedError, NotReadyError, ProtocolError
from protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \ from protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \
...@@ -35,11 +35,9 @@ from protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICAT ...@@ -35,11 +35,9 @@ from protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICAT
ASK_OBJECT, ANSWER_OBJECT, ASK_TIDS, ANSWER_TIDS, ASK_TRANSACTION_INFORMATION, \ ASK_OBJECT, ANSWER_OBJECT, ASK_TIDS, ANSWER_TIDS, ASK_TRANSACTION_INFORMATION, \
ANSWER_TRANSACTION_INFORMATION, ASK_OBJECT_HISTORY, ANSWER_OBJECT_HISTORY, \ ANSWER_TRANSACTION_INFORMATION, ASK_OBJECT_HISTORY, ANSWER_OBJECT_HISTORY, \
ASK_OIDS, ANSWER_OIDS, ADD_PENDING_NODES, ANSWER_NEW_NODES, \ ASK_OIDS, ANSWER_OIDS, ADD_PENDING_NODES, ANSWER_NEW_NODES, \
NOT_READY_CODE, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \ ASK_PARTITION_LIST, ANSWER_PARTITION_LIST, ASK_NODE_LIST, \
PROTOCOL_ERROR_CODE, BROKEN_NODE_DISALLOWED_CODE, \
INTERNAL_ERROR_CODE, ASK_PARTITION_LIST, ANSWER_PARTITION_LIST, ASK_NODE_LIST, \
ANSWER_NODE_LIST, SET_NODE_STATE, ANSWER_NODE_STATE, SET_CLUSTER_STATE, \ ANSWER_NODE_LIST, SET_NODE_STATE, ANSWER_NODE_STATE, SET_CLUSTER_STATE, \
ASK_NODE_INFORMATION, ANSWER_NODE_INFORMATION, NO_ERROR_CODE, \ ASK_NODE_INFORMATION, ANSWER_NODE_INFORMATION, \
ASK_CLUSTER_STATE, ANSWER_CLUSTER_STATE, NOTIFY_CLUSTER_INFORMATION, \ ASK_CLUSTER_STATE, ANSWER_CLUSTER_STATE, NOTIFY_CLUSTER_INFORMATION, \
NOTIFY_LAST_OID NOTIFY_LAST_OID
...@@ -462,13 +460,13 @@ class EventHandler(object): ...@@ -462,13 +460,13 @@ class EventHandler(object):
def initErrorDispatchTable(self): def initErrorDispatchTable(self):
d = {} d = {}
d[NO_ERROR_CODE] = self.handleNoError d[ErrorCodes.NO_ERROR] = self.handleNoError
d[NOT_READY_CODE] = self.handleNotReady d[ErrorCodes.NOT_READY] = self.handleNotReady
d[OID_NOT_FOUND_CODE] = self.handleOidNotFound d[ErrorCodes.OID_NOT_FOUND] = self.handleOidNotFound
d[TID_NOT_FOUND_CODE] = self.handleTidNotFound d[ErrorCodes.TID_NOT_FOUND] = self.handleTidNotFound
d[PROTOCOL_ERROR_CODE] = self.handleProtocolError d[ErrorCodes.PROTOCOL_ERROR] = self.handleProtocolError
d[BROKEN_NODE_DISALLOWED_CODE] = self.handleBrokenNodeDisallowedError d[ErrorCodes.BROKEN_NODE] = self.handleBrokenNodeDisallowedError
d[INTERNAL_ERROR_CODE] = self.handleInternalError d[ErrorCodes.INTERNAL_ERROR] = self.handleInternalError
return d return d
...@@ -18,8 +18,7 @@ ...@@ -18,8 +18,7 @@
from neo import logging from neo import logging
from neo import protocol from neo import protocol
from neo.protocol import INTERNAL_ERROR_CODE from neo.protocol import UnexpectedPacketError, CellStates, ErrorCodes
from neo.protocol import UnexpectedPacketError, CellStates
from neo.master.handlers import BaseServiceHandler from neo.master.handlers import BaseServiceHandler
from neo.exception import OperationFailure from neo.exception import OperationFailure
from neo.util import dump from neo.util import dump
...@@ -109,7 +108,7 @@ class StorageServiceHandler(BaseServiceHandler): ...@@ -109,7 +108,7 @@ class StorageServiceHandler(BaseServiceHandler):
%s but where %s for that offset" % (dump(node.getUUID()), offset, %s but where %s for that offset" % (dump(node.getUUID()), offset,
xcell.getState()) xcell.getState())
logging.warning(msg) logging.warning(msg)
self.handleError(conn, packet, INTERNAL_ERROR_CODE, msg) self.handleError(conn, packet, ErrorCodes.INTERNAL_ERROR, msg)
return return
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +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.handler import EventHandler from neo.handler import EventHandler
from neo.protocol import ErrorCodes
from neo import protocol from neo import protocol
class CommandEventHandler(EventHandler): class CommandEventHandler(EventHandler):
...@@ -54,10 +55,10 @@ class CommandEventHandler(EventHandler): ...@@ -54,10 +55,10 @@ class CommandEventHandler(EventHandler):
self.__respond((packet.getType(), ) + args) self.__respond((packet.getType(), ) + args)
def handleNoError(self, conn, packet, msg): def handleNoError(self, conn, packet, msg):
self.__respond((packet.getType(), protocol.NO_ERROR_CODE, msg)) self.__respond((packet.getType(), ErrorCodes.NO_ERROR, msg))
def handleNotReady(self, conn, packet, msg): def handleNotReady(self, conn, packet, msg):
self.__respond((packet.getType(), protocol.NOT_READY_CODE, msg)) self.__respond((packet.getType(), ErrorCodes.NOT_READY, msg))
handleAnswerPartitionList = __handleAnswer handleAnswerPartitionList = __handleAnswer
handleAnswerNodeList = __handleAnswer handleAnswerNodeList = __handleAnswer
......
...@@ -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 from neo.protocol import ClusterStates, NodeStates, ErrorCodes
class NotReadyException(Exception): class NotReadyException(Exception):
pass pass
...@@ -60,7 +60,7 @@ class NeoCTL(object): ...@@ -60,7 +60,7 @@ class NeoCTL(object):
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] == protocol.ERROR and \
response[1] == protocol.NOT_READY_CODE: response[1] == ErrorCodes.NOT_READY:
raise NotReadyException(response[2]) raise NotReadyException(response[2])
return response return response
...@@ -71,7 +71,7 @@ class NeoCTL(object): ...@@ -71,7 +71,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] == protocol.ERROR
assert response[1] == protocol.NO_ERROR_CODE assert response[1] == ErrorCodes.NO_ERROR
def setClusterState(self, state): def setClusterState(self, state):
""" """
...@@ -80,7 +80,7 @@ class NeoCTL(object): ...@@ -80,7 +80,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] == protocol.ERROR
assert response[1] == protocol.NO_ERROR_CODE assert response[1] == ErrorCodes.NO_ERROR
def setNodeState(self, node, state, update_partition_table=False): def setNodeState(self, node, state, update_partition_table=False):
""" """
...@@ -93,7 +93,7 @@ class NeoCTL(object): ...@@ -93,7 +93,7 @@ class NeoCTL(object):
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] == protocol.ERROR
assert response[1] == protocol.NO_ERROR_CODE assert response[1] == ErrorCodes.NO_ERROR
def getClusterState(self): def getClusterState(self):
""" """
......
...@@ -306,16 +306,16 @@ packet_types = OldEnum({ ...@@ -306,16 +306,16 @@ packet_types = OldEnum({
}) })
# Error codes. class ErrorCodes(Enum):
error_codes = OldEnum({ # TODO: clarify the use of each error code
'NO_ERROR_CODE': 0, NO_ERROR = Enum.Item(0)
'NOT_READY_CODE': 1, NOT_READY = Enum.Item(1)
'OID_NOT_FOUND_CODE': 2, OID_NOT_FOUND = Enum.Item(2)
'TID_NOT_FOUND_CODE': 4, TID_NOT_FOUND = Enum.Item(3)
'PROTOCOL_ERROR_CODE': 5, PROTOCOL_ERROR = Enum.Item(4)
'BROKEN_NODE_DISALLOWED_CODE': 7, BROKEN_NODE = Enum.Item(5)
'INTERNAL_ERROR_CODE': 8, INTERNAL_ERROR = Enum.Item(6)
}) ErrorCodes = ErrorCodes()
class ClusterStates(Enum): class ClusterStates(Enum):
BOOTING = Enum.Item(1) BOOTING = Enum.Item(1)
...@@ -511,7 +511,7 @@ def _decodeNodeType(original_node_type): ...@@ -511,7 +511,7 @@ def _decodeNodeType(original_node_type):
return node_type return node_type
def _decodeErrorCode(original_error_code): def _decodeErrorCode(original_error_code):
error_code = error_codes.get(original_error_code) error_code = ErrorCodes.get(original_error_code)
if error_code is None: if error_code is None:
raise PacketMalformedError('invalid error code %d' % original_error_code) raise PacketMalformedError('invalid error code %d' % original_error_code)
return error_code return error_code
...@@ -1111,26 +1111,26 @@ def _error(error_code, error_message): ...@@ -1111,26 +1111,26 @@ def _error(error_code, error_message):
return Packet(ERROR, body) return Packet(ERROR, body)
def noError(message): def noError(message):
return _error(NO_ERROR_CODE, message) return _error(ErrorCodes.NO_ERROR, message)
def protocolError(error_message): def protocolError(error_message):
return _error(PROTOCOL_ERROR_CODE, 'protocol error: ' + error_message) return _error(ErrorCodes.PROTOCOL_ERROR, 'protocol error: ' + error_message)
def internalError(error_message): def internalError(error_message):
return _error(INTERNAL_ERROR_CODE, 'internal error: ' + error_message) return _error(ErrorCodes.INTERNAL_ERROR, 'internal error: ' + error_message)
def notReady(error_message): def notReady(error_message):
return _error(NOT_READY_CODE, 'not ready: ' + error_message) return _error(ErrorCodes.NOT_READY, 'not ready: ' + error_message)
def brokenNodeDisallowedError(error_message): def brokenNodeDisallowedError(error_message):
return _error(BROKEN_NODE_DISALLOWED_CODE, return _error(ErrorCodes.BROKEN_NODE,
'broken node disallowed error: ' + error_message) 'broken node disallowed error: ' + error_message)
def oidNotFound(error_message): def oidNotFound(error_message):
return _error(OID_NOT_FOUND_CODE, 'oid not found: ' + error_message) return _error(ErrorCodes.OID_NOT_FOUND, 'oid not found: ' + error_message)
def tidNotFound(error_message): def tidNotFound(error_message):
return _error(TID_NOT_FOUND_CODE, 'tid not found: ' + error_message) return _error(ErrorCodes.TID_NOT_FOUND, 'tid not found: ' + error_message)
def ping(): def ping():
return Packet(PING) return Packet(PING)
......
...@@ -39,9 +39,7 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF ...@@ -39,9 +39,7 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF
ABORT_TRANSACTION, ASK_STORE_TRANSACTION, ANSWER_STORE_TRANSACTION, \ ABORT_TRANSACTION, ASK_STORE_TRANSACTION, ANSWER_STORE_TRANSACTION, \
ASK_OBJECT, ANSWER_OBJECT, ASK_TIDS, ANSWER_TIDS, ASK_TRANSACTION_INFORMATION, \ ASK_OBJECT, ANSWER_OBJECT, ASK_TIDS, ANSWER_TIDS, ASK_TRANSACTION_INFORMATION, \
ANSWER_TRANSACTION_INFORMATION, ASK_OBJECT_HISTORY, ANSWER_OBJECT_HISTORY, \ ANSWER_TRANSACTION_INFORMATION, ASK_OBJECT_HISTORY, ANSWER_OBJECT_HISTORY, \
ASK_OIDS, ANSWER_OIDS, \ ASK_OIDS, ANSWER_OIDS
NOT_READY_CODE, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \
PROTOCOL_ERROR_CODE, BROKEN_NODE_DISALLOWED_CODE, INTERNAL_ERROR_CODE
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
......
...@@ -39,8 +39,7 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF ...@@ -39,8 +39,7 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF
ABORT_TRANSACTION, ASK_STORE_TRANSACTION, ANSWER_STORE_TRANSACTION, \ ABORT_TRANSACTION, ASK_STORE_TRANSACTION, ANSWER_STORE_TRANSACTION, \
ASK_OBJECT, ANSWER_OBJECT, ASK_TIDS, ANSWER_TIDS, ASK_TRANSACTION_INFORMATION, \ ASK_OBJECT, ANSWER_OBJECT, ASK_TIDS, ANSWER_TIDS, ASK_TRANSACTION_INFORMATION, \
ANSWER_TRANSACTION_INFORMATION, ASK_OBJECT_HISTORY, ANSWER_OBJECT_HISTORY, \ ANSWER_TRANSACTION_INFORMATION, ASK_OBJECT_HISTORY, ANSWER_OBJECT_HISTORY, \
ASK_OIDS, ANSWER_OIDS, NOT_READY_CODE, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \ ASK_OIDS, ANSWER_OIDS
PROTOCOL_ERROR_CODE, BROKEN_NODE_DISALLOWED_CODE, INTERNAL_ERROR_CODE
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
......
...@@ -22,14 +22,14 @@ from mock import Mock ...@@ -22,14 +22,14 @@ 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, INVALID_UUID from neo.protocol import Packet, 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 import protocol
from neo.protocol import ERROR, ANNOUNCE_PRIMARY_MASTER, \ from neo.protocol import ERROR, ANNOUNCE_PRIMARY_MASTER, INVALID_UUID, \
NOTIFY_NODE_INFORMATION, ANSWER_LAST_IDS, ANSWER_PARTITION_TABLE, \ NOTIFY_NODE_INFORMATION, ANSWER_LAST_IDS, ANSWER_PARTITION_TABLE, \
ANSWER_UNFINISHED_TRANSACTIONS, ANSWER_OBJECT_PRESENT, \ ANSWER_UNFINISHED_TRANSACTIONS, ANSWER_OBJECT_PRESENT, \
ANSWER_TRANSACTION_INFORMATION, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE 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
...@@ -239,7 +239,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -239,7 +239,7 @@ class MasterVerificationTests(NeoTestBase):
def test_13_handleTidNotFound(self): def test_13_handleTidNotFound(self):
verification = self.verification verification = self.verification
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=TID_NOT_FOUND_CODE) packet = Packet(msg_type=ErrorCodes.TID_NOT_FOUND)
# do nothing as asking_uuid_dict is True # do nothing as asking_uuid_dict is True
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)
...@@ -282,7 +282,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -282,7 +282,7 @@ class MasterVerificationTests(NeoTestBase):
def test_15_handleOidNotFound(self): def test_15_handleOidNotFound(self):
verification = self.verification verification = self.verification
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=OID_NOT_FOUND_CODE) packet = Packet(msg_type=ErrorCodes.OID_NOT_FOUND)
# do nothinf as asking_uuid_dict is True # do nothinf as asking_uuid_dict is True
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)
......
...@@ -24,14 +24,13 @@ from neo import protocol ...@@ -24,14 +24,13 @@ 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, \ from neo.protocol import Packet, CellStates, INVALID_UUID, INVALID_TID
INVALID_TID, PROTOCOL_ERROR_CODE
from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION, \ from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION, \
NOTIFY_PARTITION_CHANGES, STOP_OPERATION, ASK_LAST_IDS, ASK_PARTITION_TABLE, \ NOTIFY_PARTITION_CHANGES, STOP_OPERATION, ASK_LAST_IDS, ASK_PARTITION_TABLE, \
ANSWER_OBJECT_PRESENT, ASK_OBJECT_PRESENT, OID_NOT_FOUND_CODE, LOCK_INFORMATION, \ ANSWER_OBJECT_PRESENT, ASK_OBJECT_PRESENT, LOCK_INFORMATION, \
UNLOCK_INFORMATION, TID_NOT_FOUND_CODE, ASK_TRANSACTION_INFORMATION, \ UNLOCK_INFORMATION, ASK_TRANSACTION_INFORMATION, \
COMMIT_TRANSACTION, ASK_UNFINISHED_TRANSACTIONS, SEND_PARTITION_TABLE COMMIT_TRANSACTION, ASK_UNFINISHED_TRANSACTIONS, SEND_PARTITION_TABLE
from neo.protocol import ERROR, BROKEN_NODE_DISALLOWED_CODE, ASK_PRIMARY_MASTER from neo.protocol import ERROR, ASK_PRIMARY_MASTER
from neo.protocol import ANSWER_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
......
...@@ -24,10 +24,10 @@ from neo import protocol ...@@ -24,10 +24,10 @@ 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, INVALID_OID, INVALID_TID from neo.protocol import Packet, CellStates, NodeTypes, ErrorCodes
from neo.protocol import NOTIFY_PARTITION_CHANGES, STOP_OPERATION, \ from neo.protocol import NOTIFY_PARTITION_CHANGES, STOP_OPERATION, \
ASK_OBJECT_PRESENT, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \ ASK_OBJECT_PRESENT, ASK_TRANSACTION_INFORMATION, COMMIT_TRANSACTION, \
ASK_TRANSACTION_INFORMATION, COMMIT_TRANSACTION, ASK_UNFINISHED_TRANSACTIONS 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
...@@ -245,7 +245,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -245,7 +245,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
packet = Packet(msg_type=ASK_TRANSACTION_INFORMATION) packet = Packet(msg_type=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, TID_NOT_FOUND_CODE) self.assertEqual(code, ErrorCodes.TID_NOT_FOUND)
# input some tmp data and ask from client, must find both transaction # input some tmp data and ask from client, must find both transaction
self.app.dm.begin() self.app.dm.begin()
...@@ -298,7 +298,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -298,7 +298,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
packet = Packet(msg_type=ASK_TRANSACTION_INFORMATION) packet = Packet(msg_type=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, TID_NOT_FOUND_CODE) self.assertEqual(code, ErrorCodes.TID_NOT_FOUND)
def test_15_handleAskObjectPresent(self): def test_15_handleAskObjectPresent(self):
# client connection with no data # client connection with no data
...@@ -307,7 +307,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -307,7 +307,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
packet = Packet(msg_type=ASK_OBJECT_PRESENT) packet = Packet(msg_type=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, OID_NOT_FOUND_CODE) self.assertEqual(code, ErrorCodes.OID_NOT_FOUND)
# client connection with some data # client connection with some data
self.app.dm.begin() self.app.dm.begin()
......
...@@ -25,8 +25,7 @@ from neo.handler import EventHandler ...@@ -25,8 +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, PROTOCOL_ERROR_CODE, ERROR,INTERNAL_ERROR_CODE, \ from neo.protocol import Packet, ProtocolError, ANSWER_PRIMARY_MASTER
ANSWER_PRIMARY_MASTER
from neo import protocol from neo import protocol
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
......
...@@ -19,7 +19,7 @@ import unittest, os ...@@ -19,7 +19,7 @@ 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 from neo.protocol import NodeTypes, NodeStates, CellStates, ErrorCodes
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
...@@ -44,31 +44,31 @@ class ProtocolTests(NeoTestBase): ...@@ -44,31 +44,31 @@ class ProtocolTests(NeoTestBase):
def test_02_error(self): def test_02_error(self):
p = protocol._error(0, "error message") p = protocol._error(0, "error message")
code, msg = protocol._decodeError(p._body) code, msg = protocol._decodeError(p._body)
self.assertEqual(code, protocol.NO_ERROR_CODE) self.assertEqual(code, ErrorCodes.NO_ERROR)
self.assertEqual(msg, "error message") self.assertEqual(msg, "error message")
def test_03_protocolError(self): def test_03_protocolError(self):
p = protocol.protocolError("bad protocol") p = protocol.protocolError("bad protocol")
error_code, error_msg = p.decode() error_code, error_msg = p.decode()
self.assertEqual(error_code, PROTOCOL_ERROR_CODE) self.assertEqual(error_code, ErrorCodes.PROTOCOL_ERROR)
self.assertEqual(error_msg, "protocol error: bad protocol") self.assertEqual(error_msg, "protocol error: bad protocol")
def test_04_internalError(self): def test_04_internalError(self):
p = protocol.internalError("bad internal") p = protocol.internalError("bad internal")
error_code, error_msg = p.decode() error_code, error_msg = p.decode()
self.assertEqual(error_code, INTERNAL_ERROR_CODE) self.assertEqual(error_code, ErrorCodes.INTERNAL_ERROR)
self.assertEqual(error_msg, "internal error: bad internal") self.assertEqual(error_msg, "internal error: bad internal")
def test_05_notReady(self): def test_05_notReady(self):
p = protocol.notReady("wait") p = protocol.notReady("wait")
error_code, error_msg = p.decode() error_code, error_msg = p.decode()
self.assertEqual(error_code, NOT_READY_CODE) self.assertEqual(error_code, ErrorCodes.NOT_READY)
self.assertEqual(error_msg, "not ready: wait") self.assertEqual(error_msg, "not ready: wait")
def test_06_brokenNodeDisallowedError(self): def test_06_brokenNodeDisallowedError(self):
p = protocol.brokenNodeDisallowedError("broken") p = protocol.brokenNodeDisallowedError("broken")
error_code, error_msg = p.decode() error_code, error_msg = p.decode()
self.assertEqual(error_code, BROKEN_NODE_DISALLOWED_CODE) self.assertEqual(error_code, ErrorCodes.BROKEN_NODE)
self.assertEqual(error_msg, "broken node disallowed error: broken") self.assertEqual(error_msg, "broken node disallowed error: broken")
def test_07_oidNotFound(self): def test_07_oidNotFound(self):
...@@ -79,7 +79,7 @@ class ProtocolTests(NeoTestBase): ...@@ -79,7 +79,7 @@ class ProtocolTests(NeoTestBase):
def test_08_oidNotFound(self): def test_08_oidNotFound(self):
p = protocol.tidNotFound("no tid") p = protocol.tidNotFound("no tid")
error_code, error_msg = p.decode() error_code, error_msg = p.decode()
self.assertEqual(error_code, TID_NOT_FOUND_CODE) self.assertEqual(error_code, ErrorCodes.TID_NOT_FOUND)
self.assertEqual(error_msg, "tid not found: no tid") self.assertEqual(error_msg, "tid not found: no tid")
def test_09_ping(self): def test_09_ping(self):
......
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