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