Commit 5f4ba33b authored by Grégory Wisniewski's avatar Grégory Wisniewski

Update client application and handlers tests according to previous commit. Some

checks added for changes included with previous commit, but it might be better
to split the test class too.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@477 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent d1226479
...@@ -19,7 +19,7 @@ import unittest ...@@ -19,7 +19,7 @@ import unittest
import logging import logging
from mock import Mock, ReturnValues, ReturnIterator from mock import Mock, ReturnValues, ReturnIterator
from ZODB.POSException import StorageTransactionError, UndoError, ConflictError from ZODB.POSException import StorageTransactionError, UndoError, ConflictError
from neo.protocol import INVALID_UUID from neo.protocol import INVALID_UUID, ERROR
from neo.client.app import Application from neo.client.app import Application
from neo.protocol import Packet from neo.protocol import Packet
from neo.client.exception import NEOStorageError, NEOStorageNotFoundError, \ from neo.client.exception import NEOStorageError, NEOStorageNotFoundError, \
...@@ -35,10 +35,11 @@ def connectToPrimaryMasterNode(self): ...@@ -35,10 +35,11 @@ def connectToPrimaryMasterNode(self):
Application.connectToPrimaryMasterNode_org = Application.connectToPrimaryMasterNode Application.connectToPrimaryMasterNode_org = Application.connectToPrimaryMasterNode
Application.connectToPrimaryMasterNode = connectToPrimaryMasterNode Application.connectToPrimaryMasterNode = connectToPrimaryMasterNode
def _waitMessage(self, conn=None, msg_id=None): def _waitMessage(self, conn=None, msg_id=None, handler=None):
if conn is None: if conn is not None and handler is not None:
handler.dispatch(conn, conn.fakeReceived())
else:
raise NotImplementedError raise NotImplementedError
self.answer_handler.dispatch(conn, conn.fakeReceived())
Application._waitMessage_org = Application._waitMessage Application._waitMessage_org = Application._waitMessage
Application._waitMessage = _waitMessage Application._waitMessage = _waitMessage
...@@ -509,6 +510,7 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -509,6 +510,7 @@ class ClientApplicationTest(unittest.TestCase):
conn = Mock({ conn = Mock({
'getNextId': 1, 'getNextId': 1,
'fakeReceived': packet, 'fakeReceived': packet,
'getAddress': ('127.0.0.1', 0),
}) })
cell = Mock({ cell = Mock({
'getServer': 'FakeServer', 'getServer': 'FakeServer',
...@@ -519,9 +521,15 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -519,9 +521,15 @@ class ClientApplicationTest(unittest.TestCase):
app.dispatcher = Mock() app.dispatcher = Mock()
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.checkPacketSent(conn, 1, ASK_STORE_TRANSACTION) self.assertEquals(len(conn.mockGetNamedCalls('abort')), 1)
self.checkMessageExpected(conn, 1) calls = conn.mockGetNamedCalls('addPacket')
self.checkDispatcherRegisterCalled(app, conn, 1) self.assertEquals(len(calls), 2)
packet = calls[0].getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet._type, ASK_STORE_TRANSACTION)
packet = calls[1].getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet._type, ERROR)
def test_tpc_vote3(self): def test_tpc_vote3(self):
app = self.getApp() app = self.getApp()
...@@ -784,7 +792,7 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -784,7 +792,7 @@ class ClientApplicationTest(unittest.TestCase):
'getCellList': ReturnValues([cell1], [cell2]), 'getCellList': ReturnValues([cell1], [cell2]),
}) })
app.cp = Mock({ 'getConnForNode': conn}) app.cp = Mock({ 'getConnForNode': conn})
def _waitMessage(self, conn=None, msg_id=None): def _waitMessage(self, conn=None, msg_id=None, handler=None):
self.local_var.node_tids = {uuid1: (tid1, ), uuid2: (tid2, )} self.local_var.node_tids = {uuid1: (tid1, ), uuid2: (tid2, )}
Application._waitMessage = _waitMessage_old Application._waitMessage = _waitMessage_old
_waitMessage_old = Application._waitMessage _waitMessage_old = Application._waitMessage
...@@ -841,22 +849,22 @@ class ClientApplicationTest(unittest.TestCase): ...@@ -841,22 +849,22 @@ class ClientApplicationTest(unittest.TestCase):
# will raise IndexError at the third iteration # will raise IndexError at the third iteration
app = self.getApp('127.0.0.1:10010 127.0.0.1:10011') app = self.getApp('127.0.0.1:10010 127.0.0.1:10011')
# third iteration : node not ready # third iteration : node not ready
def _waitMessage4(app, conn=None, msg_id=None): def _waitMessage4(app, conn=None, msg_id=None, handler=None):
app.local_var.node_ready = False app.local_var.node_ready = False
self.all_passed = True self.all_passed = True
# second iteration : master node changed # second iteration : master node changed
def _waitMessage3(app, conn=None, msg_id=None): def _waitMessage3(app, conn=None, msg_id=None, handler=None):
app.primary_master_node = Mock({ app.primary_master_node = Mock({
'getServer': ('192.168.1.1', 10000), 'getServer': ('192.168.1.1', 10000),
'__str__': 'Fake master node', '__str__': 'Fake master node',
}) })
Application._waitMessage = _waitMessage4 Application._waitMessage = _waitMessage4
# first iteration : connection failed # first iteration : connection failed
def _waitMessage2(app, conn=None, msg_id=None): def _waitMessage2(app, conn=None, msg_id=None, handler=None):
app.primary_master_node = -1 app.primary_master_node = -1
Application._waitMessage = _waitMessage3 Application._waitMessage = _waitMessage3
# do nothing for the first call # do nothing for the first call
def _waitMessage1(app, conn=None, msg_id=None): def _waitMessage1(app, conn=None, msg_id=None, handler=None):
Application._waitMessage = _waitMessage2 Application._waitMessage = _waitMessage2
_waitMessage_old = Application._waitMessage _waitMessage_old = Application._waitMessage
Application._waitMessage = _waitMessage1 Application._waitMessage = _waitMessage1
......
...@@ -34,7 +34,7 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF ...@@ -34,7 +34,7 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF
ABORT_TRANSACTION, ASK_STORE_TRANSACTION, ANSWER_STORE_TRANSACTION, \ ABORT_TRANSACTION, ASK_STORE_TRANSACTION, ANSWER_STORE_TRANSACTION, \
ASK_OBJECT, ANSWER_OBJECT, ASK_TIDS, ANSWER_TIDS, ASK_TRANSACTION_INFORMATION, \ ASK_OBJECT, ANSWER_OBJECT, ASK_TIDS, ANSWER_TIDS, ASK_TRANSACTION_INFORMATION, \
ANSWER_TRANSACTION_INFORMATION, ASK_OBJECT_HISTORY, ANSWER_OBJECT_HISTORY, \ ANSWER_TRANSACTION_INFORMATION, ASK_OBJECT_HISTORY, ANSWER_OBJECT_HISTORY, \
ASK_OIDS, ANSWER_OIDS, \ ASK_OIDS, ANSWER_OIDS, INVALID_PTID, \
NOT_READY_CODE, OID_NOT_FOUND_CODE, SERIAL_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \ NOT_READY_CODE, OID_NOT_FOUND_CODE, SERIAL_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \
PROTOCOL_ERROR_CODE, TIMEOUT_ERROR_CODE, BROKEN_NODE_DISALLOWED_CODE, \ PROTOCOL_ERROR_CODE, TIMEOUT_ERROR_CODE, BROKEN_NODE_DISALLOWED_CODE, \
INTERNAL_ERROR_CODE, \ INTERNAL_ERROR_CODE, \
...@@ -42,12 +42,29 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF ...@@ -42,12 +42,29 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \ RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import ElectionFailure from neo.exception import ElectionFailure
from neo.client.handler import BaseClientEventHandler, PrimaryBoostrapEventHandler, \
from neo.client.handler import ClientEventHandler, ClientAnswerEventHandler PrimaryEventHandler, StorageBootstrapEventHandler, StorageEventHandler
from neo.node import StorageNode from neo.node import StorageNode
MARKER = [] MARKER = []
class BaseClientEventHandlerTest(unittest.TestCase):
def setUp(self):
dispatcher = Mock({'getQueue': queue, 'connectToPrimaryMasterNode': None})
self.handler = BaseClientEventHandler(dispatcher)
def getConnection(self, uuid=None, port=10010, next_id=None, ip='127.0.0.1'):
if uuid is None:
uuid = self.getUUID()
return Mock({'addPacket': None,
'getUUID': uuid,
'getAddress': (ip, port),
'getNextId': next_id,
'lock': None,
'unlock': None})
class ClientEventHandlerTest(unittest.TestCase): class ClientEventHandlerTest(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -80,7 +97,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -80,7 +97,7 @@ class ClientEventHandlerTest(unittest.TestCase):
packet. packet.
""" """
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = ClientEventHandler(None, dispatcher) client_handler = BaseClientEventHandler(None, dispatcher)
conn = self.getConnection() conn = self.getConnection()
client_handler.packetReceived(conn, Packet().ping(1)) client_handler.packetReceived(conn, Packet().ping(1))
pong = conn.mockGetNamedCalls('addPacket')[0].getParam(0) pong = conn.mockGetNamedCalls('addPacket')[0].getParam(0)
...@@ -91,23 +108,23 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -91,23 +108,23 @@ class ClientEventHandlerTest(unittest.TestCase):
class App: class App:
primary_master_node = None primary_master_node = None
app = App() app = App()
method(self.getDispatcher(), app) method(self.getDispatcher(), app, PrimaryBoostrapEventHandler)
self.assertEqual(app.primary_master_node, -1) self.assertEqual(app.primary_master_node, -1)
def _testMasterWithMethod(self, method): def _testMasterWithMethod(self, method, handler_class):
uuid = self.getUUID() uuid = self.getUUID()
app = Mock({'connectToPrimaryMasterNode': None}) app = Mock({'connectToPrimaryMasterNode': None})
app.primary_master_node = Mock({'getUUID': uuid}) app.primary_master_node = Mock({'getUUID': uuid})
app.master_conn = Mock({'close': None, 'getUUID': uuid}) app.master_conn = Mock({'close': None, 'getUUID': uuid})
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
method(dispatcher, app, uuid=uuid) method(dispatcher, app, handler_class, uuid=uuid)
# XXX: should connection closure be tested ? It's not implemented in all cases # XXX: should connection closure be tested ? It's not implemented in all cases
#self.assertEquals(len(App.master_conn.mockGetNamedCalls('close')), 1) #self.assertEquals(len(App.master_conn.mockGetNamedCalls('close')), 1)
#self.assertEquals(app.master_conn, None) #self.assertEquals(app.master_conn, None)
#self.assertEquals(app.primary_master_node, None) #self.assertEquals(app.primary_master_node, None)
self.assertEquals(len(app.mockGetNamedCalls('connectToPrimaryMasterNode')), 1) self.assertEquals(len(app.mockGetNamedCalls('connectToPrimaryMasterNode')), 1)
def _testStorageWithMethod(self, method, state=TEMPORARILY_DOWN_STATE): def _testStorageWithMethod(self, method, handler_class, state=TEMPORARILY_DOWN_STATE):
storage_ip = '127.0.0.1' storage_ip = '127.0.0.1'
storage_port = 10011 storage_port = 10011
fake_storage_node_uuid = self.getUUID() fake_storage_node_uuid = self.getUUID()
...@@ -129,7 +146,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -129,7 +146,7 @@ class ClientEventHandlerTest(unittest.TestCase):
message_table = {key_1: queue_1, message_table = {key_1: queue_1,
key_2: queue_2} key_2: queue_2}
dispatcher = Dispatcher() dispatcher = Dispatcher()
method(dispatcher, app, 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('addPacket')
# Test sanity check # Test sanity check
...@@ -154,8 +171,8 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -154,8 +171,8 @@ class ClientEventHandlerTest(unittest.TestCase):
self.assertEqual(queue_1_put_call_list[0].getParam(0), (conn, None)) self.assertEqual(queue_1_put_call_list[0].getParam(0), (conn, None))
self.assertEqual(len(queue_2.mockGetNamedCalls('put')), 0) self.assertEqual(len(queue_2.mockGetNamedCalls('put')), 0)
def _testConnectionFailed(self, dispatcher, app, uuid=None, conn=None): def _testConnectionFailed(self, dispatcher, app, handler_class, uuid=None, conn=None):
client_handler = ClientEventHandler(app, dispatcher) client_handler = handler_class(app, dispatcher)
if conn is None: if conn is None:
conn = self.getConnection(uuid=uuid) conn = self.getConnection(uuid=uuid)
client_handler.connectionFailed(conn) client_handler.connectionFailed(conn)
...@@ -163,14 +180,12 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -163,14 +180,12 @@ class ClientEventHandlerTest(unittest.TestCase):
def test_initialMasterConnectionFailed(self): def test_initialMasterConnectionFailed(self):
self._testInitialMasterWithMethod(self._testConnectionFailed) self._testInitialMasterWithMethod(self._testConnectionFailed)
def test_masterConnectionFailed(self):
self._testMasterWithMethod(self._testConnectionFailed)
def test_storageConnectionFailed(self): def test_storageConnectionFailed(self):
self._testStorageWithMethod(self._testConnectionFailed) self._testStorageWithMethod(self._testConnectionFailed,
StorageBootstrapEventHandler)
def _testConnectionClosed(self, dispatcher, app, uuid=None, conn=None): def _testConnectionClosed(self, dispatcher, app, handler_class, uuid=None, conn=None):
client_handler = ClientEventHandler(app, dispatcher) client_handler = handler_class(app, dispatcher)
if conn is None: if conn is None:
conn = self.getConnection(uuid=uuid) conn = self.getConnection(uuid=uuid)
client_handler.connectionClosed(conn) client_handler.connectionClosed(conn)
...@@ -179,13 +194,17 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -179,13 +194,17 @@ class ClientEventHandlerTest(unittest.TestCase):
self._testInitialMasterWithMethod(self._testConnectionClosed) self._testInitialMasterWithMethod(self._testConnectionClosed)
def test_masterConnectionClosed(self): def test_masterConnectionClosed(self):
self._testMasterWithMethod(self._testConnectionClosed) self._testMasterWithMethod(self._testConnectionClosed,
PrimaryEventHandler)
def test_storageConnectionClosed(self): def test_storageConnectionClosed(self):
self._testStorageWithMethod(self._testConnectionClosed) self._testStorageWithMethod(self._testConnectionClosed,
StorageBootstrapEventHandler)
self._testStorageWithMethod(self._testConnectionClosed,
StorageEventHandler)
def _testTimeoutExpired(self, dispatcher, app, uuid=None, conn=None): def _testTimeoutExpired(self, dispatcher, app, handler_class, uuid=None, conn=None):
client_handler = ClientEventHandler(app, dispatcher) client_handler = handler_class(app, dispatcher)
if conn is None: if conn is None:
conn = self.getConnection(uuid=uuid) conn = self.getConnection(uuid=uuid)
client_handler.timeoutExpired(conn) client_handler.timeoutExpired(conn)
...@@ -194,13 +213,16 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -194,13 +213,16 @@ class ClientEventHandlerTest(unittest.TestCase):
self._testInitialMasterWithMethod(self._testTimeoutExpired) self._testInitialMasterWithMethod(self._testTimeoutExpired)
def test_masterTimeoutExpired(self): def test_masterTimeoutExpired(self):
self._testMasterWithMethod(self._testTimeoutExpired) self._testMasterWithMethod(self._testTimeoutExpired, PrimaryEventHandler)
def test_storageTimeoutExpired(self): def test_storageTimeoutExpired(self):
self._testStorageWithMethod(self._testTimeoutExpired) self._testStorageWithMethod(self._testTimeoutExpired,
StorageEventHandler)
self._testStorageWithMethod(self._testTimeoutExpired,
StorageBootstrapEventHandler)
def _testPeerBroken(self, dispatcher, app, uuid=None, conn=None): def _testPeerBroken(self, dispatcher, app, handler_class, uuid=None, conn=None):
client_handler = ClientEventHandler(app, dispatcher) client_handler = handler_class(app, dispatcher)
if conn is None: if conn is None:
conn = self.getConnection(uuid=uuid) conn = self.getConnection(uuid=uuid)
client_handler.peerBroken(conn) client_handler.peerBroken(conn)
...@@ -209,18 +231,24 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -209,18 +231,24 @@ class ClientEventHandlerTest(unittest.TestCase):
self._testInitialMasterWithMethod(self._testPeerBroken) self._testInitialMasterWithMethod(self._testPeerBroken)
def test_masterPeerBroken(self): def test_masterPeerBroken(self):
self._testMasterWithMethod(self._testPeerBroken) self._testMasterWithMethod(self._testPeerBroken, PrimaryEventHandler)
def test_storagePeerBroken(self): def test_storagePeerBroken(self):
self._testStorageWithMethod(self._testPeerBroken, state=BROKEN_STATE) self._testStorageWithMethod(self._testPeerBroken,
StorageBootstrapEventHandler, state=BROKEN_STATE)
self._testStorageWithMethod(self._testPeerBroken,
StorageEventHandler, state=BROKEN_STATE)
def test_notReady(self): def test_notReady(self):
app = Mock({'setNodeNotReady': None}) app = Mock({'setNodeNotReady': None})
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = ClientAnswerEventHandler(app, dispatcher) client_handler = PrimaryBoostrapEventHandler(app, dispatcher)
conn = self.getConnection() conn = self.getConnection()
client_handler.handleNotReady(conn, None, None) client_handler.handleNotReady(conn, None, None)
self.assertEquals(len(app.mockGetNamedCalls('setNodeNotReady')), 1) self.assertEquals(len(app.mockGetNamedCalls('setNodeNotReady')), 1)
client_handler = StorageBootstrapEventHandler(app, dispatcher)
client_handler.handleNotReady(conn, None, None)
self.assertEquals(len(app.mockGetNamedCalls('setNodeNotReady')), 2)
def test_clientAcceptNodeIdentification(self): def test_clientAcceptNodeIdentification(self):
class App: class App:
...@@ -229,7 +257,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -229,7 +257,7 @@ class ClientEventHandlerTest(unittest.TestCase):
pt = None pt = None
app = App() app = App()
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = ClientAnswerEventHandler(app, dispatcher) client_handler = PrimaryBoostrapEventHandler(app, dispatcher)
conn = self.getConnection() conn = self.getConnection()
uuid = self.getUUID() uuid = self.getUUID()
app.uuid = 'C' * 16 app.uuid = 'C' * 16
...@@ -252,7 +280,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -252,7 +280,7 @@ class ClientEventHandlerTest(unittest.TestCase):
return None return None
app = App() app = App()
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = ClientAnswerEventHandler(app, dispatcher) client_handler = PrimaryBoostrapEventHandler(app, dispatcher)
conn = self.getConnection() conn = self.getConnection()
uuid = self.getUUID() uuid = self.getUUID()
your_uuid = 'C' * 16 your_uuid = 'C' * 16
...@@ -280,7 +308,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -280,7 +308,7 @@ class ClientEventHandlerTest(unittest.TestCase):
return None return None
app = App() app = App()
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = ClientAnswerEventHandler(app, dispatcher) client_handler = StorageBootstrapEventHandler(app, dispatcher)
conn = self.getConnection() conn = self.getConnection()
uuid = self.getUUID() uuid = self.getUUID()
app.uuid = 'C' * 16 app.uuid = 'C' * 16
...@@ -292,7 +320,6 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -292,7 +320,6 @@ class ClientEventHandlerTest(unittest.TestCase):
setUUID_call_list = node.mockGetNamedCalls('setUUID') setUUID_call_list = node.mockGetNamedCalls('setUUID')
self.assertEquals(len(setUUID_call_list), 1) self.assertEquals(len(setUUID_call_list), 1)
self.assertEquals(setUUID_call_list[0].getParam(0), uuid) self.assertEquals(setUUID_call_list[0].getParam(0), uuid)
self.assertTrue(app.storage_node is node)
self.assertEquals(app.pt, None) self.assertEquals(app.pt, None)
self.assertEquals(app.uuid, 'C' * 16) self.assertEquals(app.uuid, 'C' * 16)
...@@ -315,7 +342,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -315,7 +342,7 @@ class ClientEventHandlerTest(unittest.TestCase):
# Master node handler # Master node handler
def test_initialAnswerPrimaryMaster(self): def test_initialAnswerPrimaryMaster(self):
client_handler = ClientAnswerEventHandler(None, self.getDispatcher()) client_handler = PrimaryBoostrapEventHandler(None, self.getDispatcher())
conn = Mock({'getUUID': None}) conn = Mock({'getUUID': None})
call_list = self._testHandleUnexpectedPacketCalledWithMedhod( call_list = self._testHandleUnexpectedPacketCalledWithMedhod(
client_handler, client_handler.handleAnswerPrimaryMaster, client_handler, client_handler.handleAnswerPrimaryMaster,
...@@ -330,7 +357,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -330,7 +357,7 @@ class ClientEventHandlerTest(unittest.TestCase):
class App: class App:
nm = Mock({'getNodeByUUID': node, 'getNodeByServer': None, 'add': None}) nm = Mock({'getNodeByUUID': node, 'getNodeByServer': None, 'add': None})
app = App() app = App()
client_handler = ClientAnswerEventHandler(app, self.getDispatcher()) client_handler = PrimaryBoostrapEventHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
client_handler.handleAnswerPrimaryMaster(conn, None, 0, []) client_handler.handleAnswerPrimaryMaster(conn, None, 0, [])
# Check that nothing happened # Check that nothing happened
...@@ -343,7 +370,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -343,7 +370,7 @@ class ClientEventHandlerTest(unittest.TestCase):
nm = Mock({'getNodeByUUID': node, 'getNodeByServer': None, 'add': None}) nm = Mock({'getNodeByUUID': node, 'getNodeByServer': None, 'add': None})
primary_master_node = None primary_master_node = None
app = App() app = App()
client_handler = ClientAnswerEventHandler(app, self.getDispatcher()) client_handler = PrimaryBoostrapEventHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
test_master_list = [('127.0.0.1', 10010, self.getUUID())] test_master_list = [('127.0.0.1', 10010, self.getUUID())]
client_handler.handleAnswerPrimaryMaster(conn, None, INVALID_UUID, test_master_list) client_handler.handleAnswerPrimaryMaster(conn, None, INVALID_UUID, test_master_list)
...@@ -372,7 +399,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -372,7 +399,7 @@ class ClientEventHandlerTest(unittest.TestCase):
nm = Mock({'getNodeByUUID': node, 'getNodeByServer': node, 'add': None}) nm = Mock({'getNodeByUUID': node, 'getNodeByServer': node, 'add': None})
primary_master_node = None primary_master_node = None
app = App() app = App()
client_handler = ClientAnswerEventHandler(app, self.getDispatcher()) client_handler = PrimaryBoostrapEventHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
test_node_uuid = self.getUUID() test_node_uuid = self.getUUID()
test_master_list = [('127.0.0.1', 10010, test_node_uuid)] test_master_list = [('127.0.0.1', 10010, test_node_uuid)]
...@@ -404,7 +431,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -404,7 +431,7 @@ class ClientEventHandlerTest(unittest.TestCase):
nm = Mock({'getNodeByUUID': node, 'getNodeByServer': node, 'add': None}) nm = Mock({'getNodeByUUID': node, 'getNodeByServer': node, 'add': None})
primary_master_node = None primary_master_node = None
app = App() app = App()
client_handler = ClientAnswerEventHandler(app, self.getDispatcher()) client_handler = PrimaryBoostrapEventHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
test_master_list = [('127.0.0.1', 10010, test_node_uuid)] test_master_list = [('127.0.0.1', 10010, test_node_uuid)]
client_handler.handleAnswerPrimaryMaster(conn, None, INVALID_UUID, test_master_list) client_handler.handleAnswerPrimaryMaster(conn, None, INVALID_UUID, test_master_list)
...@@ -442,7 +469,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -442,7 +469,7 @@ class ClientEventHandlerTest(unittest.TestCase):
nm = Mock({'getNodeByUUID': node, 'getNodeByServer': node, 'add': None}) nm = Mock({'getNodeByUUID': node, 'getNodeByServer': node, 'add': None})
primary_master_node = test_primary_master_node primary_master_node = test_primary_master_node
app = App() app = App()
client_handler = ClientAnswerEventHandler(app, self.getDispatcher()) client_handler = PrimaryBoostrapEventHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
# If primary master is already set *and* is not given primary master # If primary master is already set *and* is not given primary master
# handle call raises. # handle call raises.
...@@ -463,7 +490,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -463,7 +490,7 @@ class ClientEventHandlerTest(unittest.TestCase):
nm = Mock({'getNodeByUUID': node, 'getNodeByServer': node, 'add': None}) nm = Mock({'getNodeByUUID': node, 'getNodeByServer': node, 'add': None})
primary_master_node = node primary_master_node = node
app = App() app = App()
client_handler = ClientAnswerEventHandler(app, self.getDispatcher()) client_handler = PrimaryBoostrapEventHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
client_handler.handleAnswerPrimaryMaster(conn, None, test_node_uuid, []) client_handler.handleAnswerPrimaryMaster(conn, None, test_node_uuid, [])
# Check that primary node is (still) node. # Check that primary node is (still) node.
...@@ -479,7 +506,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -479,7 +506,7 @@ class ClientEventHandlerTest(unittest.TestCase):
nm = Mock({'getNodeByUUID': ReturnValues(node, None), 'getNodeByServer': node, 'add': None}) nm = Mock({'getNodeByUUID': ReturnValues(node, None), 'getNodeByServer': node, 'add': None})
primary_master_node = None primary_master_node = None
app = App() app = App()
client_handler = ClientAnswerEventHandler(app, self.getDispatcher()) client_handler = PrimaryBoostrapEventHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
client_handler.handleAnswerPrimaryMaster(conn, None, test_primary_node_uuid, []) client_handler.handleAnswerPrimaryMaster(conn, None, test_primary_node_uuid, [])
# Test sanity checks # Test sanity checks
...@@ -497,7 +524,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -497,7 +524,7 @@ class ClientEventHandlerTest(unittest.TestCase):
nm = Mock({'getNodeByUUID': node, 'getNodeByServer': node, 'add': None}) nm = Mock({'getNodeByUUID': node, 'getNodeByServer': node, 'add': None})
primary_master_node = None primary_master_node = None
app = App() app = App()
client_handler = ClientAnswerEventHandler(app, self.getDispatcher()) client_handler = PrimaryBoostrapEventHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
test_master_list = [('127.0.0.1', 10010, test_node_uuid)] test_master_list = [('127.0.0.1', 10010, test_node_uuid)]
client_handler.handleAnswerPrimaryMaster(conn, None, test_node_uuid, test_master_list) client_handler.handleAnswerPrimaryMaster(conn, None, test_node_uuid, test_master_list)
...@@ -513,7 +540,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -513,7 +540,7 @@ class ClientEventHandlerTest(unittest.TestCase):
self.assertTrue(app.primary_master_node is node) self.assertTrue(app.primary_master_node is node)
def test_initialSendPartitionTable(self): def test_initialSendPartitionTable(self):
client_handler = ClientEventHandler(None, self.getDispatcher()) client_handler = PrimaryBoostrapEventHandler(None, self.getDispatcher())
conn = Mock({'getUUID': None}) conn = Mock({'getUUID': None})
call_list = self._testHandleUnexpectedPacketCalledWithMedhod( call_list = self._testHandleUnexpectedPacketCalledWithMedhod(
client_handler, client_handler.handleSendPartitionTable, client_handler, client_handler.handleSendPartitionTable,
...@@ -527,7 +554,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -527,7 +554,7 @@ class ClientEventHandlerTest(unittest.TestCase):
nm = Mock({'getNodeByUUID': node}) nm = Mock({'getNodeByUUID': node})
pt = None pt = None
app = App() app = App()
client_handler = ClientEventHandler(app, self.getDispatcher()) client_handler = PrimaryBoostrapEventHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
client_handler.handleSendPartitionTable(conn, None, 0, []) client_handler.handleSendPartitionTable(conn, None, 0, [])
# Check that nothing happened # Check that nothing happened
...@@ -541,7 +568,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -541,7 +568,7 @@ class ClientEventHandlerTest(unittest.TestCase):
pt = Mock({'clear': None}) pt = Mock({'clear': None})
ptid = test_ptid ptid = test_ptid
app = App() app = App()
client_handler = ClientEventHandler(app, self.getDispatcher()) client_handler = PrimaryBoostrapEventHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
client_handler.handleSendPartitionTable(conn, None, test_ptid + 1, []) client_handler.handleSendPartitionTable(conn, None, test_ptid + 1, [])
# Check that partition table got cleared and ptid got updated # Check that partition table got cleared and ptid got updated
...@@ -557,7 +584,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -557,7 +584,7 @@ class ClientEventHandlerTest(unittest.TestCase):
ptid = test_ptid ptid = test_ptid
test_storage_uuid = self.getUUID() test_storage_uuid = self.getUUID()
app = App() app = App()
client_handler = ClientEventHandler(app, self.getDispatcher()) client_handler = PrimaryBoostrapEventHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
# TODO: use realistic values # TODO: use realistic values
test_row_list = [(0, [(test_storage_uuid, 0)])] test_row_list = [(0, [(test_storage_uuid, 0)])]
...@@ -586,7 +613,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -586,7 +613,7 @@ class ClientEventHandlerTest(unittest.TestCase):
ptid = test_ptid ptid = test_ptid
test_storage_uuid = self.getUUID() test_storage_uuid = self.getUUID()
app = App() app = App()
client_handler = ClientEventHandler(app, self.getDispatcher()) client_handler = PrimaryBoostrapEventHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
# TODO: use realistic values # TODO: use realistic values
test_row_list = [(0, [(test_storage_uuid, 0)])] test_row_list = [(0, [(test_storage_uuid, 0)])]
...@@ -604,7 +631,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -604,7 +631,7 @@ class ClientEventHandlerTest(unittest.TestCase):
self.assertEqual(state, test_row_list[0][1][0][1]) self.assertEqual(state, test_row_list[0][1][0][1])
def test_initialNotifyNodeInformation(self): def test_initialNotifyNodeInformation(self):
client_handler = ClientEventHandler(None, self.getDispatcher()) client_handler = PrimaryBoostrapEventHandler(None, self.getDispatcher())
conn = Mock({'getUUID': None}) conn = Mock({'getUUID': None})
call_list = self._testHandleUnexpectedPacketCalledWithMedhod( call_list = self._testHandleUnexpectedPacketCalledWithMedhod(
client_handler, client_handler.handleNotifyNodeInformation, client_handler, client_handler.handleNotifyNodeInformation,
...@@ -618,13 +645,9 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -618,13 +645,9 @@ class ClientEventHandlerTest(unittest.TestCase):
class App: class App:
nm = Mock({'getNodeByUUID': node}) nm = Mock({'getNodeByUUID': node})
app = App() app = App()
client_handler = ClientEventHandler(app, self.getDispatcher()) client_handler = PrimaryEventHandler(app, self.getDispatcher())
conn = self.getConnection(uuid=test_master_uuid) conn = self.getConnection(uuid=test_master_uuid)
client_handler.handleNotifyNodeInformation(conn, None, None) client_handler.handleNotifyNodeInformation(conn, None, ())
# If handleNotifyNodeInformation tries to read node_list
# parameter, it will fail (it is not a list).
# This test assumes that this failure will cause an exception to
# be raised, making it fail.
def test_nonIterableParameterRaisesNotifyNodeInformation(self): def test_nonIterableParameterRaisesNotifyNodeInformation(self):
# XXX: this test is here for sanity self-check: it verifies the # XXX: this test is here for sanity self-check: it verifies the
...@@ -636,7 +659,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -636,7 +659,7 @@ class ClientEventHandlerTest(unittest.TestCase):
class App: class App:
nm = Mock({'getNodeByUUID': node}) nm = Mock({'getNodeByUUID': node})
app = App() app = App()
client_handler = ClientEventHandler(app, self.getDispatcher()) client_handler = PrimaryEventHandler(app, self.getDispatcher())
conn = self.getConnection(uuid=test_master_uuid) conn = self.getConnection(uuid=test_master_uuid)
self.assertRaises(TypeError, client_handler.handleNotifyNodeInformation, self.assertRaises(TypeError, client_handler.handleNotifyNodeInformation,
conn, None, None) conn, None, None)
...@@ -655,7 +678,8 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -655,7 +678,8 @@ class ClientEventHandlerTest(unittest.TestCase):
'add': None, 'add': None,
'remove': None}) 'remove': None})
app = App() app = App()
client_handler = ClientEventHandler(app, self.getDispatcher()) #client_handler = ClientEventHandler(app, selClientEventHandlerf.getDispatcher())
client_handler = PrimaryBoostrapEventHandler(app, self.getDispatcher())
conn = self.getConnection(uuid=test_master_uuid) conn = self.getConnection(uuid=test_master_uuid)
client_handler.handleNotifyNodeInformation(conn, None, test_node_list) client_handler.handleNotifyNodeInformation(conn, None, test_node_list)
# Return nm so caller can check handler actions. # Return nm so caller can check handler actions.
...@@ -721,8 +745,9 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -721,8 +745,9 @@ class ClientEventHandlerTest(unittest.TestCase):
class App: class App:
nm = None nm = None
pt = None pt = None
ptid = INVALID_PTID
app = App() app = App()
client_handler = ClientEventHandler(app, self.getDispatcher()) client_handler = PrimaryBoostrapEventHandler(app, self.getDispatcher())
conn = Mock({'getUUID': None}) conn = Mock({'getUUID': None})
call_list = self._testHandleUnexpectedPacketCalledWithMedhod( call_list = self._testHandleUnexpectedPacketCalledWithMedhod(
client_handler, client_handler.handleNotifyPartitionChanges, client_handler, client_handler.handleNotifyPartitionChanges,
...@@ -736,9 +761,10 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -736,9 +761,10 @@ class ClientEventHandlerTest(unittest.TestCase):
class App: class App:
nm = Mock({'getNodeByUUID': node}) nm = Mock({'getNodeByUUID': node})
pt = None pt = None
ptid = INVALID_PTID
primary_master_node = node primary_master_node = node
app = App() app = App()
client_handler = ClientEventHandler(app, self.getDispatcher()) client_handler = PrimaryEventHandler(app, self.getDispatcher())
conn = self.getConnection(uuid=test_master_uuid) conn = self.getConnection(uuid=test_master_uuid)
client_handler.handleNotifyPartitionChanges(conn, None, 0, []) client_handler.handleNotifyPartitionChanges(conn, None, 0, [])
# Check that nothing happened # Check that nothing happened
...@@ -749,9 +775,10 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -749,9 +775,10 @@ class ClientEventHandlerTest(unittest.TestCase):
class App: class App:
nm = Mock({'getNodeByUUID': node}) nm = Mock({'getNodeByUUID': node})
pt = None pt = None
ptid = INVALID_PTID
primary_master_node = None primary_master_node = None
app = App() app = App()
client_handler = ClientEventHandler(app, self.getDispatcher()) client_handler = PrimaryEventHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
client_handler.handleNotifyPartitionChanges(conn, None, 0, []) client_handler.handleNotifyPartitionChanges(conn, None, 0, [])
# Check that nothing happened # Check that nothing happened
...@@ -767,9 +794,10 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -767,9 +794,10 @@ class ClientEventHandlerTest(unittest.TestCase):
class App: class App:
nm = Mock({'getNodeByUUID': node}) nm = Mock({'getNodeByUUID': node})
pt = None pt = None
ptid = INVALID_PTID
primary_master_node = test_master_node primary_master_node = test_master_node
app = App() app = App()
client_handler = ClientEventHandler(app, self.getDispatcher()) client_handler = PrimaryEventHandler(app, self.getDispatcher())
conn = self.getConnection(uuid=test_sender_uuid) conn = self.getConnection(uuid=test_sender_uuid)
client_handler.handleNotifyPartitionChanges(conn, None, 0, []) client_handler.handleNotifyPartitionChanges(conn, None, 0, [])
# Check that nothing happened # Check that nothing happened
...@@ -785,7 +813,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -785,7 +813,7 @@ class ClientEventHandlerTest(unittest.TestCase):
primary_master_node = node primary_master_node = node
ptid = test_ptid ptid = test_ptid
app = App() app = App()
client_handler = ClientEventHandler(app, self.getDispatcher()) client_handler = PrimaryEventHandler(app, self.getDispatcher())
conn = self.getConnection(uuid=test_master_uuid) conn = self.getConnection(uuid=test_master_uuid)
client_handler.handleNotifyPartitionChanges(conn, None, test_ptid, []) client_handler.handleNotifyPartitionChanges(conn, None, test_ptid, [])
# Check that nothing happened # Check that nothing happened
...@@ -797,17 +825,17 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -797,17 +825,17 @@ class ClientEventHandlerTest(unittest.TestCase):
test_node = Mock({'getNodeType': MASTER_NODE_TYPE, 'getUUID': test_master_uuid}) test_node = Mock({'getNodeType': MASTER_NODE_TYPE, 'getUUID': test_master_uuid})
test_ptid = 1 test_ptid = 1
class App: class App:
nm = Mock({'getNodeByUUID': ReturnValues(test_node, None)}) nm = Mock({'getNodeByUUID': ReturnValues(None)})
pt = Mock({'setCell': None}) pt = Mock({'setCell': None})
primary_master_node = test_node primary_master_node = test_node
ptid = test_ptid ptid = test_ptid
uuid = None # XXX: Is it really needed ? uuid = None # XXX: Is it really needed ?
app = App() app = App()
client_handler = ClientEventHandler(app, self.getDispatcher()) client_handler = PrimaryEventHandler(app, self.getDispatcher())
conn = self.getConnection(uuid=test_master_uuid) conn = self.getConnection(uuid=test_master_uuid)
test_storage_uuid = self.getUUID() test_storage_uuid = self.getUUID()
# TODO: use realistic values # TODO: use realistic values
test_cell_list = [(0, test_storage_uuid, 0)] test_cell_list = [(0, test_storage_uuid, UP_TO_DATE_STATE)]
client_handler.handleNotifyPartitionChanges(conn, None, test_ptid + 1, test_cell_list) client_handler.handleNotifyPartitionChanges(conn, None, test_ptid + 1, test_cell_list)
# Check that a new node got added # Check that a new node got added
add_call_list = app.nm.mockGetNamedCalls('add') add_call_list = app.nm.mockGetNamedCalls('add')
...@@ -827,38 +855,50 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -827,38 +855,50 @@ class ClientEventHandlerTest(unittest.TestCase):
# TODO: confirm condition under which an unknown node should be added with a TEMPORARILY_DOWN_STATE (implementation is unclear) # TODO: confirm condition under which an unknown node should be added with a TEMPORARILY_DOWN_STATE (implementation is unclear)
def test_knownNodeNotifyPartitionChanges(self): def test_knownNodeNotifyPartitionChanges(self):
test_master_uuid = self.getUUID()
test_node = Mock({'getNodeType': MASTER_NODE_TYPE, 'getUUID': test_master_uuid})
test_ptid = 1 test_ptid = 1
uuid1, uuid2 = self.getUUID(), self.getUUID()
uuid3, uuid4 = self.getUUID(), self.getUUID()
test_node = Mock({'getNodeType': MASTER_NODE_TYPE, 'getUUID': uuid1})
class App: class App:
nm = Mock({'getNodeByUUID': test_node, 'add': None}) nm = Mock({'getNodeByUUID': ReturnValues(test_node, None, None, None), 'add': None})
pt = Mock({'setCell': None}) pt = Mock({'setCell': None})
primary_master_node = test_node primary_master_node = test_node
ptid = test_ptid ptid = test_ptid
uuid = uuid4
app = App() app = App()
client_handler = ClientEventHandler(app, self.getDispatcher()) client_handler = PrimaryEventHandler(app, self.getDispatcher())
conn = self.getConnection(uuid=test_master_uuid) conn = self.getConnection(uuid=uuid1)
test_storage_uuid = self.getUUID() test_cell_list = [
# TODO: use realistic values (0, uuid1, UP_TO_DATE_STATE),
test_cell_list = [(0, test_storage_uuid, 0)] (0, uuid2, DISCARDED_STATE),
(0, uuid3, FEEDING_STATE),
(0, uuid4, UP_TO_DATE_STATE),
]
client_handler.handleNotifyPartitionChanges(conn, None, test_ptid + 1, test_cell_list) client_handler.handleNotifyPartitionChanges(conn, None, test_ptid + 1, test_cell_list)
# Check that no node got added # Check that the three last node got added
self.assertEqual(len(app.nm.mockGetNamedCalls('add')), 0) calls = app.nm.mockGetNamedCalls('add')
# Check that partition got updated self.assertEquals(len(calls), 3)
self.assertEquals(calls[0].getParam(0).getUUID(), uuid2)
self.assertEquals(calls[1].getParam(0).getUUID(), uuid3)
self.assertEquals(calls[2].getParam(0).getUUID(), uuid4)
self.assertEquals(calls[0].getParam(0).getState(), TEMPORARILY_DOWN_STATE)
self.assertEquals(calls[1].getParam(0).getState(), TEMPORARILY_DOWN_STATE)
# check two are dropped from the pt
calls = app.pt.mockGetNamedCalls('dropNode')
self.assertEquals(len(calls), 2)
self.assertEquals(calls[0].getParam(0).getUUID(), uuid2)
self.assertEquals(calls[1].getParam(0).getUUID(), uuid3)
# and the others are updated
self.assertEqual(app.ptid, test_ptid + 1) self.assertEqual(app.ptid, test_ptid + 1)
setCell_call_list = app.pt.mockGetNamedCalls('setCell') calls = app.pt.mockGetNamedCalls('setCell')
self.assertEqual(len(setCell_call_list), 1) self.assertEqual(len(calls), 2)
offset = setCell_call_list[0].getParam(0) self.assertEquals(calls[0].getParam(1).getUUID(), uuid1)
node = setCell_call_list[0].getParam(1) self.assertEquals(calls[1].getParam(1).getUUID(), uuid4)
state = setCell_call_list[0].getParam(2)
self.assertEqual(offset, test_cell_list[0][0])
self.assertTrue(node is test_node)
self.assertEqual(state, test_cell_list[0][2])
def test_AnswerNewTID(self): def test_AnswerNewTID(self):
app = Mock({'setTID': None}) app = Mock({'setTID': None})
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = ClientAnswerEventHandler(app, dispatcher) client_handler = PrimaryEventHandler(app, dispatcher)
conn = self.getConnection() conn = self.getConnection()
test_tid = 1 test_tid = 1
client_handler.handleAnswerNewTID(conn, None, test_tid) client_handler.handleAnswerNewTID(conn, None, test_tid)
...@@ -870,7 +910,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -870,7 +910,7 @@ class ClientEventHandlerTest(unittest.TestCase):
test_tid = 1 test_tid = 1
app = Mock({'getTID': test_tid, 'setTransactionFinished': None}) app = Mock({'getTID': test_tid, 'setTransactionFinished': None})
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = ClientAnswerEventHandler(app, dispatcher) client_handler = PrimaryEventHandler(app, dispatcher)
conn = self.getConnection() conn = self.getConnection()
client_handler.handleNotifyTransactionFinished(conn, None, test_tid) client_handler.handleNotifyTransactionFinished(conn, None, test_tid)
self.assertEquals(len(app.mockGetNamedCalls('setTransactionFinished')), 1) self.assertEquals(len(app.mockGetNamedCalls('setTransactionFinished')), 1)
...@@ -893,7 +933,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -893,7 +933,7 @@ class ClientEventHandlerTest(unittest.TestCase):
mq_cache = Mock({'__delitem__': None}) mq_cache = Mock({'__delitem__': None})
app = App() app = App()
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = ClientEventHandler(app, dispatcher) client_handler = StorageEventHandler(app, dispatcher)
conn = self.getConnection() conn = self.getConnection()
test_tid = 1 test_tid = 1
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']
...@@ -923,7 +963,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -923,7 +963,7 @@ class ClientEventHandlerTest(unittest.TestCase):
new_oid_list = [] new_oid_list = []
app = App() app = App()
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = ClientAnswerEventHandler(app, dispatcher) client_handler = PrimaryEventHandler(app, dispatcher)
conn = self.getConnection() conn = self.getConnection()
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']
client_handler.handleAnswerNewOIDs(conn, None, test_oid_list[:]) client_handler.handleAnswerNewOIDs(conn, None, test_oid_list[:])
...@@ -941,7 +981,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -941,7 +981,7 @@ class ClientEventHandlerTest(unittest.TestCase):
local_var = FakeLocal() local_var = FakeLocal()
app = App() app = App()
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = ClientAnswerEventHandler(app, dispatcher) client_handler = StorageEventHandler(app, dispatcher)
conn = self.getConnection() conn = self.getConnection()
# TODO: use realistic values # TODO: use realistic values
test_object_data = ('\x00\x00\x00\x00\x00\x00\x00\x01', 0, 0, 0, 0, 'test') test_object_data = ('\x00\x00\x00\x00\x00\x00\x00\x01', 0, 0, 0, 0, 'test')
...@@ -950,7 +990,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -950,7 +990,7 @@ class ClientEventHandlerTest(unittest.TestCase):
def _testAnswerStoreObject(self, app, conflicting, oid, serial): def _testAnswerStoreObject(self, app, conflicting, oid, serial):
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = ClientAnswerEventHandler(app, dispatcher) client_handler = StorageEventHandler(app, dispatcher)
conn = self.getConnection() conn = self.getConnection()
client_handler.handleAnswerStoreObject(conn, None, conflicting, oid, serial) client_handler.handleAnswerStoreObject(conn, None, conflicting, oid, serial)
...@@ -976,7 +1016,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -976,7 +1016,7 @@ class ClientEventHandlerTest(unittest.TestCase):
test_tid = 10 test_tid = 10
app = Mock({'getTID': test_tid, 'setTransactionVoted': None}) app = Mock({'getTID': test_tid, 'setTransactionVoted': None})
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = ClientAnswerEventHandler(app, dispatcher) client_handler = StorageEventHandler(app, dispatcher)
conn = self.getConnection() conn = self.getConnection()
client_handler.handleAnswerStoreTransaction(conn, None, test_tid) client_handler.handleAnswerStoreTransaction(conn, None, test_tid)
self.assertEquals(len(app.mockGetNamedCalls('setTransactionVoted')), 1) self.assertEquals(len(app.mockGetNamedCalls('setTransactionVoted')), 1)
...@@ -989,7 +1029,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -989,7 +1029,7 @@ class ClientEventHandlerTest(unittest.TestCase):
local_var = FakeLocal() local_var = FakeLocal()
app = App() app = App()
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = ClientAnswerEventHandler(app, dispatcher) client_handler = StorageEventHandler(app, dispatcher)
conn = self.getConnection() conn = self.getConnection()
tid = '\x00\x00\x00\x00\x00\x00\x00\x01' # TODO: use a more realistic tid tid = '\x00\x00\x00\x00\x00\x00\x00\x01' # TODO: use a more realistic tid
user = 'bar' user = 'bar'
...@@ -1011,7 +1051,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -1011,7 +1051,7 @@ class ClientEventHandlerTest(unittest.TestCase):
local_var = FakeLocal() local_var = FakeLocal()
app = App() app = App()
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = ClientAnswerEventHandler(app, dispatcher) client_handler = StorageEventHandler(app, dispatcher)
conn = self.getConnection() conn = self.getConnection()
test_oid = '\x00\x00\x00\x00\x00\x00\x00\x01' test_oid = '\x00\x00\x00\x00\x00\x00\x00\x01'
# TODO: use realistic values # TODO: use realistic values
...@@ -1030,7 +1070,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -1030,7 +1070,7 @@ class ClientEventHandlerTest(unittest.TestCase):
local_var = FakeLocal() local_var = FakeLocal()
app = App() app = App()
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = ClientAnswerEventHandler(app, dispatcher) client_handler = StorageEventHandler(app, dispatcher)
conn = self.getConnection() conn = self.getConnection()
client_handler.handleOidNotFound(conn, None, None) client_handler.handleOidNotFound(conn, None, None)
self.assertEquals(app.local_var.asked_object, -1) self.assertEquals(app.local_var.asked_object, -1)
...@@ -1043,7 +1083,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -1043,7 +1083,7 @@ class ClientEventHandlerTest(unittest.TestCase):
local_var = FakeLocal() local_var = FakeLocal()
app = App() app = App()
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = ClientAnswerEventHandler(app, dispatcher) client_handler = StorageEventHandler(app, dispatcher)
conn = self.getConnection() conn = self.getConnection()
client_handler.handleTidNotFound(conn, None, None) client_handler.handleTidNotFound(conn, None, None)
self.assertEquals(app.local_var.txn_info, -1) self.assertEquals(app.local_var.txn_info, -1)
...@@ -1055,7 +1095,7 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -1055,7 +1095,7 @@ class ClientEventHandlerTest(unittest.TestCase):
local_var = FakeLocal() local_var = FakeLocal()
app = App() app = App()
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = ClientAnswerEventHandler(app, dispatcher) client_handler = StorageEventHandler(app, dispatcher)
conn = self.getConnection() conn = self.getConnection()
test_tid_list = ['\x00\x00\x00\x00\x00\x00\x00\x01', '\x00\x00\x00\x00\x00\x00\x00\x02'] test_tid_list = ['\x00\x00\x00\x00\x00\x00\x00\x01', '\x00\x00\x00\x00\x00\x00\x00\x02']
client_handler.handleAnswerTIDs(conn, None, test_tid_list[:]) client_handler.handleAnswerTIDs(conn, None, test_tid_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