Commit 64213d90 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Update tests according to remove of 'packet' parameter from handler methods.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1571 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 8030b635
......@@ -228,16 +228,13 @@ class NeoTestBase(unittest.TestCase):
return packet.decode()
return packet
def checkAnswerPacket(self, conn, packet_type, answered_packet=None, decode=False):
def checkAnswerPacket(self, conn, packet_type, decode=False):
""" Check if an answer-packet with the right type is sent """
calls = conn.mockGetNamedCalls('answer')
self.assertEquals(len(calls), 1)
packet = calls[0].getParam(0)
self.assertTrue(isinstance(packet, protocol.Packet))
self.assertEquals(packet.getType(), packet_type)
if answered_packet is not None:
msg_id = calls[0].getParam(1)
self.assertEqual(msg_id, answered_packet.getId())
if decode:
return packet.decode()
return packet
......
This diff is collapsed.
......@@ -69,13 +69,11 @@ class MasterClientHandlerTests(NeoTestBase):
def test_07_askBeginTransaction(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packets.AskBeginTransaction()
packet.setId(0)
ltid = self.app.tm.getLastTID()
# client call it
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address)
service.askBeginTransaction(conn, packet, None)
service.askBeginTransaction(conn, None)
self.assertTrue(ltid < self.app.tm.getLastTID())
self.assertEqual(len(self.app.tm.getPendingList()), 1)
tid = self.app.tm.getPendingList()[0]
......@@ -84,27 +82,23 @@ class MasterClientHandlerTests(NeoTestBase):
def test_08_askNewOIDs(self):
service = self.service
uuid = self.identifyToMasterNode()
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)
conn = self.getFakeConnection(client_uuid, self.client_address)
service.askNewOIDs(conn, packet, 1)
service.askNewOIDs(conn, 1)
self.assertTrue(loid < self.app.loid)
def test_09_finishTransaction(self):
service = self.service
uuid = self.identifyToMasterNode()
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)
conn = self.getFakeConnection(client_uuid, self.client_address)
oid_list = []
upper, lower = unpack('!LL', self.app.tm.getLastTID())
new_tid = pack('!LL', upper, lower + 10)
self.checkProtocolErrorRaised(service.finishTransaction, conn, packet, oid_list, new_tid)
self.checkProtocolErrorRaised(service.finishTransaction, conn, oid_list, new_tid)
old_node = self.app.nm.getByUUID(uuid)
self.app.nm.remove(old_node)
self.app.pt.dropNode(old_node)
......@@ -119,12 +113,12 @@ class MasterClientHandlerTests(NeoTestBase):
'getPartition': 0,
'getCellList': [Mock({'getUUID': storage_uuid})],
})
service.askBeginTransaction(conn, packet, None)
service.askBeginTransaction(conn, None)
oid_list = []
tid = self.app.tm.getLastTID()
conn = self.getFakeConnection(client_uuid, self.client_address)
self.app.em = Mock({"getConnectionList" : [conn, storage_conn]})
service.finishTransaction(conn, packet, oid_list, tid)
service.finishTransaction(conn, oid_list, tid)
self.checkLockInformation(storage_conn)
self.assertEquals(len(self.app.tm.getPendingList()), 1)
apptid = self.app.tm.getPendingList()[0]
......@@ -132,18 +126,16 @@ class MasterClientHandlerTests(NeoTestBase):
txn = self.app.tm[tid]
self.assertEquals(len(txn.getOIDList()), 0)
self.assertEquals(len(txn.getUUIDList()), 1)
self.assertEquals(txn.getMessageId(), 9)
def test_11_abortTransaction(self):
service = self.service
uuid = self.identifyToMasterNode()
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)
self.assertFalse(self.app.tm.hasPending())
service.abortTransaction(conn, packet, None)
service.abortTransaction(conn, None)
self.assertFalse(self.app.tm.hasPending())
# give a known tid
conn = self.getFakeConnection(client_uuid, self.client_address)
......@@ -151,7 +143,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.app.tm.remove(tid)
self.app.tm.begin(Mock({'__hash__': 1}), tid)
self.assertTrue(self.app.tm.hasPending())
service.abortTransaction(conn, packet, tid)
service.abortTransaction(conn, tid)
self.assertFalse(self.app.tm.hasPending())
def __testWithMethod(self, method, state):
......@@ -160,11 +152,9 @@ class MasterClientHandlerTests(NeoTestBase):
port = self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID()
packet = Packets.AskBeginTransaction()
packet.setId(0)
self.service.askBeginTransaction(conn, packet, None)
self.service.askBeginTransaction(conn, packet, None)
self.service.askBeginTransaction(conn, packet, None)
self.service.askBeginTransaction(conn, None)
self.service.askBeginTransaction(conn, None)
self.service.askBeginTransaction(conn, None)
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING)
self.assertEquals(len(self.app.tm.getPendingList()), 3)
......
This diff is collapsed.
......@@ -94,7 +94,6 @@ class MasterRecoveryTests(NeoTestBase):
def test_09_answerLastIDs(self):
recovery = self.recovery
uuid = self.identifyToMasterNode()
packet = Packets.AnswerLastIDs()
loid = self.app.loid = '\1' * 8
self.app.tm.setLastTID('\1' * 8)
ltid = self.app.tm.getLastTID()
......@@ -113,7 +112,7 @@ class MasterRecoveryTests(NeoTestBase):
self.assertTrue(new_oid > self.app.loid)
self.assertTrue(new_tid > self.app.tm.getLastTID())
self.assertEquals(self.app.target_uuid, None)
recovery.answerLastIDs(conn, packet, new_oid, new_tid, new_ptid)
recovery.answerLastIDs(conn, new_oid, new_tid, new_ptid)
self.assertEquals(new_oid, self.app.loid)
self.assertEquals(new_tid, self.app.tm.getLastTID())
self.assertEquals(new_ptid, self.app.pt.getID())
......@@ -123,7 +122,6 @@ class MasterRecoveryTests(NeoTestBase):
def test_10_answerPartitionTable(self):
recovery = self.recovery
uuid = self.identifyToMasterNode(NodeTypes.MASTER, port=self.master_port)
packet = Packets.AnswerPartitionTable()
# not from target node, ignore
uuid = self.identifyToMasterNode(NodeTypes.STORAGE, port=self.storage_port)
conn = self.getFakeConnection(uuid, self.storage_port)
......@@ -133,7 +131,7 @@ class MasterRecoveryTests(NeoTestBase):
cells = self.app.pt.getRow(offset)
for cell, state in cells:
self.assertEquals(state, CellStates.OUT_OF_DATE)
recovery.answerPartitionTable(conn, packet, None, cell_list)
recovery.answerPartitionTable(conn, None, cell_list)
cells = self.app.pt.getRow(offset)
for cell, state in cells:
self.assertEquals(state, CellStates.OUT_OF_DATE)
......@@ -147,7 +145,7 @@ class MasterRecoveryTests(NeoTestBase):
cells = self.app.pt.getRow(offset)
for cell, state in cells:
self.assertEquals(state, CellStates.OUT_OF_DATE)
recovery.answerPartitionTable(conn, packet, None, cell_list)
recovery.answerPartitionTable(conn, None, cell_list)
cells = self.app.pt.getRow(offset)
for cell, state in cells:
self.assertEquals(state, CellStates.UP_TO_DATE)
......@@ -158,7 +156,7 @@ class MasterRecoveryTests(NeoTestBase):
self.assertFalse(self.app.pt.hasOffset(offset))
cell_list = [(offset, ((uuid, NodeStates.DOWN,),),)]
self.checkProtocolErrorRaised(recovery.answerPartitionTable, conn,
packet, None, cell_list)
None, cell_list)
if __name__ == '__main__':
......
......@@ -83,9 +83,8 @@ class MasterStorageHandlerTests(NeoTestBase):
self.app.tm.setLastTID(tid1)
self.assertTrue(tid1 < tid2)
node, conn = self.identifyToMasterNode()
packet = Packets.NotifyInformationLocked(tid2)
self.checkProtocolErrorRaised(self.service.notifyInformationLocked,
conn, packet, tid2)
conn, tid2)
self.checkNoPacketSent(conn)
def test_notifyInformationLocked_2(self):
......@@ -112,15 +111,14 @@ class MasterStorageHandlerTests(NeoTestBase):
tid = self.app.tm.begin(client_1, None)
self.app.tm.prepare(tid, oid_list, uuid_list, msg_id)
self.assertTrue(tid in self.app.tm)
packet = Packets.NotifyInformationLocked(tid)
# the first storage acknowledge the lock
self.service.notifyInformationLocked(storage_conn_1, packet, tid)
self.service.notifyInformationLocked(storage_conn_1, tid)
self.checkNoPacketSent(client_conn_1)
self.checkNoPacketSent(client_conn_2)
self.checkNoPacketSent(storage_conn_1)
self.checkNoPacketSent(storage_conn_2)
# then the second
self.service.notifyInformationLocked(storage_conn_2, packet, tid)
self.service.notifyInformationLocked(storage_conn_2, tid)
self.checkAnswerTransactionFinished(client_conn_1)
self.checkInvalidateObjects(client_conn_2)
self.checkNotifyUnlockInformation(storage_conn_1)
......@@ -129,16 +127,14 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_12_askLastIDs(self):
service = self.service
node, conn = self.identifyToMasterNode()
packet = Packets.AskLastIDs()
packet.setId(0)
# give a uuid
conn = self.getFakeConnection(node.getUUID(), self.storage_address)
ptid = self.app.pt.getID()
oid = self.app.loid = '\1' * 8
tid = '\1' * 8
self.app.tm.setLastTID(tid)
service.askLastIDs(conn, packet)
packet = self.checkAnswerLastIDs(conn, answered_packet=packet)
service.askLastIDs(conn)
packet = self.checkAnswerLastIDs(conn)
loid, ltid, lptid = packet.decode()
self.assertEqual(loid, oid)
self.assertEqual(ltid, tid)
......@@ -148,24 +144,21 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_13_askUnfinishedTransactions(self):
service = self.service
node, conn = self.identifyToMasterNode()
packet = Packets.AskUnfinishedTransactions()
packet.setId(0)
# give a uuid
service.askUnfinishedTransactions(conn, packet)
packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet)
packet.setId(0)
service.askUnfinishedTransactions(conn)
packet = self.checkAnswerUnfinishedTransactions(conn)
tid_list, = packet.decode()
self.assertEqual(tid_list, [])
# create some transaction
node, conn = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
port=self.client_port)
client_uuid = node.getUUID()
self.client_handler.askBeginTransaction(conn, packet, None)
self.client_handler.askBeginTransaction(conn, packet, None)
self.client_handler.askBeginTransaction(conn, packet, None)
self.client_handler.askBeginTransaction(conn, None)
self.client_handler.askBeginTransaction(conn, None)
self.client_handler.askBeginTransaction(conn, None)
conn = self.getFakeConnection(node.getUUID(), self.storage_address)
service.askUnfinishedTransactions(conn, packet)
packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet)
service.askUnfinishedTransactions(conn)
packet = self.checkAnswerUnfinishedTransactions(conn)
(tid_list, ) = packet.decode()
self.assertEqual(len(tid_list), 3)
......
......@@ -104,7 +104,6 @@ class MasterVerificationTests(NeoTestBase):
def test_09_answerLastIDs(self):
verification = self.verification
uuid = self.identifyToMasterNode()
packet = Packets.AnswerLastIDs()
loid = self.app.loid
ltid = self.app.tm.getLastTID()
lptid = '\0' * 8
......@@ -120,7 +119,7 @@ class MasterVerificationTests(NeoTestBase):
self.assertTrue(new_ptid > self.app.pt.getID())
self.assertTrue(new_oid > self.app.loid)
self.assertTrue(new_tid > self.app.tm.getLastTID())
self.assertRaises(VerificationFailure, verification.answerLastIDs, conn, packet, new_oid, new_tid, new_ptid)
self.assertRaises(VerificationFailure, verification.answerLastIDs, conn, new_oid, new_tid, new_ptid)
self.assertNotEquals(new_oid, self.app.loid)
self.assertNotEquals(new_tid, self.app.tm.getLastTID())
self.assertNotEquals(new_ptid, self.app.pt.getID())
......@@ -128,7 +127,6 @@ class MasterVerificationTests(NeoTestBase):
def test_11_answerUnfinishedTransactions(self):
verification = self.verification
uuid = self.identifyToMasterNode()
packet = Packets.AnswerUnfinishedTransactions()
# do nothing
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 0)
......@@ -137,7 +135,7 @@ class MasterVerificationTests(NeoTestBase):
self.assertEquals(len(self.app.unfinished_tid_set), 0)
upper, lower = unpack('!LL', self.app.tm.getLastTID())
new_tid = pack('!LL', upper, lower + 10)
verification.answerUnfinishedTransactions(conn, packet, [new_tid])
verification.answerUnfinishedTransactions(conn, [new_tid])
self.assertEquals(len(self.app.unfinished_tid_set), 0)
# update dict
conn = self.getFakeConnection(uuid, self.storage_address)
......@@ -146,7 +144,7 @@ class MasterVerificationTests(NeoTestBase):
self.assertEquals(len(self.app.unfinished_tid_set), 0)
upper, lower = unpack('!LL', self.app.tm.getLastTID())
new_tid = pack('!LL', upper, lower + 10)
verification.answerUnfinishedTransactions(conn, packet, [new_tid,])
verification.answerUnfinishedTransactions(conn, [new_tid,])
self.assertTrue(self.app.asking_uuid_dict[uuid])
self.assertEquals(len(self.app.unfinished_tid_set), 1)
self.assertTrue(new_tid in self.app.unfinished_tid_set)
......@@ -155,7 +153,6 @@ class MasterVerificationTests(NeoTestBase):
def test_12_answerTransactionInformation(self):
verification = self.verification
uuid = self.identifyToMasterNode()
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)
......@@ -166,7 +163,7 @@ class MasterVerificationTests(NeoTestBase):
new_tid = pack('!LL', upper, lower + 10)
oid = unpack('!Q', self.app.loid)[0]
new_oid = pack('!Q', oid + 1)
verification.answerTransactionInformation(conn, packet, new_tid,
verification.answerTransactionInformation(conn, new_tid,
"user", "desc", "ext", [new_oid,])
self.assertEquals(self.app.unfinished_oid_set, None)
# do nothing as asking_uuid_dict is True
......@@ -176,7 +173,7 @@ class MasterVerificationTests(NeoTestBase):
self.app.unfinished_oid_set = set()
self.assertTrue(self.app.asking_uuid_dict.has_key(uuid))
self.assertEquals(len(self.app.unfinished_oid_set), 0)
verification.answerTransactionInformation(conn, packet, new_tid,
verification.answerTransactionInformation(conn, new_tid,
"user", "desc", "ext", [new_oid,])
self.assertEquals(len(self.app.unfinished_oid_set), 0)
# do work
......@@ -185,7 +182,7 @@ class MasterVerificationTests(NeoTestBase):
self.app.asking_uuid_dict[uuid] = False
self.assertTrue(self.app.asking_uuid_dict.has_key(uuid))
self.assertEquals(len(self.app.unfinished_oid_set), 0)
verification.answerTransactionInformation(conn, packet, new_tid,
verification.answerTransactionInformation(conn, new_tid,
"user", "desc", "ext", [new_oid,])
self.assertEquals(len(self.app.unfinished_oid_set), 1)
self.assertTrue(new_oid in self.app.unfinished_oid_set)
......@@ -199,21 +196,20 @@ class MasterVerificationTests(NeoTestBase):
oid = unpack('!Q', old_oid)[0]
new_oid = pack('!Q', oid + 1)
self.assertNotEqual(new_oid, old_oid)
verification.answerTransactionInformation(conn, packet, new_tid,
verification.answerTransactionInformation(conn, new_tid,
"user", "desc", "ext", [new_oid,])
self.assertEquals(self.app.unfinished_oid_set, None)
def test_13_tidNotFound(self):
verification = self.verification
uuid = self.identifyToMasterNode()
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)
self.app.asking_uuid_dict[uuid] = True
self.app.unfinished_oid_set = []
self.assertTrue(self.app.asking_uuid_dict.has_key(uuid))
verification.tidNotFound(conn, packet, "msg")
verification.tidNotFound(conn, "msg")
self.assertNotEqual(self.app.unfinished_oid_set, None)
# do work as asking_uuid_dict is False
conn = self.getFakeConnection(uuid, self.storage_address)
......@@ -221,13 +217,12 @@ class MasterVerificationTests(NeoTestBase):
self.app.asking_uuid_dict[uuid] = False
self.app.unfinished_oid_set = []
self.assertTrue(self.app.asking_uuid_dict.has_key(uuid))
verification.tidNotFound(conn, packet, "msg")
verification.tidNotFound(conn, "msg")
self.assertEqual(self.app.unfinished_oid_set, None)
def test_14_answerObjectPresent(self):
verification = self.verification
uuid = self.identifyToMasterNode()
packet = Packets.AnswerObjectPresent()
# do nothing as asking_uuid_dict is True
upper, lower = unpack('!LL', self.app.tm.getLastTID())
new_tid = pack('!LL', upper, lower + 10)
......@@ -237,26 +232,25 @@ class MasterVerificationTests(NeoTestBase):
self.assertEquals(len(self.app.asking_uuid_dict), 0)
self.app.asking_uuid_dict[uuid] = True
self.assertTrue(self.app.asking_uuid_dict.has_key(uuid))
verification.answerObjectPresent(conn, packet, new_oid, new_tid)
verification.answerObjectPresent(conn, new_oid, new_tid)
# do work
conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 1)
self.app.asking_uuid_dict[uuid] = False
self.assertFalse(self.app.asking_uuid_dict[uuid])
verification.answerObjectPresent(conn, packet, new_oid, new_tid)
verification.answerObjectPresent(conn, new_oid, new_tid)
self.assertTrue(self.app.asking_uuid_dict[uuid])
def test_15_oidNotFound(self):
verification = self.verification
uuid = self.identifyToMasterNode()
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
self.app.object_present = True
self.assertTrue(self.app.object_present)
verification.oidNotFound(conn, packet, "msg")
verification.oidNotFound(conn, "msg")
self.assertTrue(self.app.object_present)
# do work as asking_uuid_dict is False
conn = self.getFakeConnection(uuid, self.storage_address)
......@@ -264,7 +258,7 @@ class MasterVerificationTests(NeoTestBase):
self.app.asking_uuid_dict[uuid] = False
self.assertFalse(self.app.asking_uuid_dict[uuid ])
self.assertTrue(self.app.object_present)
verification.oidNotFound(conn, packet, "msg")
verification.oidNotFound(conn, "msg")
self.assertFalse(self.app.object_present)
self.assertTrue(self.app.asking_uuid_dict[uuid ])
......
This diff is collapsed.
......@@ -80,7 +80,6 @@ class StorageInitializationHandlerTests(NeoTestBase):
self.checkNoPacketSent(conn)
def test_09_sendPartitionTable(self):
packet = Packets.SendPartitionTable()
uuid = self.getNewUUID()
# send a table
conn = Mock({"getUUID" : uuid,
......@@ -101,19 +100,19 @@ class StorageInitializationHandlerTests(NeoTestBase):
(2, ((node_2, CellStates.UP_TO_DATE), (node_3, CellStates.UP_TO_DATE)))]
self.assertFalse(self.app.pt.filled())
# send part of the table, won't be filled
self.verification.sendPartitionTable(conn, packet, 1, row_list[:1])
self.verification.sendPartitionTable(conn, 1, row_list[:1])
self.assertFalse(self.app.pt.filled())
self.assertEqual(self.app.pt.getID(), 1)
self.assertEqual(self.app.dm.getPartitionTable(), [])
# send remaining of the table (ack with AnswerPartitionTable)
self.verification.sendPartitionTable(conn, packet, 1, row_list[1:])
self.verification.answerPartitionTable(conn, packet, 1, [])
self.verification.sendPartitionTable(conn, 1, row_list[1:])
self.verification.answerPartitionTable(conn, 1, [])
self.assertTrue(self.app.pt.filled())
self.assertEqual(self.app.pt.getID(), 1)
self.assertNotEqual(self.app.dm.getPartitionTable(), [])
# send a complete new table and ack
self.verification.sendPartitionTable(conn, packet, 2, row_list)
self.verification.answerPartitionTable(conn, packet, 2, [])
self.verification.sendPartitionTable(conn, 2, row_list)
self.verification.answerPartitionTable(conn, 2, [])
self.assertTrue(self.app.pt.filled())
self.assertEqual(self.app.pt.getID(), 2)
self.assertNotEqual(self.app.dm.getPartitionTable(), [])
......
......@@ -33,10 +33,9 @@ class StorageMasterHandlerTests(NeoTestBase):
"getAddress" : ("127.0.0.1", self.master_port),
"isServer": _listening,
})
packet = Packet(msg_type=_msg_type)
# hook
self.operation.peerBroken = lambda c: c.peerBrokendCalled()
self.checkUnexpectedPacketRaised(_call, conn=conn, packet=packet, **kwargs)
self.checkUnexpectedPacketRaised(_call, conn=conn, **kwargs)
def setUp(self):
self.prepareDatabase(number=1)
......@@ -95,10 +94,9 @@ class StorageMasterHandlerTests(NeoTestBase):
"getAddress" : ("127.0.0.1", self.master_port),
})
app.replicator = Mock({})
packet = Packets.NotifyPartitionChanges()
self.app.pt = Mock({'getID': 1})
count = len(self.app.nm.getList())
self.operation.notifyPartitionChanges(conn, packet, 0, ())
self.operation.notifyPartitionChanges(conn, 0, ())
self.assertEquals(self.app.pt.getID(), 1)
self.assertEquals(len(self.app.nm.getList()), count)
calls = self.app.replicator.mockGetNamedCalls('removePartition')
......@@ -119,7 +117,6 @@ class StorageMasterHandlerTests(NeoTestBase):
"isServer": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
packet = Packets.NotifyPartitionChanges()
app = self.app
# register nodes
app.nm.createStorage(uuid=uuid1)
......@@ -131,7 +128,7 @@ class StorageMasterHandlerTests(NeoTestBase):
app.dm = Mock({ })
app.replicator = Mock({})
count = len(app.nm.getList())
self.operation.notifyPartitionChanges(conn, packet, ptid2, cells)
self.operation.notifyPartitionChanges(conn, ptid2, cells)
# ptid set
self.assertEquals(app.pt.getID(), ptid2)
# dm call
......@@ -142,39 +139,34 @@ class StorageMasterHandlerTests(NeoTestBase):
def test_16_stopOperation1(self):
# OperationFailure
conn = Mock({ 'isServer': False })
packet = Packets.StopOperation()
self.assertRaises(OperationFailure, self.operation.stopOperation, conn, packet)
self.assertRaises(OperationFailure, self.operation.stopOperation, conn)
def test_22_lockInformation2(self):
# load transaction informations
conn = Mock({ 'isServer': False, })
self.app.dm = Mock({ })
packet = Packets.LockInformation()
packet.setId(1)
transaction = Mock({ 'getObjectList': ((0, ), ), })
self.app.transaction_dict[INVALID_TID] = transaction
self.operation.lockInformation(conn, packet, INVALID_TID)
self.operation.lockInformation(conn, INVALID_TID)
self.assertEquals(self.app.load_lock_dict[0], INVALID_TID)
calls = self.app.dm.mockGetNamedCalls('storeTransaction')
self.assertEquals(len(calls), 1)
self.checkNotifyInformationLocked(conn, answered_packet=packet)
self.checkNotifyInformationLocked(conn)
# transaction not in transaction_dict -> KeyError
transaction = Mock({ 'getObjectList': ((0, ), ), })
conn = Mock({ 'isServer': False, })
self.operation.lockInformation(conn, packet, '\x01' * 8)
self.checkNotifyInformationLocked(conn, answered_packet=packet)
self.operation.lockInformation(conn, '\x01' * 8)
self.checkNotifyInformationLocked(conn)
def test_23_notifyUnlockInformation2(self):
# delete transaction informations
conn = Mock({ 'isServer': False, })
self.app.dm = Mock({ })
packet = Packets.LockInformation()
packet.setId(1)
transaction = Mock({ 'getObjectList': ((0, ), ), })
self.app.transaction_dict[INVALID_TID] = transaction
self.app.load_lock_dict[0] = transaction
self.app.store_lock_dict[0] = transaction
self.operation.notifyUnlockInformation(conn, packet, INVALID_TID)
self.operation.notifyUnlockInformation(conn, INVALID_TID)
self.assertEquals(len(self.app.load_lock_dict), 0)
self.assertEquals(len(self.app.store_lock_dict), 0)
self.assertEquals(len(self.app.store_lock_dict), 0)
......@@ -184,33 +176,29 @@ class StorageMasterHandlerTests(NeoTestBase):
# transaction not in transaction_dict -> KeyError
transaction = Mock({ 'getObjectList': ((0, ), ), })
conn = Mock({ 'isServer': False, })
self.operation.lockInformation(conn, packet, '\x01' * 8)
self.checkNotifyInformationLocked(conn, answered_packet=packet)
self.operation.lockInformation(conn, '\x01' * 8)
self.checkNotifyInformationLocked(conn)
def test_30_answerLastIDs(self):
# set critical TID on replicator
conn = Mock()
packet = Packets.AnswerLastIDs()
self.app.replicator = Mock()
self.operation.answerLastIDs(
conn=conn,
packet=packet,
loid=INVALID_OID,
ltid=INVALID_TID,
lptid=INVALID_TID,
)
calls = self.app.replicator.mockGetNamedCalls('setCriticalTID')
self.assertEquals(len(calls), 1)
calls[0].checkArgs(packet, INVALID_TID)
calls[0].checkArgs(conn.getUUID(), INVALID_TID)
def test_31_answerUnfinishedTransactions(self):
# set unfinished TID on replicator
conn = Mock()
packet = Packets.AnswerUnfinishedTransactions()
self.app.replicator = Mock()
self.operation.answerUnfinishedTransactions(
conn=conn,
packet=packet,
tid_list=(INVALID_TID, ),
)
calls = self.app.replicator.mockGetNamedCalls('setUnfinishedTIDList')
......
......@@ -31,10 +31,9 @@ class StorageStorageHandlerTests(NeoTestBase):
"getAddress" : ("127.0.0.1", self.master_port),
"isServer": _listening,
})
packet = Packet(msg_type=_msg_type)
# hook
self.operation.peerBroken = lambda c: c.peerBrokendCalled()
self.checkUnexpectedPacketRaised(_call, conn=conn, packet=packet, **kwargs)
self.checkUnexpectedPacketRaised(_call, conn=conn, **kwargs)
def setUp(self):
self.prepareDatabase(number=1)
......@@ -60,19 +59,15 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_18_askTransactionInformation1(self):
# transaction does not exists
conn = Mock({ })
packet = Packets.AskTransactionInformation()
packet.setId(0)
self.operation.askTransactionInformation(conn, packet, INVALID_TID)
self.operation.askTransactionInformation(conn, INVALID_TID)
self.checkErrorPacket(conn)
def test_18_askTransactionInformation2(self):
# answer
conn = Mock({ })
packet = Packets.AskTransactionInformation()
packet.setId(0)
dm = Mock({ "getTransaction": (INVALID_TID, 'user', 'desc', '', ), })
self.app.dm = dm
self.operation.askTransactionInformation(conn, packet, INVALID_TID)
self.operation.askTransactionInformation(conn, INVALID_TID)
self.checkAnswerTransactionInformation(conn)
def test_24_askObject1(self):
......@@ -82,10 +77,8 @@ class StorageStorageHandlerTests(NeoTestBase):
packet = Packets.AskObject()
self.app.load_lock_dict[INVALID_OID] = object()
self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet,
oid=INVALID_OID,
serial=INVALID_SERIAL,
tid=INVALID_TID)
self.operation.askObject(conn, oid=INVALID_OID,
serial=INVALID_SERIAL, tid=INVALID_TID)
self.assertEquals(len(self.app.event_queue), 1)
self.checkNoPacketSent(conn)
self.assertEquals(len(self.app.dm.mockGetNamedCalls('getObject')), 0)
......@@ -94,13 +87,9 @@ class StorageStorageHandlerTests(NeoTestBase):
# invalid serial / tid / packet not found
self.app.dm = Mock({'getObject': None})
conn = Mock({})
packet = Packets.AskObject()
packet.setId(0)
self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet,
oid=INVALID_OID,
serial=INVALID_SERIAL,
tid=INVALID_TID)
self.operation.askObject(conn, oid=INVALID_OID,
serial=INVALID_SERIAL, tid=INVALID_TID)
calls = self.app.dm.mockGetNamedCalls('getObject')
self.assertEquals(len(self.app.event_queue), 0)
self.assertEquals(len(calls), 1)
......@@ -111,13 +100,9 @@ class StorageStorageHandlerTests(NeoTestBase):
# object found => answer
self.app.dm = Mock({'getObject': ('', '', 0, 0, '', )})
conn = Mock({})
packet = Packets.AskObject()
packet.setId(0)
self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet,
oid=INVALID_OID,
serial=INVALID_SERIAL,
tid=INVALID_TID)
self.operation.askObject(conn, oid=INVALID_OID,
serial=INVALID_SERIAL, tid=INVALID_TID)
self.assertEquals(len(self.app.event_queue), 0)
self.checkAnswerObject(conn)
......@@ -127,19 +112,16 @@ class StorageStorageHandlerTests(NeoTestBase):
app.pt = Mock()
app.dm = Mock()
conn = Mock({})
packet = Packets.AskTIDs()
self.checkProtocolErrorRaised(self.operation.askTIDs, conn, packet, 1, 1, None)
self.checkProtocolErrorRaised(self.operation.askTIDs, conn, 1, 1, None)
self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0)
self.assertEquals(len(app.dm.mockGetNamedCalls('getTIDList')), 0)
def test_25_askTIDs2(self):
# well case => answer
conn = Mock({})
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)
self.operation.askTIDs(conn, 1, 2, 1)
calls = self.app.dm.mockGetNamedCalls('getTIDList')
self.assertEquals(len(calls), 1)
calls[0].checkArgs(1, 1, 1, [1, ])
......@@ -148,8 +130,6 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_25_askTIDs3(self):
# invalid partition => answer usable partitions
conn = Mock({})
packet = Packets.AskTIDs()
packet.setId(0)
cell = Mock({'getUUID':self.app.uuid})
self.app.dm = Mock({'getTIDList': (INVALID_TID, )})
self.app.pt = Mock({
......@@ -157,7 +137,7 @@ class StorageStorageHandlerTests(NeoTestBase):
'getPartitions': 1,
'getAssignedPartitionList': [0],
})
self.operation.askTIDs(conn, packet, 1, 2, INVALID_PARTITION)
self.operation.askTIDs(conn, 1, 2, INVALID_PARTITION)
self.assertEquals(len(self.app.pt.mockGetNamedCalls('getAssignedPartitionList')), 1)
calls = self.app.dm.mockGetNamedCalls('getTIDList')
self.assertEquals(len(calls), 1)
......@@ -169,23 +149,20 @@ class StorageStorageHandlerTests(NeoTestBase):
app = self.app
app.dm = Mock()
conn = Mock({})
packet = Packets.AskObjectHistory()
packet.setId(0)
self.checkProtocolErrorRaised(self.operation.askObjectHistory, conn, packet, 1, 1, None)
self.checkProtocolErrorRaised(self.operation.askObjectHistory, conn,
1, 1, None)
self.assertEquals(len(app.dm.mockGetNamedCalls('getObjectHistory')), 0)
def test_26_askObjectHistory2(self):
# first case: empty history
packet = Packets.AskObjectHistory()
packet.setId(0)
conn = Mock({})
self.app.dm = Mock({'getObjectHistory': None})
self.operation.askObjectHistory(conn, packet, INVALID_OID, 1, 2)
self.operation.askObjectHistory(conn, INVALID_OID, 1, 2)
self.checkAnswerObjectHistory(conn)
# second case: not empty history
conn = Mock({})
self.app.dm = Mock({'getObjectHistory': [('', 0, ), ]})
self.operation.askObjectHistory(conn, packet, INVALID_OID, 1, 2)
self.operation.askObjectHistory(conn, INVALID_OID, 1, 2)
self.checkAnswerObjectHistory(conn)
def test_25_askOIDs1(self):
......@@ -194,20 +171,16 @@ class StorageStorageHandlerTests(NeoTestBase):
app.pt = Mock()
app.dm = Mock()
conn = Mock({})
packet = Packets.AskOIDs()
packet.setId(0)
self.checkProtocolErrorRaised(self.operation.askOIDs, conn, packet, 1, 1, None)
self.checkProtocolErrorRaised(self.operation.askOIDs, conn, 1, 1, None)
self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0)
self.assertEquals(len(app.dm.mockGetNamedCalls('getOIDList')), 0)
def test_25_askOIDs2(self):
# well case > answer OIDs
conn = Mock({})
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)
self.operation.askOIDs(conn, 1, 2, 1)
calls = self.app.dm.mockGetNamedCalls('getOIDList')
self.assertEquals(len(calls), 1)
calls[0].checkArgs(1, 1, 1, [1, ])
......@@ -216,8 +189,6 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_25_askOIDs3(self):
# invalid partition => answer usable partitions
conn = Mock({})
packet = Packets.AskOIDs()
packet.setId(0)
cell = Mock({'getUUID':self.app.uuid})
self.app.dm = Mock({'getOIDList': (INVALID_OID, )})
self.app.pt = Mock({
......@@ -225,7 +196,7 @@ class StorageStorageHandlerTests(NeoTestBase):
'getPartitions': 1,
'getAssignedPartitionList': [0],
})
self.operation.askOIDs(conn, packet, 1, 2, INVALID_PARTITION)
self.operation.askOIDs(conn, 1, 2, INVALID_PARTITION)
self.assertEquals(len(self.app.pt.mockGetNamedCalls('getAssignedPartitionList')), 1)
calls = self.app.dm.mockGetNamedCalls('getOIDList')
self.assertEquals(len(calls), 1)
......
......@@ -54,8 +54,7 @@ class BootstrapManagerTests(NeoTestBase):
def testHandleNotReady(self):
# the primary is not ready
conn = Mock({})
packet = Mock({})
self.bootstrap.notReady(conn, packet, '')
self.bootstrap.notReady(conn, '')
self.checkClosed(conn)
self.checkNoPacketSent(conn)
......
......@@ -44,39 +44,39 @@ class HandlerTests(NeoTestBase):
conn = Mock({'getAddress': ('127.0.0.1', 10000)})
packet = self.getFakePacket()
# all is ok
self.setFakeMethod(lambda c, p: None)
self.setFakeMethod(lambda c: None)
self.handler.dispatch(conn, packet)
# raise UnexpectedPacketError
conn.mockCalledMethods = {}
def fake(c, p): raise UnexpectedPacketError('fake packet')
def fake(c): raise UnexpectedPacketError('fake packet')
self.setFakeMethod(fake)
self.handler.dispatch(conn, packet)
self.checkErrorPacket(conn)
self.checkAborted(conn)
# raise PacketMalformedError
conn.mockCalledMethods = {}
def fake(c, p): raise PacketMalformedError('message')
def fake(c): raise PacketMalformedError('message')
self.setFakeMethod(fake)
self.handler.dispatch(conn, packet)
self.checkErrorPacket(conn)
self.checkAborted(conn)
# raise BrokenNodeDisallowedError
conn.mockCalledMethods = {}
def fake(c, p): raise BrokenNodeDisallowedError
def fake(c): raise BrokenNodeDisallowedError
self.setFakeMethod(fake)
self.handler.dispatch(conn, packet)
self.checkErrorPacket(conn)
self.checkAborted(conn)
# raise NotReadyError
conn.mockCalledMethods = {}
def fake(c, p): raise NotReadyError
def fake(c): raise NotReadyError
self.setFakeMethod(fake)
self.handler.dispatch(conn, packet)
self.checkErrorPacket(conn)
self.checkAborted(conn)
# raise ProtocolError
conn.mockCalledMethods = {}
def fake(c, p): raise ProtocolError
def fake(c): raise ProtocolError
self.setFakeMethod(fake)
self.handler.dispatch(conn, packet)
self.checkErrorPacket(conn)
......
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