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': ('',