[Neo-report] r2055 gregory - in /trunk/neo/tests: ./ master/ storage/
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Apr 30 15:47:46 CEST 2010
Author: gregory
Date: Fri Apr 30 15:47:42 2010
New Revision: 2055
Log:
Use more getFakeConnection() to build a clean mock object.
Modified:
trunk/neo/tests/__init__.py
trunk/neo/tests/master/testElectionHandler.py
trunk/neo/tests/storage/testInitializationHandler.py
trunk/neo/tests/storage/testMasterHandler.py
trunk/neo/tests/storage/testVerificationHandler.py
trunk/neo/tests/testHandler.py
Modified: trunk/neo/tests/__init__.py
==============================================================================
--- trunk/neo/tests/__init__.py [iso-8859-1] (original)
+++ trunk/neo/tests/__init__.py [iso-8859-1] Fri Apr 30 15:47:42 2010
@@ -149,10 +149,14 @@
uuids = self.getNewUUID(), self.getNewUUID()
return min(uuids), max(uuids)
- 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):
return Mock({
'getUUID': uuid,
'getAddress': address,
+ 'isServer': is_server,
+ '__repr__': 'FakeConnection',
+ '__nonzero__': 0,
})
def checkProtocolErrorRaised(self, method, *args, **kwargs):
Modified: trunk/neo/tests/master/testElectionHandler.py
==============================================================================
--- trunk/neo/tests/master/testElectionHandler.py [iso-8859-1] (original)
+++ trunk/neo/tests/master/testElectionHandler.py [iso-8859-1] Fri Apr 30 15:47:42 2010
@@ -62,11 +62,8 @@
def identifyToMasterNode(self):
node = self.app.nm.getMasterList()[0]
node.setUUID(self.getNewUUID())
- conn = Mock({
- "getUUID": node.getUUID(),
- "getAddress": node.getAddress(),
- "getConnector": Mock(),
- })
+ conn = self.getFakeConnection(uuid=node.getUUID(),
+ address=node.getAddress())
return (node, conn)
def _checkUnconnected(self, node):
Modified: trunk/neo/tests/storage/testInitializationHandler.py
==============================================================================
--- trunk/neo/tests/storage/testInitializationHandler.py [iso-8859-1] (original)
+++ trunk/neo/tests/storage/testInitializationHandler.py [iso-8859-1] Fri Apr 30 15:47:42 2010
@@ -49,43 +49,31 @@
def getLastUUID(self):
return self.uuid
+ def getClientConnection(self):
+ address = ("127.0.0.1", self.client_port)
+ return self.getFakeConnection(uuid=self.getNewUUID(), address=address)
+
def test_02_timeoutExpired(self):
- # client connection
- uuid = self.getNewUUID()
- conn = Mock({"getUUID" : uuid,
- "getAddress" : ("127.0.0.1", self.client_port),
- "isServer" : False})
+ conn = self.getClientConnection()
self.assertRaises(PrimaryFailure, self.verification.timeoutExpired, conn,)
# nothing happens
self.checkNoPacketSent(conn)
def test_03_connectionClosed(self):
- # client connection
- uuid = self.getNewUUID()
- conn = Mock({"getUUID" : uuid,
- "getAddress" : ("127.0.0.1", self.client_port),
- "isServer" : False})
+ conn = self.getClientConnection()
self.assertRaises(PrimaryFailure, self.verification.connectionClosed, conn,)
# nothing happens
self.checkNoPacketSent(conn)
def test_04_peerBroken(self):
- # client connection
- uuid = self.getNewUUID()
- conn = Mock({"getUUID" : uuid,
- "getAddress" : ("127.0.0.1", self.client_port),
- "isServer" : False})
+ conn = self.getClientConnection()
self.assertRaises(PrimaryFailure, self.verification.peerBroken, conn,)
# nothing happens
self.checkNoPacketSent(conn)
def test_09_sendPartitionTable(self):
- uuid = self.getNewUUID()
# send a table
- conn = Mock({"getUUID" : uuid,
- "getAddress" : ("127.0.0.1", self.client_port),
- "isServer" : False})
-
+ conn = self.getClientConnection()
self.app.pt = PartitionTable(3, 2)
node_1 = self.getNewUUID()
node_2 = self.getNewUUID()
Modified: trunk/neo/tests/storage/testMasterHandler.py
==============================================================================
--- trunk/neo/tests/storage/testMasterHandler.py [iso-8859-1] (original)
+++ trunk/neo/tests/storage/testMasterHandler.py [iso-8859-1] Fri Apr 30 15:47:42 2010
@@ -29,10 +29,7 @@
class StorageMasterHandlerTests(NeoTestBase):
def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs):
- conn = Mock({
- "getAddress" : ("127.0.0.1", self.master_port),
- "isServer": _listening,
- })
+ conn = self.getMasterConnection(is_server=_listening)
# hook
self.operation.peerBroken = lambda c: c.peerBrokendCalled()
self.checkUnexpectedPacketRaised(_call, conn=conn, **kwargs)
@@ -58,41 +55,32 @@
def tearDown(self):
NeoTestBase.tearDown(self)
+ def getMasterConnection(self):
+ address = ("127.0.0.1", self.master_port)
+ return self.getFakeConnection(uuid=self.master_uuid, address=address)
def test_06_timeoutExpired(self):
# client connection
- conn = Mock({
- "getUUID": self.master_uuid,
- "getAddress" : ("127.0.0.1", self.master_port),
- })
+ conn = self.getMasterConnection()
self.assertRaises(PrimaryFailure, self.operation.timeoutExpired, conn)
self.checkNoPacketSent(conn)
def test_07_connectionClosed2(self):
# primary has closed the connection
- conn = Mock({
- "getUUID": self.master_uuid,
- "getAddress" : ("127.0.0.1", self.master_port),
- })
+ conn = self.getMasterConnection()
self.assertRaises(PrimaryFailure, self.operation.connectionClosed, conn)
self.checkNoPacketSent(conn)
def test_08_peerBroken(self):
# client connection
- conn = Mock({
- "getUUID": self.master_uuid,
- "getAddress" : ("127.0.0.1", self.master_port),
- })
+ conn = self.getMasterConnection()
self.assertRaises(PrimaryFailure, self.operation.peerBroken, conn)
self.checkNoPacketSent(conn)
def test_14_notifyPartitionChanges1(self):
# old partition change -> do nothing
app = self.app
- conn = Mock({
- "isServer": False,
- "getAddress" : ("127.0.0.1", self.master_port),
- })
+ conn = self.getMasterConnection()
app.replicator = Mock({})
self.app.pt = Mock({'getID': 1})
count = len(self.app.nm.getList())
@@ -113,10 +101,7 @@
(2, uuid3, CellStates.OUT_OF_DATE),
)
# context
- conn = Mock({
- "isServer": False,
- "getAddress" : ("127.0.0.1", self.master_port),
- })
+ conn = self.getMasterConnection()
app = self.app
# register nodes
app.nm.createStorage(uuid=uuid1)
Modified: trunk/neo/tests/storage/testVerificationHandler.py
==============================================================================
--- trunk/neo/tests/storage/testVerificationHandler.py [iso-8859-1] (original)
+++ trunk/neo/tests/storage/testVerificationHandler.py [iso-8859-1] Fri Apr 30 15:47:42 2010
@@ -52,43 +52,34 @@
def getLastUUID(self):
return self.uuid
+ def getClientConnection(self):
+ address = ("127.0.0.1", self.client_port)
+ return self.getFakeConnection(uuid=self.getNewUUID(), address=address)
+
+ def getMasterConnection(self):
+ return self.getFakeConnection(address=("127.0.0.1", self.master_port))
+
# Tests
def test_02_timeoutExpired(self):
- # client connection
- uuid = self.getNewUUID()
- conn = Mock({"getUUID" : uuid,
- "getAddress" : ("127.0.0.1", self.client_port),
- "isServer" : False})
+ conn = self.getClientConnection()
self.assertRaises(PrimaryFailure, self.verification.timeoutExpired, conn,)
# nothing happens
self.checkNoPacketSent(conn)
def test_03_connectionClosed(self):
- # client connection
- uuid = self.getNewUUID()
- conn = Mock({"getUUID" : uuid,
- "getAddress" : ("127.0.0.1", self.client_port),
- "isServer" : False})
+ conn = self.getClientConnection()
self.assertRaises(PrimaryFailure, self.verification.connectionClosed, conn,)
# nothing happens
self.checkNoPacketSent(conn)
def test_04_peerBroken(self):
- # client connection
- uuid = self.getNewUUID()
- conn = Mock({"getUUID" : uuid,
- "getAddress" : ("127.0.0.1", self.client_port),
- "isServer" : False})
+ conn = self.getClientConnection()
self.assertRaises(PrimaryFailure, self.verification.peerBroken, conn,)
# nothing happens
self.checkNoPacketSent(conn)
def test_07_askLastIDs(self):
- uuid = self.getNewUUID()
- # return invalid if db store nothing
- conn = Mock({"getUUID" : uuid,
- "getAddress" : ("127.0.0.1", self.client_port),
- "isServer" : False})
+ conn = self.getClientConnection()
last_ptid = '\x01' * 8
last_oid = '\x02' * 8
self.app.pt = Mock({'getID': last_ptid})
@@ -100,9 +91,7 @@
# return value stored in db
# insert some oid
- conn = Mock({"getUUID" : uuid,
- "getAddress" : ("127.0.0.1", self.client_port),
- "isServer" : False})
+ conn = self.getClientConnection()
self.app.dm.begin()
self.app.dm.query("""insert into obj (oid, serial, compression,
checksum, value) values (3, 'A', 0, 0, '')""")
@@ -132,14 +121,11 @@
self.assertEqual(ptid, self.app.pt.getID())
def test_08_askPartitionTable(self):
- uuid = self.getNewUUID()
# try to get unknown offset
self.assertEqual(len(self.app.pt.getNodeList()), 0)
self.assertFalse(self.app.pt.hasOffset(1))
self.assertEqual(len(self.app.pt.getCellList(1)), 0)
- conn = Mock({"getUUID" : uuid,
- "getAddress" : ("127.0.0.1", self.client_port),
- "isServer" : False})
+ conn = self.getClientConnection()
self.verification.askPartitionTable(conn, [1])
ptid, row_list = self.checkAnswerPartitionTable(conn, decode=True)
self.assertEqual(len(row_list), 1)
@@ -154,9 +140,7 @@
)
self.app.pt.setCell(1, node, CellStates.UP_TO_DATE)
self.assertTrue(self.app.pt.hasOffset(1))
- conn = Mock({"getUUID" : uuid,
- "getAddress" : ("127.0.0.1", self.client_port),
- "isServer" : False})
+ conn = self.getClientConnection()
self.verification.askPartitionTable(conn, [1])
ptid, row_list = self.checkAnswerPartitionTable(conn, decode=True)
self.assertEqual(len(row_list), 1)
@@ -166,19 +150,13 @@
def test_10_notifyPartitionChanges(self):
# old partition change
- conn = Mock({
- "isServer": False,
- "getAddress" : ("127.0.0.1", self.master_port),
- })
+ conn = self.getMasterConnection()
self.verification.notifyPartitionChanges(conn, 1, ())
self.verification.notifyPartitionChanges(conn, 0, ())
self.assertEqual(self.app.pt.getID(), 1)
# new node
- conn = Mock({
- "isServer": False,
- "getAddress" : ("127.0.0.1", self.master_port),
- })
+ conn = self.getMasterConnection()
new_uuid = self.getNewUUID()
cell = (0, new_uuid, CellStates.UP_TO_DATE)
self.app.nm.createStorage(uuid=new_uuid)
@@ -194,21 +172,18 @@
self.assertEquals(calls[0].getParam(1), (cell, ))
def test_11_startOperation(self):
- conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
- 'isServer': False })
+ conn = self.getMasterConnection()
self.assertFalse(self.app.operational)
self.verification.startOperation(conn)
self.assertTrue(self.app.operational)
def test_12_stopOperation(self):
- conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
- 'isServer': False })
+ conn = self.getMasterConnection()
self.assertRaises(OperationFailure, self.verification.stopOperation, conn)
def test_13_askUnfinishedTransactions(self):
# client connection with no data
- conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
- 'isServer': False})
+ conn = self.getMasterConnection()
self.verification.askUnfinishedTransactions(conn)
(tid_list, ) = self.checkAnswerUnfinishedTransactions(conn, decode=True)
self.assertEqual(len(tid_list), 0)
@@ -218,8 +193,7 @@
self.app.dm.query("""insert into tobj (oid, serial, compression,
checksum, value) values (0, 4, 0, 0, '')""")
self.app.dm.commit()
- conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
- 'isServer': False})
+ conn = self.getMasterConnection()
self.verification.askUnfinishedTransactions(conn)
(tid_list, ) = self.checkAnswerUnfinishedTransactions(conn, decode=True)
self.assertEqual(len(tid_list), 1)
@@ -227,8 +201,7 @@
def test_14_askTransactionInformation(self):
# ask from client conn with no data
- conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
- 'isServer': False })
+ conn = self.getMasterConnection()
self.verification.askTransactionInformation(conn, p64(1))
code, message = self.checkErrorPacket(conn, decode=True)
self.assertEqual(code, ErrorCodes.TID_NOT_FOUND)
@@ -241,8 +214,7 @@
description, ext) values (1,'%s', 'u2', 'd2', 'e2')""" %(p64(2),))
self.app.dm.commit()
# object from trans
- conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
- 'isServer': False })
+ conn = self.getClientConnection()
self.verification.askTransactionInformation(conn, p64(1))
tid, user, desc, ext, packed, oid_list = self.checkAnswerTransactionInformation(conn, decode=True)
self.assertEqual(u64(tid), 1)
@@ -252,8 +224,7 @@
self.assertEqual(len(oid_list), 1)
self.assertEqual(u64(oid_list[0]), 2)
# object from ttrans
- conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
- 'isServer': False })
+ conn = self.getMasterConnection()
self.verification.askTransactionInformation(conn, p64(3))
tid, user, desc, ext, packed, oid_list = self.checkAnswerTransactionInformation(conn, decode=True)
self.assertEqual(u64(tid), 3)
@@ -264,8 +235,7 @@
self.assertEqual(u64(oid_list[0]), 4)
# input some tmp data and ask from server, must find one transaction
- conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
- 'isServer': True })
+ conn = self.getMasterConnection()
# find the one in trans
self.verification.askTransactionInformation(conn, p64(1))
tid, user, desc, ext, packed, oid_list = self.checkAnswerTransactionInformation(conn, decode=True)
@@ -276,16 +246,14 @@
self.assertEqual(len(oid_list), 1)
self.assertEqual(u64(oid_list[0]), 2)
# do not find the one in ttrans
- conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
- 'isServer': True })
+ conn = self.getMasterConnection()
self.verification.askTransactionInformation(conn, p64(2))
code, message = self.checkErrorPacket(conn, decode=True)
self.assertEqual(code, ErrorCodes.TID_NOT_FOUND)
def test_15_askObjectPresent(self):
# client connection with no data
- conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
- 'isServer': False})
+ conn = self.getMasterConnection()
self.verification.askObjectPresent(conn, p64(1), p64(2))
code, message = self.checkErrorPacket(conn, decode=True)
self.assertEqual(code, ErrorCodes.OID_NOT_FOUND)
@@ -295,8 +263,7 @@
self.app.dm.query("""insert into tobj (oid, serial, compression,
checksum, value) values (1, 2, 0, 0, '')""")
self.app.dm.commit()
- conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
- 'isServer': False})
+ conn = self.getMasterConnection()
self.verification.askObjectPresent(conn, p64(1), p64(2))
oid, tid = self.checkAnswerObjectPresent(conn, decode=True)
self.assertEqual(u64(tid), 2)
@@ -304,8 +271,7 @@
def test_16_deleteTransaction(self):
# client connection with no data
- conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
- 'isServer': False})
+ conn = self.getMasterConnection()
self.verification.deleteTransaction(conn, p64(1))
# client connection with data
self.app.dm.begin()
@@ -318,8 +284,7 @@
def test_17_commitTransaction(self):
# commit a transaction
- conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
- 'isServer': False })
+ conn = self.getMasterConnection()
dm = Mock()
self.app.dm = dm
self.verification.commitTransaction(conn, p64(1))
Modified: trunk/neo/tests/testHandler.py
==============================================================================
--- trunk/neo/tests/testHandler.py [iso-8859-1] (original)
+++ trunk/neo/tests/testHandler.py [iso-8859-1] Fri Apr 30 15:47:42 2010
@@ -45,7 +45,7 @@
self.assertEquals(len(calls), 1)
def test_dispatch(self):
- conn = Mock({'getAddress': ('127.0.0.1', 10000)})
+ conn = self.getFakeConnection()
packet = self.getFakePacket()
# all is ok
self.setFakeMethod(lambda c: None)
More information about the Neo-report
mailing list