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

Unify packets checking in master and storage.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@521 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent bdc2f9b5
......@@ -18,13 +18,14 @@
import unittest, logging, os
from tempfile import mkstemp
from mock import Mock
from neo.tests.base import NeoTestBase
from neo.master.app import Application
from neo.protocol import INVALID_PTID, INVALID_OID, INVALID_TID, \
INVALID_UUID, Packet, NOTIFY_NODE_INFORMATION
from neo.node import MasterNode, ClientNode, StorageNode
from neo.storage.mysqldb import p64, u64
class MasterAppTests(unittest.TestCase):
class MasterAppTests(NeoTestBase):
def setUp(self):
logging.basicConfig(level = logging.WARNING)
......@@ -81,18 +82,6 @@ server: 127.0.0.1:10023
# Delete tmp file
os.remove(self.tmp_path)
def getNewUUID(self):
uuid = INVALID_UUID
while uuid == INVALID_UUID:
uuid = os.urandom(16)
self.uuid = uuid
return uuid
def checkNoPacketSent(self, conn):
self.assertEquals(len(conn.mockGetNamedCalls('notify')), 0)
self.assertEquals(len(conn.mockGetNamedCalls('answer')), 0)
self.assertEquals(len(conn.mockGetNamedCalls('ask')), 0)
def test_01_getNextPartitionTableID(self):
# must raise as we don"t have one
self.assertEqual(self.app.lptid, INVALID_PTID)
......@@ -166,16 +155,8 @@ server: 127.0.0.1:10023
self.app.broadcastNodeInformation(c_node)
# check conn
self.checkNoPacketSent(client_conn)
self.assertEquals(len(master_conn.mockGetNamedCalls("notify")), 1)
call = master_conn.mockGetNamedCalls("notify")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION)
self.assertEquals(len(storage_conn.mockGetNamedCalls("notify")), 1)
call = storage_conn.mockGetNamedCalls("notify")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION)
self.checkNotifyNodeInformation(master_conn)
self.checkNotifyNodeInformation(storage_conn)
# address defined and client type
master_conn = Mock({"getUUID" : master_uuid})
......@@ -186,16 +167,8 @@ server: 127.0.0.1:10023
self.app.broadcastNodeInformation(c_node)
# check conn
self.checkNoPacketSent(client_conn)
self.assertEquals(len(master_conn.mockGetNamedCalls("notify")), 1)
call = master_conn.mockGetNamedCalls("notify")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION)
self.assertEquals(len(storage_conn.mockGetNamedCalls("notify")), 1)
call = storage_conn.mockGetNamedCalls("notify")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION)
self.checkNotifyNodeInformation(master_conn)
self.checkNotifyNodeInformation(storage_conn)
# address defined and storage type
master_conn = Mock({"getUUID" : master_uuid})
......@@ -205,21 +178,9 @@ server: 127.0.0.1:10023
s_node = StorageNode(uuid = self.getNewUUID(), server=("127.0.0.1", 1351))
self.app.broadcastNodeInformation(s_node)
# check conn
self.assertEquals(len(client_conn.mockGetNamedCalls("notify")), 1)
call = client_conn.mockGetNamedCalls("notify")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION)
self.assertEquals(len(master_conn.mockGetNamedCalls("notify")), 1)
call = master_conn.mockGetNamedCalls("notify")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION)
self.assertEquals(len(storage_conn.mockGetNamedCalls("notify")), 1)
call = storage_conn.mockGetNamedCalls("notify")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEqual(packet.getType(), NOTIFY_NODE_INFORMATION)
self.checkNotifyNodeInformation(client_conn)
self.checkNotifyNodeInformation(master_conn)
self.checkNotifyNodeInformation(storage_conn)
if __name__ == '__main__':
......
......@@ -163,7 +163,7 @@ server: 127.0.0.1:10023
ip_address=ip,
port=port,
name=self.app.name,)
self.checkAcceptNodeIdentification(conn, packet)
self.checkAcceptNodeIdentification(conn, answered_packet=packet)
return uuid
# Method to test the kind of packet returned in answer
......@@ -521,7 +521,7 @@ server: 127.0.0.1:10023
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
self.assertEqual(node.getUUID(), uuid)
self.assertEqual(node.getState(), RUNNING_STATE)
self.checkAcceptNodeIdentification(conn, packet)
self.checkAcceptNodeIdentification(conn, answered_packet=packet)
# unknown node
conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None,
"isServerConnection" : True})
......@@ -537,7 +537,7 @@ server: 127.0.0.1:10023
port=self.master_port+1,
name=self.app.name,)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 2)
self.checkAcceptNodeIdentification(conn, packet)
self.checkAcceptNodeIdentification(conn, answered_packet=packet)
self.assertEqual(len(self.app.unconnected_master_node_set), 2)
self.assertEqual(len(self.app.negotiating_master_node_set), 0)
# broken node
......
......@@ -130,7 +130,7 @@ server: 127.0.0.1:10023
# test alien cluster
conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None})
self.service.handleRequestNodeIdentification(conn, packet, *args)
self.checkAcceptNodeIdentification(conn, packet)
self.checkAcceptNodeIdentification(conn, answered_packet=packet)
return uuid
# Tests
......@@ -156,7 +156,7 @@ server: 127.0.0.1:10023
ip_address='127.0.0.1',
port=self.storage_port,
name=self.app.name,)
self.checkAcceptNodeIdentification(conn, packet)
self.checkAcceptNodeIdentification(conn, answered_packet=packet)
self.assertEquals(len(self.app.nm.getStorageNodeList()), 1)
sn = self.app.nm.getStorageNodeList()[0]
self.assertEquals(sn.getServer(), ('127.0.0.1', self.storage_port))
......@@ -174,7 +174,7 @@ server: 127.0.0.1:10023
ip_address='127.0.0.1',
port=self.storage_port,
name=self.app.name,)
self.checkAcceptNodeIdentification(conn, packet)
self.checkAcceptNodeIdentification(conn, answered_packet=packet)
sn = self.app.nm.getStorageNodeList()[0]
self.assertEquals(sn.getServer(), ('127.0.0.1', self.storage_port))
self.assertEquals(sn.getUUID(), uuid)
......@@ -220,7 +220,7 @@ server: 127.0.0.1:10023
ip_address='127.0.0.1',
port=self.storage_port,
name=self.app.name,)
self.checkAcceptNodeIdentification(conn, packet)
self.checkAcceptNodeIdentification(conn, answered_packet=packet)
self.assertEquals(len(self.app.nm.getStorageNodeList()), 1)
sn = self.app.nm.getStorageNodeList()[0]
self.assertEquals(sn.getServer(), ('127.0.0.1', self.storage_port))
......@@ -241,7 +241,7 @@ server: 127.0.0.1:10023
ip_address='127.0.0.2',
port=10022,
name=self.app.name,)
self.checkAcceptNodeIdentification(conn, packet)
self.checkAcceptNodeIdentification(conn, answered_packet=packet)
call = conn.mockGetNamedCalls('answer')[0]
new_uuid = call.getParam(0)._body[-16:]
self.assertNotEquals(uuid, new_uuid)
......@@ -296,11 +296,11 @@ server: 127.0.0.1:10023
"getAddress" : ("127.0.0.1", self.storage_port)})
service.handleAskPrimaryMaster(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.checkAnswerPrimaryMaster(conn, packet)
self.checkNotifyNodeInformation(conn, 0)
self.checkSendPartitionTable(conn, 1)
self.checkSendPartitionTable(conn, 2)
self.checkStartOperation(conn, 3)
self.checkAnswerPrimaryMaster(conn, answered_packet=packet)
self.checkNotifyNodeInformation(conn, packet_number=0)
self.checkSendPartitionTable(conn, packet_number=1)
self.checkSendPartitionTable(conn, packet_number=2)
self.checkStartOperation(conn, packet_number=3)
# Same but identify as a client node, must not get start operation message
uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=11021)
......@@ -310,10 +310,10 @@ server: 127.0.0.1:10023
"getUUID" : uuid, "getAddress" : ("127.0.0.1", 11021)})
service.handleAskPrimaryMaster(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.checkAnswerPrimaryMaster(conn, packet)
self.checkNotifyNodeInformation(conn, 0)
self.checkSendPartitionTable(conn, 1)
self.checkSendPartitionTable(conn, 2)
self.checkAnswerPrimaryMaster(conn, answered_packet=packet)
self.checkNotifyNodeInformation(conn, packet_number=0)
self.checkSendPartitionTable(conn, packet_number=1)
self.checkSendPartitionTable(conn, packet_number=2)
def test_03_handleAnnouncePrimaryMaster(self):
service = self.service
......@@ -675,7 +675,7 @@ server: 127.0.0.1:10023
tid = self.app.ltid
oid = self.app.loid
service.handleAskLastIDs(conn, packet)
packet = self.checkAnswerLastIDs(conn, packet)
packet = self.checkAnswerLastIDs(conn, answered_packet=packet)
loid, ltid, lptid = protocol._decodeAnswerLastIDs(packet._body)
self.assertEqual(loid, oid)
self.assertEqual(ltid, tid)
......@@ -695,7 +695,7 @@ server: 127.0.0.1:10023
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
service.handleAskUnfinishedTransactions(conn, packet)
packet = self.checkAnswerUnfinishedTransactions(conn, packet)
packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet)
tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0]
self.assertEqual(len(tid_list), 0)
# create some transaction
......@@ -709,7 +709,7 @@ server: 127.0.0.1:10023
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
service.handleAskUnfinishedTransactions(conn, packet)
packet = self.checkAnswerUnfinishedTransactions(conn, packet)
packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet)
tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0]
self.assertEqual(len(tid_list), 3)
......
......@@ -39,14 +39,6 @@ NEO_SQL_DATABASE = 'test_storage_neo1'
class StorageOperationTests(NeoTestBase):
# TODO: move this check to base class and rename as checkAnswerPacket
def checkPacket(self, conn, packet_type=ERROR):
self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
call = conn.mockGetNamedCalls("answer")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), packet_type)
def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs):
conn = Mock({
"getAddress" : ("127.0.0.1", self.master_port),
......@@ -387,13 +379,9 @@ server: 127.0.0.1:10020
n = self.app.nm.getNodeByServer(('192.168.1.1', self.master_port))
self.assertNotEquals(n, None)
self.assertEquals(n.getUUID(), uuid)
self.checkPacket(conn, packet_type=ACCEPT_NODE_IDENTIFICATION)
# uuid
self.assertEquals(len(conn.mockGetNamedCalls("setUUID")), 1)
call = conn.mockGetNamedCalls("setUUID")[0]
self.assertEquals(call.getParam(0), uuid)
# abort
self.assertEquals(len(conn.mockGetNamedCalls('abort')), 1)
self.checkAcceptNodeIdentification(conn)
self.checkUUIDSet(conn, uuid)
self.checkAborted(conn)
def test_09_handleRequestNodeIdentification6(self):
# not new & accepted
......@@ -416,14 +404,10 @@ server: 127.0.0.1:10020
name=self.app.name,)
# no new node
self.assertEquals(len(self.app.nm.getNodeList()), count)
self.checkPacket(conn, packet_type=ACCEPT_NODE_IDENTIFICATION)
# uuid
self.assertEquals(len(conn.mockGetNamedCalls("setUUID")), 1)
call = conn.mockGetNamedCalls("setUUID")[0]
self.assertEquals(call.getParam(0), self.uuid)
self.assertEquals(mn.getUUID(), self.uuid)
# abort
self.assertEquals(len(conn.mockGetNamedCalls('abort')), 0)
self.checkAcceptNodeIdentification(conn)
self.checkUUIDSet(conn, uuid)
self.checkNotAborted(conn)
def test_10_handleAcceptNodeIdentification1(self):
# client connection not implemented
......@@ -605,7 +589,7 @@ server: 127.0.0.1:10020
conn = Mock({ })
packet = Packet(msg_type=ASK_TRANSACTION_INFORMATION)
self.operation.handleAskTransactionInformation(conn, packet, INVALID_TID)
self.checkPacket(conn, packet_type=ERROR)
self.checkErrorPacket(conn)
def test_18_handleAskTransactionInformation2(self):
# answer
......@@ -614,7 +598,7 @@ server: 127.0.0.1:10020
dm = Mock({ "getTransaction": (INVALID_TID, 'user', 'desc', '', ), })
self.app.dm = dm
self.operation.handleAskTransactionInformation(conn, packet, INVALID_TID)
self.checkPacket(conn, packet_type=ANSWER_TRANSACTION_INFORMATION)
self.checkAnswerTransactionInformation(conn)
def test_19_handleAskObjectPresent(self):
# unexpected packet
......@@ -663,12 +647,12 @@ server: 127.0.0.1:10020
self.assertEquals(self.app.load_lock_dict[0], INVALID_TID)
calls = self.app.dm.mockGetNamedCalls('storeTransaction')
self.assertEquals(len(calls), 1)
self.checkPacket(conn, packet_type=NOTIFY_INFORMATION_LOCKED)
self.checkNotifyInformationLocked(conn, answered_packet=packet)
# transaction not in transaction_dict -> KeyError
transaction = Mock({ 'getObjectList': ((0, ), ), })
conn = Mock({ 'isServerConnection': False, })
self.operation.handleLockInformation(conn, packet, '\x01' * 8)
self.checkPacket(conn, packet_type=NOTIFY_INFORMATION_LOCKED)
self.checkNotifyInformationLocked(conn, answered_packet=packet)
def test_23_handleUnlockInformation1(self):
# reject server connection
......@@ -701,7 +685,7 @@ server: 127.0.0.1:10020
transaction = Mock({ 'getObjectList': ((0, ), ), })
conn = Mock({ 'isServerConnection': False, })
self.operation.handleLockInformation(conn, packet, '\x01' * 8)
self.checkPacket(conn, packet_type=NOTIFY_INFORMATION_LOCKED)
self.checkNotifyInformationLocked(conn, answered_packet=packet)
def test_24_handleAskObject1(self):
# delayed response
......@@ -734,7 +718,7 @@ server: 127.0.0.1:10020
self.assertEquals(calls[0].getParam(0), INVALID_OID)
self.assertEquals(calls[0].getParam(1), None)
self.assertEquals(calls[0].getParam(2), None)
self.checkPacket(conn, packet_type=ERROR)
self.checkErrorPacket(conn)
def test_24_handleAskObject3(self):
# object found => answer
......@@ -747,7 +731,7 @@ server: 127.0.0.1:10020
serial=INVALID_SERIAL,
tid=INVALID_TID)
self.assertEquals(len(self.app.event_queue), 0)
self.checkPacket(conn, packet_type=ANSWER_OBJECT)
self.checkAnswerObject(conn)
def test_25_handleAskTIDs1(self):
# invalid offsets => error
......@@ -773,7 +757,7 @@ server: 127.0.0.1:10020
self.assertEquals(calls[0].getParam(1), 1)
self.assertEquals(calls[0].getParam(2), 1)
self.assertEquals(calls[0].getParam(3), [1, ])
self.checkPacket(conn, packet_type=ANSWER_TIDS)
self.checkAnswerTids(conn)
def test_25_handleAskTIDs3(self):
# invalid partition => answer usable partitions
......@@ -791,7 +775,7 @@ server: 127.0.0.1:10020
self.assertEquals(calls[0].getParam(1), 1)
self.assertEquals(calls[0].getParam(2), 1)
self.assertEquals(calls[0].getParam(3), [0, ])
self.checkPacket(conn, packet_type=ANSWER_TIDS)
self.checkAnswerTids(conn)
def test_26_handleAskObjectHistory1(self):
# invalid offsets => error
......@@ -808,12 +792,12 @@ server: 127.0.0.1:10020
conn = Mock({})
self.app.dm = Mock({'getObjectHistory': None})
self.operation.handleAskObjectHistory(conn, packet, INVALID_OID, 1, 2)
self.checkPacket(conn, packet_type=ANSWER_OBJECT_HISTORY)
self.checkAnswerObjectHistory(conn)
# second case: not empty history
conn = Mock({})
self.app.dm = Mock({'getObjectHistory': [('', 0, ), ]})
self.operation.handleAskObjectHistory(conn, packet, INVALID_OID, 1, 2)
self.checkPacket(conn, packet_type=ANSWER_OBJECT_HISTORY)
self.checkAnswerObjectHistory(conn)
def test_27_handleAskStoreTransaction1(self):
# no uuid => abort
......@@ -840,7 +824,7 @@ server: 127.0.0.1:10020
self.assertNotEquals(t, None)
self.assertTrue(isinstance(t, TransactionInformation))
self.assertEquals(t.getTransaction(), ((), '', '', ''))
self.checkPacket(conn, packet_type=ANSWER_STORE_TRANSACTION)
self.checkAnswerStoreTransaction(conn)
def test_28_handleAskStoreObject1(self):
# no uuid => abort
......@@ -892,7 +876,7 @@ server: 127.0.0.1:10020
self.app.store_lock_dict[INVALID_OID] = tid2
self.operation.handleAskStoreObject(conn, packet, INVALID_OID,
INVALID_SERIAL, 0, 0, '', tid1)
self.checkPacket(conn, packet_type=ANSWER_STORE_OBJECT)
self.checkAnswerStoreObject(conn)
self.assertEquals(self.app.store_lock_dict[INVALID_OID], tid2)
# conflicting
packet = conn.mockGetNamedCalls('answer')[0].getParam(0)
......@@ -906,7 +890,7 @@ server: 127.0.0.1:10020
self.assertEquals(self.app.store_lock_dict.get(INVALID_OID, None), None)
self.operation.handleAskStoreObject(conn, packet, INVALID_OID,
INVALID_SERIAL, 0, 0, '', INVALID_TID)
self.checkPacket(conn, packet_type=ANSWER_STORE_OBJECT)
self.checkAnswerStoreObject(conn)
self.assertEquals(self.app.store_lock_dict.get(INVALID_OID, None), None)
# conflicting
packet = conn.mockGetNamedCalls('answer')[0].getParam(0)
......@@ -923,9 +907,8 @@ server: 127.0.0.1:10020
self.assertEquals(len(t.getObjectList()), 1)
object = t.getObjectList()[0]
self.assertEquals(object, (INVALID_OID, 0, 0, ''))
self.checkPacket(conn, packet_type=ANSWER_STORE_OBJECT)
# no conflict
packet = conn.mockGetNamedCalls('answer')[0].getParam(0)
packet = self.checkAnswerStoreObject(conn)
self.assertFalse(unpack('!B8s8s', packet._body)[0])
def test_29_handleAbortTransaction(self):
......@@ -1026,7 +1009,7 @@ server: 127.0.0.1:10020
self.assertEquals(calls[0].getParam(1), 1)
self.assertEquals(calls[0].getParam(2), 1)
self.assertEquals(calls[0].getParam(3), [1, ])
self.checkPacket(conn, packet_type=ANSWER_OIDS)
self.checkAnswerOids(conn)
def test_25_handleAskOIDs3(self):
# invalid partition => answer usable partitions
......@@ -1044,7 +1027,7 @@ server: 127.0.0.1:10020
self.assertEquals(calls[0].getParam(1), 1)
self.assertEquals(calls[0].getParam(2), 1)
self.assertEquals(calls[0].getParam(3), [0, ])
self.checkPacket(conn, packet_type=ANSWER_OIDS)
self.checkAnswerOids(conn)
if __name__ == "__main__":
......
......@@ -22,7 +22,7 @@ from neo import protocol
class NeoTestBase(unittest.TestCase):
""" Base class for neo tests, implements common checks """
# XXX: according to changes with namespaced UUIDs, it whould be better to
# XXX: according to changes with namespaced UUIDs, it would be better to
# implement get<NodeType>UUID() methods
def getNewUUID(self):
""" Return a valid UUID """
......@@ -59,25 +59,65 @@ class NeoTestBase(unittest.TestCase):
""" Check if the NotReadyError exception wxas raised """
self.assertRaises(protocol.NotReadyError, method, *args, **kwargs)
def checkAborted(self, conn):
""" Ensure the connection was aborted """
self.assertEquals(len(conn.mockGetNamedCalls('abort')), 1)
def checkNotAborted(self, conn):
""" Ensure the connection was not aborted """
self.assertEquals(len(conn.mockGetNamedCalls('abort')), 0)
def checkClosed(self, conn):
""" Ensure the connection was closed """
self.assertEquals(len(conn.mockGetNamedCalls('close')), 1)
def checkNotClosed(self, conn):
""" Ensure the connection was not closed """
self.assertEquals(len(conn.mockGetNamedCalls('close')), 0)
def checkNoPacketSent(self, conn):
# no packet should be sent
""" check if no packet were sent """
self.assertEquals(len(conn.mockGetNamedCalls('notify')), 0)
self.assertEquals(len(conn.mockGetNamedCalls('answer')), 0)
self.assertEquals(len(conn.mockGetNamedCalls('ask')), 0)
def checkNoUUIDSet(self, conn):
""" ensure no UUID was set on the connection """
self.assertEquals(len(conn.mockGetNamedCalls('setUUID')), 0)
def checkUUIDSet(self, conn, uuid=None):
""" ensure no UUID was set on the connection """
calls = conn.mockGetNamedCalls('setUUID')
self.assertEquals(len(calls), 1)
if uuid is not None:
self.assertEquals(calls[0].getParam(0), uuid)
# in check(Ask|Answer|Notify)Packet we return the packet so it can be used
# in tests if more accurates checks are required
def checkAskPacket(self, conn, packet_type):
def checkErrorPacket(self, conn, decode=False):
""" Check if an error packet was answered """
calls = conn.mockGetNamedCalls("answer")
self.assertEquals(len(calls), 1)
packet = calls[0].getParam(0)
self.assertTrue(isinstance(packet, protocol.Packet))
self.assertEquals(packet.getType(), protocol.ERROR)
if decode:
return protocol.decode_table[packet.getType()](packet._body)
return packet
def checkAskPacket(self, conn, packet_type, decode=False):
""" Check if an ask-packet with the right type is sent """
calls = conn.mockGetNamedCalls('ask')
self.assertEquals(len(calls), 1)
packet = calls[0].getParam(0)
self.assertTrue(isinstance(packet, protocol.Packet))
self.assertEquals(packet.getType(), packet_type)
if decode:
return protocol.decode_table[packet.getType()](packet._body)
return packet
def checkAnswerPacket(self, conn, packet_type, answered_packet=None):
def checkAnswerPacket(self, conn, packet_type, answered_packet=None, decode=False):
""" Check if an answer-packet with the right type is sent """
calls = conn.mockGetNamedCalls('answer')
self.assertEquals(len(calls), 1)
......@@ -88,61 +128,92 @@ class NeoTestBase(unittest.TestCase):
a_packet = calls[0].getParam(1)
self.assertEquals(a_packet, answered_packet)
self.assertEquals(a_packet.getId(), answered_packet.getId())
if decode:
return protocol.decode_table[packet.getType()](packet._body)
return packet
def checkNotifyPacket(self, conn, packet_type, packet_number=0):
def checkNotifyPacket(self, conn, packet_type, packet_number=0, decode=False):
""" Check if a notify-packet with the right type is sent """
calls = conn.mockGetNamedCalls('notify')
self.assertTrue(len(calls) > packet_number)
packet = calls[packet_number].getParam(0)
self.assertTrue(isinstance(packet, protocol.Packet))
self.assertEquals(packet.getType(), packet_type)
if decode:
return protocol.decode_table[packet.getType()](packet._body)
return packet
def checkNotifyNodeInformation(self, conn, packet_number=0):
""" Check Notify Node Information message has been send"""
return self.checkNotifyPacket(conn, protocol.NOTIFY_NODE_INFORMATION,
packet_number)
def checkSendPartitionTable(self, conn, packet_number=0):
""" Check partition table has been send"""
return self.checkNotifyPacket(conn, protocol.SEND_PARTITION_TABLE,
packet_number)
def checkStartOperation(self, conn, packet_number=0):
""" Check start operation message has been send"""
return self.checkNotifyPacket(conn, protocol.START_OPERATION,
packet_number)
def checkNotifyTransactionFinished(self, conn, packet_number=0):
""" Check notifyTransactionFinished message has been send"""
return self.checkNotifyPacket(conn, protocol.NOTIFY_TRANSACTION_FINISHED,
packet_number)
def checkLockInformation(self, conn):
""" Check lockInformation message has been send"""
return self.checkAskPacket(conn, protocol.LOCK_INFORMATION)
def checkUnlockInformation(self, conn):
""" Check unlockInformation message has been send"""
return self.checkAskPacket(conn, protocol.UNLOCK_INFORMATION)
def checkAcceptNodeIdentification(self, conn, answered_packet=None):
""" Check Accept Node Identification has been answered """
return self.checkAnswerPacket(conn, protocol.ACCEPT_NODE_IDENTIFICATION,
answered_packet)
def checkAnswerPrimaryMaster(self, conn, answered_packet=None):
""" Check Answer primaty master message has been send"""
return self.checkAnswerPacket(conn, protocol.ANSWER_PRIMARY_MASTER,
answered_packet)
def checkAnswerLastIDs(self, conn, packet_number=0):
""" Check answerLastIDs message has been send"""
return self.checkAnswerPacket(conn, protocol.ANSWER_LAST_IDS)
def checkAnswerUnfinishedTransactions(self, conn, packet_number=0):
""" Check answerUnfinishedTransactions message has been send"""
return self.checkAnswerPacket(conn,
protocol.ANSWER_UNFINISHED_TRANSACTIONS)
def checkNotifyNodeInformation(self, conn, **kw):
return self.checkNotifyPacket(conn, protocol.NOTIFY_NODE_INFORMATION, **kw)
def checkSendPartitionTable(self, conn, **kw):
return self.checkNotifyPacket(conn, protocol.SEND_PARTITION_TABLE, **kw)
def checkStartOperation(self, conn, **kw):
return self.checkNotifyPacket(conn, protocol.START_OPERATION, **kw)
def checkNotifyTransactionFinished(self, conn, **kw):
return self.checkNotifyPacket(conn, protocol.NOTIFY_TRANSACTION_FINISHED, **kw)
def checkNotifyInformationLocked(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.NOTIFY_INFORMATION_LOCKED, **kw)
def checkLockInformation(self, conn, **kw):
return self.checkAskPacket(conn, protocol.LOCK_INFORMATION, **kw)
def checkUnlockInformation(self, conn, **kw):
return self.checkAskPacket(conn, protocol.UNLOCK_INFORMATION, **kw)
def checkRequestNodeIdentification(self, conn, **kw):
return self.checkAskPacket(conn, protocol.REQUEST_NODE_IDENTIFICATION, **kw)
def checkAskPrimaryMaster(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_PRIMARY_MASTER)
def checkAskUnfinishedTransactions(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_UNFINISHED_TRANSACTIONS)
def checkAskTransactionInformation(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_TRANSACTION_INFORMATION, **kw)
def checkAskObjectPresent(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_OBJECT_PRESENT, **kw)
def checkAcceptNodeIdentification(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ACCEPT_NODE_IDENTIFICATION, **kw)
def checkAnswerPrimaryMaster(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_PRIMARY_MASTER, **kw)
def checkAnswerLastIDs(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_LAST_IDS, **kw)
def checkAnswerUnfinishedTransactions(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_UNFINISHED_TRANSACTIONS, **kw)
def checkAnswerObject(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_OBJECT, **kw)
def checkAnswerTransactionInformation(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_TRANSACTION_INFORMATION, **kw)
def checkAnswerTids(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_TIDS, **kw)
def checkAnswerObjectHistory(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_OBJECT_HISTORY, **kw)
def checkAnswerStoreTransaction(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_STORE_TRANSACTION, **kw)
def checkAnswerStoreObject(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_STORE_OBJECT, **kw)
def checkAnswerOids(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_OIDS, **kw)
def checkAnswerPartitionTable(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_PARTITION_TABLE, **kw)
def checkAnswerObjectPresent(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_OBJECT_PRESENT, **kw)
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