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

Update tests to follow changes introduced in previous commit.


git-svn-id: https://svn.erp5.org/repos/neo/trunk@1357 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent a6aae268
......@@ -22,7 +22,7 @@ import MySQLdb
from neo import logging
from mock import Mock
from neo import protocol
from neo.protocol import PacketTypes
from neo.protocol import Packets
DB_PREFIX = 'test_neo_'
DB_ADMIN = 'root'
......@@ -169,8 +169,9 @@ class NeoTestBase(unittest.TestCase):
self.assertEquals(len(calls), 1)
packet = calls[0].getParam(0)
self.assertTrue(isinstance(packet, protocol.Packet))
self.assertEquals(packet.getType(), PacketTypes.ERROR)
self.assertEquals(packet.getType(), Packets.Error)
if decode:
return packet.decode()
return protocol.decode_table[packet.getType()](packet._body)
return packet
......@@ -182,7 +183,7 @@ class NeoTestBase(unittest.TestCase):
self.assertTrue(isinstance(packet, protocol.Packet))
self.assertEquals(packet.getType(), packet_type)
if decode:
return protocol.decode_table[packet.getType()](packet._body)
return packet.decode()
return packet
def checkAnswerPacket(self, conn, packet_type, answered_packet=None, decode=False):
......@@ -196,7 +197,7 @@ class NeoTestBase(unittest.TestCase):
msg_id = calls[0].getParam(1)
self.assertEqual(msg_id, answered_packet.getId())
if decode:
return protocol.decode_table[packet.getType()](packet._body)
return packet.decode()
return packet
def checkNotifyPacket(self, conn, packet_type, packet_number=0, decode=False):
......@@ -207,101 +208,101 @@ class NeoTestBase(unittest.TestCase):
self.assertTrue(isinstance(packet, protocol.Packet))
self.assertEquals(packet.getType(), packet_type)
if decode:
return protocol.decode_table[packet.getType()](packet._body)
return packet.decode()
return packet
def checkNotifyNodeInformation(self, conn, **kw):
return self.checkNotifyPacket(conn, PacketTypes.NOTIFY_NODE_INFORMATION, **kw)
return self.checkNotifyPacket(conn, Packets.NotifyNodeInformation, **kw)
def checkSendPartitionTable(self, conn, **kw):
return self.checkNotifyPacket(conn, PacketTypes.SEND_PARTITION_TABLE, **kw)
return self.checkNotifyPacket(conn, Packets.SendPartitionTable, **kw)
def checkStartOperation(self, conn, **kw):
return self.checkNotifyPacket(conn, PacketTypes.START_OPERATION, **kw)
return self.checkNotifyPacket(conn, Packets.StartOperation, **kw)
def checkNotifyTransactionFinished(self, conn, **kw):
return self.checkNotifyPacket(conn, PacketTypes.NOTIFY_TRANSACTION_FINISHED, **kw)
return self.checkNotifyPacket(conn, Packets.NotifyTransactionFinished, **kw)
def checkNotifyInformationLocked(self, conn, **kw):
return self.checkAnswerPacket(conn, PacketTypes.NOTIFY_INFORMATION_LOCKED, **kw)
return self.checkAnswerPacket(conn, Packets.NotifyInformationLocked, **kw)
def checkLockInformation(self, conn, **kw):
return self.checkAskPacket(conn, PacketTypes.LOCK_INFORMATION, **kw)
return self.checkAskPacket(conn, Packets.LockInformation, **kw)
def checkUnlockInformation(self, conn, **kw):
return self.checkAskPacket(conn, PacketTypes.UNLOCK_INFORMATION, **kw)
return self.checkAskPacket(conn, Packets.UnlockInformation, **kw)
def checkRequestNodeIdentification(self, conn, **kw):
return self.checkAskPacket(conn, PacketTypes.REQUEST_NODE_IDENTIFICATION, **kw)
def checkRequestIdentification(self, conn, **kw):
return self.checkAskPacket(conn, Packets.RequestIdentification, **kw)
def checkAskPrimaryMaster(self, conn, **kw):
return self.checkAskPacket(conn, PacketTypes.ASK_PRIMARY_MASTER)
def checkAskPrimary(self, conn, **kw):
return self.checkAskPacket(conn, Packets.AskPrimary)
def checkAskUnfinishedTransactions(self, conn, **kw):
return self.checkAskPacket(conn, PacketTypes.ASK_UNFINISHED_TRANSACTIONS)
return self.checkAskPacket(conn, Packets.AskUnfinishedTransactions)
def checkAskTransactionInformation(self, conn, **kw):
return self.checkAskPacket(conn, PacketTypes.ASK_TRANSACTION_INFORMATION, **kw)
return self.checkAskPacket(conn, Packets.AskTransactionInformation, **kw)
def checkAskObjectPresent(self, conn, **kw):
return self.checkAskPacket(conn, PacketTypes.ASK_OBJECT_PRESENT, **kw)
return self.checkAskPacket(conn, Packets.AskObjectPresent, **kw)
def checkAskObject(self, conn, **kw):
return self.checkAskPacket(conn, PacketTypes.ASK_OBJECT, **kw)
return self.checkAskPacket(conn, Packets.AskObject, **kw)
def checkAskStoreObject(self, conn, **kw):
return self.checkAskPacket(conn, PacketTypes.ASK_STORE_OBJECT, **kw)
return self.checkAskPacket(conn, Packets.AskStoreObject, **kw)
def checkAskStoreTransaction(self, conn, **kw):
return self.checkAskPacket(conn, PacketTypes.ASK_STORE_TRANSACTION, **kw)
return self.checkAskPacket(conn, Packets.AskStoreTransaction, **kw)
def checkFinishTransaction(self, conn, **kw):
return self.checkAskPacket(conn, PacketTypes.FINISH_TRANSACTION, **kw)
return self.checkAskPacket(conn, Packets.FinishTransaction, **kw)
def checkAskNewTid(self, conn, **kw):
return self.checkAskPacket(conn, PacketTypes.ASK_BEGIN_TRANSACTION, **kw)
return self.checkAskPacket(conn, Packets.AskBeginTransaction, **kw)
def checkAskLastIDs(self, conn, **kw):
return self.checkAskPacket(conn, PacketTypes.ASK_LAST_IDS, **kw)
return self.checkAskPacket(conn, Packets.AskLastIDs, **kw)
def checkAcceptNodeIdentification(self, conn, **kw):
return self.checkAnswerPacket(conn, PacketTypes.ACCEPT_NODE_IDENTIFICATION, **kw)
def checkAcceptIdentification(self, conn, **kw):
return self.checkAnswerPacket(conn, Packets.AcceptIdentification, **kw)
def checkAnswerPrimaryMaster(self, conn, **kw):
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_PRIMARY_MASTER, **kw)
def checkAnswerPrimary(self, conn, **kw):
return self.checkAnswerPacket(conn, Packets.AnswerPrimary, **kw)
def checkAnswerLastIDs(self, conn, **kw):
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_LAST_IDS, **kw)
return self.checkAnswerPacket(conn, Packets.AnswerLastIDs, **kw)
def checkAnswerUnfinishedTransactions(self, conn, **kw):
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_UNFINISHED_TRANSACTIONS, **kw)
return self.checkAnswerPacket(conn, Packets.AnswerUnfinishedTransactions, **kw)
def checkAnswerObject(self, conn, **kw):
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_OBJECT, **kw)
return self.checkAnswerPacket(conn, Packets.AnswerObject, **kw)
def checkAnswerTransactionInformation(self, conn, **kw):
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_TRANSACTION_INFORMATION, **kw)
return self.checkAnswerPacket(conn, Packets.AnswerTransactionInformation, **kw)
def checkAnswerTids(self, conn, **kw):
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_TIDS, **kw)
return self.checkAnswerPacket(conn, Packets.AnswerTIDs, **kw)
def checkAnswerObjectHistory(self, conn, **kw):
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_OBJECT_HISTORY, **kw)
return self.checkAnswerPacket(conn, Packets.AnswerObjectHistory, **kw)
def checkAnswerStoreTransaction(self, conn, **kw):
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_STORE_TRANSACTION, **kw)
return self.checkAnswerPacket(conn, Packets.AnswerStoreTransaction, **kw)
def checkAnswerStoreObject(self, conn, **kw):
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_STORE_OBJECT, **kw)
return self.checkAnswerPacket(conn, Packets.AnswerStoreObject, **kw)
def checkAnswerOids(self, conn, **kw):
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_OIDS, **kw)
return self.checkAnswerPacket(conn, Packets.AnswerOIDs, **kw)
def checkAnswerPartitionTable(self, conn, **kw):
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_PARTITION_TABLE, **kw)
return self.checkAnswerPacket(conn, Packets.AnswerPartitionTable, **kw)
def checkAnswerObjectPresent(self, conn, **kw):
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_OBJECT_PRESENT, **kw)
return self.checkAnswerPacket(conn, Packets.AnswerObjectPresent, **kw)
# XXX: imported from neo.master.test.connector since it's used at many places
......@@ -335,7 +336,7 @@ class TestElectionConnector(DoNothingConnector):
logging.info("in patched analyse / IDENTIFICATION")
p = protocol.Packet()
self.uuid = getNewUUID()
p.acceptNodeIdentification(1, NodeType.MASTER, self.uuid,
p.AcceptIdentification(1, NodeType.MASTER, self.uuid,
self.getAddress()[0], self.getAddress()[1], 1009, 2)
self.packet_cpt += 1
return p.encode()
......@@ -343,7 +344,7 @@ class TestElectionConnector(DoNothingConnector):
# second : answer primary master nodes
logging.info("in patched analyse / ANSWER PM")
p = protocol.Packet()
p.answerPrimaryMaster(2, protocol.INVALID_UUID, [])
p.answerPrimary(2, protocol.INVALID_UUID, [])
self.packet_cpt += 1
return p.encode()
else:
......
This diff is collapsed.
This diff is collapsed.
......@@ -292,7 +292,7 @@ class NEOCluster(object):
def _killMaster(self, primary=False, all=False):
killed_uuid_list = []
primary_uuid = self.neoctl.getPrimaryMaster()
primary_uuid = self.neoctl.getPrimary()
for master in self.getMasterProcessList():
master_uuid = master.getUUID()
is_primary = master_uuid == primary_uuid
......@@ -304,7 +304,7 @@ class NEOCluster(object):
break
return killed_uuid_list
def killPrimaryMaster(self):
def killPrimary(self):
return self._killMaster(primary=True)
def killSecondaryMaster(self, all=False):
......@@ -312,7 +312,7 @@ class NEOCluster(object):
def killMasters(self):
secondary_list = self.killSecondaryMaster(all=True)
primary_list = self.killPrimaryMaster()
primary_list = self.killPrimary()
return secondary_list + primary_list
def killStorage(self, all=False):
......@@ -347,9 +347,9 @@ class NEOCluster(object):
def getMasterNodeState(self, uuid):
return self.__getNodeState(NodeTypes.MASTER, uuid)
def getPrimaryMaster(self):
def getPrimary(self):
try:
current_try = self.neoctl.getPrimaryMaster()
current_try = self.neoctl.getPrimary()
except NotReadyException:
current_try = None
return current_try
......@@ -394,9 +394,9 @@ class NEOCluster(object):
self.__expectNodeState(NodeTypes.STORAGE, uuid, state,
timeout,delay)
def expectPrimaryMaster(self, uuid=None, timeout=0, delay=1):
def expectPrimary(self, uuid=None, timeout=0, delay=1):
def callback(last_try):
current_try = self.getPrimaryMaster()
current_try = self.getPrimary()
if None not in (uuid, current_try) and uuid != current_try:
raise AssertionError, 'An unexpected primary arised: %r, ' \
'expected %r' % (dump(current_try), dump(uuid))
......
......@@ -49,25 +49,25 @@ class MasterTests(NEOFunctionalTest):
# Check node state has changed.
self.neo.expectMasterState(uuid, None)
def testStoppingPrimaryMasterWithTwoSecondaries(self):
def testStoppingPrimaryWithTwoSecondaries(self):
# Wait for masters to stabilize
self.neo.expectAllMasters(MASTER_NODE_COUNT)
# Kill
killed_uuid_list = self.neo.killPrimaryMaster()
killed_uuid_list = self.neo.killPrimary()
# Test sanity check.
self.assertEqual(len(killed_uuid_list), 1)
uuid = killed_uuid_list[0]
# Check the state of the primary we just killed
self.neo.expectMasterState(uuid, (None, NodeStates.UNKNOWN))
self.assertEqual(self.neo.getPrimaryMaster(), None)
self.assertEqual(self.neo.getPrimary(), None)
# Check that a primary master arised.
self.neo.expectPrimaryMaster(timeout=10)
self.neo.expectPrimary(timeout=10)
# Check that the uuid really changed.
new_uuid = self.neo.getPrimaryMaster()
new_uuid = self.neo.getPrimary()
self.assertNotEqual(new_uuid, uuid)
def testStoppingPrimaryMasterWithOneSecondary(self):
def testStoppingPrimaryWithOneSecondary(self):
self.neo.expectAllMasters(MASTER_NODE_COUNT,
state=NodeStates.RUNNING)
......@@ -78,17 +78,17 @@ class MasterTests(NEOFunctionalTest):
self.neo.expectMasterState(killed_uuid_list[0], None)
self.assertEqual(len(self.neo.getMasterList()), 2)
killed_uuid_list = self.neo.killPrimaryMaster()
killed_uuid_list = self.neo.killPrimary()
# Test sanity check.
self.assertEqual(len(killed_uuid_list), 1)
uuid = killed_uuid_list[0]
# Check the state of the primary we just killed
self.neo.expectMasterState(uuid, (None, NodeStates.UNKNOWN))
self.assertEqual(self.neo.getPrimaryMaster(), None)
self.assertEqual(self.neo.getPrimary(), None)
# Check that a primary master arised.
self.neo.expectPrimaryMaster(timeout=10)
self.neo.expectPrimary(timeout=10)
# Check that the uuid really changed.
new_uuid = self.neo.getPrimaryMaster()
new_uuid = self.neo.getPrimary()
self.assertNotEqual(new_uuid, uuid)
def testMasterSequentialStart(self):
......@@ -104,7 +104,7 @@ class MasterTests(NEOFunctionalTest):
first_master.start()
first_master_uuid = first_master.getUUID()
# Check that the master node we started elected itself.
self.neo.expectPrimaryMaster(first_master_uuid, timeout=30)
self.neo.expectPrimary(first_master_uuid, timeout=30)
# Check that no other node is known as running.
self.assertEqual(len(self.neo.getMasterList(
state=NodeStates.RUNNING)), 1)
......@@ -119,7 +119,7 @@ class MasterTests(NEOFunctionalTest):
self.neo.expectMasterState(second_master.getUUID(),
NodeStates.RUNNING)
# Check that the primary master didn't change.
self.assertEqual(self.neo.getPrimaryMaster(), first_master_uuid)
self.assertEqual(self.neo.getPrimary(), first_master_uuid)
# Start a third master.
third_master = master_list[2]
......@@ -131,7 +131,7 @@ class MasterTests(NEOFunctionalTest):
self.neo.expectMasterState(third_master.getUUID(),
NodeStates.RUNNING)
# Check that the primary master didn't change.
self.assertEqual(self.neo.getPrimaryMaster(), first_master_uuid)
self.assertEqual(self.neo.getPrimary(), first_master_uuid)
def test_suite():
return unittest.makeSuite(MasterTests)
......
......@@ -20,7 +20,7 @@ from mock import Mock
from struct import pack, unpack
from neo.tests import NeoTestBase
from neo import protocol
from neo.protocol import Packet, PacketTypes, NodeTypes, NodeStates
from neo.protocol import Packet, Packets, NodeTypes, NodeStates
from neo.master.handlers.client import ClientServiceHandler
from neo.master.app import Application
from neo.exception import OperationFailure
......@@ -74,7 +74,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_05_notifyNodeInformation(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION)
packet = Packets.NotifyNodeInformation()
# tell the master node that is not running any longer, it must raises
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.MASTER, ('127.0.0.1', self.master_port),
......@@ -145,7 +145,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_06_answerLastIDs(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
packet = Packets.AnswerLastIDs()
loid = self.app.loid
ltid = self.app.ltid
lptid = self.app.pt.getID()
......@@ -172,7 +172,8 @@ class MasterClientHandlerTests(NeoTestBase):
def test_07_askBeginTransaction(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ASK_BEGIN_TRANSACTION)
packet = Packets.AskBeginTransaction()
packet.setId(0)
ltid = self.app.ltid
# client call it
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
......@@ -182,12 +183,12 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEquals(len(self.app.finishing_transaction_dict), 1)
tid = self.app.finishing_transaction_dict.keys()[0]
self.assertEquals(tid, self.app.ltid)
def test_08_askNewOIDs(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ASK_NEW_OIDS)
packet = Packets.AskNewOIDs()
packet.setId(0)
loid = self.app.loid
# client call it
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
......@@ -198,7 +199,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_09_finishTransaction(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.FINISH_TRANSACTION)
packet = Packets.FinishTransaction()
packet.setId(9)
# give an older tid than the PMN known, must abort
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
......@@ -236,7 +237,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_11_abortTransaction(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ABORT_TRANSACTION)
packet = Packets.AbortTransaction()
# give a bad tid, must not failed, just ignored it
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address)
......@@ -255,7 +256,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_12_askLastIDs(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ASK_LAST_IDS)
packet = Packets.AskLastIDs()
# give a uuid
conn = self.getFakeConnection(uuid, self.storage_address)
ptid = self.app.pt.getID()
......@@ -272,7 +273,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_13_askUnfinishedTransactions(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ASK_UNFINISHED_TRANSACTIONS)
packet = Packets.AskUnfinishedTransactions()
# give a uuid
conn = self.getFakeConnection(uuid, self.storage_address)
service.askUnfinishedTransactions(conn, packet)
......@@ -323,7 +324,7 @@ class MasterClientHandlerTests(NeoTestBase):
port = self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID()
packet = Packet(msg_type=ASK_BEGIN_TRANSACTION)
packet = AskBeginTransaction()
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
......@@ -367,7 +368,7 @@ class MasterClientHandlerTests(NeoTestBase):
port = self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID()
packet = Packet(msg_type=ASK_BEGIN_TRANSACTION)
packet = AskBeginTransaction()
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
......@@ -411,7 +412,7 @@ class MasterClientHandlerTests(NeoTestBase):
port = self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID()
packet = Packet(msg_type=ASK_BEGIN_TRANSACTION)
packet = AskBeginTransaction()
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
......
This diff is collapsed.
......@@ -18,7 +18,7 @@
import unittest
from struct import pack, unpack
from neo.tests import NeoTestBase
from neo.protocol import Packet, PacketTypes
from neo.protocol import Packet, Packets
from neo.protocol import NodeTypes, NodeStates, CellStates
from neo.master.handlers.recovery import RecoveryHandler
from neo.master.app import Application
......@@ -93,7 +93,7 @@ class MasterRecoveryTests(NeoTestBase):
def test_08_notifyNodeInformation(self):
recovery = self.recovery
uuid = self.identifyToMasterNode(NodeTypes.MASTER, port=self.master_port)
packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION)
packet = Packets.NotifyNodeInformation()
# tell about a client node, do nothing
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(NodeTypes.CLIENT, '127.0.0.1', self.client_port,
......@@ -151,7 +151,7 @@ class MasterRecoveryTests(NeoTestBase):
def test_09_answerLastIDs(self):
recovery = self.recovery
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
packet = Packets.AnswerLastIDs()
loid = self.app.loid
ltid = self.app.ltid
lptid = self.app.pt.getID()
......@@ -178,7 +178,7 @@ class MasterRecoveryTests(NeoTestBase):
def test_10_answerPartitionTable(self):
recovery = self.recovery
uuid = self.identifyToMasterNode(NodeTypes.MASTER, port=self.master_port)
packet = Packet(msg_type=PacketTypes.ANSWER_PARTITION_TABLE)
packet = Packets.AnswerPartitionTable()
# not from target node, ignore
uuid = self.identifyToMasterNode(NodeTypes.STORAGE, port=self.storage_port)
conn = self.getFakeConnection(uuid, self.storage_port)
......
......@@ -21,7 +21,7 @@ from mock import Mock
from struct import pack, unpack
from neo.tests import NeoTestBase
from neo import protocol
from neo.protocol import Packet, PacketTypes
from neo.protocol import Packet, Packets
from neo.protocol import NodeTypes, NodeStates, CellStates
from neo.master.handlers.storage import StorageServiceHandler
from neo.master.app import Application
......@@ -66,7 +66,7 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_05_notifyNodeInformation(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION)
packet = Packets.NotifyNodeInformation()
# tell the master node that is not running any longer, it must raises
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port,
......@@ -136,7 +136,7 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_06_answerLastIDs(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
packet = Packets.AnswerLastIDs()
loid = self.app.loid
ltid = self.app.ltid
lptid = self.app.pt.getID()
......@@ -154,7 +154,7 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_10_notifyInformationLocked(self):
service = self.service
uuid = self.identifyToMasterNode(port=10020)
packet = Packet(msg_type=PacketTypes.NOTIFY_INFORMATION_LOCKED)
packet = Packets.NotifyInformationLocked()
# give an older tid than the PMN known, must abort
conn = self.getFakeConnection(uuid, self.storage_address)
oid_list = []
......@@ -197,7 +197,8 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_12_askLastIDs(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ASK_LAST_IDS)
packet = Packets.AskLastIDs()
packet.setId(0)
# give a uuid
conn = self.getFakeConnection(uuid, self.storage_address)
ptid = self.app.pt.getID()
......@@ -205,7 +206,7 @@ class MasterStorageHandlerTests(NeoTestBase):
oid = self.app.loid
service.askLastIDs(conn, packet)
packet = self.checkAnswerLastIDs(conn, answered_packet=packet)
loid, ltid, lptid = protocol._decodeAnswerLastIDs(packet._body)
loid, ltid, lptid = packet.decode()
self.assertEqual(loid, oid)
self.assertEqual(ltid, tid)
self.assertEqual(lptid, ptid)
......@@ -214,12 +215,13 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_13_askUnfinishedTransactions(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ASK_UNFINISHED_TRANSACTIONS)
packet = Packets.AskUnfinishedTransactions()
packet.setId(0)
# give a uuid
conn = self.getFakeConnection(uuid, self.storage_address)
service.askUnfinishedTransactions(conn, packet)
packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet)
tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0]
tid_list = packet.decode()
self.assertEqual(len(tid_list), 0)
# create some transaction
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
......@@ -238,7 +240,7 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_14_notifyPartitionChanges(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.NOTIFY_PARTITION_CHANGES)
packet = Packets.NotifyPartitionChanges()
# do not answer if not a storage node
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
port=self.client_port)
......@@ -335,7 +337,7 @@ class MasterStorageHandlerTests(NeoTestBase):
port = self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID()
packet = Packet(msg_type=ASK_BEGIN_TRANSACTION)
packet = AskBeginTransaction()
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
......@@ -384,7 +386,7 @@ class MasterStorageHandlerTests(NeoTestBase):
port = self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID()
packet = Packet(msg_type=ASK_BEGIN_TRANSACTION)
packet = AskBeginTransaction()
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
......@@ -433,7 +435,7 @@ class MasterStorageHandlerTests(NeoTestBase):
port = self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID()
packet = Packet(msg_type=ASK_BEGIN_TRANSACTION)
packet = AskBeginTransaction()
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
......
......@@ -18,7 +18,8 @@
import unittest
from struct import pack, unpack
from neo.tests import NeoTestBase
from neo.protocol import Packet, PacketTypes
from neo import protocol
from neo.protocol import Packet, Packets
from neo.protocol import NodeTypes, NodeStates, ErrorCodes
from neo.master.handlers.verification import VerificationHandler
from neo.master.app import Application
......@@ -127,7 +128,7 @@ class MasterVerificationTests(NeoTestBase):
def test_09_answerLastIDs(self):
verification = self.verification
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
packet = Packets.AnswerLastIDs()
loid = self.app.loid
ltid = self.app.ltid
lptid = '\0' * 8
......@@ -151,7 +152,7 @@ class MasterVerificationTests(NeoTestBase):
def test_11_answerUnfinishedTransactions(self):
verification = self.verification
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ANSWER_UNFINISHED_TRANSACTIONS)
packet = Packets.AnswerUnfinishedTransactions()
# do nothing
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 0)
......@@ -178,7 +179,7 @@ class MasterVerificationTests(NeoTestBase):
def test_12_answerTransactionInformation(self):
verification = self.verification
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ANSWER_TRANSACTION_INFORMATION)
packet = Packets.AnswerTransactionInformation()
# do nothing, as unfinished_oid_set is None
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 0)
......@@ -229,7 +230,7 @@ class MasterVerificationTests(NeoTestBase):
def test_13_tidNotFound(self):
verification = self.verification
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ErrorCodes.TID_NOT_FOUND)
packet = protocol.tidNotFound('')
# do nothing as asking_uuid_dict is True
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 0)
......@@ -250,7 +251,7 @@ class MasterVerificationTests(NeoTestBase):
def test_14_answerObjectPresent(self):
verification = self.verification
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=PacketTypes.ANSWER_OBJECT_PRESENT)
packet = Packets.AnswerObjectPresent()
# do nothing as asking_uuid_dict is True
upper, lower = unpack('!LL', self.app.ltid)
new_tid = pack('!LL', upper, lower + 10)
......@@ -272,8 +273,8 @@ class MasterVerificationTests(NeoTestBase):
def test_15_oidNotFound(self):
verification = self.verification
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ErrorCodes.OID_NOT_FOUND)
# do nothinf as asking_uuid_dict is True
packet = protocol.oidNotFound('')
# do nothing as asking_uuid_dict is True
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 0)
self.app.asking_uuid_dict[uuid] = True
......
......@@ -27,7 +27,7 @@ from neo.storage.handlers.client import TransactionInformation
from neo.storage.handlers.client import ClientOperationHandler
from neo.exception import PrimaryFailure, OperationFailure
from neo.pt import PartitionTable
from neo.protocol import PacketTypes, Packet, INVALID_PARTITION
from neo.protocol import Packets, Packet, INVALID_PARTITION
from neo.protocol import INVALID_TID, INVALID_OID, INVALID_SERIAL
class StorageClientHandlerTests(NeoTestBase):
......@@ -107,14 +107,16 @@ class StorageClientHandlerTests(NeoTestBase):
def test_18_askTransactionInformation1(self):
# transaction does not exists
conn = Mock({ })
packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
packet = Packets.AskTransactionInformation()
packet.setId(0)
self.operation.askTransactionInformation(conn, packet, INVALID_TID)
self.checkErrorPacket(conn)
def test_18_askTransactionInformation2(self):
# answer
conn = Mock({ })
packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
packet = Packets.AskTransactionInformation()
packet.setId(0)
dm = Mock({ "getTransaction": (INVALID_TID, 'user', 'desc', '', ), })
self.app.dm = dm
self.operation.askTransactionInformation(conn, packet, INVALID_TID)
......@@ -124,7 +126,8 @@ class StorageClientHandlerTests(NeoTestBase):
# delayed response
conn = Mock({})
self.app.dm = Mock()
packet = Packet(msg_type=PacketTypes.ASK_OBJECT)
packet = Packets.AskObject()
packet.setId(0)
self.app.load_lock_dict[INVALID_OID] = object()
self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet,
......@@ -139,7 +142,8 @@ class StorageClientHandlerTests(NeoTestBase):
# invalid serial / tid / packet not found
self.app.dm = Mock({'getObject': None})
conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_OBJECT)
packet = Packets.AskObject()
packet.setId(0)
self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet,
oid=INVALID_OID,
......@@ -155,7 +159,8 @@ class StorageClientHandlerTests(NeoTestBase):
# object found => answer
self.app.dm = Mock({'getObject': ('', '', 0, 0, '', )})
conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_OBJECT)
packet = Packets.AskObject()
packet.setId(0)
self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet,
oid=INVALID_OID,
......@@ -170,7 +175,8 @@ class StorageClientHandlerTests(NeoTestBase):
app.pt = Mock()
app.dm = Mock()
conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_TIDS)
packet = Packets.AskTIDs()
packet.setId(0)
self.checkProtocolErrorRaised(self.operation.askTIDs, conn, packet, 1, 1, None)
self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0)
self.assertEquals(len(app.dm.mockGetNamedCalls('getTIDList')), 0)
......@@ -178,7 +184,8 @@ class StorageClientHandlerTests(NeoTestBase):
def test_25_askTIDs2(self):
# well case => answer
conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_TIDS)
packet = Packets.AskTIDs()
packet.setId(0)
self.app.pt = Mock({'getPartitions': 1})
self.app.dm = Mock({'getTIDList': (INVALID_TID, )})
self.operation.askTIDs(conn, packet, 1, 2, 1)
......@@ -190,7 +197,8 @@ class StorageClientHandlerTests(NeoTestBase):
def test_25_askTIDs3(self):
# invalid partition => answer usable partitions
conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_TIDS)
packet = Packets.AskTIDs()
packet.setId(0)
cell = Mock({'getUUID':self.app.uuid})
self.app.dm = Mock({'getTIDList': (INVALID_TID, )})
self.app.pt = Mock({'getCellList': (cell, ), 'getPartitions': 1})
......@@ -206,13 +214,15 @@ class StorageClientHandlerTests(NeoTestBase):
app = self.app
app.dm = Mock()
conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_OBJECT_HISTORY)
packet = Packets.AskObjectHistory()
packet.setId(0)
self.checkProtocolErrorRaised(self.operation.askObjectHistory, conn, packet, 1, 1, None)
self.assertEquals(len(app.dm.mockGetNamedCalls('getObjectHistory')), 0)
def test_26_askObjectHistory2(self):
# first case: empty history
packet = Packet(msg_type=PacketTypes.ASK_OBJECT_HISTORY)
packet = Packets.AskObjectHistory()
packet.setId(0)
conn = Mock({})
self.app.dm = Mock({'getObjectHistory': None})
self.operation.askObjectHistory(conn, packet, INVALID_OID, 1, 2)
......@@ -225,7 +235,8 @@ class StorageClientHandlerTests(NeoTestBase):
def test_27_askStoreTransaction2(self):
# add transaction entry
packet = Packet(msg_type=PacketTypes.ASK_STORE_TRANSACTION)
packet = Packets.AskStoreTransaction()
packet.setId(0)
conn = Mock({'getUUID': self.getNewUUID()})
self.operation.askStoreTransaction(conn, packet,
INVALID_TID, '', '', '', ())
......@@ -237,7 +248,8 @@ class StorageClientHandlerTests(NeoTestBase):
def test_28_askStoreObject2(self):
# locked => delayed response
packet = Packet(msg_type=PacketTypes.ASK_STORE_OBJECT)
packet = Packets.AskStoreObject()
packet.setId(0)
conn = Mock({'getUUID': self.app.uuid})
oid = '\x02' * 8
tid1, tid2 = self.getTwoIDs()
......@@ -254,7 +266,8 @@ class StorageClientHandlerTests(NeoTestBase):
def test_28_askStoreObject3(self):
# locked => unresolvable conflict => answer
packet = Packet(msg_type=PacketTypes.ASK_STORE_OBJECT)
packet = Packets.AskStoreObject()
packet.setId(0)
conn = Mock({'getUUID': self.app.uuid})
tid1, tid2 = self.getTwoIDs()
self.app.store_lock_dict[INVALID_OID] = tid2
......@@ -268,7 +281,8 @@ class StorageClientHandlerTests(NeoTestBase):
def test_28_askStoreObject4(self):
# resolvable conflict => answer
packet = Packet(msg_type=PacketTypes.ASK_STORE_OBJECT)
packet = Packets.AskStoreObject()
packet.setId(0)
conn = Mock({'getUUID': self.app.uuid})
self.app.dm = Mock({'getObjectHistory':((self.getNewUUID(), ), )})
self.assertEquals(self.app.store_lock_dict.get(INVALID_OID, None), None)
......@@ -282,7 +296,8 @@ class StorageClientHandlerTests(NeoTestBase):
def test_28_askStoreObject5(self):
# no conflict => answer
packet = Packet(msg_type=PacketTypes.ASK_STORE_OBJECT)
packet = Packets.AskStoreObject()
packet.setId(0)
conn = Mock({'getUUID': self.app.uuid})
self.operation.askStoreObject(conn, packet, INVALID_OID,
INVALID_SERIAL, 0, 0, '', INVALID_TID)
......@@ -297,7 +312,8 @@ class StorageClientHandlerTests(NeoTestBase):
def test_29_abortTransaction(self):
# remove transaction
packet = Packet(msg_type=PacketTypes.ABORT_TRANSACTION)
packet = Packets.AbortTransaction()
packet.setId(0)
conn = Mock({'getUUID': self.app.uuid})
transaction = Mock({ 'getObjectList': ((0, ), ), })
self.called = False
......
......@@ -21,7 +21,7 @@ from neo.tests import NeoTestBase
from neo.pt import PartitionTable
from neo.storage.app import Application
from neo.storage.handlers.initialization import InitializationHandler
from neo.protocol import Packet, PacketTypes, CellStates
from neo.protocol import Packet, Packets, CellStates
from neo.exception import PrimaryFailure
class StorageInitializationHandlerTests(NeoTestBase):
......@@ -80,7 +80,7 @@ class StorageInitializationHandlerTests(NeoTestBase):
self.checkNoPacketSent(conn)
def test_09_sendPartitionTable(self):
packet = Packet(msg_type=PacketTypes.SEND_PARTITION_TABLE)
packet = Packets.SendPartitionTable()
uuid = self.getNewUUID()
# send a table
conn = Mock({"getUUID" : uuid,
......
......@@ -26,7 +26,7 @@ from neo.storage.app import Application
from neo.storage.handlers.master import MasterOperationHandler
from neo.exception import PrimaryFailure, OperationFailure
from neo.pt import PartitionTable
from neo.protocol import CellStates, PacketTypes, Packet
from neo.protocol import CellStates, Packets, Packet
from neo.protocol import INVALID_TID, INVALID_OID
class StorageMasterHandlerTests(NeoTestBase):
......@@ -100,7 +100,7 @@ class StorageMasterHandlerTests(NeoTestBase):
"getAddress" : ("127.0.0.1", self.master_port),
})
app.replicator = Mock({})
packet = Packet(msg_type=PacketTypes.NOTIFY_PARTITION_CHANGES)
packet = Packets.NotifyPartitionChanges()
self.app.pt = Mock({'getID': 1})
count = len(self.app.nm.getList())
self.operation.notifyPartitionChanges(conn, packet, 0, ())
......@@ -124,7 +124,7 @@ class StorageMasterHandlerTests(NeoTestBase):
"isServer": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
packet = Packet(msg_type=PacketTypes.NOTIFY_PARTITION_CHANGES)
packet = Packets.NotifyPartitionChanges()
app = self.app
# register nodes
app.nm.createStorage(uuid=uuid1)
......@@ -147,14 +147,14 @@ class StorageMasterHandlerTests(NeoTestBase):
def test_16_stopOperation1(self):
# OperationFailure
conn = Mock({ 'isServer': False })
packet = Packet(msg_type=PacketTypes.STOP_OPERATION)
packet = Packets.StopOperation()
self.assertRaises(OperationFailure, self.operation.stopOperation, conn, packet)
def test_22_lockInformation2(self):
# load transaction informations
conn = Mock({ 'isServer': False, })
self.app.dm = Mock({ })
packet = Packet(msg_type=PacketTypes.LOCK_INFORMATION)
packet = Packets.LockInformation()
packet.setId(1)
transaction = Mock({ 'getObjectList': ((0, ), ), })
self.app.transaction_dict[INVALID_TID] = transaction
......@@ -173,7 +173,7 @@ class StorageMasterHandlerTests(NeoTestBase):
# delete transaction informations
conn = Mock({ 'isServer': False, })
self.app.dm = Mock({ })
packet = Packet(msg_type=PacketTypes.LOCK_INFORMATION)
packet = Packets.LockInformation()
packet.setId(1)
transaction = Mock({ 'getObjectList': ((0, ), ), })
self.app.transaction_dict[INVALID_TID] = transaction
......@@ -195,7 +195,7 @@ class StorageMasterHandlerTests(NeoTestBase):
def test_30_answerLastIDs(self):
# set critical TID on replicator
conn = Mock()
packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
packet = Packets.AnswerLastIDs()
self.app.replicator = Mock()
self.operation.answerLastIDs(
conn=conn,
......@@ -211,7 +211,7 @@ class StorageMasterHandlerTests(NeoTestBase):
def test_31_answerUnfinishedTransactions(self):
# set unfinished TID on replicator
conn = Mock()
packet = Packet(msg_type=PacketTypes.ANSWER_UNFINISHED_TRANSACTIONS)
packet = Packets.AnswerUnfinishedTransactions()
self.app.replicator = Mock()
self.operation.answerUnfinishedTransactions(
conn=conn,
......
......@@ -24,7 +24,7 @@ from collections import deque
from neo.tests import NeoTestBase
from neo.storage.app import Application
from neo.storage.handlers.storage import StorageOperationHandler
from neo.protocol import PacketTypes, Packet, INVALID_PARTITION
from neo.protocol import Packets, Packet, INVALID_PARTITION
from neo.protocol import INVALID_TID, INVALID_OID, INVALID_SERIAL
class StorageStorageHandlerTests(NeoTestBase):
......@@ -65,14 +65,16 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_18_askTransactionInformation1(self):
# transaction does not exists
conn = Mock({ })
packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
packet = Packets.AskTransactionInformation()
packet.setId(0)
self.operation.askTransactionInformation(conn, packet, INVALID_TID)
self.checkErrorPacket(conn)
def test_18_askTransactionInformation2(self):
# answer
conn = Mock({ })
packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
packet = Packets.AskTransactionInformation()
packet.setId(0)
dm = Mock({ "getTransaction": (INVALID_TID, 'user', 'desc', '', ), })
self.app.dm = dm
self.operation.askTransactionInformation(conn, packet, INVALID_TID)
......@@ -82,7 +84,7 @@ class StorageStorageHandlerTests(NeoTestBase):
# delayed response
conn = Mock({})
self.app.dm = Mock()
packet = Packet(msg_type=PacketTypes.ASK_OBJECT)
packet = Packets.AskObject()
self.app.load_lock_dict[INVALID_OID] = object()
self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet,
......@@ -97,7 +99,8 @@ class StorageStorageHandlerTests(NeoTestBase):
# invalid serial / tid / packet not found
self.app.dm = Mock({'getObject': None})
conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_OBJECT)
packet = Packets.AskObject()
packet.setId(0)
self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet,
oid=INVALID_OID,
......@@ -113,7 +116,8 @@ class StorageStorageHandlerTests(NeoTestBase):
# object found => answer
self.app.dm = Mock({'getObject': ('', '', 0, 0, '', )})
conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_OBJECT)
packet = Packets.AskObject()
packet.setId(0)
self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet,
oid=INVALID_OID,
......@@ -128,7 +132,7 @@ class StorageStorageHandlerTests(NeoTestBase):
app.pt = Mock()
app.dm = Mock()
conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_TIDS)
packet = Packets.AskTIDs()
self.checkProtocolErrorRaised(self.operation.askTIDs, conn, packet, 1, 1, None)
self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0)
self.assertEquals(len(app.dm.mockGetNamedCalls('getTIDList')), 0)
......@@ -136,7 +140,8 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_25_askTIDs2(self):
# well case => answer
conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_TIDS)
packet = Packets.AskTIDs()
packet.setId(0)
self.app.dm = Mock({'getTIDList': (INVALID_TID, )})
self.app.pt = Mock({'getPartitions': 1})
self.operation.askTIDs(conn, packet, 1, 2, 1)
......@@ -148,7 +153,8 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_25_askTIDs3(self):
# invalid partition => answer usable partitions
conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_TIDS)
packet = Packets.AskTIDs()
packet.setId(0)
cell = Mock({'getUUID':self.app.uuid})
self.app.dm = Mock({'getTIDList': (INVALID_TID, )})
self.app.pt = Mock({'getCellList': (cell, ), 'getPartitions': 1})
......@@ -164,13 +170,15 @@ class StorageStorageHandlerTests(NeoTestBase):
app = self.app
app.dm = Mock()
conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_OBJECT_HISTORY)
packet = Packets.AskObjectHistory()
packet.setId(0)
self.checkProtocolErrorRaised(self.operation.askObjectHistory, conn, packet, 1, 1, None)
self.assertEquals(len(app.dm.mockGetNamedCalls('getObjectHistory')), 0)
def test_26_askObjectHistory2(self):
# first case: empty history
packet = Packet(msg_type=PacketTypes.ASK_OBJECT_HISTORY)
packet = Packets.AskObjectHistory()
packet.setId(0)
conn = Mock({})
self.app.dm = Mock({'getObjectHistory': None})
self.operation.askObjectHistory(conn, packet, INVALID_OID, 1, 2)
......@@ -187,7 +195,8 @@ class StorageStorageHandlerTests(NeoTestBase):
app.pt = Mock()
app.dm = Mock()
conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_OIDS)
packet = Packets.AskOIDs()
packet.setId(0)
self.checkProtocolErrorRaised(self.operation.askOIDs, conn, packet, 1, 1, None)
self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0)
self.assertEquals(len(app.dm.mockGetNamedCalls('getOIDList')), 0)
......@@ -195,7 +204,8 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_25_askOIDs2(self):
# well case > answer OIDs
conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_OIDS)
packet = Packets.AskOIDs()
packet.setId(0)
self.app.pt = Mock({'getPartitions': 1})
self.app.dm = Mock({'getOIDList': (INVALID_OID, )})
self.operation.askOIDs(conn, packet, 1, 2, 1)
......@@ -207,7 +217,8 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_25_askOIDs3(self):
# invalid partition => answer usable partitions
conn = Mock({})
packet = Packet(msg_type=PacketTypes.ASK_OIDS)
packet = Packets.AskOIDs()
packet.setId(0)
cell = Mock({'getUUID':self.app.uuid})
self.app.dm = Mock({'getOIDList': (INVALID_OID, )})
self.app.pt = Mock({'getCellList': (cell, ), 'getPartitions': 1})
......
......@@ -21,7 +21,7 @@ from neo.tests import NeoTestBase
from neo.pt import PartitionTable
from neo.storage.app import Application
from neo.storage.handlers.verification import VerificationHandler
from neo.protocol import Packet, PacketTypes, CellStates, ErrorCodes
from neo.protocol import Packet, Packets, CellStates, ErrorCodes
from neo.protocol import INVALID_OID, INVALID_TID
from neo.exception import PrimaryFailure, OperationFailure
from neo.storage.mysqldb import p64, u64
......@@ -172,7 +172,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
"isServer": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
packet = Packet(msg_type=PacketTypes.NOTIFY_PARTITION_CHANGES)
packet = Packets.NotifyPartitionChanges()
self.verification.notifyPartitionChanges(conn, packet, 1, ())
self.verification.notifyPartitionChanges(conn, packet, 0, ())
self.assertEqual(self.app.pt.getID(), 1)
......@@ -182,7 +182,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
"isServer": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
packet = Packet(msg_type=PacketTypes.NOTIFY_PARTITION_CHANGES)
packet = Packets.NotifyPartitionChanges()
new_uuid = self.getNewUUID()
cell = (0, new_uuid, CellStates.UP_TO_DATE)
self.app.nm.createStorage(uuid=new_uuid)
......@@ -201,21 +201,22 @@ class StorageVerificationHandlerTests(NeoTestBase):
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False })
self.assertFalse(self.app.operational)
packet = Packet(msg_type=PacketTypes.STOP_OPERATION)
packet = Packets.StopOperation()
self.verification.startOperation(conn, packet)
self.assertTrue(self.app.operational)
def test_12_stopOperation(self):
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False })
packet = Packet(msg_type=PacketTypes.STOP_OPERATION)
packet = Packets.StopOperation()
self.assertRaises(OperationFailure, self.verification.stopOperation, conn, packet)
def test_13_askUnfinishedTransactions(self):
# client connection with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False})
packet = Packet(msg_type=PacketTypes.ASK_UNFINISHED_TRANSACTIONS)
packet = Packets.AskUnfinishedTransactions()
packet.setId(0)
self.verification.askUnfinishedTransactions(conn, packet)
(tid_list, ) = self.checkAnswerUnfinishedTransactions(conn, decode=True)
self.assertEqual(len(tid_list), 0)
......@@ -227,7 +228,8 @@ class StorageVerificationHandlerTests(NeoTestBase):
self.app.dm.commit()
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False})
packet = Packet(msg_type=PacketTypes.ASK_UNFINISHED_TRANSACTIONS)
packet = Packets.AskUnfinishedTransactions()
packet.setId(0)
self.verification.askUnfinishedTransactions(conn, packet)
(tid_list, ) = self.checkAnswerUnfinishedTransactions(conn, decode=True)
self.assertEqual(len(tid_list), 1)
......@@ -237,7 +239,8 @@ class StorageVerificationHandlerTests(NeoTestBase):
# ask from client conn with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False })
packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
packet = Packets.AskTransactionInformation()
packet.setId(0)
self.verification.askTransactionInformation(conn, packet, p64(1))
code, message = self.checkErrorPacket(conn, decode=True)
self.assertEqual(code, ErrorCodes.TID_NOT_FOUND)
......@@ -252,7 +255,8 @@ class StorageVerificationHandlerTests(NeoTestBase):
# object from trans
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False })
packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
packet = Packets.AskTransactionInformation()
packet.setId(0)
self.verification.askTransactionInformation(conn, packet, p64(1))
tid, user, desc, ext, oid_list = self.checkAnswerTransactionInformation(conn, decode=True)
self.assertEqual(u64(tid), 1)
......@@ -264,7 +268,8 @@ class StorageVerificationHandlerTests(NeoTestBase):
# object from ttrans
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False })
packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
packet = Packets.AskTransactionInformation()
packet.setId(0)
self.verification.askTransactionInformation(conn, packet, p64(3))
tid, user, desc, ext, oid_list = self.checkAnswerTransactionInformation(conn, decode=True)
self.assertEqual(u64(tid), 3)
......@@ -278,7 +283,8 @@ class StorageVerificationHandlerTests(NeoTestBase):
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': True })
# find the one in trans
packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
packet = Packets.AskTransactionInformation()
packet.setId(0)
self.verification.askTransactionInformation(conn, packet, p64(1))
tid, user, desc, ext, oid_list = self.checkAnswerTransactionInformation(conn, decode=True)
self.assertEqual(u64(tid), 1)
......@@ -290,7 +296,8 @@ class StorageVerificationHandlerTests(NeoTestBase):
# do not find the one in ttrans
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': True })
packet = Packet(msg_type=PacketTypes.ASK_TRANSACTION_INFORMATION)
packet = Packets.AskTransactionInformation()
packet.setId(0)
self.verification.askTransactionInformation(conn, packet, p64(2))
code, message = self.checkErrorPacket(conn, decode=True)
self.assertEqual(code, ErrorCodes.TID_NOT_FOUND)
......@@ -299,7 +306,8 @@ class StorageVerificationHandlerTests(NeoTestBase):
# client connection with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False})
packet = Packet(msg_type=PacketTypes.ASK_OBJECT_PRESENT)
packet = Packets.AskObjectPresent()
packet.setId(0)
self.verification.askObjectPresent(conn, packet, p64(1), p64(2))
code, message = self.checkErrorPacket(conn, decode=True)
self.assertEqual(code, ErrorCodes.OID_NOT_FOUND)
......@@ -311,7 +319,8 @@ class StorageVerificationHandlerTests(NeoTestBase):
self.app.dm.commit()
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False})
packet = Packet(msg_type=PacketTypes.ASK_OBJECT_PRESENT)
packet = Packets.AskObjectPresent()
packet.setId(0)
self.verification.askObjectPresent(conn, packet, p64(1), p64(2))
oid, tid = self.checkAnswerObjectPresent(conn, decode=True)
self.assertEqual(u64(tid), 2)
......@@ -321,7 +330,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
# client connection with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServer': False})
packet = Packet(msg_type=PacketTypes.ASK_OBJECT_PRESENT)
packet = Packets.AskObjectPresent()
self.verification.deleteTransaction(conn, packet, p64(1))
# client connection with data
self.app.dm.begin()
......@@ -338,7 +347,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
'isServer': False })
dm = Mock()
self.app.dm = dm
packet = Packet(msg_type=PacketTypes.COMMIT_TRANSACTION)
packet = Packets.CommitTransaction()
self.verification.commitTransaction(conn, packet, p64(1))
self.assertEqual(len(dm.mockGetNamedCalls("finishTransaction")), 1)
call = dm.mockGetNamedCalls("finishTransaction")[0]
......
......@@ -51,7 +51,7 @@ class BootstrapManagerTests(NeoTestBase):
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
self.bootstrap.connectionCompleted(conn)
self.checkAskPrimaryMaster(conn)
self.checkAskPrimary(conn)
def testHandleNotReady(self):
# the primary is not ready
......
......@@ -23,8 +23,7 @@ from neo.handler import EventHandler
from neo.tests import DoNothingConnector
from neo.connector import ConnectorException, ConnectorTryAgainException, \
ConnectorInProgressException, ConnectorConnectionRefusedException
from neo.protocol import PacketTypes
from neo import protocol
from neo.protocol import Packets
from neo.tests import NeoTestBase
class ConnectionTests(NeoTestBase):
......@@ -394,7 +393,7 @@ class ConnectionTests(NeoTestBase):
def test_07_Connection_addPacket(self):
# no connector
p = Mock({"encode" : "testdata"})
p = Mock({"__str__" : "testdata"})
em = Mock()
handler = Mock()
bc = Connection(em, handler, connector_handler=DoNothingConnector,
......@@ -467,9 +466,9 @@ class ConnectionTests(NeoTestBase):
(("127.0.0.1", 2133), self.getNewUUID()),
(("127.0.0.1", 2435), self.getNewUUID()),
(("127.0.0.1", 2132), self.getNewUUID()))
p = protocol.answerPrimaryMaster(self.getNewUUID(), master_list)
p = Packets.AnswerPrimary(self.getNewUUID(), master_list)
p.setId(1)
data = p.encode()
data = str(p)
bc.read_buf += data
self.assertEqual(len(bc.event_dict), 0)
bc.analyse()
......@@ -500,9 +499,9 @@ class ConnectionTests(NeoTestBase):
(("127.0.0.1", 2133), self.getNewUUID()),
(("127.0.0.1", 2435), self.getNewUUID()),
(("127.0.0.1", 2132), self.getNewUUID()))
p1 = protocol.answerPrimaryMaster(self.getNewUUID(), master_list)
p1 = Packets.AnswerPrimary(self.getNewUUID(), master_list)
p1.setId(1)
data = p1.encode()
data = str(p1)
bc.read_buf += data
# packet 2
master_list = (
......@@ -514,11 +513,11 @@ class ConnectionTests(NeoTestBase):
(("127.0.0.1", 2133), self.getNewUUID()),
(("127.0.0.1", 2435), self.getNewUUID()),
(("127.0.0.1", 2132), self.getNewUUID()))
p2 = protocol.answerPrimaryMaster( self.getNewUUID(), master_list)
p2 = Packets.AnswerPrimary( self.getNewUUID(), master_list)
p2.setId(2)
data = p2.encode()
data = str(p2)
bc.read_buf += data
self.assertEqual(len(bc.read_buf), len(p1.encode()) + len(p2.encode()))
self.assertEqual(len(bc.read_buf), len(p1) + len(p2))
self.assertEqual(len(bc.event_dict), 0)
bc.analyse()
# check two packets decoded
......@@ -569,9 +568,9 @@ class ConnectionTests(NeoTestBase):
(("127.0.0.1", 2133), self.getNewUUID()),
(("127.0.0.1", 2435), self.getNewUUID()),
(("127.0.0.1", 2132), self.getNewUUID()))
p = protocol.answerPrimaryMaster(self.getNewUUID(), master_list)
p = Packets.AnswerPrimary(self.getNewUUID(), master_list)
p.setId(1)
data = p.encode()
data = str(p)
bc.read_buf += data
self.assertEqual(len(bc.event_dict), 0)
bc.expectMessage(1)
......@@ -700,10 +699,9 @@ class ConnectionTests(NeoTestBase):
(("127.0.0.1", 2435), self.getNewUUID()),
(("127.0.0.1", 2132), self.getNewUUID()))
uuid = self.getNewUUID()
p = protocol.answerPrimaryMaster(uuid, master_list)
p = Packets.AnswerPrimary(uuid, master_list)
p.setId(1)
data = p.encode()
return data
return str(p)
DoNothingConnector.receive = receive
connector = DoNothingConnector()
bc = Connection(em, handler, connector_handler=DoNothingConnector,
......@@ -719,7 +717,7 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(bc._queue.mockGetNamedCalls("append")), 1)
call = bc._queue.mockGetNamedCalls("append")[0]
data = call.getParam(0)
self.assertEqual(data.getType(), PacketTypes.ANSWER_PRIMARY_MASTER)
self.assertEqual(data.getType(), Packets.AnswerPrimary)
self.assertEqual(data.getId(), 1)
self.assertEqual(len(bc.event_dict), 0)
self.assertEqual(bc.read_buf, '')
......
This diff is collapsed.
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