示例#1
0
 def test_06_clear(self):
     # add some nodes
     num_partitions = 5
     num_replicas = 2
     pt = PartitionTable(num_partitions, num_replicas)
     # add two kind of node, usable and unusable
     uuid1 = self.getStorageUUID()
     server1 = ("127.0.0.1", 19001)
     sn1 = self.createStorage(server1, uuid1)
     pt._setCell(0, sn1, CellStates.UP_TO_DATE)
     uuid2 = self.getStorageUUID()
     server2 = ("127.0.0.2", 19001)
     sn2 = self.createStorage(server2, uuid2)
     pt._setCell(1, sn2, CellStates.OUT_OF_DATE)
     uuid3 = self.getStorageUUID()
     server3 = ("127.0.0.3", 19001)
     sn3 = self.createStorage(server3, uuid3)
     pt._setCell(2, sn3, CellStates.FEEDING)
     # now checks result
     self.assertEqual(len(pt.partition_list[0]), 1)
     self.assertEqual(len(pt.partition_list[1]), 1)
     self.assertEqual(len(pt.partition_list[2]), 1)
     pt.clear()
     partition_list = pt.partition_list
     self.assertEqual(len(partition_list), num_partitions)
     for x in xrange(num_partitions):
         part = partition_list[x]
         self.assertTrue(isinstance(part, list))
         self.assertEqual(len(part), 0)
     self.assertEqual(len(pt.count_dict), 0)
示例#2
0
文件: testPT.py 项目: Nexedi/neoppod
 def test_06_clear(self):
     # add some nodes
     num_partitions = 5
     num_replicas = 2
     pt = PartitionTable(num_partitions, num_replicas)
     # add two kind of node, usable and unsable
     uuid1 = self.getStorageUUID()
     server1 = ("127.0.0.1", 19001)
     sn1 = StorageNode(Mock(), server1, uuid1)
     pt.setCell(0, sn1, CellStates.UP_TO_DATE)
     uuid2 = self.getStorageUUID()
     server2 = ("127.0.0.2", 19001)
     sn2 = StorageNode(Mock(), server2, uuid2)
     pt.setCell(1, sn2, CellStates.OUT_OF_DATE)
     uuid3 = self.getStorageUUID()
     server3 = ("127.0.0.3", 19001)
     sn3 = StorageNode(Mock(), server3, uuid3)
     pt.setCell(2, sn3, CellStates.FEEDING)
     # now checks result
     self.assertEqual(len(pt.partition_list[0]), 1)
     self.assertEqual(len(pt.partition_list[1]), 1)
     self.assertEqual(len(pt.partition_list[2]), 1)
     pt.clear()
     partition_list = pt.partition_list
     self.assertEqual(len(partition_list), num_partitions)
     for x in xrange(num_partitions):
         part = partition_list[x]
         self.assertTrue(isinstance(part, list))
         self.assertEqual(len(part), 0)
     self.assertEqual(len(pt.count_dict), 0)
示例#3
0
    def test_10_operational(self):
        num_partitions = 5
        num_replicas = 2
        pt = PartitionTable(num_partitions, num_replicas)
        self.assertFalse(pt.filled())
        self.assertFalse(pt.operational())
        # adding a node in all partition
        uuid1 = self.getStorageUUID()
        server1 = ("127.0.0.1", 19001)
        sn1 = StorageNode(Mock(), server1, uuid1)
        for x in xrange(num_partitions):
            pt.setCell(x, sn1, CellStates.UP_TO_DATE)
        self.assertTrue(pt.filled())
        # it's up to date and running, so operational
        sn1.setState(NodeStates.RUNNING)
        self.assertTrue(pt.operational())
        # same with feeding state
        pt.clear()
        self.assertFalse(pt.filled())
        self.assertFalse(pt.operational())
        # adding a node in all partition
        uuid1 = self.getStorageUUID()
        server1 = ("127.0.0.1", 19001)
        sn1 = StorageNode(Mock(), server1, uuid1)
        for x in xrange(num_partitions):
            pt.setCell(x, sn1, CellStates.FEEDING)
        self.assertTrue(pt.filled())
        # it's feeding and running, so operational
        sn1.setState(NodeStates.RUNNING)
        self.assertTrue(pt.operational())

        # same with feeding state but non running node
        pt.clear()
        self.assertFalse(pt.filled())
        self.assertFalse(pt.operational())
        # adding a node in all partition
        uuid1 = self.getStorageUUID()
        server1 = ("127.0.0.1", 19001)
        sn1 = StorageNode(Mock(), server1, uuid1)
        sn1.setState(NodeStates.TEMPORARILY_DOWN)
        for x in xrange(num_partitions):
            pt.setCell(x, sn1, CellStates.FEEDING)
        self.assertTrue(pt.filled())
        # it's up to date and not running, so not operational
        self.assertFalse(pt.operational())

        # same with out of date state and running
        pt.clear()
        self.assertFalse(pt.filled())
        self.assertFalse(pt.operational())
        # adding a node in all partition
        uuid1 = self.getStorageUUID()
        server1 = ("127.0.0.1", 19001)
        sn1 = StorageNode(Mock(), server1, uuid1)
        for x in xrange(num_partitions):
            pt.setCell(x, sn1, CellStates.OUT_OF_DATE)
        self.assertTrue(pt.filled())
        # it's not up to date and running, so not operational
        self.assertFalse(pt.operational())
示例#4
0
    def test_10_operational(self):
        def createStorage():
            uuid = self.getStorageUUID()
            return self.createStorage(("127.0.0.1", uuid), uuid)

        num_partitions = 5
        num_replicas = 2
        pt = PartitionTable(num_partitions, num_replicas)
        self.assertFalse(pt.filled())
        self.assertFalse(pt.operational())
        # adding a node in all partition
        sn1 = createStorage()
        for x in xrange(num_partitions):
            pt._setCell(x, sn1, CellStates.UP_TO_DATE)
        self.assertTrue(pt.filled())
        # it's up to date and running, so operational
        sn1.setState(NodeStates.RUNNING)
        self.assertTrue(pt.operational())
        # same with feeding state
        pt.clear()
        self.assertFalse(pt.filled())
        self.assertFalse(pt.operational())
        # adding a node in all partition
        sn1 = createStorage()
        for x in xrange(num_partitions):
            pt._setCell(x, sn1, CellStates.FEEDING)
        self.assertTrue(pt.filled())
        # it's feeding and running, so operational
        sn1.setState(NodeStates.RUNNING)
        self.assertTrue(pt.operational())

        # same with feeding state but non running node
        pt.clear()
        self.assertFalse(pt.filled())
        self.assertFalse(pt.operational())
        # adding a node in all partition
        sn1 = createStorage()
        sn1.setState(NodeStates.DOWN)
        for x in xrange(num_partitions):
            pt._setCell(x, sn1, CellStates.FEEDING)
        self.assertTrue(pt.filled())
        # it's up to date and not running, so not operational
        self.assertFalse(pt.operational())

        # same with out of date state and running
        pt.clear()
        self.assertFalse(pt.filled())
        self.assertFalse(pt.operational())
        # adding a node in all partition
        sn1 = createStorage()
        for x in xrange(num_partitions):
            pt._setCell(x, sn1, CellStates.OUT_OF_DATE)
        self.assertTrue(pt.filled())
        # it's not up to date and running, so not operational
        self.assertFalse(pt.operational())