Commit dd02fa4c authored by Grégory Wisniewski's avatar Grégory Wisniewski

Remove manager getter/setter from Node class and require it in the constructor

since a node must always be registered to the manager. Remove *args parameters,
positional arguments are no more allowed for node creation.
Fix wrong definition of dict in createFromNodeType.


git-svn-id: https://svn.erp5.org/repos/neo/trunk@1313 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 68835978
...@@ -29,18 +29,12 @@ from neo.util import dump ...@@ -29,18 +29,12 @@ from neo.util import dump
class Node(object): class Node(object):
"""This class represents a node.""" """This class represents a node."""
def __init__(self, server=None, uuid=None, state=protocol.UNKNOWN_STATE): def __init__(self, manager, server=None, uuid=None, state=protocol.UNKNOWN_STATE):
self.state = state self.state = state
self.server = server self.server = server
self.uuid = uuid self.uuid = uuid
self.manager = None
self.last_state_change = time()
def setManager(self, manager):
self.manager = manager self.manager = manager
self.last_state_change = time()
def getManager(self):
return self.manager
def getLastStateChange(self): def getLastStateChange(self):
return self.last_state_change return self.last_state_change
...@@ -135,7 +129,6 @@ class NodeManager(object): ...@@ -135,7 +129,6 @@ class NodeManager(object):
self.uuid_dict = {} self.uuid_dict = {}
def add(self, node): def add(self, node):
node.setManager(self)
self.node_list.append(node) self.node_list.append(node)
if node.getServer() is not None: if node.getServer() is not None:
self.registerServer(node) self.registerServer(node)
...@@ -200,38 +193,38 @@ class NodeManager(object): ...@@ -200,38 +193,38 @@ class NodeManager(object):
return None return None
return self.uuid_dict.get(uuid) return self.uuid_dict.get(uuid)
def _createNode(self, klass, *args, **kw): def _createNode(self, klass, **kw):
node = klass(*args, **kw) node = klass(self, **kw)
self.add(node) self.add(node)
return node return node
def createMaster(self, *args, **kw): def createMaster(self, **kw):
""" Create and register a new master """ """ Create and register a new master """
return self._createNode(MasterNode, *args, **kw) return self._createNode(MasterNode, **kw)
def createStorage(self, *args, **kw): def createStorage(self, *args, **kw):
""" Create and register a new storage """ """ Create and register a new storage """
return self._createNode(StorageNode, *args, **kw) return self._createNode(StorageNode, **kw)
def createClient(self, *args, **kw): def createClient(self, *args, **kw):
""" Create and register a new client """ """ Create and register a new client """
return self._createNode(ClientNode, *args, **kw) return self._createNode(ClientNode, **kw)
def createAdmin(self, *args, **kw): def createAdmin(self, *args, **kw):
""" Create and register a new admin """ """ Create and register a new admin """
return self._createNode(AdminNode, *args, **kw) return self._createNode(AdminNode, **kw)
def createFromNodeType(self, node_type, *args, **kw): def createFromNodeType(self, node_type, **kw):
# XXX: use a static dict or drop this # XXX: use a static dict or drop this
klass = { klass = {
protocol.MASTER_NODE_TYPE: self.createMaster, protocol.MASTER_NODE_TYPE: MasterNode,
protocol.STORAGE_NODE_TYPE: self.createStorage, protocol.STORAGE_NODE_TYPE: StorageNode,
protocol.CLIENT_NODE_TYPE: self.createClient, protocol.CLIENT_NODE_TYPE: ClientNode,
protocol.ADMIN_NODE_TYPE: self.createAdmin, protocol.ADMIN_NODE_TYPE: AdminNode,
}.get(node_type) }.get(node_type)
if klass is None: if klass is None:
raise RuntimeError('Unknown node type : %s' % node_type) raise RuntimeError('Unknown node type : %s' % node_type)
return self._createNode(klass, *args, **kw) return self._createNode(klass, **kw)
def clear(self, filter=None): def clear(self, filter=None):
for node in self.getNodeList(): for node in self.getNodeList():
...@@ -264,7 +257,7 @@ class NodeManager(object): ...@@ -264,7 +257,7 @@ class NodeManager(object):
klass = NODE_TYPE_MAPPING.get(node_type, None) klass = NODE_TYPE_MAPPING.get(node_type, None)
if klass is None: if klass is None:
raise RuntimeError('Unknown node type') raise RuntimeError('Unknown node type')
node = klass(server=addr, uuid=uuid) node = klass(self, server=addr, uuid=uuid)
node.setState(state) node.setState(state)
self.add(node) self.add(node)
logging.info('create node %s %s %s %s' % log_args) logging.info('create node %s %s %s %s' % log_args)
......
...@@ -72,18 +72,18 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -72,18 +72,18 @@ class MasterPartitionTableTests(NeoTestBase):
# add nodes # add nodes
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
pt.setCell(0, sn1, UP_TO_DATE_STATE) pt.setCell(0, sn1, UP_TO_DATE_STATE)
pt.setCell(1, sn1, UP_TO_DATE_STATE) pt.setCell(1, sn1, UP_TO_DATE_STATE)
pt.setCell(2, sn1, UP_TO_DATE_STATE) pt.setCell(2, sn1, UP_TO_DATE_STATE)
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
server2 = ("127.0.0.2", 19001) server2 = ("127.0.0.2", 19001)
sn2 = StorageNode(server2, uuid2) sn2 = StorageNode(Mock(), server2, uuid2)
pt.setCell(0, sn2, UP_TO_DATE_STATE) pt.setCell(0, sn2, UP_TO_DATE_STATE)
pt.setCell(1, sn2, UP_TO_DATE_STATE) pt.setCell(1, sn2, UP_TO_DATE_STATE)
uuid3 = self.getNewUUID() uuid3 = self.getNewUUID()
server3 = ("127.0.0.3", 19001) server3 = ("127.0.0.3", 19001)
sn3 = StorageNode(server3, uuid3) sn3 = StorageNode(Mock(), server3, uuid3)
pt.setCell(0, sn3, UP_TO_DATE_STATE) pt.setCell(0, sn3, UP_TO_DATE_STATE)
# test # test
node = pt.findLeastUsedNode() node = pt.findLeastUsedNode()
...@@ -97,19 +97,19 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -97,19 +97,19 @@ class MasterPartitionTableTests(NeoTestBase):
# create nodes # create nodes
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
server2 = ("127.0.0.2", 19002) server2 = ("127.0.0.2", 19002)
sn2 = StorageNode(server2, uuid2) sn2 = StorageNode(Mock(), server2, uuid2)
uuid3 = self.getNewUUID() uuid3 = self.getNewUUID()
server3 = ("127.0.0.3", 19003) server3 = ("127.0.0.3", 19003)
sn3 = StorageNode(server3, uuid3) sn3 = StorageNode(Mock(), server3, uuid3)
uuid4 = self.getNewUUID() uuid4 = self.getNewUUID()
server4 = ("127.0.0.4", 19004) server4 = ("127.0.0.4", 19004)
sn4 = StorageNode(server4, uuid4) sn4 = StorageNode(Mock(), server4, uuid4)
uuid5 = self.getNewUUID() uuid5 = self.getNewUUID()
server5 = ("127.0.0.5", 19005) server5 = ("127.0.0.5", 19005)
sn5 = StorageNode(server5, uuid5) sn5 = StorageNode(Mock(), server5, uuid5)
# create partition table # create partition table
num_partitions = 5 num_partitions = 5
num_replicas = 3 num_replicas = 3
...@@ -165,7 +165,7 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -165,7 +165,7 @@ class MasterPartitionTableTests(NeoTestBase):
# add nodes # add nodes
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
# add it to an empty pt # add it to an empty pt
cell_list = pt.addNode(sn1) cell_list = pt.addNode(sn1)
self.assertEqual(len(cell_list), 5) self.assertEqual(len(cell_list), 5)
...@@ -186,7 +186,7 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -186,7 +186,7 @@ class MasterPartitionTableTests(NeoTestBase):
# add a second node to fill the partition table # add a second node to fill the partition table
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
server2 = ("127.0.0.2", 19002) server2 = ("127.0.0.2", 19002)
sn2 = StorageNode(server2, uuid2) sn2 = StorageNode(Mock(), server2, uuid2)
# add it # add it
cell_list = pt.addNode(sn2) cell_list = pt.addNode(sn2)
self.assertEqual(len(cell_list), 5) self.assertEqual(len(cell_list), 5)
...@@ -197,13 +197,13 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -197,13 +197,13 @@ class MasterPartitionTableTests(NeoTestBase):
# test the most used node is remove from some partition # test the most used node is remove from some partition
uuid3 = self.getNewUUID() uuid3 = self.getNewUUID()
server3 = ("127.0.0.3", 19001) server3 = ("127.0.0.3", 19001)
sn3 = StorageNode(server3, uuid3) sn3 = StorageNode(Mock(), server3, uuid3)
uuid4 = self.getNewUUID() uuid4 = self.getNewUUID()
server4 = ("127.0.0.4", 19001) server4 = ("127.0.0.4", 19001)
sn4 = StorageNode(server4, uuid4) sn4 = StorageNode(Mock(), server4, uuid4)
uuid5 = self.getNewUUID() uuid5 = self.getNewUUID()
server5 = ("127.0.0.5", 1900) server5 = ("127.0.0.5", 1900)
sn5 = StorageNode(server5, uuid5) sn5 = StorageNode(Mock(), server5, uuid5)
# partition looks like: # partition looks like:
# 0 : sn1, sn2 # 0 : sn1, sn2
# 1 : sn1, sn3 # 1 : sn1, sn3
...@@ -223,7 +223,7 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -223,7 +223,7 @@ class MasterPartitionTableTests(NeoTestBase):
pt.setCell(3, sn5, UP_TO_DATE_STATE) pt.setCell(3, sn5, UP_TO_DATE_STATE)
uuid6 = self.getNewUUID() uuid6 = self.getNewUUID()
server6 = ("127.0.0.6", 19006) server6 = ("127.0.0.6", 19006)
sn6 = StorageNode(server6, uuid6) sn6 = StorageNode(Mock(), server6, uuid6)
cell_list = pt.addNode(sn6) cell_list = pt.addNode(sn6)
# sn1 is removed twice and sn6 is added twice # sn1 is removed twice and sn6 is added twice
self.assertEqual(len(cell_list), 4) self.assertEqual(len(cell_list), 4)
...@@ -301,16 +301,16 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -301,16 +301,16 @@ class MasterPartitionTableTests(NeoTestBase):
# add nodes # add nodes
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
server2 = ("127.0.0.2", 19002) server2 = ("127.0.0.2", 19002)
sn2 = StorageNode(server2, uuid2) sn2 = StorageNode(Mock(), server2, uuid2)
uuid3 = self.getNewUUID() uuid3 = self.getNewUUID()
server3 = ("127.0.0.3", 19001) server3 = ("127.0.0.3", 19001)
sn3 = StorageNode(server3, uuid3) sn3 = StorageNode(Mock(), server3, uuid3)
uuid4 = self.getNewUUID() uuid4 = self.getNewUUID()
server4 = ("127.0.0.4", 19001) server4 = ("127.0.0.4", 19001)
sn4 = StorageNode(server4, uuid4) sn4 = StorageNode(Mock(), server4, uuid4)
# partition looks like: # partition looks like:
# 0 : sn1, sn2 # 0 : sn1, sn2
# 1 : sn1, sn3 # 1 : sn1, sn3
...@@ -368,22 +368,22 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -368,22 +368,22 @@ class MasterPartitionTableTests(NeoTestBase):
# add nodes # add nodes
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
# add not running node # add not running node
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
server2 = ("127.0.0.2", 19001) server2 = ("127.0.0.2", 19001)
sn2 = StorageNode(server2, uuid2) sn2 = StorageNode(Mock(), server2, uuid2)
sn2.setState(TEMPORARILY_DOWN_STATE) sn2.setState(TEMPORARILY_DOWN_STATE)
# add node without uuid # add node without uuid
server3 = ("127.0.0.3", 19001) server3 = ("127.0.0.3", 19001)
sn3 = StorageNode(server3, None) sn3 = StorageNode(Mock(), server3, None)
# add clear node # add clear node
uuid4 = self.getNewUUID() uuid4 = self.getNewUUID()
server4 = ("127.0.0.4", 19001) server4 = ("127.0.0.4", 19001)
sn4 = StorageNode(server4, uuid4) sn4 = StorageNode(Mock(), server4, uuid4)
uuid5 = self.getNewUUID() uuid5 = self.getNewUUID()
server5 = ("127.0.0.5", 1900) server5 = ("127.0.0.5", 1900)
sn5 = StorageNode(server5, uuid5) sn5 = StorageNode(Mock(), server5, uuid5)
# make the table # make the table
pt.make([sn1, sn2, sn3, sn4, sn5,]) pt.make([sn1, sn2, sn3, sn4, sn5,])
# check it's ok, only running nodes and node with uuid # check it's ok, only running nodes and node with uuid
...@@ -422,19 +422,19 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -422,19 +422,19 @@ class MasterPartitionTableTests(NeoTestBase):
# create nodes # create nodes
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
server2 = ("127.0.0.2", 19002) server2 = ("127.0.0.2", 19002)
sn2 = StorageNode(server2, uuid2) sn2 = StorageNode(Mock(), server2, uuid2)
uuid3 = self.getNewUUID() uuid3 = self.getNewUUID()
server3 = ("127.0.0.3", 19003) server3 = ("127.0.0.3", 19003)
sn3 = StorageNode(server3, uuid3) sn3 = StorageNode(Mock(), server3, uuid3)
uuid4 = self.getNewUUID() uuid4 = self.getNewUUID()
server4 = ("127.0.0.4", 19004) server4 = ("127.0.0.4", 19004)
sn4 = StorageNode(server4, uuid4) sn4 = StorageNode(Mock(), server4, uuid4)
uuid5 = self.getNewUUID() uuid5 = self.getNewUUID()
server5 = ("127.0.0.5", 19005) server5 = ("127.0.0.5", 19005)
sn5 = StorageNode(server5, uuid5) sn5 = StorageNode(Mock(), server5, uuid5)
# create partition table # create partition table
# 0 : sn1(discarded), sn2(up), -> sn2 must remain # 0 : sn1(discarded), sn2(up), -> sn2 must remain
# 1 : sn1(feeding), sn2(feeding), sn3(up) -> one feeding and sn3 must remain # 1 : sn1(feeding), sn2(feeding), sn3(up) -> one feeding and sn3 must remain
......
...@@ -51,24 +51,15 @@ class NodesTests(NeoTestBase): ...@@ -51,24 +51,15 @@ class NodesTests(NeoTestBase):
""" Check the node initialization """ """ Check the node initialization """
server = ('127.0.0.1', 10000) server = ('127.0.0.1', 10000)
uuid = self.getNewUUID() uuid = self.getNewUUID()
node = Node(server=server, uuid=uuid) node = Node(self.manager, server=server, uuid=uuid)
self.assertEqual(node.getState(), protocol.UNKNOWN_STATE) self.assertEqual(node.getState(), protocol.UNKNOWN_STATE)
self.assertEqual(node.getServer(), server) self.assertEqual(node.getServer(), server)
self.assertEqual(node.getUUID(), uuid) self.assertEqual(node.getUUID(), uuid)
self.assertEqual(node.getManager(), None)
self.assertTrue(time() - 1 < node.getLastStateChange() < time()) self.assertTrue(time() - 1 < node.getLastStateChange() < time())
def testManager(self):
""" Check if the node manager is well binded to the node """
node = Node()
self.assertEqual(node.getManager(), None)
node.setManager(self.manager)
self.assertTrue(node.getManager() is self.manager)
# XXX: the manager should index the node by uuid and address
def testState(self): def testState(self):
""" Check if the last changed time is updated when state is changed """ """ Check if the last changed time is updated when state is changed """
node = Node() node = Node(self.manager)
self.assertEqual(node.getState(), protocol.UNKNOWN_STATE) self.assertEqual(node.getState(), protocol.UNKNOWN_STATE)
self.assertTrue(time() - 1 < node.getLastStateChange() < time()) self.assertTrue(time() - 1 < node.getLastStateChange() < time())
previous_time = node.getLastStateChange() previous_time = node.getLastStateChange()
...@@ -78,26 +69,24 @@ class NodesTests(NeoTestBase): ...@@ -78,26 +69,24 @@ class NodesTests(NeoTestBase):
self.assertTrue(time() - 1 < node.getLastStateChange() < time()) self.assertTrue(time() - 1 < node.getLastStateChange() < time())
def testServer(self): def testServer(self):
""" Check if the manager is updated when a node change it's address """ """ Check if the node is indexed by server """
node = Node() node = Node(self.manager)
self.assertEqual(node.getServer(), None) self.assertEqual(node.getServer(), None)
node.setManager(self.manager)
server = ('127.0.0.1', 10000) server = ('127.0.0.1', 10000)
node.setServer(server) node.setServer(server)
self._updatedByServer(node) self._updatedByServer(node)
def testUUID(self): def testUUID(self):
""" As for Server but UUID """ """ As for Server but UUID """
node = Node() node = Node(self.manager)
self.assertEqual(node.getServer(), None) self.assertEqual(node.getServer(), None)
node.setManager(self.manager)
uuid = self.getNewUUID() uuid = self.getNewUUID()
node.setUUID(uuid) node.setUUID(uuid)
self._updatedByUUID(node) self._updatedByUUID(node)
def testTypes(self): def testTypes(self):
""" Check that the abstract node has no type """ """ Check that the abstract node has no type """
node = Node() node = Node(self.manager)
self.assertRaises(NotImplementedError, node.getType) self.assertRaises(NotImplementedError, node.getType)
self.assertFalse(node.isStorage()) self.assertFalse(node.isStorage())
self.assertFalse(node.isMaster()) self.assertFalse(node.isMaster())
...@@ -106,7 +95,7 @@ class NodesTests(NeoTestBase): ...@@ -106,7 +95,7 @@ class NodesTests(NeoTestBase):
def testMaster(self): def testMaster(self):
""" Check Master sub class """ """ Check Master sub class """
node = MasterNode() node = MasterNode(self.manager)
self.assertEqual(node.getType(), protocol.MASTER_NODE_TYPE) self.assertEqual(node.getType(), protocol.MASTER_NODE_TYPE)
self.assertTrue(node.isMaster()) self.assertTrue(node.isMaster())
self.assertFalse(node.isStorage()) self.assertFalse(node.isStorage())
...@@ -115,7 +104,7 @@ class NodesTests(NeoTestBase): ...@@ -115,7 +104,7 @@ class NodesTests(NeoTestBase):
def testStorage(self): def testStorage(self):
""" Check Storage sub class """ """ Check Storage sub class """
node = StorageNode() node = StorageNode(self.manager)
self.assertEqual(node.getType(), protocol.STORAGE_NODE_TYPE) self.assertEqual(node.getType(), protocol.STORAGE_NODE_TYPE)
self.assertTrue(node.isStorage()) self.assertTrue(node.isStorage())
self.assertFalse(node.isMaster()) self.assertFalse(node.isMaster())
...@@ -124,7 +113,7 @@ class NodesTests(NeoTestBase): ...@@ -124,7 +113,7 @@ class NodesTests(NeoTestBase):
def testClient(self): def testClient(self):
""" Check Client sub class """ """ Check Client sub class """
node = ClientNode() node = ClientNode(self.manager)
self.assertEqual(node.getType(), protocol.CLIENT_NODE_TYPE) self.assertEqual(node.getType(), protocol.CLIENT_NODE_TYPE)
self.assertTrue(node.isClient()) self.assertTrue(node.isClient())
self.assertFalse(node.isMaster()) self.assertFalse(node.isMaster())
...@@ -133,7 +122,7 @@ class NodesTests(NeoTestBase): ...@@ -133,7 +122,7 @@ class NodesTests(NeoTestBase):
def testAdmin(self): def testAdmin(self):
""" Check Admin sub class """ """ Check Admin sub class """
node = AdminNode() node = AdminNode(self.manager)
self.assertEqual(node.getType(), protocol.ADMIN_NODE_TYPE) self.assertEqual(node.getType(), protocol.ADMIN_NODE_TYPE)
self.assertTrue(node.isAdmin()) self.assertTrue(node.isAdmin())
self.assertFalse(node.isMaster()) self.assertFalse(node.isMaster())
...@@ -141,16 +130,14 @@ class NodesTests(NeoTestBase): ...@@ -141,16 +130,14 @@ class NodesTests(NeoTestBase):
self.assertFalse(node.isClient()) self.assertFalse(node.isClient())
class NodeManagerTests(NeoTestBase): class NodeManagerTests(NeoTestBase):
def setUp(self): def setUp(self):
self.manager = NodeManager() self.manager = nm = NodeManager()
self.storage = StorageNode(('127.0.0.1', 1000), self.getNewUUID()) self.storage = StorageNode(nm, ('127.0.0.1', 1000), self.getNewUUID())
self.master = MasterNode(('127.0.0.1', 2000), self.getNewUUID()) self.master = MasterNode(nm, ('127.0.0.1', 2000), self.getNewUUID())
self.client = ClientNode(None, self.getNewUUID()) self.client = ClientNode(nm, None, self.getNewUUID())
self.admin = AdminNode(('127.0.0.1', 4000), self.getNewUUID()) self.admin = AdminNode(nm, ('127.0.0.1', 4000), self.getNewUUID())
def checkNodes(self, node_list): def checkNodes(self, node_list):
manager = self.manager manager = self.manager
......
...@@ -29,7 +29,7 @@ class PartitionTableTests(NeoTestBase): ...@@ -29,7 +29,7 @@ class PartitionTableTests(NeoTestBase):
def test_01_Cell(self): def test_01_Cell(self):
uuid = self.getNewUUID() uuid = self.getNewUUID()
server = ("127.0.0.1", 19001) server = ("127.0.0.1", 19001)
sn = StorageNode(server, uuid) sn = StorageNode(Mock(), server, uuid)
cell = Cell(sn) cell = Cell(sn)
self.assertEquals(cell.node, sn) self.assertEquals(cell.node, sn)
self.assertEquals(cell.state, UP_TO_DATE_STATE) self.assertEquals(cell.state, UP_TO_DATE_STATE)
...@@ -53,7 +53,7 @@ class PartitionTableTests(NeoTestBase): ...@@ -53,7 +53,7 @@ class PartitionTableTests(NeoTestBase):
pt = PartitionTable(num_partitions, num_replicas) pt = PartitionTable(num_partitions, num_replicas)
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
for x in xrange(num_partitions): for x in xrange(num_partitions):
self.assertEqual(len(pt.partition_list[x]), 0) self.assertEqual(len(pt.partition_list[x]), 0)
# add a cell to an empty row # add a cell to an empty row
...@@ -132,7 +132,7 @@ class PartitionTableTests(NeoTestBase): ...@@ -132,7 +132,7 @@ class PartitionTableTests(NeoTestBase):
pt = PartitionTable(num_partitions, num_replicas) pt = PartitionTable(num_partitions, num_replicas)
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
for x in xrange(num_partitions): for x in xrange(num_partitions):
self.assertEqual(len(pt.partition_list[x]), 0) self.assertEqual(len(pt.partition_list[x]), 0)
# add a cell to an empty row # add a cell to an empty row
...@@ -172,19 +172,19 @@ class PartitionTableTests(NeoTestBase): ...@@ -172,19 +172,19 @@ class PartitionTableTests(NeoTestBase):
# add two kind of node, usable and unsable # add two kind of node, usable and unsable
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
pt.setCell(0, sn1, UP_TO_DATE_STATE) pt.setCell(0, sn1, UP_TO_DATE_STATE)
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
server2 = ("127.0.0.2", 19001) server2 = ("127.0.0.2", 19001)
sn2 = StorageNode(server2, uuid2) sn2 = StorageNode(Mock(), server2, uuid2)
pt.setCell(0, sn2, OUT_OF_DATE_STATE) pt.setCell(0, sn2, OUT_OF_DATE_STATE)
uuid3 = self.getNewUUID() uuid3 = self.getNewUUID()
server3 = ("127.0.0.3", 19001) server3 = ("127.0.0.3", 19001)
sn3 = StorageNode(server3, uuid3) sn3 = StorageNode(Mock(), server3, uuid3)
pt.setCell(0, sn3, FEEDING_STATE) pt.setCell(0, sn3, FEEDING_STATE)
uuid4 = self.getNewUUID() uuid4 = self.getNewUUID()
server4 = ("127.0.0.4", 19001) server4 = ("127.0.0.4", 19001)
sn4 = StorageNode(server4, uuid4) sn4 = StorageNode(Mock(), server4, uuid4)
pt.setCell(0, sn4, DISCARDED_STATE) # won't be added pt.setCell(0, sn4, DISCARDED_STATE) # won't be added
# now checks result # now checks result
self.assertEqual(len(pt.partition_list[0]), 3) self.assertEqual(len(pt.partition_list[0]), 3)
...@@ -234,15 +234,15 @@ class PartitionTableTests(NeoTestBase): ...@@ -234,15 +234,15 @@ class PartitionTableTests(NeoTestBase):
# add two kind of node, usable and unsable # add two kind of node, usable and unsable
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
pt.setCell(0, sn1, UP_TO_DATE_STATE) pt.setCell(0, sn1, UP_TO_DATE_STATE)
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
server2 = ("127.0.0.2", 19001) server2 = ("127.0.0.2", 19001)
sn2 = StorageNode(server2, uuid2) sn2 = StorageNode(Mock(), server2, uuid2)
pt.setCell(1, sn2, OUT_OF_DATE_STATE) pt.setCell(1, sn2, OUT_OF_DATE_STATE)
uuid3 = self.getNewUUID() uuid3 = self.getNewUUID()
server3 = ("127.0.0.3", 19001) server3 = ("127.0.0.3", 19001)
sn3 = StorageNode(server3, uuid3) sn3 = StorageNode(Mock(), server3, uuid3)
pt.setCell(2, sn3, FEEDING_STATE) pt.setCell(2, sn3, FEEDING_STATE)
# now checks result # now checks result
self.assertEqual(len(pt.partition_list[0]), 1) self.assertEqual(len(pt.partition_list[0]), 1)
...@@ -264,19 +264,19 @@ class PartitionTableTests(NeoTestBase): ...@@ -264,19 +264,19 @@ class PartitionTableTests(NeoTestBase):
# add two kind of node, usable and unsable # add two kind of node, usable and unsable
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
pt.setCell(0, sn1, UP_TO_DATE_STATE) pt.setCell(0, sn1, UP_TO_DATE_STATE)
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
server2 = ("127.0.0.2", 19001) server2 = ("127.0.0.2", 19001)
sn2 = StorageNode(server2, uuid2) sn2 = StorageNode(Mock(), server2, uuid2)
pt.setCell(0, sn2, OUT_OF_DATE_STATE) pt.setCell(0, sn2, OUT_OF_DATE_STATE)
uuid3 = self.getNewUUID() uuid3 = self.getNewUUID()
server3 = ("127.0.0.3", 19001) server3 = ("127.0.0.3", 19001)
sn3 = StorageNode(server3, uuid3) sn3 = StorageNode(Mock(), server3, uuid3)
pt.setCell(0, sn3, FEEDING_STATE) pt.setCell(0, sn3, FEEDING_STATE)
uuid4 = self.getNewUUID() uuid4 = self.getNewUUID()
server4 = ("127.0.0.4", 19001) server4 = ("127.0.0.4", 19001)
sn4 = StorageNode(server4, uuid4) sn4 = StorageNode(Mock(), server4, uuid4)
pt.setCell(0, sn4, DISCARDED_STATE) # won't be added pt.setCell(0, sn4, DISCARDED_STATE) # won't be added
# must get only two node as feeding and discarded not taken # must get only two node as feeding and discarded not taken
# into account # into account
...@@ -297,7 +297,7 @@ class PartitionTableTests(NeoTestBase): ...@@ -297,7 +297,7 @@ class PartitionTableTests(NeoTestBase):
# adding a node in all partition # adding a node in all partition
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
for x in xrange(num_partitions): for x in xrange(num_partitions):
pt.setCell(x, sn1, UP_TO_DATE_STATE) pt.setCell(x, sn1, UP_TO_DATE_STATE)
self.assertEqual(pt.num_filled_rows, num_partitions) self.assertEqual(pt.num_filled_rows, num_partitions)
...@@ -310,7 +310,7 @@ class PartitionTableTests(NeoTestBase): ...@@ -310,7 +310,7 @@ class PartitionTableTests(NeoTestBase):
# add two kind of node, usable and unsable # add two kind of node, usable and unsable
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
pt.setCell(0, sn1, UP_TO_DATE_STATE) pt.setCell(0, sn1, UP_TO_DATE_STATE)
# now test # now test
self.assertTrue(pt.hasOffset(0)) self.assertTrue(pt.hasOffset(0))
...@@ -327,7 +327,7 @@ class PartitionTableTests(NeoTestBase): ...@@ -327,7 +327,7 @@ class PartitionTableTests(NeoTestBase):
# adding a node in all partition # adding a node in all partition
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
for x in xrange(num_partitions): for x in xrange(num_partitions):
pt.setCell(x, sn1, UP_TO_DATE_STATE) pt.setCell(x, sn1, UP_TO_DATE_STATE)
self.assertTrue(pt.filled()) self.assertTrue(pt.filled())
...@@ -341,7 +341,7 @@ class PartitionTableTests(NeoTestBase): ...@@ -341,7 +341,7 @@ class PartitionTableTests(NeoTestBase):
# adding a node in all partition # adding a node in all partition
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
for x in xrange(num_partitions): for x in xrange(num_partitions):
pt.setCell(x, sn1, FEEDING_STATE) pt.setCell(x, sn1, FEEDING_STATE)
self.assertTrue(pt.filled()) self.assertTrue(pt.filled())
...@@ -356,7 +356,7 @@ class PartitionTableTests(NeoTestBase): ...@@ -356,7 +356,7 @@ class PartitionTableTests(NeoTestBase):
# adding a node in all partition # adding a node in all partition
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
sn1.setState(TEMPORARILY_DOWN_STATE) sn1.setState(TEMPORARILY_DOWN_STATE)
for x in xrange(num_partitions): for x in xrange(num_partitions):
pt.setCell(x, sn1, FEEDING_STATE) pt.setCell(x, sn1, FEEDING_STATE)
...@@ -371,7 +371,7 @@ class PartitionTableTests(NeoTestBase): ...@@ -371,7 +371,7 @@ class PartitionTableTests(NeoTestBase):
# adding a node in all partition # adding a node in all partition
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
for x in xrange(num_partitions): for x in xrange(num_partitions):
pt.setCell(x, sn1, OUT_OF_DATE_STATE) pt.setCell(x, sn1, OUT_OF_DATE_STATE)
self.assertTrue(pt.filled()) self.assertTrue(pt.filled())
...@@ -385,18 +385,18 @@ class PartitionTableTests(NeoTestBase): ...@@ -385,18 +385,18 @@ class PartitionTableTests(NeoTestBase):
# add nodes # add nodes
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
pt.setCell(0, sn1, UP_TO_DATE_STATE) pt.setCell(0, sn1, UP_TO_DATE_STATE)
pt.setCell(1, sn1, UP_TO_DATE_STATE) pt.setCell(1, sn1, UP_TO_DATE_STATE)
pt.setCell(2, sn1, UP_TO_DATE_STATE) pt.setCell(2, sn1, UP_TO_DATE_STATE)
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
server2 = ("127.0.0.2", 19001) server2 = ("127.0.0.2", 19001)
sn2 = StorageNode(server2, uuid2) sn2 = StorageNode(Mock(), server2, uuid2)
pt.setCell(0, sn2, UP_TO_DATE_STATE) pt.setCell(0, sn2, UP_TO_DATE_STATE)
pt.setCell(1, sn2, UP_TO_DATE_STATE) pt.setCell(1, sn2, UP_TO_DATE_STATE)
uuid3 = self.getNewUUID() uuid3 = self.getNewUUID()
server3 = ("127.0.0.3", 19001) server3 = ("127.0.0.3", 19001)
sn3 = StorageNode(server3, uuid3) sn3 = StorageNode(Mock(), server3, uuid3)
pt.setCell(0, sn3, UP_TO_DATE_STATE) pt.setCell(0, sn3, UP_TO_DATE_STATE)
# test # test
row_0 = pt.getRow(0) row_0 = pt.getRow(0)
......
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