Commit 6fe1e76b authored by Grégory Wisniewski's avatar Grégory Wisniewski

Update all tests according to previous commit.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@484 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 0d82139d
......@@ -122,7 +122,7 @@ class ClientApplicationTest(unittest.TestCase):
if oid is None:
oid = self.makeOID()
obj = (oid, tid, 'DATA', '', app.local_var.txn)
packet = protocol.answerStoreObject(msg_id=1, conflicting=0, oid=oid, serial=tid)
packet = protocol.answerStoreObject(conflicting=0, oid=oid, serial=tid)
conn = Mock({ 'getNextId': 1, 'fakeReceived': packet, })
cell = Mock({ 'getServer': 'FakeServer', 'getState': 'FakeState', })
app.cp = Mock({ 'getConnForNode': conn})
......@@ -132,7 +132,7 @@ class ClientApplicationTest(unittest.TestCase):
def voteTransaction(self, app):
tid = app.local_var.tid
txn = app.local_var.txn
packet = protocol.answerStoreTransaction(msg_id=1, tid=tid)
packet = protocol.answerStoreTransaction(tid=tid)
conn = Mock({ 'getNextId': 1, 'fakeReceived': packet, })
cell = Mock({ 'getServer': 'FakeServer', 'getState': 'FakeState', })
app.pt = Mock({ 'getCellList': (cell, cell, ) })
......@@ -142,7 +142,7 @@ class ClientApplicationTest(unittest.TestCase):
def finishTransaction(self, app):
txn = app.local_var.txn
tid = app.local_var.tid
packet = protocol.notifyTransactionFinished(1, tid)
packet = protocol.notifyTransactionFinished(tid)
app.master_conn = Mock({
'getNextId': 1,
'getAddress': ('127.0.0.1', 10010),
......@@ -152,24 +152,27 @@ class ClientApplicationTest(unittest.TestCase):
# common checks
def checkDispatcherRegisterCalled(self, app, conn, msg_id):
def checkDispatcherRegisterCalled(self, app, conn):
calls = app.dispatcher.mockGetNamedCalls('register')
self.assertEquals(len(calls), 1)
self.assertTrue(calls[0].getParam(0) is conn)
self.assertEquals(calls[0].getParam(1), msg_id)
self.assertEquals(calls[0].getParam(2), app.local_var.queue)
def checkPacketSent(self, conn, msg_id, packet_type):
calls = conn.mockGetNamedCalls('addPacket')
def checkPacketSent(self, conn, packet_type, method='addPacket'):
calls = conn.mockGetNamedCalls(method)
self.assertEquals(len(calls), 1)
packet = calls[0].getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet._type, packet_type)
def checkMessageExpected(self, conn, msg_id):
calls = conn.mockGetNamedCalls('expectMessage')
self.assertEquals(len(calls), 1)
self.assertEquals(calls[0].getParam(0), msg_id)
def checkAnswer(self, conn, packet_type):
self.checkPacketSent(conn, packet_type, 'answer')
def checkAsk(self, conn, packet_type):
self.checkPacketSent(conn, packet_type, 'ask')
def checkNotify(self, conn, packet_type):
self.checkPacketSent(conn, packet_type, 'notify')
def checkNoPacketSent(self, conn):
self.assertEquals(len(conn.mockGetNamedCalls('addPacket')), 0)
......@@ -197,7 +200,7 @@ class ClientApplicationTest(unittest.TestCase):
app = self.getApp()
test_msg_id = 50
test_oid_list = ['\x00\x00\x00\x00\x00\x00\x00\x01', '\x00\x00\x00\x00\x00\x00\x00\x02']
response_packet = protocol.answerNewOIDs(test_msg_id, test_oid_list[:])
response_packet = protocol.answerNewOIDs(test_oid_list[:])
app.master_conn = Mock({'getNextId': test_msg_id, 'addPacket': None,
'expectMessage': None, 'lock': None,
'unlock': None,
......@@ -237,7 +240,7 @@ class ClientApplicationTest(unittest.TestCase):
an_object = (1, oid, tid1, tid2, 0, 0, '')
# object not found in NEO -> NEOStorageNotFoundError
self.assertTrue(oid not in mq)
packet = protocol.oidNotFound(oid, '')
packet = protocol.oidNotFound('')
cell = Mock({ 'getUUID': '\x00' * 16})
conn = Mock({
'getServer': ('127.0.0.1', 0),
......@@ -247,9 +250,9 @@ class ClientApplicationTest(unittest.TestCase):
app.cp = Mock({ 'getConnForNode' : conn})
app.local_var.asked_object = -1
self.assertRaises(NEOStorageNotFoundError, app.load, oid)
self.checkPacketSent(conn, 1, ASK_OBJECT)
self.checkAsk(conn, ASK_OBJECT)
# object found on storage nodes and put in cache
packet = protocol.answerObject(*an_object)
packet = protocol.answerObject(*an_object[1:])
conn = Mock({
'getServer': ('127.0.0.1', 0),
'fakeReceived': packet,
......@@ -258,7 +261,7 @@ class ClientApplicationTest(unittest.TestCase):
app.local_var.asked_object = an_object
result = app.load(oid)
self.assertEquals(result, ('', tid1))
self.checkPacketSent(conn, 1, ASK_OBJECT)
self.checkAsk(conn, ASK_OBJECT)
self.assertTrue(oid in mq)
# object is now cached, try to reload it
conn = Mock({
......@@ -277,7 +280,7 @@ class ClientApplicationTest(unittest.TestCase):
tid2 = self.makeTID(2)
# object not found in NEO -> NEOStorageNotFoundError
self.assertTrue(oid not in mq)
packet = protocol.oidNotFound(oid, '')
packet = protocol.oidNotFound('')
cell = Mock({ 'getUUID': '\x00' * 16})
conn = Mock({
'getServer': ('127.0.0.1', 0),
......@@ -287,14 +290,14 @@ class ClientApplicationTest(unittest.TestCase):
app.cp = Mock({ 'getConnForNode' : conn})
app.local_var.asked_object = -1
self.assertRaises(NEOStorageNotFoundError, app.loadSerial, oid, tid2)
self.checkPacketSent(conn, 1, ASK_OBJECT)
self.checkAsk(conn, ASK_OBJECT)
# object should not have been cached
self.assertFalse(oid in mq)
# now a cached version ewxists but should not be hit
mq.store(oid, (tid1, 'WRONG'))
self.assertTrue(oid in mq)
another_object = (1, oid, tid2, INVALID_SERIAL, 0, 0, 'RIGHT')
packet = protocol.answerObject(*another_object)
packet = protocol.answerObject(*another_object[1:])
conn = Mock({
'getServer': ('127.0.0.1', 0),
'fakeReceived': packet,
......@@ -303,7 +306,7 @@ class ClientApplicationTest(unittest.TestCase):
app.local_var.asked_object = another_object
result = app.loadSerial(oid, tid1)
self.assertEquals(result, 'RIGHT')
self.checkPacketSent(conn, 1, ASK_OBJECT)
self.checkAsk(conn, ASK_OBJECT)
self.assertTrue(oid in mq)
def test_loadBefore(self):
......@@ -314,7 +317,7 @@ class ClientApplicationTest(unittest.TestCase):
tid2 = self.makeTID(2)
# object not found in NEO -> NEOStorageNotFoundError
self.assertTrue(oid not in mq)
packet = protocol.oidNotFound(oid, '')
packet = protocol.oidNotFound('')
cell = Mock({ 'getUUID': '\x00' * 16})
conn = Mock({
'getServer': ('127.0.0.1', 0),
......@@ -324,10 +327,10 @@ class ClientApplicationTest(unittest.TestCase):
app.cp = Mock({ 'getConnForNode' : conn})
app.local_var.asked_object = -1
self.assertRaises(NEOStorageNotFoundError, app.loadBefore, oid, tid2)
self.checkPacketSent(conn, 1, ASK_OBJECT)
self.checkAsk(conn, ASK_OBJECT)
# no previous versions -> return None
an_object = (1, oid, tid2, INVALID_SERIAL, 0, 0, '')
packet = protocol.answerObject(*an_object)
packet = protocol.answerObject(*an_object[1:])
conn = Mock({
'getServer': ('127.0.0.1', 0),
'fakeReceived': packet,
......@@ -342,7 +345,7 @@ class ClientApplicationTest(unittest.TestCase):
mq.store(oid, (tid1, 'WRONG'))
self.assertTrue(oid in mq)
another_object = (1, oid, tid1, tid2, 0, 0, 'RIGHT')
packet = protocol.answerObject(*another_object)
packet = protocol.answerObject(*another_object[1:])
conn = Mock({
'getServer': ('127.0.0.1', 0),
'fakeReceived': packet,
......@@ -351,7 +354,7 @@ class ClientApplicationTest(unittest.TestCase):
app.local_var.asked_object = another_object
result = app.loadBefore(oid, tid1)
self.assertEquals(result, ('RIGHT', tid1, tid2))
self.checkPacketSent(conn, 1, ASK_OBJECT)
self.checkAsk(conn, ASK_OBJECT)
self.assertTrue(oid in mq)
def test_tpc_begin(self):
......@@ -374,7 +377,7 @@ class ClientApplicationTest(unittest.TestCase):
# no connection -> NEOStorageError
self.assertRaises(NEOStorageError, app.tpc_begin, transaction=txn, tid=None)
# ask a tid to pmn
packet = protocol.answerNewTID(msg_id=1, tid=tid)
packet = protocol.answerNewTID(tid=tid)
app.master_conn = Mock({
'getNextId': 1,
'expectMessage': None,
......@@ -385,9 +388,8 @@ class ClientApplicationTest(unittest.TestCase):
app.dispatcher = Mock({
})
app.tpc_begin(transaction=txn, tid=None)
self.checkPacketSent(app.master_conn, 1, ASK_NEW_TID)
self.checkMessageExpected(app.master_conn, 1)
self.checkDispatcherRegisterCalled(app, app.master_conn, 1)
self.checkAsk(app.master_conn, ASK_NEW_TID)
self.checkDispatcherRegisterCalled(app, app.master_conn)
# check attributes
self.assertTrue(app.local_var.txn is txn)
self.assertEquals(app.local_var.tid, tid)
......@@ -420,7 +422,7 @@ class ClientApplicationTest(unittest.TestCase):
# build conflicting state
app.local_var.txn = txn
app.local_var.tid = tid
packet = protocol.answerStoreObject(msg_id=1, conflicting=1, oid=oid, serial=tid)
packet = protocol.answerStoreObject(conflicting=1, oid=oid, serial=tid)
conn = Mock({
'getNextId': 1,
'fakeReceived': packet,
......@@ -438,9 +440,8 @@ class ClientApplicationTest(unittest.TestCase):
self.assertTrue(oid not in app.local_var.data_dict)
self.assertEquals(app.conflict_serial, tid)
self.assertEquals(app.local_var.object_stored, (-1, tid))
self.checkPacketSent(conn, 1, ASK_STORE_OBJECT)
self.checkMessageExpected(conn, 1)
self.checkDispatcherRegisterCalled(app, conn, 1)
self.checkAsk(conn, ASK_STORE_OBJECT)
self.checkDispatcherRegisterCalled(app, conn)
def test_store3(self):
app = self.getApp()
......@@ -450,7 +451,7 @@ class ClientApplicationTest(unittest.TestCase):
# case with no conflict
app.local_var.txn = txn
app.local_var.tid = tid
packet = protocol.answerStoreObject(msg_id=1, conflicting=0, oid=oid, serial=tid)
packet = protocol.answerStoreObject(conflicting=0, oid=oid, serial=tid)
conn = Mock({
'getNextId': 1,
'fakeReceived': packet,
......@@ -468,9 +469,8 @@ class ClientApplicationTest(unittest.TestCase):
self.assertEquals(app.local_var.object_stored, (oid, tid))
self.assertEquals(app.local_var.data_dict.get(oid, None), 'DATA')
self.assertNotEquals(app.conflict_serial, tid)
self.checkPacketSent(conn, 1, ASK_STORE_OBJECT)
self.checkMessageExpected(conn, 1)
self.checkDispatcherRegisterCalled(app, conn, 1)
self.checkAsk(conn, ASK_STORE_OBJECT)
self.checkDispatcherRegisterCalled(app, conn)
def test_tpc_vote1(self):
app = self.getApp()
......@@ -490,7 +490,7 @@ class ClientApplicationTest(unittest.TestCase):
app.local_var.txn = txn
app.local_var.tid = tid
# wrong answer -> failure
packet = protocol.answerNewOIDs(1, ())
packet = protocol.answerNewOIDs(())
conn = Mock({
'getNextId': 1,
'fakeReceived': packet,
......@@ -506,14 +506,11 @@ class ClientApplicationTest(unittest.TestCase):
app.tpc_begin(txn, tid)
self.assertRaises(NEOStorageError, app.tpc_vote, txn)
self.assertEquals(len(conn.mockGetNamedCalls('abort')), 1)
calls = conn.mockGetNamedCalls('addPacket')
self.assertEquals(len(calls), 2)
calls = conn.mockGetNamedCalls('ask')
self.assertEquals(len(calls), 1)
packet = calls[0].getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet._type, ASK_STORE_TRANSACTION)
packet = calls[1].getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet._type, ERROR)
def test_tpc_vote3(self):
app = self.getApp()
......@@ -522,7 +519,7 @@ class ClientApplicationTest(unittest.TestCase):
app.local_var.txn = txn
app.local_var.tid = tid
# response -> OK
packet = protocol.answerStoreTransaction(msg_id=1, tid=tid)
packet = protocol.answerStoreTransaction(tid=tid)
conn = Mock({
'getNextId': 1,
'fakeReceived': packet,
......@@ -536,9 +533,8 @@ class ClientApplicationTest(unittest.TestCase):
app.dispatcher = Mock()
app.tpc_begin(txn, tid)
app.tpc_vote(txn)
self.checkPacketSent(conn, 1, ASK_STORE_TRANSACTION)
self.checkMessageExpected(conn, 1)
self.checkDispatcherRegisterCalled(app, conn, 1)
self.checkAsk(conn, ASK_STORE_TRANSACTION)
self.checkDispatcherRegisterCalled(app, conn)
def test_tpc_abort1(self):
# ignore mismatch transaction
......@@ -580,9 +576,9 @@ class ClientApplicationTest(unittest.TestCase):
app.local_var.data_dict = {oid1: '', oid2: ''}
app.tpc_abort(txn)
# will check if there was just one call/packet :
self.checkPacketSent(conn1, 1, ABORT_TRANSACTION)
self.checkPacketSent(conn2, 2, ABORT_TRANSACTION)
self.checkPacketSent(app.master_conn, app.master_conn.getNextId(), ABORT_TRANSACTION)
self.checkNotify(conn1, ABORT_TRANSACTION)
self.checkNotify(conn2, ABORT_TRANSACTION)
self.checkNotify(app.master_conn, ABORT_TRANSACTION)
self.assertEquals(app.local_var.tid, None)
self.assertEquals(app.local_var.txn, None)
self.assertEquals(app.local_var.data_dict, {})
......@@ -619,7 +615,7 @@ class ClientApplicationTest(unittest.TestCase):
def hook(tid):
self.f_called = True
self.f_called_with_tid = tid
packet = protocol.answerNewTID(1, INVALID_TID)
packet = protocol.answerNewTID(INVALID_TID)
app.master_conn = Mock({
'getNextId': 1,
'getAddress': ('127.0.0.1', 10000),
......@@ -630,8 +626,8 @@ class ClientApplicationTest(unittest.TestCase):
self.assertRaises(NEOStorageError, app.tpc_finish, txn, hook)
self.assertTrue(self.f_called)
self.assertEquals(self.f_called_with_tid, tid)
self.checkPacketSent(app.master_conn, 1, FINISH_TRANSACTION)
self.checkDispatcherRegisterCalled(app, app.master_conn, 1)
self.checkAsk(app.master_conn, FINISH_TRANSACTION)
self.checkDispatcherRegisterCalled(app, app.master_conn)
def test_tpc_finish3(self):
# transaction is finished
......@@ -644,7 +640,7 @@ class ClientApplicationTest(unittest.TestCase):
def hook(tid):
self.f_called = True
self.f_called_with_tid = tid
packet = protocol.notifyTransactionFinished(1, tid)
packet = protocol.notifyTransactionFinished(tid)
app.master_conn = Mock({
'getNextId': 1,
'getAddress': ('127.0.0.1', 10010),
......@@ -655,8 +651,8 @@ class ClientApplicationTest(unittest.TestCase):
app.tpc_finish(txn, hook)
self.assertTrue(self.f_called)
self.assertEquals(self.f_called_with_tid, tid)
self.checkPacketSent(app.master_conn, 1, FINISH_TRANSACTION)
self.checkDispatcherRegisterCalled(app, app.master_conn, 1)
self.checkAsk(app.master_conn, FINISH_TRANSACTION)
self.checkDispatcherRegisterCalled(app, app.master_conn)
self.assertEquals(app.local_var.tid, None)
self.assertEquals(app.local_var.txn, None)
self.assertEquals(app.local_var.data_dict, {})
......@@ -710,19 +706,19 @@ class ClientApplicationTest(unittest.TestCase):
self.voteTransaction(app)
self.finishTransaction(app)
# undo 1 -> no previous revision
u1p1 = protocol.answerTransactionInformation(1, tid1, '', '', '', (oid1, ))
u1p2 = protocol.oidNotFound(1, 'oid not found')
u1p1 = protocol.answerTransactionInformation(tid1, '', '', '', (oid1, ))
u1p2 = protocol.oidNotFound('oid not found')
# undo 2 -> not end tid
u2p1 = protocol.answerTransactionInformation(1, tid2, '', '', '', (oid2, ))
u2p2 = protocol.answerObject(1, oid2, tid2, tid3, 0, 0, 'O2V1')
u2p1 = protocol.answerTransactionInformation(tid2, '', '', '', (oid2, ))
u2p2 = protocol.answerObject(oid2, tid2, tid3, 0, 0, 'O2V1')
# undo 3 -> conflict
u3p1 = protocol.answerTransactionInformation(1, tid3, '', '', '', (oid2, ))
u3p2 = protocol.answerObject(1, oid2, tid3, tid3, 0, 0, 'O2V2')
u3p3 = protocol.answerStoreObject(msg_id=1, conflicting=1, oid=oid2, serial=tid2)
u3p1 = protocol.answerTransactionInformation(tid3, '', '', '', (oid2, ))
u3p2 = protocol.answerObject(oid2, tid3, tid3, 0, 0, 'O2V2')
u3p3 = protocol.answerStoreObject(conflicting=1, oid=oid2, serial=tid2)
# undo 4 -> ok
u4p1 = protocol.answerTransactionInformation(1, tid3, '', '', '', (oid2, ))
u4p2 = protocol.answerObject(1, oid2, tid3, tid3, 0, 0, 'O2V2')
u4p3 = protocol.answerStoreObject(msg_id=1, conflicting=0, oid=oid2, serial=tid2)
u4p1 = protocol.answerTransactionInformation(tid3, '', '', '', (oid2, ))
u4p2 = protocol.answerObject(oid2, tid3, tid3, 0, 0, 'O2V2')
u4p3 = protocol.answerStoreObject(conflicting=0, oid=oid2, serial=tid2)
# test logic
packets = (u1p1, u1p2, u2p1, u2p2, u3p1, u3p2, u3p3, u3p1, u4p2, u4p3)
conn = Mock({
......@@ -754,8 +750,8 @@ class ClientApplicationTest(unittest.TestCase):
oid1, oid2 = self.makeOID(1), self.makeOID(2)
# TIDs packets supplied by _waitMessage hook
# TXN info packets
p3 = protocol.answerTransactionInformation(1, tid1, '', '', '', (oid1, ))
p4 = protocol.answerTransactionInformation(1, tid2, '', '', '', (oid2, ))
p3 = protocol.answerTransactionInformation(tid1, '', '', '', (oid1, ))
p4 = protocol.answerTransactionInformation(tid2, '', '', '', (oid2, ))
conn = Mock({
'getNextId': 1,
'getUUID': ReturnValues(uuid1, uuid2),
......@@ -785,11 +781,11 @@ class ClientApplicationTest(unittest.TestCase):
tid1, tid2 = self.makeTID(1), self.makeTID(2)
object_history = ( (tid1, 42), (tid2, 42),)
# object history, first is a wrong oid, second is valid
p1 = protocol.answerObjectHistory(1, self.makeOID(2), ())
p2 = protocol.answerObjectHistory(1, oid, object_history)
p1 = protocol.answerObjectHistory(self.makeOID(2), ())
p2 = protocol.answerObjectHistory(oid, object_history)
# transaction history
p3 = protocol.answerTransactionInformation(1, tid1, 'u', 'd', 'e', (oid, ))
p4 = protocol.answerTransactionInformation(1, tid2, 'u', 'd', 'e', (oid, ))
p3 = protocol.answerTransactionInformation(tid1, 'u', 'd', 'e', (oid, ))
p4 = protocol.answerTransactionInformation(tid2, 'u', 'd', 'e', (oid, ))
# faked environnement
conn = Mock({
'getNextId': 1,
......
......@@ -47,6 +47,7 @@ from neo.exception import ElectionFailure
from neo.client.handler import BaseClientEventHandler, PrimaryBoostrapEventHandler, \
PrimaryEventHandler, StorageBootstrapEventHandler, StorageEventHandler
from neo.node import StorageNode
from neo.util import dump
MARKER = []
......@@ -101,8 +102,8 @@ class ClientEventHandlerTest(unittest.TestCase):
dispatcher = self.getDispatcher()
client_handler = BaseClientEventHandler(None, dispatcher)
conn = self.getConnection()
client_handler.packetReceived(conn, protocol.ping(1))
pong = conn.mockGetNamedCalls('addPacket')[0].getParam(0)
client_handler.packetReceived(conn, protocol.ping())
pong = conn.mockGetNamedCalls('answer')[0].getParam(0)
self.assertTrue(isinstance(pong, Packet))
self.assertEquals(pong.getType(), PONG)
......@@ -136,7 +137,14 @@ class ClientEventHandlerTest(unittest.TestCase):
primary_master_node = Mock({'getUUID': self.getUUID()})
nm = Mock({'getNodeByServer': fake_storage_node})
cp = Mock({'removeConnection': None})
master_conn = self.getConnection(next_id=ReturnValues(master_node_next_packet_id))
master_conn = Mock({
'addPacket': None,
'getUUID': self.getUUID(),
'getAddress': ('127.0.0.1', 10010),
'getNextId': master_node_next_packet_id,
'lock': None,
'unlock': None
})
app = App()
conn = self.getConnection(port=storage_port, ip=storage_ip)
key_1 = (id(conn), 0)
......@@ -150,13 +158,14 @@ class ClientEventHandlerTest(unittest.TestCase):
dispatcher = Dispatcher()
method(dispatcher, app, handler_class, conn=conn)
# Check that master was notified of the failure
addPacket_call_list = app.master_conn.mockGetNamedCalls('addPacket')
addPacket_call_list = app.master_conn.mockGetNamedCalls('notify')
# Test sanity check
self.assertEqual(len(addPacket_call_list), 1)
node_status_packet = addPacket_call_list[0].getParam(0)
self.assertTrue(isinstance(node_status_packet, Packet))
# Test sanity check
self.assertEquals(node_status_packet.getId(), master_node_next_packet_id)
# the test below is disabled because the msg_id is now set by the connection
#self.assertEquals(node_status_packet.getId(), master_node_next_packet_id)
self.assertEquals(node_status_packet.getType(), NOTIFY_NODE_INFORMATION)
self.assertEquals(node_status_packet.decode()[0],
[(STORAGE_NODE_TYPE, storage_ip, storage_port,
......
......@@ -161,13 +161,13 @@ server: 127.0.0.1:10023
self.app.broadcastNodeInformation(c_node)
# check conn
self.assertEquals(len(client_conn.mockGetNamedCalls("addPacket")), 0)
self.assertEquals(len(master_conn.mockGetNamedCalls("addPacket")), 1)
call = master_conn.mockGetNamedCalls("addPacket")[0]
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("addPacket")), 1)
call = storage_conn.mockGetNamedCalls("addPacket")[0]
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)
......@@ -181,13 +181,13 @@ server: 127.0.0.1:10023
self.app.broadcastNodeInformation(c_node)
# check conn
self.assertEquals(len(client_conn.mockGetNamedCalls("addPacket")), 0)
self.assertEquals(len(master_conn.mockGetNamedCalls("addPacket")), 1)
call = master_conn.mockGetNamedCalls("addPacket")[0]
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("addPacket")), 1)
call = storage_conn.mockGetNamedCalls("addPacket")[0]
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)
......@@ -200,18 +200,18 @@ 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("addPacket")), 1)
call = client_conn.mockGetNamedCalls("addPacket")[0]
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("addPacket")), 1)
call = master_conn.mockGetNamedCalls("addPacket")[0]
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("addPacket")), 1)
call = storage_conn.mockGetNamedCalls("addPacket")[0]
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)
......
......@@ -136,10 +136,9 @@ server: 127.0.0.1:10023
def checkCalledAcceptNodeIdentification(self, conn, packet_number=0):
""" Check Accept Node Identification has been send"""
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
call = conn.mockGetNamedCalls("addPacket")[packet_number]
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ACCEPT_NODE_IDENTIFICATION)
......@@ -161,7 +160,7 @@ server: 127.0.0.1:10023
"""
uuid = self.getNewUUID()
args = (node_type, uuid, ip, port, self.app.name)
packet = protocol.requestNodeIdentification(1, *args)
packet = protocol.requestNodeIdentification(*args)
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None,
"isServerConnection" : True})
......@@ -178,10 +177,9 @@ server: 127.0.0.1:10023
# Method to test the kind of packet returned in answer
def checkCalledRequestNodeIdentification(self, conn, packet_number=0):
""" Check Request Node Identification has been send"""
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
call = conn.mockGetNamedCalls("addPacket")[packet_number]
call = conn.mockGetNamedCalls("ask")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), REQUEST_NODE_IDENTIFICATION)
......@@ -196,17 +194,23 @@ server: 127.0.0.1:10023
def checkCalledAbort(self, conn, packet_number=0):
"""Check the abort method has been called and an error packet has been sent"""
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1) # XXX required here ????
# sometimes we answer an error, sometimes we just send it
send_calls_len = len(conn.mockGetNamedCalls("send"))
answer_calls_len = len(conn.mockGetNamedCalls('answer'))
self.assertEquals(send_calls_len + answer_calls_len, 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0)
call = conn.mockGetNamedCalls("addPacket")[packet_number]
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 1)
if send_calls_len == 1:
call = conn.mockGetNamedCalls("send")[packet_number]
else:
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ERROR)
def checkCalledAnswerPrimaryMaster(self, conn, packet_number=0):
""" Check Answer primaty master message has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number]
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_PRIMARY_MASTER)
......@@ -301,7 +305,7 @@ server: 127.0.0.1:10023
def test_07_packetReceived(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, port=self.master_port)
p = protocol.acceptNodeIdentification(1, MASTER_NODE_TYPE, uuid,
p = protocol.acceptNodeIdentification(MASTER_NODE_TYPE, uuid,
"127.0.0.1", self.master_port, 1009, 2, self.app.uuid)
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
......@@ -323,7 +327,7 @@ server: 127.0.0.1:10023
connector_handler = DoNothingConnector)
args = (MASTER_NODE_TYPE, uuid, '127.0.0.1', self.master_port,
self.app.num_partitions, self.app.num_replicas, self.app.uuid)
p = protocol.acceptNodeIdentification(1, *args)
p = protocol.acceptNodeIdentification(*args)
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), None)
......@@ -346,7 +350,7 @@ server: 127.0.0.1:10023
connector_handler = DoNothingConnector)
args = (MASTER_NODE_TYPE, uuid, '127.0.0.1', self.master_port,
self.app.num_partitions, self.app.num_replicas, self.app.uuid)
p = protocol.acceptNodeIdentification(1, *args)
p = protocol.acceptNodeIdentification(*args)
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), None)
......@@ -366,7 +370,7 @@ server: 127.0.0.1:10023
connector_handler = DoNothingConnector)
args = (MASTER_NODE_TYPE, uuid, '127.0.0.1', self.master_port,
self.app.num_partitions, self.app.num_replicas, self.app.uuid)
p = protocol.acceptNodeIdentification(1, *args)
p = protocol.acceptNodeIdentification(*args)
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), None)
......@@ -381,7 +385,7 @@ server: 127.0.0.1:10023
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getUUID(), uuid)
self.assertEqual(conn.getUUID(), uuid)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),2)
self.checkCalledAskPrimaryMaster(conn.getConnector(), -1)
self.checkCalledAskPrimaryMaster(conn.getConnector(), 1)
def test_09_handleAnswerPrimaryMaster1(self):
......@@ -392,7 +396,7 @@ server: 127.0.0.1:10023
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector)
conn.setUUID(uuid)
p = protocol.askPrimaryMaster(0)
p = protocol.askPrimaryMaster()
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1)
......@@ -413,7 +417,7 @@ server: 127.0.0.1:10023
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector)
conn.setUUID(uuid)
p = protocol.askPrimaryMaster(0)
p = protocol.askPrimaryMaster()
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1)
......@@ -432,7 +436,7 @@ server: 127.0.0.1:10023
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector)
conn.setUUID(uuid)
p = protocol.askPrimaryMaster(0)
p = protocol.askPrimaryMaster()
self.app.nm.add(MasterNode(("127.0.0.1", self.master_port), uuid))
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
......@@ -454,7 +458,7 @@ server: 127.0.0.1:10023
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector)
conn.setUUID(uuid)
p = protocol.askPrimaryMaster(1)
p = protocol.askPrimaryMaster()
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("addPacket")),1)
......@@ -475,7 +479,7 @@ server: 127.0.0.1:10023
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector)
conn.setUUID(uuid)
p = protocol.askPrimaryMaster(1)
p = protocol.askPrimaryMaster()
self.app.nm.add(MasterNode(("127.0.0.1", self.master_port), uuid))
self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1)
......@@ -498,7 +502,7 @@ server: 127.0.0.1:10023
election = self.election
uuid = self.getNewUUID()
args = (MASTER_NODE_TYPE, uuid, '127.0.0.1', self.storage_port, 'INVALID_NAME')
packet = protocol.requestNodeIdentification(1, *args)
packet = protocol.requestNodeIdentification(*args)
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None,
"isServerConnection" : True})
......@@ -579,21 +583,21 @@ server: 127.0.0.1:10023
def test_11_handleAskPrimaryMaster(self):
election = self.election
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = protocol.askPrimaryMaster(0)
packet = protocol.askPrimaryMaster()
conn = Mock({"addPacket" : None,
"getUUID" : uuid,
"isServerConnection" : True,
"getAddress" : ("127.0.0.1", self.master_port)})
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
election.handleAskPrimaryMaster(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.checkCalledAnswerPrimaryMaster(conn, 0)
def test_12_handleAnnouncePrimaryMaster(self):
election = self.election
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_id=3, msg_type=ANNOUNCE_PRIMARY_MASTER)
packet = Packet(msg_type=ANNOUNCE_PRIMARY_MASTER)
# No uuid
conn = Mock({"addPacket" : None,
"getUUID" : None,
......@@ -625,7 +629,7 @@ server: 127.0.0.1:10023
def test_13_handleReelectPrimaryMaster(self):
election = self.election
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = protocol.askPrimaryMaster(0)
packet = protocol.askPrimaryMaster()
# No uuid
conn = Mock({"addPacket" : None,
"getUUID" : None,
......@@ -636,7 +640,7 @@ server: 127.0.0.1:10023
def test_14_handleNotifyNodeInformation(self):
election = self.election
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_id=5, msg_type=NOTIFY_NODE_INFORMATION)
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.master_port)})
......
......@@ -122,10 +122,9 @@ server: 127.0.0.1:10023
def checkCalledAcceptNodeIdentification(self, conn, packet_number=0):
""" Check Accept Node Identification has been send"""
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
call = conn.mockGetNamedCalls("addPacket")[packet_number]
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ACCEPT_NODE_IDENTIFICATION)
......@@ -147,7 +146,7 @@ server: 127.0.0.1:10023
"""
uuid = self.getNewUUID()
args = (node_type, uuid, ip, port,self.app.name)
packet = protocol.requestNodeIdentification(1, *args)
packet = protocol.requestNodeIdentification(*args)
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None})
self.recovery.handleRequestNodeIdentification(conn, packet, *args)
......@@ -175,24 +174,28 @@ server: 127.0.0.1:10023
def checkCalledAbort(self, conn, packet_number=0):
"""Check the abort method has been called and an error packet has been sent"""
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1) # XXX required here ????
send_calls_len = len(conn.mockGetNamedCalls("send"))
answer_calls_len = len(conn.mockGetNamedCalls('answer'))
self.assertEquals(send_calls_len + answer_calls_len, 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0)
call = conn.mockGetNamedCalls("addPacket")[packet_number]
if send_calls_len == 1:
call = conn.mockGetNamedCalls("send")[packet_number]
else:
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ERROR)
def checkCalledNotifyNodeInformation(self, conn, packet_number=0):
""" Check Notify Node Information message has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number]
call = conn.mockGetNamedCalls("notify")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), NOTIFY_NODE_INFORMATION)
def checkCalledAnswerPrimaryMaster(self, conn, packet_number=0):
""" Check Answer primaty master message has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number]
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_PRIMARY_MASTER)
......@@ -207,7 +210,7 @@ server: 127.0.0.1:10023
def checkCalledAskLastIDs(self, conn, packet_number=0):
""" Check start operation message has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number]
call = conn.mockGetNamedCalls("ask")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ASK_LAST_IDS)
......@@ -243,7 +246,7 @@ server: 127.0.0.1:10023
recovery = self.recovery
uuid = self.getNewUUID()
args = (MASTER_NODE_TYPE, uuid, '127.0.0.1', self.storage_port, "INVALID_NAME")
packet = protocol.requestNodeIdentification(1, *args)
packet = protocol.requestNodeIdentification(*args)
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None})
recovery.handleRequestNodeIdentification(conn,
......@@ -391,7 +394,7 @@ server: 127.0.0.1:10023
self.assertEqual(len(self.app.nm.getMasterNodeList()), 2)
self.checkCalledAcceptNodeIdentification(conn)
# a new uuid is sent
call = conn.mockGetNamedCalls('addPacket')[0]
call = conn.mockGetNamedCalls('answer')[0]
body = call.getParam(0)._body
new_uuid = body[:-16]
self.assertNotEquals(new_uuid, uuid)
......@@ -499,38 +502,39 @@ server: 127.0.0.1:10023
def test_05_handleAskPrimaryMaster(self):
recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = protocol.askPrimaryMaster(msg_id=2)
packet = protocol.askPrimaryMaster()
conn = Mock({"addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
recovery.handleAskPrimaryMaster(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 2)
self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("notify")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0)
self.checkCalledAnswerPrimaryMaster(conn, 0)
self.checkCalledNotifyNodeInformation(conn, 1)
self.checkCalledNotifyNodeInformation(conn, 0)
# if storage node, expect message
uuid = self.identifyToMasterNode(STORAGE_NODE_TYPE, port=self.storage_port)
packet = protocol.askPrimaryMaster(msg_id=2)
packet = protocol.askPrimaryMaster()
conn = Mock({"addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
recovery.handleAskPrimaryMaster(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 3)
self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("notify")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
self.checkCalledAnswerPrimaryMaster(conn, 0)
self.checkCalledNotifyNodeInformation(conn, 1)
self.checkCalledAskLastIDs(conn, 2)
self.checkCalledNotifyNodeInformation(conn, 0)
self.checkCalledAskLastIDs(conn, 0)
def test_06_handleAnnouncePrimaryMaster(self):
recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_id=3, msg_type=ANNOUNCE_PRIMARY_MASTER)
packet = Packet(msg_type=ANNOUNCE_PRIMARY_MASTER)
# No uuid
conn = Mock({"addPacket" : None,
"getUUID" : None,
......@@ -550,7 +554,7 @@ server: 127.0.0.1:10023
def test_07_handleReelectPrimaryMaster(self):
recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = protocol.askPrimaryMaster(msg_id=0)
packet = protocol.askPrimaryMaster()
# No uuid
conn = Mock({"addPacket" : None,
"getUUID" : None,
......@@ -561,7 +565,7 @@ server: 127.0.0.1:10023
def test_08_handleNotifyNodeInformation(self):
recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_id=5, msg_type=NOTIFY_NODE_INFORMATION)
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.master_port)})
......@@ -625,7 +629,7 @@ server: 127.0.0.1:10023
def test_09_handleAnswerLastIDs(self):
recovery = self.recovery
uuid = self.identifyToMasterNode()
packet = Packet(msg_id=5, msg_type=ANSWER_LAST_IDS)
packet = Packet(msg_type=ANSWER_LAST_IDS)
loid = self.app.loid
ltid = self.app.ltid
lptid = self.app.lptid
......@@ -672,7 +676,7 @@ server: 127.0.0.1:10023
def test_10_handleAnswerPartitionTable(self):
recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_type=ANSWER_PARTITION_TABLE, msg_id=10)
packet = Packet(msg_type=ANSWER_PARTITION_TABLE)
# No uuid
conn = Mock({"addPacket" : None,
"getUUID" : None,
......
......@@ -119,84 +119,97 @@ server: 127.0.0.1:10023
# Method to test the kind of packet returned in answer
def checkCalledAbort(self, conn, packet_number=0):
"""Check the abort method has been called and an error packet has been sent"""
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1) # XXX required here ????
# sometimes we answer an error, sometimes we just send it
send_calls_len = len(conn.mockGetNamedCalls("send"))
answer_calls_len = len(conn.mockGetNamedCalls('answer'))
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0)
call = conn.mockGetNamedCalls("addPacket")[packet_number]
if send_calls_len == 1:
call = conn.mockGetNamedCalls("send")[packet_number]
else:
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ERROR)
def checkCalledNotifyAbort(self, conn, packet_number=0):
"""Check the abort method has been called and an error packet has been sent"""
# sometimes we answer an error, sometimes we just send it
self.assertEquals(len(conn.mockGetNamedCalls("notify")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 1)
call = conn.mockGetNamedCalls("notify")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ERROR)
def checkCalledAcceptNodeIdentification(self, conn, packet_number=0):
""" Check Accept Node Identification has been send"""
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
call = conn.mockGetNamedCalls("addPacket")[packet_number]
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ACCEPT_NODE_IDENTIFICATION)
def checkCalledNotifyNodeInformation(self, conn, packet_number=0):
""" Check Notify Node Information message has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number]
call = conn.mockGetNamedCalls("notify")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), NOTIFY_NODE_INFORMATION)
def checkCalledAnswerPrimaryMaster(self, conn, packet_number=0):
""" Check Answer primaty master message has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number]
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_PRIMARY_MASTER)
def checkCalledSendPartitionTable(self, conn, packet_number=0):
""" Check partition table has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number]
call = conn.mockGetNamedCalls("notify")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), SEND_PARTITION_TABLE)
def checkCalledStartOperation(self, conn, packet_number=0):
""" Check start operation message has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number]
call = conn.mockGetNamedCalls("notify")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), START_OPERATION)
def checkCalledLockInformation(self, conn, packet_number=0):
""" Check start operation message has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number]
""" Check lockInformation message has been send"""
call = conn.mockGetNamedCalls("ask")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), LOCK_INFORMATION)
def checkCalledUnlockInformation(self, conn, packet_number=0):
""" Check start operation message has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number]
""" Check unlockInformation message has been send"""
call = conn.mockGetNamedCalls("ask")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), UNLOCK_INFORMATION)
def checkCalledNotifyTransactionFinished(self, conn, packet_number=0):
""" Check start operation message has been send"""
""" Check notifyTransactionFinished message has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), NOTIFY_TRANSACTION_FINISHED)
def checkCalledAnswerLastIDs(self, conn, packet_number=0):
""" Check start operation message has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number]
""" Check answerLastIDs message has been send"""
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_LAST_IDS)
return packet._decodeAnswerLastIDs()
def checkCalledAnswerUnfinishedTransactions(self, conn, packet_number=0):
""" Check start operation message has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number]
""" Check answerUnfinishedTransactions message has been send"""
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_UNFINISHED_TRANSACTIONS)
......@@ -219,7 +232,7 @@ server: 127.0.0.1:10023
"""
uuid = self.getNewUUID()
args = (node_type, uuid, ip, port, self.app.name)
packet = protocol.requestNodeIdentification(1, *args)
packet = protocol.requestNodeIdentification(*args)
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None})
self.service.handleRequestNodeIdentification(conn, packet, *args)
......@@ -231,12 +244,12 @@ server: 127.0.0.1:10023
service = self.service
uuid = self.getNewUUID()
args = (STORAGE_NODE_TYPE, uuid, '127.0.0.1', self.storage_port, 'INVALID_NAME')
packet = protocol.requestNodeIdentification(1, *args)
packet = protocol.requestNodeIdentification(*args)
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None})
ptid = self.app.lptid
service.handleRequestNodeIdentification(conn, packet, *args)
self.checkCalledAbort(conn)
self.checkCalledNotifyAbort(conn)
self.assertEquals(len(self.app.nm.getStorageNodeList()), 0)
self.assertEquals(self.app.lptid, ptid)
......@@ -289,7 +302,7 @@ server: 127.0.0.1:10023
ip_address='127.0.0.1',
port=self.storage_port,
name=self.app.name,)
self.checkCalledAbort(conn)
self.checkCalledNotifyAbort(conn)
sn = self.app.nm.getStorageNodeList()[0]
self.assertEquals(sn.getServer(), ('127.0.0.1', self.storage_port))
self.assertEquals(sn.getUUID(), uuid)
......@@ -335,7 +348,7 @@ server: 127.0.0.1:10023
port=10022,
name=self.app.name,)
self.checkCalledAcceptNodeIdentification(conn)
call = conn.mockGetNamedCalls('addPacket')[0]
call = conn.mockGetNamedCalls('answer')[0]
new_uuid = call.getParam(0)._body[-16:]
self.assertNotEquals(uuid, new_uuid)
self.assertEquals(len(self.app.nm.getStorageNodeList()), 2)
......@@ -365,7 +378,7 @@ server: 127.0.0.1:10023
ip_address='127.0.0.1',
port=self.storage_port,
name=self.app.name,)
self.checkCalledAbort(conn)
self.checkCalledNotifyAbort(conn)
self.assertEquals(len(self.app.nm.getStorageNodeList()), 2)
sn = self.app.nm.getStorageNodeList()[0]
self.assertEquals(sn.getServer(), ('127.0.0.1', self.storage_port))
......@@ -378,7 +391,7 @@ server: 127.0.0.1:10023
def test_02_handleAskPrimaryMaster(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = protocol.askPrimaryMaster(msg_id=2)
packet = protocol.askPrimaryMaster()
# test answer to a storage node
conn = Mock({"addPacket" : None,
"answerPrimaryMaster" : None,
......@@ -387,32 +400,30 @@ server: 127.0.0.1:10023
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
service.handleAskPrimaryMaster(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 5)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.checkCalledAnswerPrimaryMaster(conn, 0)
self.checkCalledNotifyNodeInformation(conn, 1)
self.checkCalledNotifyNodeInformation(conn, 0)
self.checkCalledSendPartitionTable(conn, 1)
self.checkCalledSendPartitionTable(conn, 2)
self.checkCalledSendPartitionTable(conn, 3)
self.checkCalledStartOperation(conn, 4)
self.checkCalledStartOperation(conn, 3)
# Same but identify as a client node, must not get start operation message
uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=11021)
packet = protocol.askPrimaryMaster(msg_id=2)
packet = protocol.askPrimaryMaster()
conn = Mock({"addPacket" : None, "abort" : None, "answerPrimaryMaster" : None,
"notifyNodeInformation" : None, "sendPartitionTable" : None,
"getUUID" : uuid, "getAddress" : ("127.0.0.1", 11021)})
service.handleAskPrimaryMaster(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 4)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.checkCalledAnswerPrimaryMaster(conn, 0)
self.checkCalledNotifyNodeInformation(conn, 1)
self.checkCalledNotifyNodeInformation(conn, 0)
self.checkCalledSendPartitionTable(conn, 1)
self.checkCalledSendPartitionTable(conn, 2)
self.checkCalledSendPartitionTable(conn, 3)
def test_03_handleAnnouncePrimaryMaster(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_id=3, msg_type=ANNOUNCE_PRIMARY_MASTER)
packet = Packet(msg_type=ANNOUNCE_PRIMARY_MASTER)
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
# must do a relection
......@@ -427,7 +438,7 @@ server: 127.0.0.1:10023
def test_04_handleReelectPrimaryMaster(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_id=4, msg_type=REELECT_PRIMARY_MASTER)
packet = Packet(msg_type=REELECT_PRIMARY_MASTER)
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
# must do a relection
......@@ -437,7 +448,7 @@ server: 127.0.0.1:10023
def test_05_handleNotifyNodeInformation(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_id=5, msg_type=NOTIFY_NODE_INFORMATION)
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
......@@ -511,7 +522,7 @@ server: 127.0.0.1:10023
def test_06_handleAnswerLastIDs(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_id=5, msg_type=ANSWER_LAST_IDS)
packet = Packet(msg_type=ANSWER_LAST_IDS)
loid = self.app.loid
ltid = self.app.ltid
lptid = self.app.lptid
......@@ -550,7 +561,7 @@ server: 127.0.0.1:10023
def test_07_handleAskNewTID(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_id=5, msg_type=ASK_NEW_TID)
packet = Packet(msg_type=ASK_NEW_TID)
ltid = self.app.ltid
# do not answer if no uuid
conn = Mock({"getUUID" : None,
......@@ -580,7 +591,7 @@ server: 127.0.0.1:10023
def test_08_handleAskNewOIDs(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_id=5, msg_type=ASK_NEW_OIDS)
packet = Packet(msg_type=ASK_NEW_OIDS)
loid = self.app.loid
# do not answer if no uuid
conn = Mock({"getUUID" : None,
......@@ -606,7 +617,8 @@ server: 127.0.0.1:10023
def test_09_handleFinishTransaction(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_id=9, msg_type=FINISH_TRANSACTION)
packet = Packet(msg_type=FINISH_TRANSACTION)
packet.setId(9)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
......@@ -647,7 +659,7 @@ server: 127.0.0.1:10023
self.app.em = Mock({"getConnectionList" : [conn, storage_conn]})
service.handleFinishTransaction(conn, packet, oid_list, tid)
self.checkCalledLockInformation(storage_conn)
self.assertEquals(len(storage_conn.mockGetNamedCalls("expectMessage")), 1)
self.assertEquals(len(storage_conn.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(self.app.finishing_transaction_dict), 1)
apptid = self.app.finishing_transaction_dict.keys()[0]
self.assertEquals(tid, apptid)
......@@ -659,7 +671,7 @@ server: 127.0.0.1:10023
def test_10_handleNotifyInformationLocked(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_id=10, msg_type=NOTIFY_INFORMATION_LOCKED)
packet = Packet(msg_type=NOTIFY_INFORMATION_LOCKED)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
......@@ -710,20 +722,21 @@ server: 127.0.0.1:10023
self.checkCalledLockInformation(storage_conn_1)
self.checkCalledLockInformation(storage_conn_2)
self.assertFalse(self.app.finishing_transaction_dict.values()[0].allLocked())
self.assertEquals(len(storage_conn_1.mockGetNamedCalls("addPacket")), 1)
self.assertEquals(len(storage_conn_2.mockGetNamedCalls("addPacket")), 1)
self.assertEquals(len(storage_conn_1.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(storage_conn_2.mockGetNamedCalls("ask")), 1)
service.handleNotifyInformationLocked(storage_conn_1, packet, tid)
self.assertEquals(len(storage_conn_1.mockGetNamedCalls("addPacket")), 1)
self.assertEquals(len(storage_conn_2.mockGetNamedCalls("addPacket")), 1)
self.assertEquals(len(storage_conn_1.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(storage_conn_2.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 0)
self.assertFalse(self.app.finishing_transaction_dict.values()[0].allLocked())
print "notify"
service.handleNotifyInformationLocked(storage_conn_2, packet, tid)
self.checkCalledNotifyTransactionFinished(conn)
self.assertEquals(len(storage_conn_1.mockGetNamedCalls("addPacket")), 2)
self.assertEquals(len(storage_conn_2.mockGetNamedCalls("addPacket")), 2)
self.assertEquals(len(storage_conn_1.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(storage_conn_1.mockGetNamedCalls("notify")), 1)
self.assertEquals(len(storage_conn_2.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(storage_conn_2.mockGetNamedCalls("notify")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
self.checkCalledLockInformation(storage_conn_1)
self.checkCalledLockInformation(storage_conn_2)
......@@ -732,7 +745,7 @@ server: 127.0.0.1:10023
def test_11_handleAbortTransaction(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_id=11, msg_type=ABORT_TRANSACTION)
packet = Packet(msg_type=ABORT_TRANSACTION)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
......@@ -766,7 +779,7 @@ server: 127.0.0.1:10023
def test_12_handleAskLastIDs(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_id=11, msg_type=ASK_LAST_IDS)
packet = Packet(msg_type=ASK_LAST_IDS)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
......@@ -788,7 +801,7 @@ server: 127.0.0.1:10023
def test_13_handleAskUnfinishedTransactions(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_id=11, msg_type=ASK_UNFINISHED_TRANSACTIONS)
packet = Packet(msg_type=ASK_UNFINISHED_TRANSACTIONS)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
......@@ -818,7 +831,7 @@ server: 127.0.0.1:10023
def test_14_handleNotifyPartitionChanges(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_id=11, msg_type=NOTIFY_PARTITION_CHANGES)
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.storage_port)})
......@@ -924,7 +937,7 @@ server: 127.0.0.1:10023
conn = Mock({"getUUID" : client_uuid,
"getAddress" : ("127.0.0.1", self.client_port)})
lptid = self.app.lptid
packet = Packet(msg_id=15, msg_type=ASK_NEW_TID)
packet = Packet(msg_type=ASK_NEW_TID)
service.handleAskNewTID(conn, packet)
service.handleAskNewTID(conn, packet)
service.handleAskNewTID(conn, packet)
......@@ -974,7 +987,7 @@ server: 127.0.0.1:10023
conn = Mock({"getUUID" : client_uuid,
"getAddress" : ("127.0.0.1", self.client_port)})
lptid = self.app.lptid
packet = Packet(msg_id=15, msg_type=ASK_NEW_TID)
packet = Packet(msg_type=ASK_NEW_TID)
service.handleAskNewTID(conn, packet)
service.handleAskNewTID(conn, packet)
service.handleAskNewTID(conn, packet)
......@@ -1024,7 +1037,7 @@ server: 127.0.0.1:10023
conn = Mock({"getUUID" : client_uuid,
"getAddress" : ("127.0.0.1", self.client_port)})
lptid = self.app.lptid
packet = Packet(msg_id=15, msg_type=ASK_NEW_TID)
packet = Packet(msg_type=ASK_NEW_TID)
service.handleAskNewTID(conn, packet)
service.handleAskNewTID(conn, packet)
service.handleAskNewTID(conn, packet)
......
......@@ -125,10 +125,9 @@ server: 127.0.0.1:10023
def checkCalledAcceptNodeIdentification(self, conn, packet_number=0):
""" Check Accept Node Identification has been send"""
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
call = conn.mockGetNamedCalls("addPacket")[packet_number]
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ACCEPT_NODE_IDENTIFICATION)
......@@ -150,7 +149,7 @@ server: 127.0.0.1:10023
"""
uuid = self.getNewUUID()
args = (node_type, uuid, ip, port, self.app.name)
packet = protocol.requestNodeIdentification(1, *args)
packet = protocol.requestNodeIdentification(*args)
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None})
self.verification.handleRequestNodeIdentification(conn, packet, *args)
......@@ -178,31 +177,36 @@ server: 127.0.0.1:10023
def checkCalledAbort(self, conn, packet_number=0):
"""Check the abort method has been called and an error packet has been sent"""
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1) # XXX required here ????
# sometimes we answer an error, sometimes we just send it
send_calls_len = len(conn.mockGetNamedCalls("send"))
answer_calls_len = len(conn.mockGetNamedCalls('answer'))
self.assertEquals(send_calls_len + answer_calls_len, 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0)
call = conn.mockGetNamedCalls("addPacket")[packet_number]
if send_calls_len == 1:
call = conn.mockGetNamedCalls("send")[packet_number]
else:
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ERROR)
def checkCalledNotifyNodeInformation(self, conn, packet_number=0):
""" Check Notify Node Information message has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number]
call = conn.mockGetNamedCalls("notify")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), NOTIFY_NODE_INFORMATION)
def checkCalledAnswerPrimaryMaster(self, conn, packet_number=0):
""" Check Answer primaty master message has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number]
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_PRIMARY_MASTER)
def checkCalledAnswerLastIDs(self, conn, packet_number=0):
""" Check start operation message has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number]
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_LAST_IDS)
......@@ -210,7 +214,7 @@ server: 127.0.0.1:10023
def checkCalledSendPartitionTable(self, conn, packet_number=0):
""" Check partition table has been send"""
call = conn.mockGetNamedCalls("addPacket")[packet_number]
call = conn.mockGetNamedCalls("notify")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), SEND_PARTITION_TABLE)
......@@ -265,7 +269,7 @@ server: 127.0.0.1:10023
verification = self.verification
uuid = self.getNewUUID()
args = ( MASTER_NODE_TYPE, uuid, '127.0.0.1', self.storage_port, "INVALID_NAME")
packet = protocol.requestNodeIdentification(1, *args)
packet = protocol.requestNodeIdentification(*args)
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None})
verification.handleRequestNodeIdentification(conn, packet=packet,
......@@ -411,7 +415,7 @@ server: 127.0.0.1:10023
self.assertEqual(len(self.app.nm.getMasterNodeList()), 2)
self.checkCalledAcceptNodeIdentification(conn)
# a new uuid is sent
call = conn.mockGetNamedCalls('addPacket')[0]
call = conn.mockGetNamedCalls('answer')[0]
body = call.getParam(0)._body
new_uuid = body[:-16]
self.assertNotEquals(new_uuid, uuid)
......@@ -519,36 +523,37 @@ server: 127.0.0.1:10023
def test_05_handleAskPrimaryMaster(self):
verification = self.verification
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = protocol.askPrimaryMaster(msg_id=2)
packet = protocol.askPrimaryMaster()
conn = Mock({"addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
verification.handleAskPrimaryMaster(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 2)
self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("notify")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0)
self.checkCalledAnswerPrimaryMaster(conn, 0)
self.checkCalledNotifyNodeInformation(conn, 1)
self.checkCalledNotifyNodeInformation(conn, 0)
# if storage node, expect messages
uuid = self.identifyToMasterNode(STORAGE_NODE_TYPE, port=self.storage_port)
packet = protocol.askPrimaryMaster(msg_id=2)
packet = protocol.askPrimaryMaster()
conn = Mock({"addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.storage_port)})
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
verification.handleAskPrimaryMaster(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 4)
self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("notify")), 3)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.checkCalledAnswerPrimaryMaster(conn, 0)
self.checkCalledNotifyNodeInformation(conn, 1)
self.checkCalledNotifyNodeInformation(conn, 0)
self.checkCalledSendPartitionTable(conn, 1)
self.checkCalledSendPartitionTable(conn, 2)
self.checkCalledSendPartitionTable(conn, 3)
def test_06_handleAnnouncePrimaryMaster(self):
verification = self.verification
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_id=3, msg_type=ANNOUNCE_PRIMARY_MASTER)
packet = Packet(msg_type=ANNOUNCE_PRIMARY_MASTER)
# No uuid
conn = Mock({"addPacket" : None,
"getUUID" : None,
......@@ -567,7 +572,7 @@ server: 127.0.0.1:10023
def test_07_handleReelectPrimaryMaster(self):
verification = self.verification
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = protocol.askPrimaryMaster(0)
packet = protocol.askPrimaryMaster()
# No uuid
conn = Mock({"addPacket" : None,
"getUUID" : None,
......@@ -577,7 +582,7 @@ server: 127.0.0.1:10023
def test_08_handleNotifyNodeInformation(self):
verification = self.verification
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_id=5, msg_type=NOTIFY_NODE_INFORMATION)
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.master_port)})
......@@ -640,7 +645,7 @@ server: 127.0.0.1:10023
def test_09_handleAnswerLastIDs(self):
verification = self.verification
uuid = self.identifyToMasterNode()
packet = Packet(msg_id=5, msg_type=ANSWER_LAST_IDS)
packet = Packet(msg_type=ANSWER_LAST_IDS)
loid = self.app.loid
ltid = self.app.ltid
lptid = self.app.lptid
......@@ -684,7 +689,7 @@ server: 127.0.0.1:10023
def test_10_handleAnswerPartitionTable(self):
verification = self.verification
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_type=ANSWER_PARTITION_TABLE, msg_id=10)
packet = Packet(msg_type=ANSWER_PARTITION_TABLE, )
conn = Mock({"addPacket" : None,
"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
......@@ -694,7 +699,7 @@ server: 127.0.0.1:10023
def test_11_handleAnswerUnfinishedTransactions(self):
verification = self.verification
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ANSWER_UNFINISHED_TRANSACTIONS, msg_id=11)
packet = Packet(msg_type=ANSWER_UNFINISHED_TRANSACTIONS)
# reject when no uuid
conn = Mock({"addPacket" : None,
"getUUID" : None,
......@@ -738,7 +743,7 @@ server: 127.0.0.1:10023
def test_12_handleAnswerTransactionInformation(self):
verification = self.verification
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ANSWER_TRANSACTION_INFORMATION, msg_id=12)
packet = Packet(msg_type=ANSWER_TRANSACTION_INFORMATION)
# reject when no uuid
conn = Mock({"addPacket" : None,
"getUUID" : None,
......@@ -810,7 +815,7 @@ server: 127.0.0.1:10023
def test_13_handleTidNotFound(self):
verification = self.verification
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=TID_NOT_FOUND_CODE, msg_id=13)
packet = Packet(msg_type=TID_NOT_FOUND_CODE)
# reject when no uuid
conn = Mock({"addPacket" : None,
"getUUID" : None,
......@@ -848,7 +853,7 @@ server: 127.0.0.1:10023
def test_14_handleAnswerObjectPresent(self):
verification = self.verification
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ANSWER_OBJECT_PRESENT, msg_id=14)
packet = Packet(msg_type=ANSWER_OBJECT_PRESENT)
# reject when no uuid
conn = Mock({"addPacket" : None,
"getUUID" : None,
......@@ -887,7 +892,7 @@ server: 127.0.0.1:10023
def test_15_handleOidNotFound(self):
verification = self.verification
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=OID_NOT_FOUND_CODE, msg_id=15)
packet = Packet(msg_type=OID_NOT_FOUND_CODE)
# reject when no uuid
conn = Mock({"addPacket" : None,
"getUUID" : None,
......
......@@ -112,20 +112,25 @@ server: 127.0.0.1:10020
# Method to test the kind of packet returned in answer
def checkCalledRequestNodeIdentification(self, conn, packet_number=0):
""" Check Request Node Identification has been send"""
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
call = conn.mockGetNamedCalls("addPacket")[packet_number]
call = conn.mockGetNamedCalls("ask")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), REQUEST_NODE_IDENTIFICATION)
def checkCalledAbort(self, conn, packet_number=0):
"""Check the abort method has been called and an error packet has been sent"""
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1) # XXX required here ????
# sometimes we answer an error, sometimes we just send it
send_calls_len = len(conn.mockGetNamedCalls("send"))
answer_calls_len = len(conn.mockGetNamedCalls('answer'))
self.assertEquals(send_calls_len + answer_calls_len, 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0)
call = conn.mockGetNamedCalls("addPacket")[packet_number]
if send_calls_len == 1:
call = conn.mockGetNamedCalls("send")[packet_number]
else:
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ERROR)
......@@ -267,7 +272,7 @@ server: 127.0.0.1:10020
def test_08_handleRequestNodeIdentification1(self):
# client socket connection -> rejected
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
packet = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
self.app.trying_master_node = self.trying_master_node
......@@ -284,7 +289,7 @@ server: 127.0.0.1:10020
def test_08_handleRequestNodeIdentification2(self):
# not a master node -> rejected
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
packet = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port), })
self.bootstrap.handleRequestNodeIdentification(
......@@ -300,7 +305,7 @@ server: 127.0.0.1:10020
def test_08_handleRequestNodeIdentification3(self):
# bad app name -> rejected
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
packet = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port), })
self.bootstrap.handleRequestNodeIdentification(
......@@ -316,7 +321,7 @@ server: 127.0.0.1:10020
def test_08_handleRequestNodeIdentification4(self):
# new master
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
packet = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({"isServerConnection": True,
"getAddress" : ("192.168.1.1", self.master_port), })
# master not known
......@@ -334,8 +339,8 @@ server: 127.0.0.1:10020
name=self.app.name,)
self.assertEquals(len(self.app.nm.getNodeList()), count + 1)
# check packet
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
call = conn.mockGetNamedCalls("addPacket")[0]
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(), ACCEPT_NODE_IDENTIFICATION)
......@@ -346,7 +351,7 @@ server: 127.0.0.1:10020
def test_08_handleRequestNodeIdentification5(self):
# broken node -> rejected
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
packet = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port), })
master = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port))
......@@ -366,7 +371,7 @@ server: 127.0.0.1:10020
def test_08_handleRequestNodeIdentification6(self):
# master node is already known
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
packet = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port), })
# master known
......@@ -386,8 +391,8 @@ server: 127.0.0.1:10020
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0)
# packet
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
call = conn.mockGetNamedCalls("addPacket")[0]
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(), ACCEPT_NODE_IDENTIFICATION)
......@@ -400,7 +405,7 @@ server: 127.0.0.1:10020
# server socket connection -> rejected
conn = Mock({"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_id=1, msg_type=ACCEPT_NODE_IDENTIFICATION)
packet = Packet(msg_type=ACCEPT_NODE_IDENTIFICATION)
self.app.trying_master_node = self.trying_master_node
self.bootstrap.handleAcceptNodeIdentification(
conn=conn,
......@@ -419,7 +424,7 @@ server: 127.0.0.1:10020
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.storage_port), })
self.app.trying_master_node = self.trying_master_node
packet = Packet(msg_id=1, msg_type=ACCEPT_NODE_IDENTIFICATION)
packet = Packet(msg_type=ACCEPT_NODE_IDENTIFICATION)
# non-master node to be removed
server = ('127.0.0.1', self.storage_port)
self.app.nm.add((StorageNode(server=server)))
......@@ -442,7 +447,7 @@ server: 127.0.0.1:10020
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
self.app.trying_master_node = self.trying_master_node
packet = Packet(msg_id=1, msg_type=ACCEPT_NODE_IDENTIFICATION)
packet = Packet(msg_type=ACCEPT_NODE_IDENTIFICATION)
self.bootstrap.handleAcceptNodeIdentification(
conn=conn,
uuid=self.getNewUUID(),
......@@ -462,7 +467,7 @@ server: 127.0.0.1:10020
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
self.app.trying_master_node = self.trying_master_node
packet = Packet(msg_id=1, msg_type=ACCEPT_NODE_IDENTIFICATION)
packet = Packet(msg_type=ACCEPT_NODE_IDENTIFICATION)
uuid = self.getNewUUID()
args = {
'conn':conn,
......@@ -496,8 +501,7 @@ server: 127.0.0.1:10020
self.assertTrue(isinstance(self.app.pt, PartitionTable))
self.assertEquals(self.app.ptid, self.app.dm.getPTID())
self.assertEquals(len(conn.mockGetNamedCalls("setUUID")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("ask")), 1)
def test_09_handleAcceptNodeIdentification5(self):
# no errors
......@@ -510,7 +514,7 @@ server: 127.0.0.1:10020
self.app.trying_master_node = self.trying_master_node
self.assertNotEquals(self.app.trying_master_node.getUUID(), uuid)
self.assertEqual(None, self.app.dm.getNumPartitions())
packet = Packet(msg_id=1, msg_type=ACCEPT_NODE_IDENTIFICATION)
packet = Packet(msg_type=ACCEPT_NODE_IDENTIFICATION)
self.bootstrap.handleAcceptNodeIdentification(
conn=conn,
uuid=uuid,
......@@ -535,18 +539,17 @@ server: 127.0.0.1:10020
self.assertEquals(self.app.uuid, self.app.dm.getUUID())
self.assertEquals(self.app.uuid, your_uuid)
# packet
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
call = conn.mockGetNamedCalls("addPacket")[0]
self.assertEquals(len(conn.mockGetNamedCalls("ask")), 1)
call = conn.mockGetNamedCalls("ask")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ASK_PRIMARY_MASTER)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
def test_10_handleAnswerPrimaryMaster01(self):
# server connection rejected
conn = Mock({"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_id=1, msg_type=ANSWER_PRIMARY_MASTER)
packet = Packet(msg_type=ANSWER_PRIMARY_MASTER)
self.app.trying_master_node = self.trying_master_node
self.app.primary_master_node = None
self.bootstrap.handleAnswerPrimaryMaster(
......@@ -566,7 +569,7 @@ server: 127.0.0.1:10020
known_masters = (existing_master, new_master, )
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_id=1, msg_type=ANSWER_PRIMARY_MASTER)
packet = Packet(msg_type=ANSWER_PRIMARY_MASTER)
self.assertTrue(existing_master[:2] in self.app.nm.server_dict)
self.assertTrue(new_master[:2] not in self.app.nm.server_dict)
self.bootstrap.handleAnswerPrimaryMaster(
......@@ -590,7 +593,7 @@ server: 127.0.0.1:10020
# invalid primary master uuid -> close connection
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_id=1, msg_type=ANSWER_PRIMARY_MASTER)
packet = Packet(msg_type=ANSWER_PRIMARY_MASTER)
pmn = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port))
self.app.primary_master_node = pmn
self.app.trying_master_node = pmn
......@@ -610,7 +613,7 @@ server: 127.0.0.1:10020
# trying_master_node is not pmn -> close connection
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_id=1, msg_type=ANSWER_PRIMARY_MASTER)
packet = Packet(msg_type=ANSWER_PRIMARY_MASTER)
pmn = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port))
pmn.setUUID(self.getNewUUID())
self.app.primary_master_node = None
......@@ -632,7 +635,7 @@ server: 127.0.0.1:10020
# trying_master_node is pmn -> set verification handler
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_id=1, msg_type=ANSWER_PRIMARY_MASTER)
packet = Packet(msg_type=ANSWER_PRIMARY_MASTER)
pmn = self.app.nm.getNodeByServer(('127.0.0.1', self.master_port))
pmn.setUUID(self.getNewUUID())
self.app.primary_master_node = None
......@@ -656,7 +659,7 @@ server: 127.0.0.1:10020
# primary_uuid not known -> nothing happen
conn = Mock({"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port), })
packet = Packet(msg_id=1, msg_type=ANSWER_PRIMARY_MASTER)
packet = Packet(msg_type=ANSWER_PRIMARY_MASTER)
self.app.primary_master_node = None
self.app.trying_master_node = None
new_uuid = self.getNewUUID()
......
......@@ -52,17 +52,23 @@ class StorageOperationTests(unittest.TestCase):
def checkCalledAbort(self, conn, packet_number=0):
"""Check the abort method has been called and an error packet has been sent"""
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1) # XXX required here ????
# sometimes we answer an error, sometimes we just send it
send_calls_len = len(conn.mockGetNamedCalls("send"))
answer_calls_len = len(conn.mockGetNamedCalls('answer'))
self.assertEquals(send_calls_len + answer_calls_len, 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0)
call = conn.mockGetNamedCalls("addPacket")[packet_number]
if send_calls_len == 1:
call = conn.mockGetNamedCalls("send")[packet_number]
else:
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ERROR)
def checkPacket(self, conn, packet_type=ERROR):
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
call = conn.mockGetNamedCalls("addPacket")[0]
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)
......@@ -72,7 +78,7 @@ class StorageOperationTests(unittest.TestCase):
"getAddress" : ("127.0.0.1", self.master_port),
"isServerConnection": _listening,
})
packet = Packet(msg_id=1, msg_type=_msg_type)
packet = Packet(msg_type=_msg_type)
# hook
self.operation.peerBroken = lambda c: c.peerBrokendCalled()
_call(conn=conn, packet=packet, **kwargs)
......@@ -332,7 +338,7 @@ server: 127.0.0.1:10020
def test_09_handleRequestNodeIdentification2(self):
# bad app name
uuid = self.getNewUUID()
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
packet = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({
"getUUID": uuid,
"isServerConnection": True,
......@@ -354,7 +360,7 @@ server: 127.0.0.1:10020
# broken node
uuid = self.getNewUUID()
self.app.primary_master_node.setState(BROKEN_STATE)
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
packet = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({
"getUUID": uuid,
"isServerConnection": True,
......@@ -374,7 +380,7 @@ server: 127.0.0.1:10020
def test_09_handleRequestNodeIdentification4(self):
# new non-master, rejected
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
packet = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({
"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port),
......@@ -394,7 +400,7 @@ server: 127.0.0.1:10020
def test_09_handleRequestNodeIdentification5(self):
# new master, accepted
uuid = self.getNewUUID()
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
packet = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({
"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port),
......@@ -423,7 +429,7 @@ server: 127.0.0.1:10020
def test_09_handleRequestNodeIdentification6(self):
# not new & accepted
packet = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
packet = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
conn = Mock({
"isServerConnection": True,
"getAddress" : ("127.0.0.1", self.master_port),
......@@ -457,7 +463,7 @@ server: 127.0.0.1:10020
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
packet = Packet(msg_id=1, msg_type=ACCEPT_NODE_IDENTIFICATION)
packet = Packet(msg_type=ACCEPT_NODE_IDENTIFICATION)
self.assertRaises(NotImplementedError,
self.operation.handleAcceptNodeIdentification,
conn=conn,
......@@ -534,7 +540,7 @@ server: 127.0.0.1:10020
"getAddress" : ("127.0.0.1", self.master_port),
})
app.replicator = Mock({})
packet = Packet(msg_id=1, msg_type=NOTIFY_PARTITION_CHANGES)
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES)
self.app.ptid = 1
count = len(self.app.nm.getNodeList())
self.operation.handleNotifyPartitionChanges(conn, packet, 0, ())
......@@ -558,7 +564,7 @@ server: 127.0.0.1:10020
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
packet = Packet(msg_id=1, msg_type=NOTIFY_PARTITION_CHANGES)
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES)
app = self.app
ptid1, ptid2 = self.getTwoIDs()
self.assertNotEquals(ptid1, ptid2)
......@@ -609,7 +615,7 @@ server: 127.0.0.1:10020
def test_16_handleStopOperation1(self):
# OperationFailure
conn = Mock({ 'isServerConnection': False })
packet = Packet(msg_id=1, msg_type=STOP_OPERATION)
packet = Packet(msg_type=STOP_OPERATION)
self.assertRaises(OperationFailure, self.operation.handleStopOperation, conn, packet)
def test_16_handleStopOperation2(self):
......@@ -629,14 +635,14 @@ server: 127.0.0.1:10020
def test_18_handleAskTransactionInformation1(self):
# transaction does not exists
conn = Mock({ })
packet = Packet(msg_id=1, msg_type=ASK_TRANSACTION_INFORMATION)
packet = Packet(msg_type=ASK_TRANSACTION_INFORMATION)
self.operation.handleAskTransactionInformation(conn, packet, INVALID_TID)
self.checkPacket(conn, packet_type=ERROR)
def test_18_handleAskTransactionInformation2(self):
# answer
conn = Mock({ })
packet = Packet(msg_id=1, msg_type=ASK_TRANSACTION_INFORMATION)
packet = Packet(msg_type=ASK_TRANSACTION_INFORMATION)
dm = Mock({ "getTransaction": (INVALID_TID, 'user', 'desc', '', ), })
self.app.dm = dm
self.operation.handleAskTransactionInformation(conn, packet, INVALID_TID)
......@@ -682,7 +688,7 @@ server: 127.0.0.1:10020
# load transaction informations
conn = Mock({ 'isServerConnection': False, })
self.app.dm = Mock({ })
packet = Packet(msg_id=1, msg_type=LOCK_INFORMATION)
packet = Packet(msg_type=LOCK_INFORMATION)
transaction = Mock({ 'getObjectList': ((0, ), ), })
self.app.transaction_dict[INVALID_TID] = transaction
self.operation.handleLockInformation(conn, packet, INVALID_TID)
......@@ -711,7 +717,7 @@ server: 127.0.0.1:10020
# delete transaction informations
conn = Mock({ 'isServerConnection': False, })
self.app.dm = Mock({ })
packet = Packet(msg_id=1, msg_type=LOCK_INFORMATION)
packet = Packet(msg_type=LOCK_INFORMATION)
transaction = Mock({ 'getObjectList': ((0, ), ), })
self.app.transaction_dict[INVALID_TID] = transaction
self.app.load_lock_dict[0] = transaction
......@@ -733,7 +739,7 @@ server: 127.0.0.1:10020
# delayed response
conn = Mock({})
self.app.dm = Mock()
packet = Packet(msg_id=1, msg_type=ASK_OBJECT)
packet = Packet(msg_type=ASK_OBJECT)
self.app.load_lock_dict[INVALID_OID] = object()
self.assertEquals(len(self.app.event_queue), 0)
self.operation.handleAskObject(conn, packet,
......@@ -748,7 +754,7 @@ server: 127.0.0.1:10020
# invalid serial / tid / packet not found
self.app.dm = Mock({'getObject': None})
conn = Mock({})
packet = Packet(msg_id=1, msg_type=ASK_OBJECT)
packet = Packet(msg_type=ASK_OBJECT)
self.assertEquals(len(self.app.event_queue), 0)
self.operation.handleAskObject(conn, packet,
oid=INVALID_OID,
......@@ -766,7 +772,7 @@ server: 127.0.0.1:10020
# object found => answer
self.app.dm = Mock({'getObject': ('', '', 0, 0, '', )})
conn = Mock({})
packet = Packet(msg_id=1, msg_type=ASK_OBJECT)
packet = Packet(msg_type=ASK_OBJECT)
self.assertEquals(len(self.app.event_queue), 0)
self.operation.handleAskObject(conn, packet,
oid=INVALID_OID,
......@@ -781,7 +787,7 @@ server: 127.0.0.1:10020
app.pt = Mock()
app.dm = Mock()
conn = Mock({})
packet = Packet(msg_id=1, msg_type=ASK_TIDS)
packet = Packet(msg_type=ASK_TIDS)
self.operation.handleAskTIDs(conn, packet, 1, 1, None)
self.checkPacket(conn, packet_type=ERROR)
self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0)
......@@ -791,7 +797,7 @@ server: 127.0.0.1:10020
def test_25_handleAskTIDs2(self):
# well case => answer
conn = Mock({})
packet = Packet(msg_id=1, msg_type=ASK_TIDS)
packet = Packet(msg_type=ASK_TIDS)
self.app.num_partitions = 1
self.app.dm = Mock({'getTIDList': (INVALID_TID, )})
self.operation.handleAskTIDs(conn, packet, 1, 2, 1)
......@@ -806,7 +812,7 @@ server: 127.0.0.1:10020
def test_25_handleAskTIDs3(self):
# invalid partition => answer usable partitions
conn = Mock({})
packet = Packet(msg_id=1, msg_type=ASK_TIDS)
packet = Packet(msg_type=ASK_TIDS)
self.app.num_partitions = 1
cell = Mock({'getUUID':self.app.uuid})
self.app.dm = Mock({'getTIDList': (INVALID_TID, )})
......@@ -826,14 +832,14 @@ server: 127.0.0.1:10020
app = self.app
app.dm = Mock()
conn = Mock({})
packet = Packet(msg_id=1, msg_type=ASK_OBJECT_HISTORY)
packet = Packet(msg_type=ASK_OBJECT_HISTORY)
self.operation.handleAskObjectHistory(conn, packet, 1, 1, None)
self.checkPacket(conn, packet_type=ERROR)
self.assertEquals(len(app.dm.mockGetNamedCalls('getObjectHistory')), 0)
def test_26_handleAskObjectHistory2(self):
# first case: empty history
packet = Packet(msg_id=1, msg_type=ASK_OBJECT_HISTORY)
packet = Packet(msg_type=ASK_OBJECT_HISTORY)
conn = Mock({})
self.app.dm = Mock({'getObjectHistory': None})
self.operation.handleAskObjectHistory(conn, packet, INVALID_OID, 1, 2)
......@@ -861,7 +867,7 @@ server: 127.0.0.1:10020
def test_27_handleAskStoreTransaction2(self):
# add transaction entry
packet = Packet(msg_id=1, msg_type=ASK_STORE_TRANSACTION)
packet = Packet(msg_type=ASK_STORE_TRANSACTION)
conn = Mock({'getUUID': self.getNewUUID()})
self.operation.handleAskStoreTransaction(conn, packet,
INVALID_TID, '', '', '', ())
......@@ -898,7 +904,7 @@ server: 127.0.0.1:10020
def test_28_handleAskStoreObject2(self):
# locked => delayed response
packet = Packet(msg_id=1, msg_type=ASK_STORE_OBJECT)
packet = Packet(msg_type=ASK_STORE_OBJECT)
conn = Mock({'getUUID': self.app.uuid})
oid = '\x02' * 8
tid1, tid2 = self.getTwoIDs()
......@@ -915,7 +921,7 @@ server: 127.0.0.1:10020
def test_28_handleAskStoreObject3(self):
# locked => unresolvable conflict => answer
packet = Packet(msg_id=1, msg_type=ASK_STORE_OBJECT)
packet = Packet(msg_type=ASK_STORE_OBJECT)
conn = Mock({'getUUID': self.app.uuid})
tid1, tid2 = self.getTwoIDs()
self.app.store_lock_dict[INVALID_OID] = tid2
......@@ -924,12 +930,12 @@ server: 127.0.0.1:10020
self.checkPacket(conn, packet_type=ANSWER_STORE_OBJECT)
self.assertEquals(self.app.store_lock_dict[INVALID_OID], tid2)
# conflicting
packet = conn.mockGetNamedCalls('addPacket')[0].getParam(0)
packet = conn.mockGetNamedCalls('answer')[0].getParam(0)
self.assertTrue(unpack('!B8s8s', packet._body)[0])
def test_28_handleAskStoreObject4(self):
# resolvable conflict => answer
packet = Packet(msg_id=1, msg_type=ASK_STORE_OBJECT)
packet = Packet(msg_type=ASK_STORE_OBJECT)
conn = Mock({'getUUID': self.app.uuid})
self.app.dm = Mock({'getObjectHistory':((self.getNewUUID(), ), )})
self.assertEquals(self.app.store_lock_dict.get(INVALID_OID, None), None)
......@@ -938,12 +944,12 @@ server: 127.0.0.1:10020
self.checkPacket(conn, packet_type=ANSWER_STORE_OBJECT)
self.assertEquals(self.app.store_lock_dict.get(INVALID_OID, None), None)
# conflicting
packet = conn.mockGetNamedCalls('addPacket')[0].getParam(0)
packet = conn.mockGetNamedCalls('answer')[0].getParam(0)
self.assertTrue(unpack('!B8s8s', packet._body)[0])
def test_28_handleAskStoreObject5(self):
# no conflict => answer
packet = Packet(msg_id=1, msg_type=ASK_STORE_OBJECT)
packet = Packet(msg_type=ASK_STORE_OBJECT)
conn = Mock({'getUUID': self.app.uuid})
self.operation.handleAskStoreObject(conn, packet, INVALID_OID,
INVALID_SERIAL, 0, 0, '', INVALID_TID)
......@@ -954,7 +960,7 @@ server: 127.0.0.1:10020
self.assertEquals(object, (INVALID_OID, 0, 0, ''))
self.checkPacket(conn, packet_type=ANSWER_STORE_OBJECT)
# no conflict
packet = conn.mockGetNamedCalls('addPacket')[0].getParam(0)
packet = conn.mockGetNamedCalls('answer')[0].getParam(0)
self.assertFalse(unpack('!B8s8s', packet._body)[0])
def test_29_handleAbortTransaction(self):
......@@ -968,7 +974,7 @@ server: 127.0.0.1:10020
after = self.app.transaction_dict.items()
self.assertEquals(before, after)
# remove transaction
packet = Packet(msg_id=1, msg_type=ABORT_TRANSACTION)
packet = Packet(msg_type=ABORT_TRANSACTION)
conn = Mock({'getUUID': self.app.uuid})
transaction = Mock({ 'getObjectList': ((0, ), ), })
self.called = False
......@@ -996,7 +1002,7 @@ server: 127.0.0.1:10020
)
# set critical TID on replicator
conn = Mock()
packet = Packet(msg_id=1, msg_type=ANSWER_LAST_IDS)
packet = Packet(msg_type=ANSWER_LAST_IDS)
self.app.replicator = Mock()
self.operation.handleAnswerLastIDs(
conn=conn,
......@@ -1020,7 +1026,7 @@ server: 127.0.0.1:10020
)
# set unfinished TID on replicator
conn = Mock()
packet = Packet(msg_id=1, msg_type=ANSWER_UNFINISHED_TRANSACTIONS)
packet = Packet(msg_type=ANSWER_UNFINISHED_TRANSACTIONS)
self.app.replicator = Mock()
self.operation.handleAnswerUnfinishedTransactions(
conn=conn,
......@@ -1037,7 +1043,7 @@ server: 127.0.0.1:10020
app.pt = Mock()
app.dm = Mock()
conn = Mock({})
packet = Packet(msg_id=1, msg_type=ASK_OIDS)
packet = Packet(msg_type=ASK_OIDS)
self.operation.handleAskOIDs(conn, packet, 1, 1, None)
self.checkPacket(conn, packet_type=ERROR)
self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0)
......@@ -1046,7 +1052,7 @@ server: 127.0.0.1:10020
def test_25_handleAskOIDs2(self):
# well case > answer OIDs
conn = Mock({})
packet = Packet(msg_id=1, msg_type=ASK_OIDS)
packet = Packet(msg_type=ASK_OIDS)
self.app.num_partitions = 1
self.app.dm = Mock({'getOIDList': (INVALID_OID, )})
self.operation.handleAskOIDs(conn, packet, 1, 2, 1)
......@@ -1061,7 +1067,7 @@ server: 127.0.0.1:10020
def test_25_handleAskOIDs3(self):
# invalid partition => answer usable partitions
conn = Mock({})
packet = Packet(msg_id=1, msg_type=ASK_OIDS)
packet = Packet(msg_type=ASK_OIDS)
self.app.num_partitions = 1
cell = Mock({'getUUID':self.app.uuid})
self.app.dm = Mock({'getOIDList': (INVALID_OID, )})
......
......@@ -21,6 +21,7 @@ import logging
import MySQLdb
from tempfile import mkstemp
from mock import Mock
from neo import protocol
from neo.node import MasterNode
from neo.pt import PartitionTable
from neo.storage.app import Application, StorageNode
......@@ -128,10 +129,16 @@ server: 127.0.0.1:10020
def checkCalledAbort(self, conn, packet_number=0):
"""Check the abort method has been called and an error packet has been sent"""
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1) # XXX required here ????
# sometimes we answer an error, sometimes we just send it
send_calls_len = len(conn.mockGetNamedCalls("send"))
answer_calls_len = len(conn.mockGetNamedCalls('answer'))
self.assertEquals(send_calls_len + answer_calls_len, 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0)
call = conn.mockGetNamedCalls("addPacket")[packet_number]
if send_calls_len == 1:
call = conn.mockGetNamedCalls("send")[packet_number]
else:
call = conn.mockGetNamedCalls("answer")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ERROR)
......@@ -210,9 +217,9 @@ server: 127.0.0.1:10020
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : True})
p = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
p = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
self.verification.handleRequestNodeIdentification(conn, p, CLIENT_NODE_TYPE,
uuid, "127.0.0.1", self.client_port, "zatt")
uuid, "127.0.0.1", self.client_port, "zatt")
self.checkCalledAbort(conn)
# not a master node
......@@ -220,9 +227,9 @@ server: 127.0.0.1:10020
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : True})
p = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
p = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
self.verification.handleRequestNodeIdentification(conn, p, CLIENT_NODE_TYPE,
uuid, "127.0.0.1", self.client_port, "zatt")
uuid, "127.0.0.1", self.client_port, "zatt")
self.checkCalledAbort(conn)
# bad name
......@@ -230,9 +237,9 @@ server: 127.0.0.1:10020
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port),
"isServerConnection" : True})
p = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
p = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
self.verification.handleRequestNodeIdentification(conn, p, MASTER_NODE_TYPE,
uuid, "127.0.0.1", self.client_port, "zatt")
uuid, "127.0.0.1", self.client_port, "zatt")
self.checkCalledAbort(conn)
# new node
......@@ -240,7 +247,7 @@ server: 127.0.0.1:10020
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port),
"isServerConnection" : True})
p = Packet(msg_id=1, msg_type=REQUEST_NODE_IDENTIFICATION)
p = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
self.verification.handleRequestNodeIdentification(conn, p, MASTER_NODE_TYPE,
uuid, "127.0.0.1", self.master_port, "main")
......@@ -248,8 +255,8 @@ server: 127.0.0.1:10020
node = self.app.nm.getNodeByServer(conn.getAddress())
self.assertEqual(node.getUUID(), uuid)
self.assertEqual(node.getState(), RUNNING_STATE)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
call = conn.mockGetNamedCalls("addPacket")[0]
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(), ACCEPT_NODE_IDENTIFICATION)
......@@ -264,8 +271,8 @@ server: 127.0.0.1:10020
self.assertEqual(node.getUUID(), uuid)
self.verification.handleRequestNodeIdentification(conn, p, MASTER_NODE_TYPE,
uuid, "127.0.0.1", self.master_port, "main")
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
call = conn.mockGetNamedCalls("addPacket")[0]
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(), ERROR)
......@@ -285,8 +292,8 @@ server: 127.0.0.1:10020
node = self.app.nm.getNodeByServer(conn.getAddress())
self.assertEqual(node.getUUID(), uuid)
self.assertEqual(node.getState(), RUNNING_STATE)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
call = conn.mockGetNamedCalls("addPacket")[0]
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(), ACCEPT_NODE_IDENTIFICATION)
......@@ -298,15 +305,14 @@ server: 127.0.0.1:10020
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : True})
p = Packet(msg_id=1, msg_type=ACCEPT_NODE_IDENTIFICATION)
p = Packet(msg_type=ACCEPT_NODE_IDENTIFICATION)
self.verification.handleAcceptNodeIdentification(conn, p, CLIENT_NODE_TYPE,
self.getNewUUID(),"127.0.0.1", self.client_port,
1009, 2, uuid)
self.getNewUUID(),"127.0.0.1", self.client_port, 1009, 2, uuid)
self.checkCalledAbort(conn)
def test_07_handleAnswerPrimaryMaster(self):
# reject server connection
packet = Packet(msg_id=1, msg_type=ANSWER_PRIMARY_MASTER)
packet = Packet(msg_type=ANSWER_PRIMARY_MASTER)
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
......@@ -332,7 +338,7 @@ server: 127.0.0.1:10020
def test_07_handleAskLastIDs(self):
# reject server connection
packet = Packet(msg_id=1, msg_type=ASK_LAST_IDS)
packet = Packet(msg_type=ASK_LAST_IDS)
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
......@@ -345,7 +351,7 @@ server: 127.0.0.1:10020
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : False})
self.verification.handleAskLastIDs(conn, packet)
call = conn.mockGetNamedCalls("addPacket")[0]
call = conn.mockGetNamedCalls("answer")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_LAST_IDS)
......@@ -380,7 +386,7 @@ server: 127.0.0.1:10020
checksum, value) values (0, 4, 0, 0, '')""")
self.app.dm.commit()
self.verification.handleAskLastIDs(conn, packet)
call = conn.mockGetNamedCalls("addPacket")[0]
call = conn.mockGetNamedCalls("answer")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_LAST_IDS)
......@@ -391,7 +397,7 @@ server: 127.0.0.1:10020
def test_08_handleAskPartitionTable(self):
# reject server connection
packet = Packet(msg_id=1, msg_type=ASK_PARTITION_TABLE)
packet = Packet(msg_type=ASK_PARTITION_TABLE)
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
......@@ -407,7 +413,7 @@ server: 127.0.0.1:10020
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : False})
self.verification.handleAskPartitionTable(conn, packet, [1,])
call = conn.mockGetNamedCalls("addPacket")[0]
call = conn.mockGetNamedCalls("answer")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_PARTITION_TABLE)
......@@ -425,7 +431,7 @@ server: 127.0.0.1:10020
"getAddress" : ("127.0.0.1", self.client_port),
"isServerConnection" : False})
self.verification.handleAskPartitionTable(conn, packet, [1,])
call = conn.mockGetNamedCalls("addPacket")[0]
call = conn.mockGetNamedCalls("answer")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_PARTITION_TABLE)
......@@ -437,7 +443,7 @@ server: 127.0.0.1:10020
def test_09_handleSendPartitionTable(self):
# reject server connection
packet = Packet(msg_id=1, msg_type=SEND_PARTITION_TABLE)
packet = Packet(msg_type=SEND_PARTITION_TABLE)
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
......@@ -484,7 +490,7 @@ server: 127.0.0.1:10020
def test_10_handleNotifyPartitionChanges(self):
# reject server connection
packet = Packet(msg_id=1, msg_type=NOTIFY_PARTITION_CHANGES)
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES)
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
......@@ -499,7 +505,7 @@ server: 127.0.0.1:10020
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
packet = Packet(msg_id=1, msg_type=NOTIFY_PARTITION_CHANGES)
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES)
self.app.ptid = 1
self.verification.handleNotifyPartitionChanges(conn, packet, 0, ())
self.assertEquals(self.app.ptid, 1)
......@@ -509,7 +515,7 @@ server: 127.0.0.1:10020
"isServerConnection": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
packet = Packet(msg_id=1, msg_type=NOTIFY_PARTITION_CHANGES)
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES)
cell = (0, self.getNewUUID(), UP_TO_DATE_STATE)
count = len(self.app.nm.getNodeList())
self.app.pt = PartitionTable(1, 1)
......@@ -527,40 +533,40 @@ server: 127.0.0.1:10020
def test_11_handleStartOperation(self):
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': True })
packet = Packet(msg_id=1, msg_type=STOP_OPERATION)
packet = Packet(msg_type=STOP_OPERATION)
self.verification.handleStartOperation(conn, packet)
self.checkCalledAbort(conn)
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False })
self.assertFalse(self.app.operational)
packet = Packet(msg_id=1, msg_type=STOP_OPERATION)
packet = Packet(msg_type=STOP_OPERATION)
self.verification.handleStartOperation(conn, packet)
self.assertTrue(self.app.operational)
def test_12_handleStopOperation(self):
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': True })
packet = Packet(msg_id=1, msg_type=STOP_OPERATION)
packet = Packet(msg_type=STOP_OPERATION)
self.verification.handleStopOperation(conn, packet)
self.checkCalledAbort(conn)
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False })
packet = Packet(msg_id=1, msg_type=STOP_OPERATION)
packet = Packet(msg_type=STOP_OPERATION)
self.assertRaises(OperationFailure, self.verification.handleStopOperation, conn, packet)
def test_13_handleAskUnfinishedTransactions(self):
# server connection
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': True })
packet = Packet(msg_id=1, msg_type=ASK_UNFINISHED_TRANSACTIONS)
packet = Packet(msg_type=ASK_UNFINISHED_TRANSACTIONS)
self.verification.handleAskUnfinishedTransactions(conn, packet)
self.checkCalledAbort(conn)
# client connection with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False})
packet = Packet(msg_id=1, msg_type=ASK_UNFINISHED_TRANSACTIONS)
packet = Packet(msg_type=ASK_UNFINISHED_TRANSACTIONS)
self.verification.handleAskUnfinishedTransactions(conn, packet)
call = conn.mockGetNamedCalls("addPacket")[0]
call = conn.mockGetNamedCalls("answer")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_UNFINISHED_TRANSACTIONS)
......@@ -574,9 +580,9 @@ server: 127.0.0.1:10020
self.app.dm.commit()
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False})
packet = Packet(msg_id=1, msg_type=ASK_UNFINISHED_TRANSACTIONS)
packet = Packet(msg_type=ASK_UNFINISHED_TRANSACTIONS)
self.verification.handleAskUnfinishedTransactions(conn, packet)
call = conn.mockGetNamedCalls("addPacket")[0]
call = conn.mockGetNamedCalls("answer")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_UNFINISHED_TRANSACTIONS)
......@@ -588,9 +594,9 @@ server: 127.0.0.1:10020
# ask from server with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': True })
packet = Packet(msg_id=1, msg_type=ASK_TRANSACTION_INFORMATION)
packet = Packet(msg_type=ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(1))
call = conn.mockGetNamedCalls("addPacket")[0]
call = conn.mockGetNamedCalls("answer")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ERROR)
......@@ -599,9 +605,9 @@ server: 127.0.0.1:10020
# ask from client conn with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False })
packet = Packet(msg_id=1, msg_type=ASK_TRANSACTION_INFORMATION)
packet = Packet(msg_type=ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(1))
call = conn.mockGetNamedCalls("addPacket")[0]
call = conn.mockGetNamedCalls("answer")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ERROR)
......@@ -618,9 +624,9 @@ server: 127.0.0.1:10020
# object from trans
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False })
packet = Packet(msg_id=1, msg_type=ASK_TRANSACTION_INFORMATION)
packet = Packet(msg_type=ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(1))
call = conn.mockGetNamedCalls("addPacket")[0]
call = conn.mockGetNamedCalls("answer")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_TRANSACTION_INFORMATION)
......@@ -634,9 +640,9 @@ server: 127.0.0.1:10020
# object from ttrans
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False })
packet = Packet(msg_id=1, msg_type=ASK_TRANSACTION_INFORMATION)
packet = Packet(msg_type=ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(3))
call = conn.mockGetNamedCalls("addPacket")[0]
call = conn.mockGetNamedCalls("answer")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_TRANSACTION_INFORMATION)
......@@ -652,9 +658,9 @@ server: 127.0.0.1:10020
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': True })
# find the one in trans
packet = Packet(msg_id=1, msg_type=ASK_TRANSACTION_INFORMATION)
packet = Packet(msg_type=ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(1))
call = conn.mockGetNamedCalls("addPacket")[0]
call = conn.mockGetNamedCalls("answer")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_TRANSACTION_INFORMATION)
......@@ -668,9 +674,9 @@ server: 127.0.0.1:10020
# do not find the one in ttrans
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': True })
packet = Packet(msg_id=1, msg_type=ASK_TRANSACTION_INFORMATION)
packet = Packet(msg_type=ASK_TRANSACTION_INFORMATION)
self.verification.handleAskTransactionInformation(conn, packet, p64(3))
call = conn.mockGetNamedCalls("addPacket")[0]
call = conn.mockGetNamedCalls("answer")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ERROR)
......@@ -681,15 +687,15 @@ server: 127.0.0.1:10020
# server connection
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': True })
packet = Packet(msg_id=1, msg_type=ASK_OBJECT_PRESENT)
packet = Packet(msg_type=ASK_OBJECT_PRESENT)
self.verification.handleAskObjectPresent(conn, packet, p64(1), p64(2))
self.checkCalledAbort(conn)
# client connection with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False})
packet = Packet(msg_id=1, msg_type=ASK_OBJECT_PRESENT)
packet = Packet(msg_type=ASK_OBJECT_PRESENT)
self.verification.handleAskObjectPresent(conn, packet, p64(1), p64(2))
call = conn.mockGetNamedCalls("addPacket")[0]
call = conn.mockGetNamedCalls("answer")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ERROR)
......@@ -703,9 +709,9 @@ server: 127.0.0.1:10020
self.app.dm.commit()
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False})
packet = Packet(msg_id=1, msg_type=ASK_OBJECT_PRESENT)
packet = Packet(msg_type=ASK_OBJECT_PRESENT)
self.verification.handleAskObjectPresent(conn, packet, p64(1), p64(2))
call = conn.mockGetNamedCalls("addPacket")[0]
call = conn.mockGetNamedCalls("answer")[0]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ANSWER_OBJECT_PRESENT)
......@@ -717,13 +723,13 @@ server: 127.0.0.1:10020
# server connection
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': True })
packet = Packet(msg_id=1, msg_type=ASK_OBJECT_PRESENT)
packet = Packet(msg_type=ASK_OBJECT_PRESENT)
self.verification.handleDeleteTransaction(conn, packet, p64(1))
self.checkCalledAbort(conn)
# client connection with no data
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False})
packet = Packet(msg_id=1, msg_type=ASK_OBJECT_PRESENT)
packet = Packet(msg_type=ASK_OBJECT_PRESENT)
self.verification.handleDeleteTransaction(conn, packet, p64(1))
# client connection with data
self.app.dm.begin()
......@@ -740,7 +746,7 @@ server: 127.0.0.1:10020
'isServerConnection': True })
dm = Mock()
self.app.dm = dm
packet = Packet(msg_id=1, msg_type=COMMIT_TRANSACTION)
packet = Packet(msg_type=COMMIT_TRANSACTION)
self.verification.handleCommitTransaction(conn, packet, p64(1))
self.checkCalledAbort(conn)
self.assertEqual(len(dm.mockGetNamedCalls("finishTransaction")), 0)
......@@ -749,7 +755,7 @@ server: 127.0.0.1:10020
'isServerConnection': False })
dm = Mock()
self.app.dm = dm
packet = Packet(msg_id=1, msg_type=COMMIT_TRANSACTION)
packet = Packet(msg_type=COMMIT_TRANSACTION)
self.verification.handleCommitTransaction(conn, packet, p64(1))
self.assertEqual(len(dm.mockGetNamedCalls("finishTransaction")), 1)
call = dm.mockGetNamedCalls("finishTransaction")[0]
......@@ -759,7 +765,7 @@ server: 127.0.0.1:10020
def test_18_handleLockInformation(self):
conn = Mock({"getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False})
packet = Packet(msg_id=1, msg_type=LOCK_INFORMATION)
packet = Packet(msg_type=LOCK_INFORMATION)
self.assertEquals(len(self.app.load_lock_dict), 0)
self.verification.handleLockInformation(conn, packet, p64(1))
self.assertEquals(len(self.app.load_lock_dict), 0)
......@@ -768,7 +774,7 @@ server: 127.0.0.1:10020
conn = Mock({"getAddress" : ("127.0.0.1", self.master_port),
'isServerConnection': False})
self.app.load_lock_dict[p64(1)] = Mock()
packet = Packet(msg_id=1, msg_type=UNLOCK_INFORMATION)
packet = Packet(msg_type=UNLOCK_INFORMATION)
self.verification.handleUnlockInformation(conn, packet, p64(1))
self.assertEquals(len(self.app.load_lock_dict), 1)
......
......@@ -410,31 +410,36 @@ class testConnection(unittest.TestCase):
# packet witch raise protocol error
# change the max packet size and create a to big message
# be careful not to set the max packet size < error message
master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, getNewUUID()),
("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()),
("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p = protocol.answerPrimaryMaster(1, getNewUUID(), master_list)
OLD_MAX_PACKET_SIZE = protocol.MAX_PACKET_SIZE
protocol.MAX_PACKET_SIZE = 0x55
connector = DoNothingConnector()
bc = Connection(em, handler, connector_handler=DoNothingConnector,
connector=connector, addr=("127.0.0.7", 93413))
self.assertEqual(bc.write_buf, '')
self.assertNotEqual(bc.getConnector(), None)
bc.addPacket(p)
self.assertNotEqual(bc.write_buf, "testdata")
self.assertRaises(ProtocolError, p.encode)
self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 2)
# check it sends error packet
packet = Packet.parse(bc.write_buf)
self.assertEqual(packet.getType(), ERROR)
code, message = packet.decode()
self.assertEqual(code, INTERNAL_ERROR_CODE)
self.assertEqual(message, "internal error: message too big (206)")
# reset value
protocol.MAX_PACKET_SIZE = OLD_MAX_PACKET_SIZE
# this part of the test is disabled because the case where a too big
# message is send is handled in protocol.Packet.encode
# master_list = (("127.0.0.1", 2135, getNewUUID()), ("127.0.0.1", 2135, getNewUUID()),
# ("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()),
# ("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
# ("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
# p = protocol.answerPrimaryMaster(getNewUUID(), master_list)
# p.setId(1)
# OLD_MAX_PACKET_SIZE = protocol.MAX_PACKET_SIZE
# protocol.MAX_PACKET_SIZE = 0x55
#
# connector = DoNothingConnector()
# bc = Connection(em, handler, connector_handler=DoNothingConnector,
# connector=connector, addr=("127.0.0.7", 93413))
# self.assertEqual(bc.write_buf, '')
# self.assertNotEqual(bc.getConnector(), None)
# import pdb
# pdb.set_trace()
# bc.addPacket(p)
# self.assertNotEqual(bc.write_buf, "testdata")
# self.assertRaises(ProtocolError, p.encode)
# self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 2)
# # check it sends error packet
# packet = Packet.parse(bc.write_buf)
# self.assertEqual(packet.getType(), ERROR)
# code, message = packet.decode()
# self.assertEqual(code, INTERNAL_ERROR_CODE)
# self.assertEqual(message, "internal error: message too big (206)")
# # reset value
# protocol.MAX_PACKET_SIZE = OLD_MAX_PACKET_SIZE
def test_08_Connection_expectMessage(self):
......@@ -482,7 +487,8 @@ class testConnection(unittest.TestCase):
("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()),
("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p = protocol.answerPrimaryMaster(1, getNewUUID(), master_list)
p = protocol.answerPrimaryMaster(getNewUUID(), master_list)
p.setId(1)
data = p.encode()
bc.read_buf += data
self.assertEqual(len(bc.event_dict), 0)
......@@ -508,7 +514,8 @@ class testConnection(unittest.TestCase):
("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()),
("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p1 = protocol.answerPrimaryMaster(1, getNewUUID(), master_list)
p1 = protocol.answerPrimaryMaster(getNewUUID(), master_list)
p1.setId(1)
data = p1.encode()
bc.read_buf += data
# packet 2
......@@ -516,7 +523,8 @@ class testConnection(unittest.TestCase):
("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()),
("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p2 = protocol.answerPrimaryMaster(2, getNewUUID(), master_list)
p2 = protocol.answerPrimaryMaster( getNewUUID(), master_list)
p2.setId(2)
data = p2.encode()
bc.read_buf += data
self.assertEqual(len(bc.read_buf), len(p1.encode()) + len(p2.encode()))
......@@ -563,7 +571,8 @@ class testConnection(unittest.TestCase):
("127.0.0.1", 2235, getNewUUID()), ("127.0.0.1", 2134, getNewUUID()),
("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
p = protocol.answerPrimaryMaster(1, getNewUUID(), master_list)
p = protocol.answerPrimaryMaster(getNewUUID(), master_list)
p.setId(1)
data = p.encode()
bc.read_buf += data
self.assertEqual(len(bc.event_dict), 0)
......@@ -689,7 +698,8 @@ class testConnection(unittest.TestCase):
("127.0.0.1", 2335, getNewUUID()),("127.0.0.1", 2133, getNewUUID()),
("127.0.0.1", 2435, getNewUUID()),("127.0.0.1", 2132, getNewUUID()))
uuid = getNewUUID()
p = protocol.answerPrimaryMaster(1, uuid, master_list)
p = protocol.answerPrimaryMaster(uuid, master_list)
p.setId(1)
data = p.encode()
return data
DoNothingConnector.receive = receive
......@@ -1076,6 +1086,7 @@ class testConnection(unittest.TestCase):
# XXX check locking ???
if __name__ == '__main__':
unittest.main()
......@@ -160,11 +160,11 @@ class testEvent(unittest.TestCase):
self.assertEquals(len(conn.mockGetNamedCalls("getHandler")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("close")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("unlock")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 2)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 0)
# check ping packet sent
call = conn.mockGetNamedCalls("addPacket")[0]
call = conn.mockGetNamedCalls("ask")[0]
packet = call.getParam(0)
self.failUnless(isinstance(packet, Packet))
self.assertEqual(packet.getType(), PING)
......@@ -178,8 +178,8 @@ class testEvent(unittest.TestCase):
self.assertEquals(len(conn.mockGetNamedCalls("getHandler")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("close")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("unlock")), 2)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 2)
self.assertEquals(len(conn.mockGetNamedCalls("addPacket")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("ask")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 1)
# same test with additional time < 5
......
......@@ -61,63 +61,62 @@ class testProtocol(unittest.TestCase):
return uuid
def test_01_Packet_init(self):
p = Packet(msg_id=1, msg_type=ASK_PRIMARY_MASTER, body=None)
self.assertEqual(p.getId(), 1)
p = Packet(msg_type=ASK_PRIMARY_MASTER, body=None)
self.assertEqual(p.getType(), ASK_PRIMARY_MASTER)
self.assertEqual(len(p), PACKET_HEADER_SIZE)
def test_02_error(self):
p = protocol._error(1, 10, "error message")
p = protocol._error(10, "error message")
code, msg = p._decodeError()
self.assertEqual(code, 10)
self.assertEqual(msg, "error message")
def test_03_protocolError(self):
p = protocol.protocolError(1, "bad protocol")
p = protocol.protocolError("bad protocol")
error_code, error_msg = p.decode()
self.assertEqual(error_code, PROTOCOL_ERROR_CODE)
self.assertEqual(error_msg, "protocol error: bad protocol")
def test_04_internalError(self):
p = protocol.internalError(1, "bad internal")
p = protocol.internalError("bad internal")
error_code, error_msg = p.decode()
self.assertEqual(error_code, INTERNAL_ERROR_CODE)
self.assertEqual(error_msg, "internal error: bad internal")
def test_05_notReady(self):
p = protocol.notReady(1, "wait")
p = protocol.notReady("wait")
error_code, error_msg = p.decode()
self.assertEqual(error_code, NOT_READY_CODE)
self.assertEqual(error_msg, "not ready: wait")
def test_06_brokenNodeDisallowedError(self):
p = protocol.brokenNodeDisallowedError(1, "broken")
p = protocol.brokenNodeDisallowedError("broken")
error_code, error_msg = p.decode()
self.assertEqual(error_code, BROKEN_NODE_DISALLOWED_CODE)
self.assertEqual(error_msg, "broken node disallowed error: broken")
def test_07_oidNotFound(self):
p = protocol.oidNotFound(1, "no oid")
p = protocol.oidNotFound("no oid")
error_code, error_msg = p.decode()
self.assertEqual(error_msg, "oid not found: no oid")
def test_08_oidNotFound(self):
p = protocol.tidNotFound(1, "no tid")
p = protocol.tidNotFound("no tid")
error_code, error_msg = p.decode()
self.assertEqual(error_code, TID_NOT_FOUND_CODE)
self.assertEqual(error_msg, "tid not found: no tid")
def test_09_ping(self):
p = protocol.ping(1)
p = protocol.ping()
self.assertEqual(None, p.decode())
def test_10_pong(self):
p = protocol.pong(1)
p = protocol.pong()
self.assertEqual(None, p.decode())
def test_11_requestNodeIdentification(self):
uuid = self.getNewUUID()
p = protocol.requestNodeIdentification(1, CLIENT_NODE_TYPE, uuid,
p = protocol.requestNodeIdentification(CLIENT_NODE_TYPE, uuid,
"127.0.0.1", 9080, "unittest")
node, p_uuid, ip, port, name = p.decode()
self.assertEqual(node, CLIENT_NODE_TYPE)
......@@ -128,7 +127,7 @@ class testProtocol(unittest.TestCase):
def test_12_acceptNodeIdentification(self):
uuid1, uuid2 = self.getNewUUID(), self.getNewUUID()
p = protocol.acceptNodeIdentification(1, CLIENT_NODE_TYPE, uuid1,
p = protocol.acceptNodeIdentification(CLIENT_NODE_TYPE, uuid1,
"127.0.0.1", 9080, 10, 20, uuid2)
node, p_uuid, ip, port, nb_partitions, nb_replicas, your_uuid = p.decode()
self.assertEqual(node, CLIENT_NODE_TYPE)
......@@ -140,7 +139,7 @@ class testProtocol(unittest.TestCase):
self.assertEqual(your_uuid, uuid2)
def test_13_askPrimaryMaster(self):
p = protocol.askPrimaryMaster(1)
p = protocol.askPrimaryMaster()
self.assertEqual(None, p.decode())
def test_14_answerPrimaryMaster(self):
......@@ -151,17 +150,17 @@ class testProtocol(unittest.TestCase):
master_list = [("127.0.0.1", 1, uuid1),
("127.0.0.2", 2, uuid2),
("127.0.0.3", 3, uuid3)]
p = protocol.answerPrimaryMaster(1, uuid, master_list)
p = protocol.answerPrimaryMaster(uuid, master_list)
primary_uuid, p_master_list = p.decode()
self.assertEqual(primary_uuid, uuid)
self.assertEqual(master_list, p_master_list)
def test_15_announcePrimaryMaster(self):
p = protocol.announcePrimaryMaster(1)
p = protocol.announcePrimaryMaster()
self.assertEqual(p.decode(), None)
def test_16_reelectPrimaryMaster(self):
p = protocol.reelectPrimaryMaster(1)
p = protocol.reelectPrimaryMaster()
self.assertEqual(p.decode(), None)
def test_17_notifyNodeInformation(self):
......@@ -172,19 +171,19 @@ class testProtocol(unittest.TestCase):
node_list = [(CLIENT_NODE_TYPE, "127.0.0.1", 1, uuid1, RUNNING_STATE),
(CLIENT_NODE_TYPE, "127.0.0.2", 2, uuid2, DOWN_STATE),
(CLIENT_NODE_TYPE, "127.0.0.3", 3, uuid3, BROKEN_STATE)]
p = protocol.notifyNodeInformation(1, node_list)
p = protocol.notifyNodeInformation(node_list)
p_node_list = p.decode()[0]
self.assertEqual(node_list, p_node_list)
def test_18_askLastIDs(self):
p = protocol.askLastIDs(1)
p = protocol.askLastIDs()
self.assertEqual(p.decode(), None)
def test_19_answerLastIDs(self):
oid = self.getNextTID()
tid = self.getNextTID()
ptid = self.getNextTID()
p = protocol.answerLastIDs(1, oid, tid, ptid)
p = protocol.answerLastIDs(oid, tid, ptid)
loid, ltid, lptid = p.decode()
self.assertEqual(loid, oid)
self.assertEqual(ltid, tid)
......@@ -192,7 +191,7 @@ class testProtocol(unittest.TestCase):
def test_20_askPartitionTable(self):
offset_list = [1, 523, 6, 124]
p = protocol.askPartitionTable(1, offset_list)
p = protocol.askPartitionTable(offset_list)
p_offset_list = p.decode()[0]
self.assertEqual(offset_list, p_offset_list)
......@@ -204,7 +203,7 @@ class testProtocol(unittest.TestCase):
cell_list = [(0, ((uuid1, UP_TO_DATE_STATE), (uuid2, OUT_OF_DATE_STATE))),
(43, ((uuid2, OUT_OF_DATE_STATE),(uuid3, DISCARDED_STATE))),
(124, ((uuid1, DISCARDED_STATE), (uuid3, UP_TO_DATE_STATE)))]
p = protocol.answerPartitionTable(1, ptid, cell_list)
p = protocol.answerPartitionTable(ptid, cell_list)
pptid, p_cell_list = p.decode()
self.assertEqual(pptid, ptid)
self.assertEqual(p_cell_list, cell_list)
......@@ -217,7 +216,7 @@ class testProtocol(unittest.TestCase):
cell_list = [(0, ((uuid1, UP_TO_DATE_STATE), (uuid2, OUT_OF_DATE_STATE))),
(43, ((uuid2, OUT_OF_DATE_STATE),(uuid3, DISCARDED_STATE))),
(124, ((uuid1, DISCARDED_STATE), (uuid3, UP_TO_DATE_STATE)))]
p = protocol.answerPartitionTable(1, ptid, cell_list)
p = protocol.answerPartitionTable(ptid, cell_list)
pptid, p_cell_list = p.decode()
self.assertEqual(pptid, ptid)
self.assertEqual(p_cell_list, cell_list)
......@@ -230,22 +229,22 @@ class testProtocol(unittest.TestCase):
cell_list = [(0, uuid1, UP_TO_DATE_STATE),
(43, uuid2, OUT_OF_DATE_STATE),
(124, uuid1, DISCARDED_STATE)]
p = protocol.notifyPartitionChanges(1, ptid,
p = protocol.notifyPartitionChanges(ptid,
cell_list)
pptid, p_cell_list = p.decode()
self.assertEqual(pptid, ptid)
self.assertEqual(p_cell_list, cell_list)
def test_24_startOperation(self):
p = protocol.startOperation(1)
p = protocol.startOperation()
self.assertEqual(p.decode(), None)
def test_25_stopOperation(self):
p = protocol.stopOperation(1)
p = protocol.stopOperation()
self.assertEqual(p.decode(), None)
def test_26_askUnfinishedTransaction(self):
p = protocol.askUnfinishedTransactions(1)
p = protocol.askUnfinishedTransactions()
self.assertEqual(p.decode(), None)
def test_27_answerUnfinishedTransaction(self):
......@@ -254,14 +253,14 @@ class testProtocol(unittest.TestCase):
tid3 = self.getNextTID()
tid4 = self.getNextTID()
tid_list = [tid1, tid2, tid3, tid4]
p = protocol.answerUnfinishedTransactions(1,tid_list)
p = protocol.answerUnfinishedTransactions(tid_list)
p_tid_list = p.decode()[0]
self.assertEqual(p_tid_list, tid_list)
def test_28_askObjectPresent(self):
oid = self.getNextTID()
tid = self.getNextTID()
p = protocol.askObjectPresent(1, oid, tid)
p = protocol.askObjectPresent(oid, tid)
loid, ltid = p.decode()
self.assertEqual(loid, oid)
self.assertEqual(ltid, tid)
......@@ -269,38 +268,37 @@ class testProtocol(unittest.TestCase):
def test_29_answerObjectPresent(self):
oid = self.getNextTID()
tid = self.getNextTID()
p = protocol.answerObjectPresent(1, oid, tid)
p = protocol.answerObjectPresent(oid, tid)
loid, ltid = p.decode()
self.assertEqual(loid, oid)
self.assertEqual(ltid, tid)
def test_30_deleteTransaction(self):
tid = self.getNextTID()
p = protocol.deleteTransaction(1, tid)
self.assertEqual(p.getId(), 1)
p = protocol.deleteTransaction(tid)
self.assertEqual(p.getType(), DELETE_TRANSACTION)
ptid = p.decode()[0]
self.assertEqual(ptid, tid)
def test_31_commitTransaction(self):
tid = self.getNextTID()
p = protocol.commitTransaction(1, tid)
p = protocol.commitTransaction(tid)
ptid = p.decode()[0]
self.assertEqual(ptid, tid)
def test_32_askNewTID(self):
p = protocol.askNewTID(1)
p = protocol.askNewTID()
self.assertEqual(p.decode(), None)
def test_33_answerNewTID(self):
tid = self.getNextTID()
p = protocol.answerNewTID(1, tid)
p = protocol.answerNewTID(tid)
ptid = p.decode()[0]
self.assertEqual(ptid, tid)
def test_34_askNewOIDs(self):
p = protocol.askNewOIDs(1, 10)
p = protocol.askNewOIDs(10)
nb = p.decode()
self.assertEqual(nb, (10,))
......@@ -310,7 +308,7 @@ class testProtocol(unittest.TestCase):
oid3 = self.getNextTID()
oid4 = self.getNextTID()
oid_list = [oid1, oid2, oid3, oid4]
p = protocol.answerNewOIDs(1,oid_list)
p = protocol.answerNewOIDs(oid_list)
p_oid_list = p.decode()[0]
self.assertEqual(p_oid_list, oid_list)
......@@ -321,26 +319,26 @@ class testProtocol(unittest.TestCase):
oid4 = self.getNextTID()
tid = self.getNextTID()
oid_list = [oid1, oid2, oid3, oid4]
p = protocol.finishTransaction(1,oid_list, tid)
p = protocol.finishTransaction(oid_list, tid)
p_oid_list, ptid = p.decode()
self.assertEqual(ptid, tid)
self.assertEqual(p_oid_list, oid_list)
def test_37_notifyTransactionFinished(self):
tid = self.getNextTID()
p = protocol.notifyTransactionFinished(1, tid)
p = protocol.notifyTransactionFinished(tid)
ptid = p.decode()[0]
self.assertEqual(ptid, tid)
def test_38_lockInformation(self):
tid = self.getNextTID()
p = protocol.lockInformation(1, tid)
p = protocol.lockInformation(tid)
ptid = p.decode()[0]
self.assertEqual(ptid, tid)
def test_39_notifyInformationLocked(self):
tid = self.getNextTID()
p = protocol.notifyInformationLocked(1, tid)
p = protocol.notifyInformationLocked(tid)
ptid = p.decode()[0]
self.assertEqual(ptid, tid)
......@@ -351,20 +349,20 @@ class testProtocol(unittest.TestCase):
oid4 = self.getNextTID()
tid = self.getNextTID()
oid_list = [oid1, oid2, oid3, oid4]
p = protocol.invalidateObjects(1,oid_list, tid)
p = protocol.invalidateObjects(oid_list, tid)
p_oid_list, ptid = p.decode()
self.assertEqual(ptid, tid)
self.assertEqual(p_oid_list, oid_list)
def test_41_unlockInformation(self):
tid = self.getNextTID()
p = protocol.unlockInformation(1, tid)
p = protocol.unlockInformation(tid)
ptid = p.decode()[0]
self.assertEqual(ptid, tid)
def test_42_abortTransaction(self):
tid = self.getNextTID()
p = protocol.abortTransaction(1, tid)
p = protocol.abortTransaction(tid)
ptid = p.decode()[0]
self.assertEqual(ptid, tid)
......@@ -375,7 +373,7 @@ class testProtocol(unittest.TestCase):
oid3 = self.getNextTID()
oid4 = self.getNextTID()
oid_list = [oid1, oid2, oid3, oid4]
p = protocol.askStoreTransaction(1, tid, "moi", "transaction", "exti", oid_list)
p = protocol.askStoreTransaction(tid, "moi", "transaction", "exti", oid_list)
ptid, user, desc, ext, p_oid_list = p.decode()
self.assertEqual(ptid, tid)
self.assertEqual(p_oid_list, oid_list)
......@@ -385,7 +383,7 @@ class testProtocol(unittest.TestCase):
def test_44_answerStoreTransaction(self):
tid = self.getNextTID()
p = protocol.answerStoreTransaction(1, tid)
p = protocol.answerStoreTransaction(tid)
ptid = p.decode()[0]
self.assertEqual(ptid, tid)
......@@ -393,7 +391,7 @@ class testProtocol(unittest.TestCase):
oid = self.getNextTID()
serial = self.getNextTID()
tid = self.getNextTID()
p = protocol.askStoreObject(1, oid, serial, 1, 55, "to", tid)
p = protocol.askStoreObject(oid, serial, 1, 55, "to", tid)
poid, pserial, compression, checksum, data, ptid = p.decode()
self.assertEqual(oid, poid)
self.assertEqual(serial, pserial)
......@@ -405,7 +403,7 @@ class testProtocol(unittest.TestCase):
def test_46_answerStoreObject(self):
oid = self.getNextTID()
serial = self.getNextTID()
p = protocol.answerStoreObject(1, 1, oid, serial)
p = protocol.answerStoreObject(1, oid, serial)
conflicting, poid, pserial = p.decode()
self.assertEqual(oid, poid)
self.assertEqual(serial, pserial)
......@@ -415,7 +413,7 @@ class testProtocol(unittest.TestCase):
oid = self.getNextTID()
serial = self.getNextTID()
tid = self.getNextTID()
p = protocol.askObject(1, oid, serial, tid)
p = protocol.askObject(oid, serial, tid)
poid, pserial, ptid = p.decode()
self.assertEqual(oid, poid)
self.assertEqual(serial, pserial)
......@@ -425,7 +423,7 @@ class testProtocol(unittest.TestCase):
oid = self.getNextTID()
serial_start = self.getNextTID()
serial_end = self.getNextTID()
p = protocol.answerObject(1, oid, serial_start, serial_end, 1, 55, "to",)
p = protocol.answerObject(oid, serial_start, serial_end, 1, 55, "to",)
poid, pserial_start, pserial_end, compression, checksum, data= p.decode()
self.assertEqual(oid, poid)
self.assertEqual(serial_start, pserial_start)
......@@ -435,7 +433,7 @@ class testProtocol(unittest.TestCase):
self.assertEqual(data, "to")
def test_49_askTIDs(self):
p = protocol.askTIDs(1, 1, 10, 5)
p = protocol.askTIDs(1, 10, 5)
first, last, partition = p.decode()
self.assertEqual(first, 1)
self.assertEqual(last, 10)
......@@ -447,13 +445,13 @@ class testProtocol(unittest.TestCase):
tid3 = self.getNextTID()
tid4 = self.getNextTID()
tid_list = [tid1, tid2, tid3, tid4]
p = protocol.answerTIDs(1,tid_list)
p = protocol.answerTIDs(tid_list)
p_tid_list = p.decode()[0]
self.assertEqual(p_tid_list, tid_list)
def test_51_askTransactionInfomation(self):
tid = self.getNextTID()
p = protocol.askTransactionInformation(1, tid)
p = protocol.askTransactionInformation(tid)
ptid = p.decode()[0]
self.assertEqual(tid, ptid)
......@@ -464,7 +462,7 @@ class testProtocol(unittest.TestCase):
oid3 = self.getNextTID()
oid4 = self.getNextTID()
oid_list = [oid1, oid2, oid3, oid4]
p = protocol.answerTransactionInformation(1, tid, "moi",
p = protocol.answerTransactionInformation(tid, "moi",
"transaction", "exti", oid_list)
ptid, user, desc, ext, p_oid_list = p.decode()
self.assertEqual(ptid, tid)
......@@ -475,7 +473,7 @@ class testProtocol(unittest.TestCase):
def test_53_askObjectHistory(self):
oid = self.getNextTID()
p = protocol.askObjectHistory(1, oid, 1, 10,)
p = protocol.askObjectHistory(oid, 1, 10,)
poid, first, last = p.decode()
self.assertEqual(first, 1)
self.assertEqual(last, 10)
......@@ -488,13 +486,13 @@ class testProtocol(unittest.TestCase):
hist3 = (self.getNextTID(), 326)
hist4 = (self.getNextTID(), 652)
hist_list = [hist1, hist2, hist3, hist4]
p = protocol.answerObjectHistory(1, oid, hist_list)
p = protocol.answerObjectHistory(oid, hist_list)
poid, p_hist_list = p.decode()
self.assertEqual(p_hist_list, hist_list)
self.assertEqual(oid, poid)
def test_55_askOIDs(self):
p = protocol.askOIDs(1, 1, 10, 5)
p = protocol.askOIDs(1, 10, 5)
first, last, partition = p.decode()
self.assertEqual(first, 1)
self.assertEqual(last, 10)
......@@ -506,7 +504,7 @@ class testProtocol(unittest.TestCase):
oid3 = self.getNextTID()
oid4 = self.getNextTID()
oid_list = [oid1, oid2, oid3, oid4]
p = protocol.answerOIDs(1,oid_list)
p = protocol.answerOIDs(oid_list)
p_oid_list = p.decode()[0]
self.assertEqual(p_oid_list, oid_list)
......
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