Commit 76b17baf authored by Grégory Wisniewski's avatar Grégory Wisniewski

Use getFakeConnection

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2065 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 64a63d76
...@@ -149,14 +149,23 @@ class NeoTestBase(unittest.TestCase): ...@@ -149,14 +149,23 @@ class NeoTestBase(unittest.TestCase):
uuids = self.getNewUUID(), self.getNewUUID() uuids = self.getNewUUID(), self.getNewUUID()
return min(uuids), max(uuids) return min(uuids), max(uuids)
def getFakeConnector(self, descriptor=None):
return Mock({
'__repr__': 'FakeConnector',
'getDescriptor': descriptor,
})
def getFakeConnection(self, uuid=None, address=('127.0.0.1', 10000), def getFakeConnection(self, uuid=None, address=('127.0.0.1', 10000),
is_server=False): is_server=False, connector=None):
if connector is None:
connector = self.getFakeConnector()
return Mock({ return Mock({
'getUUID': uuid, 'getUUID': uuid,
'getAddress': address, 'getAddress': address,
'isServer': is_server, 'isServer': is_server,
'__repr__': 'FakeConnection', '__repr__': 'FakeConnection',
'__nonzero__': 0, '__nonzero__': 0,
'getConnector': connector,
}) })
def checkProtocolErrorRaised(self, method, *args, **kwargs): def checkProtocolErrorRaised(self, method, *args, **kwargs):
......
...@@ -33,7 +33,7 @@ class MasterHandlerTests(NeoTestBase): ...@@ -33,7 +33,7 @@ class MasterHandlerTests(NeoTestBase):
pass pass
def getConnection(self): def getConnection(self):
return Mock({'getAddress': ('fake-conn', 0)}) return self.getFakeConnection()
class MasterBootstrapHandlerTests(MasterHandlerTests): class MasterBootstrapHandlerTests(MasterHandlerTests):
...@@ -186,16 +186,19 @@ class MasterNotificationsHandlerTests(MasterHandlerTests): ...@@ -186,16 +186,19 @@ class MasterNotificationsHandlerTests(MasterHandlerTests):
(NodeTypes.STORAGE, addr, self.getNewUUID(), NodeStates.DOWN), (NodeTypes.STORAGE, addr, self.getNewUUID(), NodeStates.DOWN),
] ]
# XXX: it might be better to test with real node & node manager # XXX: it might be better to test with real node & node manager
conn1, conn2 = Mock({'__repr__': 'conn1'}), Mock({'__repr__': 'conn2'}) conn1 = self.getFakeConnection()
conn2 = self.getFakeConnection()
node1 = Mock({ node1 = Mock({
'getConnection': conn1, 'getConnection': conn1,
'__nonzero__': 1, '__nonzero__': 1,
'isConnected': True, 'isConnected': True,
'__repr__': 'Fake Node',
}) })
node2 = Mock({ node2 = Mock({
'getConnection': conn2, 'getConnection': conn2,
'__nonzero__': 1, '__nonzero__': 1,
'isConnected': True, 'isConnected': True,
'__repr__': 'Fake Node',
}) })
self.app.nm = Mock({'getByUUID': ReturnValues(node1, node2)}) self.app.nm = Mock({'getByUUID': ReturnValues(node1, node2)})
self.app.cp = Mock() self.app.cp = Mock()
......
...@@ -32,7 +32,7 @@ class StorageBootstrapHandlerTests(NeoTestBase): ...@@ -32,7 +32,7 @@ class StorageBootstrapHandlerTests(NeoTestBase):
self.handler = StorageBootstrapHandler(self.app) self.handler = StorageBootstrapHandler(self.app)
def getConnection(self): def getConnection(self):
return Mock({'getAddress': ('fake-conn', 0)}) return self.getFakeConnection()
def test_notReady(self): def test_notReady(self):
conn = self.getConnection() conn = self.getConnection()
...@@ -70,7 +70,7 @@ class StorageAnswerHandlerTests(NeoTestBase): ...@@ -70,7 +70,7 @@ class StorageAnswerHandlerTests(NeoTestBase):
self.handler = StorageAnswersHandler(self.app) self.handler = StorageAnswersHandler(self.app)
def getConnection(self): def getConnection(self):
return Mock({'getAddress': ('fake-conn', 0)}) return self.getFakeConnection()
def test_answerObject(self): def test_answerObject(self):
conn = self.getConnection() conn = self.getConnection()
...@@ -229,7 +229,7 @@ class StorageAnswerHandlerTests(NeoTestBase): ...@@ -229,7 +229,7 @@ class StorageAnswerHandlerTests(NeoTestBase):
tid1 = self.getNextTID() tid1 = self.getNextTID()
tid2 = self.getNextTID(tid1) tid2 = self.getNextTID(tid1)
tid_list = [tid1, tid2] tid_list = [tid1, tid2]
conn = Mock({'getUUID': uuid}) conn = self.getFakeConnection(uuid=uuid)
self.app.local_var.node_tids = {} self.app.local_var.node_tids = {}
self.handler.answerTIDs(conn, tid_list) self.handler.answerTIDs(conn, tid_list)
self.assertTrue(uuid in self.app.local_var.node_tids) self.assertTrue(uuid in self.app.local_var.node_tids)
......
...@@ -222,11 +222,10 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -222,11 +222,10 @@ class MasterServerElectionTests(NeoTestBase):
if uuid is True: if uuid is True:
uuid = self.getNewUUID() uuid = self.getNewUUID()
node.setUUID(uuid) node.setUUID(uuid)
conn = Mock({ conn = self.getFakeConnection(
"getUUID": node.getUUID(), uuid=node.getUUID(),
"getAddress": node.getAddress(), address=node.getAddress(),
"getConnector": Mock(), )
})
return (node, conn) return (node, conn)
...@@ -286,22 +285,14 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -286,22 +285,14 @@ class MasterServerElectionTests(NeoTestBase):
def __getClient(self): def __getClient(self):
uuid = self.getNewUUID() uuid = self.getNewUUID()
conn = Mock({ conn = self.getFakeConnection(uuid=uuid, address=self.client_address)
'getUUID': uuid,
'getAddress': self.client_address,
'getConnector': Mock(),
})
self.app.nm.createClient(uuid=uuid, address=self.client_address) self.app.nm.createClient(uuid=uuid, address=self.client_address)
return conn return conn
def __getMaster(self, port=1000, register=True): def __getMaster(self, port=1000, register=True):
uuid = self.getNewUUID() uuid = self.getNewUUID()
address = ('127.0.0.1', port) address = ('127.0.0.1', port)
conn = Mock({ conn = self.getFakeConnection(uuid=uuid, address=address)
'getUUID': uuid,
'getAddress': address,
'getConnector': Mock(),
})
if register: if register:
self.app.nm.createMaster(uuid=uuid, address=address) self.app.nm.createMaster(uuid=uuid, address=address)
return conn return conn
......
...@@ -56,9 +56,9 @@ class MasterAppTests(NeoTestBase): ...@@ -56,9 +56,9 @@ class MasterAppTests(NeoTestBase):
client_uuid = self.getNewUUID() client_uuid = self.getNewUUID()
client = self.app.nm.createClient(uuid=client_uuid) client = self.app.nm.createClient(uuid=client_uuid)
# create conn and patch em # create conn and patch em
master_conn = Mock() master_conn = self.getFakeConnection()
storage_conn = Mock() storage_conn = self.getFakeConnection()
client_conn = Mock() client_conn = self.getFakeConnection()
master.setConnection(master_conn) master.setConnection(master_conn)
storage.setConnection(storage_conn) storage.setConnection(storage_conn)
client.setConnection(client_conn) client.setConnection(client_conn)
......
...@@ -29,10 +29,8 @@ from neo.protocol import Packets ...@@ -29,10 +29,8 @@ from neo.protocol import Packets
class StorageClientHandlerTests(NeoTestBase): class StorageClientHandlerTests(NeoTestBase):
def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs): def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs):
conn = Mock({ conn = self.getFakeConnection(address=("127.0.0.1", self.master_port),
"getAddress" : ("127.0.0.1", self.master_port), is_server=_listening)
"isServer": _listening,
})
# hook # hook
self.operation.peerBroken = lambda c: c.peerBrokendCalled() self.operation.peerBroken = lambda c: c.peerBrokendCalled()
self.checkUnexpectedPacketRaised(_call, conn=conn, **kwargs) self.checkUnexpectedPacketRaised(_call, conn=conn, **kwargs)
...@@ -60,7 +58,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -60,7 +58,7 @@ class StorageClientHandlerTests(NeoTestBase):
NeoTestBase.tearDown(self) NeoTestBase.tearDown(self)
def _getConnection(self, uuid=None): def _getConnection(self, uuid=None):
return Mock({'getUUID': uuid, 'getAddress': ('127.0.0.1', 1000)}) return self.getFakeConnection(uuid=uuid, address=('127.0.0.1', 1000))
def _checkTransactionsAborted(self, uuid): def _checkTransactionsAborted(self, uuid):
calls = self.app.tm.mockGetNamedCalls('abortFor') calls = self.app.tm.mockGetNamedCalls('abortFor')
...@@ -87,13 +85,13 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -87,13 +85,13 @@ class StorageClientHandlerTests(NeoTestBase):
def test_18_askTransactionInformation1(self): def test_18_askTransactionInformation1(self):
# transaction does not exists # transaction does not exists
conn = Mock({ }) conn = self._getConnection()
self.operation.askTransactionInformation(conn, INVALID_TID) self.operation.askTransactionInformation(conn, INVALID_TID)
self.checkErrorPacket(conn) self.checkErrorPacket(conn)
def test_18_askTransactionInformation2(self): def test_18_askTransactionInformation2(self):
# answer # answer
conn = Mock({ }) conn = self._getConnection()
dm = Mock({ "getTransaction": (INVALID_TID, 'user', 'desc', '', False), }) dm = Mock({ "getTransaction": (INVALID_TID, 'user', 'desc', '', False), })
self.app.dm = dm self.app.dm = dm
self.operation.askTransactionInformation(conn, INVALID_TID) self.operation.askTransactionInformation(conn, INVALID_TID)
...@@ -101,7 +99,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -101,7 +99,7 @@ class StorageClientHandlerTests(NeoTestBase):
def test_24_askObject1(self): def test_24_askObject1(self):
# delayed response # delayed response
conn = Mock({}) conn = self._getConnection()
self.app.dm = Mock() self.app.dm = Mock()
self.app.tm = Mock({'loadLocked': True}) self.app.tm = Mock({'loadLocked': True})
self.app.load_lock_dict[INVALID_OID] = object() self.app.load_lock_dict[INVALID_OID] = object()
...@@ -115,7 +113,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -115,7 +113,7 @@ class StorageClientHandlerTests(NeoTestBase):
def test_24_askObject2(self): def test_24_askObject2(self):
# 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 = self._getConnection()
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, oid=INVALID_OID, self.operation.askObject(conn, oid=INVALID_OID,
serial=INVALID_SERIAL, tid=INVALID_TID) serial=INVALID_SERIAL, tid=INVALID_TID)
...@@ -128,7 +126,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -128,7 +126,7 @@ class StorageClientHandlerTests(NeoTestBase):
def test_24_askObject3(self): def test_24_askObject3(self):
# object found => answer # object found => answer
self.app.dm = Mock({'getObject': ('', '', 0, 0, '', None)}) self.app.dm = Mock({'getObject': ('', '', 0, 0, '', None)})
conn = Mock({}) conn = self._getConnection()
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, oid=INVALID_OID, self.operation.askObject(conn, oid=INVALID_OID,
serial=INVALID_SERIAL, tid=INVALID_TID) serial=INVALID_SERIAL, tid=INVALID_TID)
...@@ -140,14 +138,14 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -140,14 +138,14 @@ class StorageClientHandlerTests(NeoTestBase):
app = self.app app = self.app
app.pt = Mock() app.pt = Mock()
app.dm = Mock() app.dm = Mock()
conn = Mock({}) conn = self._getConnection()
self.checkProtocolErrorRaised(self.operation.askTIDs, conn, 1, 1, None) self.checkProtocolErrorRaised(self.operation.askTIDs, conn, 1, 1, None)
self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0) self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0)
self.assertEquals(len(app.dm.mockGetNamedCalls('getTIDList')), 0) self.assertEquals(len(app.dm.mockGetNamedCalls('getTIDList')), 0)
def test_25_askTIDs2(self): def test_25_askTIDs2(self):
# well case => answer # well case => answer
conn = Mock({}) conn = self._getConnection()
self.app.pt = Mock({'getPartitions': 1}) self.app.pt = Mock({'getPartitions': 1})
self.app.dm = Mock({'getTIDList': (INVALID_TID, )}) self.app.dm = Mock({'getTIDList': (INVALID_TID, )})
self.operation.askTIDs(conn, 1, 2, 1) self.operation.askTIDs(conn, 1, 2, 1)
...@@ -158,7 +156,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -158,7 +156,7 @@ class StorageClientHandlerTests(NeoTestBase):
def test_25_askTIDs3(self): def test_25_askTIDs3(self):
# invalid partition => answer usable partitions # invalid partition => answer usable partitions
conn = Mock({}) conn = self._getConnection()
cell = Mock({'getUUID':self.app.uuid}) cell = Mock({'getUUID':self.app.uuid})
self.app.dm = Mock({'getTIDList': (INVALID_TID, )}) self.app.dm = Mock({'getTIDList': (INVALID_TID, )})
self.app.pt = Mock({ self.app.pt = Mock({
...@@ -177,19 +175,19 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -177,19 +175,19 @@ class StorageClientHandlerTests(NeoTestBase):
# invalid offsets => error # invalid offsets => error
app = self.app app = self.app
app.dm = Mock() app.dm = Mock()
conn = Mock({}) conn = self._getConnection()
self.checkProtocolErrorRaised(self.operation.askObjectHistory, conn, self.checkProtocolErrorRaised(self.operation.askObjectHistory, conn,
1, 1, None) 1, 1, None)
self.assertEquals(len(app.dm.mockGetNamedCalls('getObjectHistory')), 0) self.assertEquals(len(app.dm.mockGetNamedCalls('getObjectHistory')), 0)
def test_26_askObjectHistory2(self): def test_26_askObjectHistory2(self):
# first case: empty history # first case: empty history
conn = Mock({}) conn = self._getConnection()
self.app.dm = Mock({'getObjectHistory': None}) self.app.dm = Mock({'getObjectHistory': None})
self.operation.askObjectHistory(conn, INVALID_OID, 1, 2) self.operation.askObjectHistory(conn, INVALID_OID, 1, 2)
self.checkAnswerObjectHistory(conn) self.checkAnswerObjectHistory(conn)
# second case: not empty history # second case: not empty history
conn = Mock({}) conn = self._getConnection()
self.app.dm = Mock({'getObjectHistory': [('', 0, ), ]}) self.app.dm = Mock({'getObjectHistory': [('', 0, ), ]})
self.operation.askObjectHistory(conn, INVALID_OID, 1, 2) self.operation.askObjectHistory(conn, INVALID_OID, 1, 2)
self.checkAnswerObjectHistory(conn) self.checkAnswerObjectHistory(conn)
......
...@@ -122,7 +122,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -122,7 +122,7 @@ class StorageMasterHandlerTests(NeoTestBase):
def test_16_stopOperation1(self): def test_16_stopOperation1(self):
# OperationFailure # OperationFailure
conn = Mock({ 'isServer': False }) conn = self.getFakeConnection(is_server=False)
self.assertRaises(OperationFailure, self.operation.stopOperation, conn) self.assertRaises(OperationFailure, self.operation.stopOperation, conn)
def _getConnection(self): def _getConnection(self):
...@@ -169,7 +169,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -169,7 +169,7 @@ class StorageMasterHandlerTests(NeoTestBase):
def test_30_answerLastIDs(self): def test_30_answerLastIDs(self):
# set critical TID on replicator # set critical TID on replicator
conn = Mock() conn = self.getFakeConnection()
self.app.replicator = Mock() self.app.replicator = Mock()
self.operation.answerLastIDs( self.operation.answerLastIDs(
conn=conn, conn=conn,
...@@ -183,7 +183,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -183,7 +183,7 @@ class StorageMasterHandlerTests(NeoTestBase):
def test_31_answerUnfinishedTransactions(self): def test_31_answerUnfinishedTransactions(self):
# set unfinished TID on replicator # set unfinished TID on replicator
conn = Mock() conn = self.getFakeConnection()
self.app.replicator = Mock() self.app.replicator = Mock()
self.operation.answerUnfinishedTransactions( self.operation.answerUnfinishedTransactions(
conn=conn, conn=conn,
......
...@@ -27,10 +27,8 @@ from neo.protocol import INVALID_TID, INVALID_OID, INVALID_SERIAL ...@@ -27,10 +27,8 @@ from neo.protocol import INVALID_TID, INVALID_OID, INVALID_SERIAL
class StorageStorageHandlerTests(NeoTestBase): class StorageStorageHandlerTests(NeoTestBase):
def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs): def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs):
conn = Mock({ conn = self.getFakeConnection(address=("127.0.0.1", self.master_port),
"getAddress" : ("127.0.0.1", self.master_port), is_server=_listening)
"isServer": _listening,
})
# hook # hook
self.operation.peerBroken = lambda c: c.peerBrokendCalled() self.operation.peerBroken = lambda c: c.peerBrokendCalled()
self.checkUnexpectedPacketRaised(_call, conn=conn, **kwargs) self.checkUnexpectedPacketRaised(_call, conn=conn, **kwargs)
...@@ -58,13 +56,13 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -58,13 +56,13 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_18_askTransactionInformation1(self): def test_18_askTransactionInformation1(self):
# transaction does not exists # transaction does not exists
conn = Mock({ }) conn = self.getFakeConnection()
self.operation.askTransactionInformation(conn, INVALID_TID) self.operation.askTransactionInformation(conn, INVALID_TID)
self.checkErrorPacket(conn) self.checkErrorPacket(conn)
def test_18_askTransactionInformation2(self): def test_18_askTransactionInformation2(self):
# answer # answer
conn = Mock({ }) conn = self.getFakeConnection()
dm = Mock({"getTransaction": (INVALID_TID, 'user', 'desc', '', False), }) dm = Mock({"getTransaction": (INVALID_TID, 'user', 'desc', '', False), })
self.app.dm = dm self.app.dm = dm
self.operation.askTransactionInformation(conn, INVALID_TID) self.operation.askTransactionInformation(conn, INVALID_TID)
...@@ -72,7 +70,7 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -72,7 +70,7 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_24_askObject1(self): def test_24_askObject1(self):
# delayed response # delayed response
conn = Mock({}) conn = self.getFakeConnection()
self.app.dm = Mock() self.app.dm = Mock()
self.app.tm = Mock({'loadLocked': True}) self.app.tm = Mock({'loadLocked': True})
self.app.load_lock_dict[INVALID_OID] = object() self.app.load_lock_dict[INVALID_OID] = object()
...@@ -86,7 +84,7 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -86,7 +84,7 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_24_askObject2(self): def test_24_askObject2(self):
# 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 = self.getFakeConnection()
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, oid=INVALID_OID, self.operation.askObject(conn, oid=INVALID_OID,
serial=INVALID_SERIAL, tid=INVALID_TID) serial=INVALID_SERIAL, tid=INVALID_TID)
...@@ -100,7 +98,7 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -100,7 +98,7 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_24_askObject3(self): def test_24_askObject3(self):
# object found => answer # object found => answer
self.app.dm = Mock({'getObject': ('', '', 0, 0, '', None)}) self.app.dm = Mock({'getObject': ('', '', 0, 0, '', None)})
conn = Mock({}) conn = self.getFakeConnection()
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, oid=INVALID_OID, self.operation.askObject(conn, oid=INVALID_OID,
serial=INVALID_SERIAL, tid=INVALID_TID) serial=INVALID_SERIAL, tid=INVALID_TID)
...@@ -112,14 +110,14 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -112,14 +110,14 @@ class StorageStorageHandlerTests(NeoTestBase):
app = self.app app = self.app
app.pt = Mock() app.pt = Mock()
app.dm = Mock() app.dm = Mock()
conn = Mock({}) conn = self.getFakeConnection()
self.checkProtocolErrorRaised(self.operation.askTIDs, conn, 1, 1, None) self.checkProtocolErrorRaised(self.operation.askTIDs, conn, 1, 1, None)
self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0) self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0)
self.assertEquals(len(app.dm.mockGetNamedCalls('getReplicationTIDList')), 0) self.assertEquals(len(app.dm.mockGetNamedCalls('getReplicationTIDList')), 0)
def test_25_askTIDs2(self): def test_25_askTIDs2(self):
# well case => answer # well case => answer
conn = Mock({}) conn = self.getFakeConnection()
self.app.dm = Mock({'getReplicationTIDList': (INVALID_TID, )}) self.app.dm = Mock({'getReplicationTIDList': (INVALID_TID, )})
self.app.pt = Mock({'getPartitions': 1}) self.app.pt = Mock({'getPartitions': 1})
self.operation.askTIDs(conn, 1, 2, 1) self.operation.askTIDs(conn, 1, 2, 1)
...@@ -130,7 +128,7 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -130,7 +128,7 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_25_askTIDs3(self): def test_25_askTIDs3(self):
# invalid partition => answer usable partitions # invalid partition => answer usable partitions
conn = Mock({}) conn = self.getFakeConnection()
cell = Mock({'getUUID':self.app.uuid}) cell = Mock({'getUUID':self.app.uuid})
self.app.dm = Mock({'getReplicationTIDList': (INVALID_TID, )}) self.app.dm = Mock({'getReplicationTIDList': (INVALID_TID, )})
self.app.pt = Mock({ self.app.pt = Mock({
...@@ -149,19 +147,19 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -149,19 +147,19 @@ class StorageStorageHandlerTests(NeoTestBase):
# invalid offsets => error # invalid offsets => error
app = self.app app = self.app
app.dm = Mock() app.dm = Mock()
conn = Mock({}) conn = self.getFakeConnection()
self.checkProtocolErrorRaised(self.operation.askObjectHistory, conn, self.checkProtocolErrorRaised(self.operation.askObjectHistory, conn,
1, 1, None) 1, 1, None)
self.assertEquals(len(app.dm.mockGetNamedCalls('getObjectHistory')), 0) self.assertEquals(len(app.dm.mockGetNamedCalls('getObjectHistory')), 0)
def test_26_askObjectHistory2(self): def test_26_askObjectHistory2(self):
# first case: empty history # first case: empty history
conn = Mock({}) conn = self.getFakeConnection()
self.app.dm = Mock({'getObjectHistory': None}) self.app.dm = Mock({'getObjectHistory': None})
self.operation.askObjectHistory(conn, INVALID_OID, 1, 2) self.operation.askObjectHistory(conn, INVALID_OID, 1, 2)
self.checkAnswerObjectHistory(conn) self.checkAnswerObjectHistory(conn)
# second case: not empty history # second case: not empty history
conn = Mock({}) conn = self.getFakeConnection()
self.app.dm = Mock({'getObjectHistory': [('', 0, ), ]}) self.app.dm = Mock({'getObjectHistory': [('', 0, ), ]})
self.operation.askObjectHistory(conn, INVALID_OID, 1, 2) self.operation.askObjectHistory(conn, INVALID_OID, 1, 2)
self.checkAnswerObjectHistory(conn) self.checkAnswerObjectHistory(conn)
...@@ -171,14 +169,14 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -171,14 +169,14 @@ class StorageStorageHandlerTests(NeoTestBase):
app = self.app app = self.app
app.pt = Mock() app.pt = Mock()
app.dm = Mock() app.dm = Mock()
conn = Mock({}) conn = self.getFakeConnection()
self.checkProtocolErrorRaised(self.operation.askOIDs, conn, 1, 1, None) self.checkProtocolErrorRaised(self.operation.askOIDs, conn, 1, 1, None)
self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0) self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0)
self.assertEquals(len(app.dm.mockGetNamedCalls('getOIDList')), 0) self.assertEquals(len(app.dm.mockGetNamedCalls('getOIDList')), 0)
def test_25_askOIDs2(self): def test_25_askOIDs2(self):
# well case > answer OIDs # well case > answer OIDs
conn = Mock({}) conn = self.getFakeConnection()
self.app.pt = Mock({'getPartitions': 1}) self.app.pt = Mock({'getPartitions': 1})
self.app.dm = Mock({'getOIDList': (INVALID_OID, )}) self.app.dm = Mock({'getOIDList': (INVALID_OID, )})
self.operation.askOIDs(conn, 1, 2, 1) self.operation.askOIDs(conn, 1, 2, 1)
...@@ -189,7 +187,7 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -189,7 +187,7 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_25_askOIDs3(self): def test_25_askOIDs3(self):
# invalid partition => answer usable partitions # invalid partition => answer usable partitions
conn = Mock({}) conn = self.getFakeConnection()
cell = Mock({'getUUID':self.app.uuid}) cell = Mock({'getUUID':self.app.uuid})
self.app.dm = Mock({'getOIDList': (INVALID_OID, )}) self.app.dm = Mock({'getOIDList': (INVALID_OID, )})
self.app.pt = Mock({ self.app.pt = Mock({
......
...@@ -45,15 +45,13 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -45,15 +45,13 @@ class BootstrapManagerTests(NeoTestBase):
# Tests # Tests
def testConnectionCompleted(self): def testConnectionCompleted(self):
uuid = self.getNewUUID() conn = self.getFakeConnection(address=("127.0.0.1", self.master_port))
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)})
self.bootstrap.connectionCompleted(conn) self.bootstrap.connectionCompleted(conn)
self.checkAskPrimary(conn) self.checkAskPrimary(conn)
def testHandleNotReady(self): def testHandleNotReady(self):
# the primary is not ready # the primary is not ready
conn = Mock({}) conn = self.getFakeConnection()
self.bootstrap.notReady(conn, '') self.bootstrap.notReady(conn, '')
self.checkClosed(conn) self.checkClosed(conn)
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
......
...@@ -39,8 +39,8 @@ class EventTests(NeoTestBase): ...@@ -39,8 +39,8 @@ class EventTests(NeoTestBase):
self.assertTrue(isinstance(em.epoll, Epoll)) self.assertTrue(isinstance(em.epoll, Epoll))
# use a mock object instead of epoll # use a mock object instead of epoll
em.epoll = Mock() em.epoll = Mock()
connector = Mock({"getDescriptor" : 1014}) connector = self.getFakeConnector(descriptor=1014)
conn = Mock({'getConnector': connector}) conn = self.getFakeConnection(connector=connector)
self.assertEqual(len(em.getConnectionList()), 0) self.assertEqual(len(em.getConnectionList()), 0)
# test register/unregister # test register/unregister
...@@ -52,8 +52,8 @@ class EventTests(NeoTestBase): ...@@ -52,8 +52,8 @@ class EventTests(NeoTestBase):
self.assertEqual(data, 1014) self.assertEqual(data, 1014)
self.assertEqual(len(em.getConnectionList()), 1) self.assertEqual(len(em.getConnectionList()), 1)
self.assertEqual(em.getConnectionList()[0].getDescriptor(), conn.getDescriptor()) self.assertEqual(em.getConnectionList()[0].getDescriptor(), conn.getDescriptor())
connector = Mock({"getDescriptor" : 1014}) connector = self.getFakeConnector(descriptor=1014)
conn = Mock({'getConnector': connector}) conn = self.getFakeConnection(connector=connector)
em.unregister(conn) em.unregister(conn)
self.assertEquals(len(connector.mockGetNamedCalls("getDescriptor")), 1) self.assertEquals(len(connector.mockGetNamedCalls("getDescriptor")), 1)
self.assertEquals(len(em.epoll.mockGetNamedCalls("unregister")), 1) self.assertEquals(len(em.epoll.mockGetNamedCalls("unregister")), 1)
...@@ -63,8 +63,7 @@ class EventTests(NeoTestBase): ...@@ -63,8 +63,7 @@ class EventTests(NeoTestBase):
self.assertEqual(len(em.getConnectionList()), 0) self.assertEqual(len(em.getConnectionList()), 0)
# add/removeReader # add/removeReader
connector = Mock({"getDescriptor" : 1515}) conn = self.getFakeConnection()
conn = Mock({'getConnector': connector})
self.assertEqual(len(em.reader_set), 0) self.assertEqual(len(em.reader_set), 0)
em.addReader(conn) em.addReader(conn)
self.assertEqual(len(em.reader_set), 1) self.assertEqual(len(em.reader_set), 1)
...@@ -80,8 +79,7 @@ class EventTests(NeoTestBase): ...@@ -80,8 +79,7 @@ class EventTests(NeoTestBase):
self.assertEquals(len(em.epoll.mockGetNamedCalls("modify")), 2) self.assertEquals(len(em.epoll.mockGetNamedCalls("modify")), 2)
# add/removeWriter # add/removeWriter
connector = Mock({"getDescriptor" : 1515}) conn = self.getFakeConnection()
conn = Mock({'getConnector': connector})
self.assertEqual(len(em.writer_set), 0) self.assertEqual(len(em.writer_set), 0)
em.addWriter(conn) em.addWriter(conn)
self.assertEqual(len(em.writer_set), 1) self.assertEqual(len(em.writer_set), 1)
...@@ -97,11 +95,11 @@ class EventTests(NeoTestBase): ...@@ -97,11 +95,11 @@ class EventTests(NeoTestBase):
self.assertEquals(len(em.epoll.mockGetNamedCalls("modify")), 4) self.assertEquals(len(em.epoll.mockGetNamedCalls("modify")), 4)
# poll # poll
r_connector = Mock({"getDescriptor" : 14515}) r_connector = self.getFakeConnector(descriptor=14515)
r_conn = Mock({'getConnector': r_connector}) r_conn = self.getFakeConnection(connector=r_connector)
em.register(r_conn) em.register(r_conn)
w_connector = Mock({"getDescriptor" : 351621}) w_connector = self.getFakeConnector(descriptor=351621)
w_conn = Mock({'getConnector': w_connector}) w_conn = self.getFakeConnection(connector=w_connector)
em.register(w_conn) em.register(w_conn)
em.epoll = Mock({"poll":( em.epoll = Mock({"poll":(
(r_connector.getDescriptor(),), (r_connector.getDescriptor(),),
......
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