Commit 235fdc88 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Fix some tests.


git-svn-id: https://svn.erp5.org/repos/neo/trunk@1307 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 8fdfe307
...@@ -21,6 +21,7 @@ import threading ...@@ -21,6 +21,7 @@ import threading
from mock import Mock, ReturnValues from mock import Mock, ReturnValues
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo import protocol from neo import protocol
from neo.pt import PartitionTable
from neo.protocol import UnexpectedPacketError, INVALID_UUID from neo.protocol import UnexpectedPacketError, INVALID_UUID
from neo.protocol import \ from neo.protocol import \
INVALID_PTID, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, MASTER_NODE_TYPE, \ INVALID_PTID, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, MASTER_NODE_TYPE, \
...@@ -348,12 +349,12 @@ class ClientHandlerTests(NeoTestBase): ...@@ -348,12 +349,12 @@ class ClientHandlerTests(NeoTestBase):
app = App() app = App()
client_handler = PrimaryBootstrapHandler(app) client_handler = PrimaryBootstrapHandler(app)
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)
# Test sanity checks # Test sanity checks
getNodeByServer_call_list = app.nm.mockGetNamedCalls('getNodeByServer') getNodeByServer_call_list = app.nm.mockGetNamedCalls('getNodeByServer')
self.assertEqual(len(getNodeByServer_call_list), 1) self.assertEqual(len(getNodeByServer_call_list), 1)
self.assertEqual(getNodeByServer_call_list[0].getParam(0), test_master_list[0][:2]) self.assertEqual(getNodeByServer_call_list[0].getParam(0), test_master_list[0][0])
# Check that known master node did not get added # Check that known master node did not get added
add_call_list = app.nm.mockGetNamedCalls('add') add_call_list = app.nm.mockGetNamedCalls('add')
self.assertEqual(len(add_call_list), 0) self.assertEqual(len(add_call_list), 0)
...@@ -453,41 +454,18 @@ class ClientHandlerTests(NeoTestBase): ...@@ -453,41 +454,18 @@ class ClientHandlerTests(NeoTestBase):
# Check that primary master was updated to known node # Check that primary master was updated to known node
self.assertTrue(app.primary_master_node is node) self.assertTrue(app.primary_master_node is node)
def test_initialSendPartitionTable(self):
client_handler = PrimaryBootstrapHandler(None)
conn = Mock({'getUUID': None})
self._testHandleUnexpectedPacketCalledWithMedhod(
client_handler.handleSendPartitionTable,
args=(conn, None, None, None))
def test_nonMasterSendPartitionTable(self):
for node_type in (CLIENT_NODE_TYPE, STORAGE_NODE_TYPE):
node = Mock({'getType': node_type})
class App:
nm = Mock({'getNodeByUUID': node})
pt = Mock()
app = App()
client_handler = PrimaryBootstrapHandler(app)
conn = self.getConnection()
client_handler.handleSendPartitionTable(conn, None, 0, [])
# Check that nothing happened
self.assertEquals(len(app.pt.mockGetNamedCalls('setCell')), 0)
self.assertEquals(len(app.pt.mockGetNamedCalls('removeCell')), 0)
def test_newSendPartitionTable(self): def test_newSendPartitionTable(self):
node = Mock({'getType': MASTER_NODE_TYPE}) node = Mock({'getType': MASTER_NODE_TYPE})
test_ptid = 0 test_ptid = 0
class App: class App:
nm = Mock({'getNodeByUUID': node}) nm = Mock({'getNodeByUUID': node})
pt = Mock({'clear': None}) pt = PartitionTable(1, 1)
ptid = test_ptid
app = App() app = App()
client_handler = PrimaryBootstrapHandler(app) client_handler = PrimaryNotificationsHandler(app, Mock())
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
self.assertEquals(app.ptid, test_ptid + 1) self.assertEquals(app.pt.getID(), 1)
self.assertEquals(len(app.pt.mockGetNamedCalls('clear')), 1)
def test_unknownNodeSendPartitionTable(self): def test_unknownNodeSendPartitionTable(self):
test_node = Mock({'getType': MASTER_NODE_TYPE}) test_node = Mock({'getType': MASTER_NODE_TYPE})
......
...@@ -81,6 +81,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -81,6 +81,7 @@ class MasterClientHandlerTests(NeoTestBase):
node = ClientNode(address, uuid) node = ClientNode(address, uuid)
else: else:
node = StorageNode(address, uuid) node = StorageNode(address, uuid)
node.setState(protocol.RUNNING_STATE)
self.app.nm.add(node) self.app.nm.add(node)
return uuid return uuid
......
...@@ -79,6 +79,11 @@ class MasterVerificationTests(NeoTestBase): ...@@ -79,6 +79,11 @@ class MasterVerificationTests(NeoTestBase):
"""Do first step of identification to MN """Do first step of identification to MN
""" """
uuid = self.getNewUUID() uuid = self.getNewUUID()
if node_type == STORAGE_NODE_TYPE:
node = StorageNode(uuid=uuid)
else:
node = MasterNode(uuid=uuid)
self.app.nm.add(node)
return uuid return uuid
# Tests # Tests
...@@ -121,57 +126,6 @@ class MasterVerificationTests(NeoTestBase): ...@@ -121,57 +126,6 @@ class MasterVerificationTests(NeoTestBase):
self.assertRaises(VerificationFailure, self.verification.connectionClosed,conn) self.assertRaises(VerificationFailure, self.verification.connectionClosed,conn)
self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE) self.assertEqual(self.app.nm.getNodeByServer(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE)
def test_08_handleNotifyNodeInformation(self):
verification = self.verification
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION)
# tell about a client node, do nothing
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(CLIENT_NODE_TYPE, ('127.0.0.1', self.client_port), self.getNewUUID(), DOWN_STATE),]
self.assertEqual(len(self.app.nm.getClientNodeList()), 0)
verification.handleNotifyNodeInformation(conn, packet, node_list)
self.assertEqual(len(self.app.nm.getClientNodeList()), 0)
# tell the master node about itself, if running must do nothing
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, ('127.0.0.1', self.master_port-1), self.app.uuid, RUNNING_STATE),]
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port-1))
self.assertEqual(node, None)
verification.handleNotifyNodeInformation(conn, packet, node_list)
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port-1))
# tell the master node about itself, if down must raise
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, ('127.0.0.1', self.master_port-1), self.app.uuid, DOWN_STATE),]
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port-1))
self.assertEqual(node, None)
self.assertRaises(RuntimeError, verification.handleNotifyNodeInformation, conn, packet, node_list)
# tell about an unknown storage node, do nothing
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(STORAGE_NODE_TYPE, ('127.0.0.1', self.master_port - 1), self.getNewUUID(), DOWN_STATE),]
self.assertEqual(len(self.app.nm.getStorageNodeList()), 0)
verification.handleNotifyNodeInformation(conn, packet, node_list)
self.assertEqual(len(self.app.nm.getStorageNodeList()), 0)
# tell about a known node but different address
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, ('127.0.0.2', self.master_port), uuid, DOWN_STATE),]
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port))
self.assertEqual(node.getState(), RUNNING_STATE)
verification.handleNotifyNodeInformation(conn, packet, node_list)
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port))
self.assertEqual(node.getState(), RUNNING_STATE)
# tell about a known node
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, ('127.0.0.1', self.master_port), uuid, DOWN_STATE),]
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port))
self.assertEqual(node.getState(), RUNNING_STATE)
verification.handleNotifyNodeInformation(conn, packet, node_list)
node = self.app.nm.getNodeByServer(("127.0.0.1", self.master_port))
self.assertEqual(node.getState(), DOWN_STATE)
def test_09_handleAnswerLastIDs(self): def test_09_handleAnswerLastIDs(self):
verification = self.verification verification = self.verification
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
...@@ -196,14 +150,6 @@ class MasterVerificationTests(NeoTestBase): ...@@ -196,14 +150,6 @@ class MasterVerificationTests(NeoTestBase):
self.assertNotEquals(new_tid, self.app.ltid) self.assertNotEquals(new_tid, self.app.ltid)
self.assertNotEquals(new_ptid, self.app.pt.getID()) self.assertNotEquals(new_ptid, self.app.pt.getID())
def test_10_handleAnswerPartitionTable(self):
verification = self.verification
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port)
packet = Packet(msg_type=ANSWER_PARTITION_TABLE, )
conn = self.getFakeConnection(uuid, self.master_address)
verification.handleAnswerPartitionTable(conn, packet, None, [])
self.assertEqual(len(conn.mockGetAllCalls()), 0)
def test_11_handleAnswerUnfinishedTransactions(self): def test_11_handleAnswerUnfinishedTransactions(self):
verification = self.verification verification = self.verification
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
......
...@@ -109,7 +109,6 @@ class StorageInitializationHandlerTests(NeoTestBase): ...@@ -109,7 +109,6 @@ class StorageInitializationHandlerTests(NeoTestBase):
self.app.nm.add(StorageNode(uuid=node_1)) self.app.nm.add(StorageNode(uuid=node_1))
self.app.nm.add(StorageNode(uuid=node_2)) self.app.nm.add(StorageNode(uuid=node_2))
self.app.nm.add(StorageNode(uuid=node_3)) self.app.nm.add(StorageNode(uuid=node_3))
self.app.ptid = 1
self.assertEqual(self.app.dm.getPartitionTable(), []) self.assertEqual(self.app.dm.getPartitionTable(), [])
row_list = [(0, ((node_1, UP_TO_DATE_STATE), (node_2, UP_TO_DATE_STATE))), row_list = [(0, ((node_1, UP_TO_DATE_STATE), (node_2, UP_TO_DATE_STATE))),
(1, ((node_3, UP_TO_DATE_STATE), (node_1, UP_TO_DATE_STATE))), (1, ((node_3, UP_TO_DATE_STATE), (node_1, UP_TO_DATE_STATE))),
......
...@@ -182,9 +182,9 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -182,9 +182,9 @@ class StorageVerificationHandlerTests(NeoTestBase):
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
}) })
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES) packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES)
self.app.ptid = 1 self.verification.handleNotifyPartitionChanges(conn, packet, 1, ())
self.verification.handleNotifyPartitionChanges(conn, packet, 0, ()) self.verification.handleNotifyPartitionChanges(conn, packet, 0, ())
self.assertEquals(self.app.ptid, 1) self.assertEqual(self.app.pt.getID(), 1)
# new node # new node
conn = Mock({ conn = Mock({
......
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