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