Пример #1
0
 def test_13_outdate(self):
     # create nodes
     uuid1 = self.getStorageUUID()
     server1 = ("127.0.0.1", 19001)
     sn1 = StorageNode(Mock(), server1, uuid1)
     uuid2 = self.getStorageUUID()
     server2 = ("127.0.0.2", 19002)
     sn2 = StorageNode(Mock(), server2, uuid2)
     uuid3 = self.getStorageUUID()
     server3 = ("127.0.0.3", 19003)
     sn3 = StorageNode(Mock(), server3, uuid3)
     uuid4 = self.getStorageUUID()
     server4 = ("127.0.0.4", 19004)
     sn4 = StorageNode(Mock(), server4, uuid4)
     uuid5 = self.getStorageUUID()
     server5 = ("127.0.0.5", 19005)
     sn5 = StorageNode(Mock(), server5, uuid5)
     # create partition table
     num_partitions = 5
     num_replicas = 3
     pt = PartitionTable(num_partitions, num_replicas)
     pt.setCell(0, sn1, CellStates.OUT_OF_DATE)
     sn1.setState(NodeStates.RUNNING)
     pt.setCell(1, sn2, CellStates.UP_TO_DATE)
     sn2.setState(NodeStates.TEMPORARILY_DOWN)
     pt.setCell(2, sn3, CellStates.UP_TO_DATE)
     sn3.setState(NodeStates.DOWN)
     pt.setCell(3, sn4, CellStates.UP_TO_DATE)
     sn4.setState(NodeStates.BROKEN)
     pt.setCell(4, sn5, CellStates.UP_TO_DATE)
     sn5.setState(NodeStates.RUNNING)
     # outdate nodes
     cells_outdated = pt.outdate()
     self.assertEqual(len(cells_outdated), 3)
     for offset, uuid, state in cells_outdated:
         self.assertTrue(offset in (1, 2, 3))
         self.assertTrue(uuid in (uuid2, uuid3, uuid4))
         self.assertEqual(state, CellStates.OUT_OF_DATE)
     # check each cell
     # part 1, already outdated
     cells = pt.getCellList(0)
     self.assertEqual(len(cells), 1)
     cell = cells[0]
     self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
     # part 2, must be outdated
     cells = pt.getCellList(1)
     self.assertEqual(len(cells), 1)
     cell = cells[0]
     self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
     # part 3, must be outdated
     cells = pt.getCellList(2)
     self.assertEqual(len(cells), 1)
     cell = cells[0]
     self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
     # part 4, already outdated
     cells = pt.getCellList(3)
     self.assertEqual(len(cells), 1)
     cell = cells[0]
     self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
     # part 5, remains running
     cells = pt.getCellList(4)
     self.assertEqual(len(cells), 1)
     cell = cells[0]
     self.assertEqual(cell.getState(), CellStates.UP_TO_DATE)
Пример #2
0
    def test_17_tweak(self):
        sn = [StorageNode(Mock(), None, i + 1, NodeStates.RUNNING)
              for i in xrange(5)]
        pt = PartitionTable(5, 2)
        # part 0
        pt.setCell(0, sn[0], CellStates.DISCARDED)
        pt.setCell(0, sn[1], CellStates.UP_TO_DATE)
        # part 1
        pt.setCell(1, sn[0], CellStates.FEEDING)
        pt.setCell(1, sn[1], CellStates.FEEDING)
        pt.setCell(1, sn[2], CellStates.OUT_OF_DATE)
        # part 2
        pt.setCell(2, sn[0], CellStates.FEEDING)
        pt.setCell(2, sn[1], CellStates.UP_TO_DATE)
        pt.setCell(2, sn[2], CellStates.UP_TO_DATE)
        # part 3
        pt.setCell(3, sn[0], CellStates.UP_TO_DATE)
        pt.setCell(3, sn[1], CellStates.UP_TO_DATE)
        pt.setCell(3, sn[2], CellStates.UP_TO_DATE)
        pt.setCell(3, sn[3], CellStates.UP_TO_DATE)
        # part 4
        pt.setCell(4, sn[0], CellStates.UP_TO_DATE)
        pt.setCell(4, sn[4], CellStates.UP_TO_DATE)

        count_dict = defaultdict(int)
        change_list = self.tweak(pt)
        for offset, uuid, state in change_list:
            count_dict[state] += 1
        self.assertEqual(count_dict, {CellStates.DISCARDED: 3,
                                      CellStates.OUT_OF_DATE: 5,
                                      CellStates.UP_TO_DATE: 3})
        self.update(pt, change_list)
        self.checkPT(pt)

        self.assertRaises(PartitionTableException, pt.dropNodeList, sn[1:4])
        self.assertEqual(6, len(pt.dropNodeList(sn[1:3], True)))
        self.assertEqual(3, len(pt.dropNodeList([sn[1]])))
        pt.addNodeList([sn[1]])
        change_list = self.tweak(pt)
        self.assertEqual(3, len(change_list))
        self.update(pt, change_list)
        self.checkPT(pt)

        for np, i in (12, 0), (12, 1), (13, 2):
            pt = PartitionTable(np, i)
            i += 1
            pt.make(sn[:i])
            for n in sn[i:i+3]:
                self.assertEqual([n], pt.addNodeList([n]))
                self.update(pt, self.tweak(pt))
                self.checkPT(pt)
            pt.clear()
            pt.make(sn[:i])
            for n in sn[i:i+3]:
                self.assertEqual([n], pt.addNodeList([n]))
                self.tweak(pt)
            self.update(pt)
            self.checkPT(pt)

        pt = PartitionTable(7, 0)
        pt.make(sn[:1])
        pt.addNodeList(sn[1:3])
        self.update(pt, self.tweak(pt, sn[:1]))
        self.checkPT(pt, True)
Пример #3
0
    def test_15_dropNodeList(self):
        sn = [StorageNode(Mock(), None, i + 1, NodeStates.RUNNING)
              for i in xrange(3)]
        pt = PartitionTable(3, 0)
        pt.setCell(0, sn[0], CellStates.OUT_OF_DATE)
        pt.setCell(1, sn[1], CellStates.FEEDING)
        pt.setCell(1, sn[2], CellStates.OUT_OF_DATE)
        pt.setCell(2, sn[0], CellStates.OUT_OF_DATE)
        pt.setCell(2, sn[1], CellStates.FEEDING)
        pt.setCell(2, sn[2], CellStates.UP_TO_DATE)

        self.assertEqual(sorted(pt.dropNodeList(sn[:1], True)), [
            (0, 1, CellStates.DISCARDED),
            (2, 1, CellStates.DISCARDED),
            (2, 2, CellStates.UP_TO_DATE)])

        self.assertEqual(sorted(pt.dropNodeList(sn[2:], True)), [
            (1, 2, CellStates.UP_TO_DATE),
            (1, 3, CellStates.DISCARDED),
            (2, 2, CellStates.UP_TO_DATE),
            (2, 3, CellStates.DISCARDED)])

        self.assertRaises(PartitionTableException, pt.dropNodeList, sn[1:2])
        pt.setCell(1, sn[2], CellStates.UP_TO_DATE)
        self.assertEqual(sorted(pt.dropNodeList(sn[1:2])), [
            (1, 2, CellStates.DISCARDED),
            (2, 2, CellStates.DISCARDED)])

        self.assertEqual(self.tweak(pt), [(2, 3, CellStates.FEEDING)])
Пример #4
0
 def test_13_outdate(self):
     # create nodes
     uuid1 = self.getStorageUUID()
     server1 = ("127.0.0.1", 19001)
     sn1 = StorageNode(Mock(), server1, uuid1)
     uuid2 = self.getStorageUUID()
     server2 = ("127.0.0.2", 19002)
     sn2 = StorageNode(Mock(), server2, uuid2)
     uuid3 = self.getStorageUUID()
     server3 = ("127.0.0.3", 19003)
     sn3 = StorageNode(Mock(), server3, uuid3)
     uuid4 = self.getStorageUUID()
     server4 = ("127.0.0.4", 19004)
     sn4 = StorageNode(Mock(), server4, uuid4)
     uuid5 = self.getStorageUUID()
     server5 = ("127.0.0.5", 19005)
     sn5 = StorageNode(Mock(), server5, uuid5)
     # create partition table
     num_partitions = 5
     num_replicas = 3
     pt = PartitionTable(num_partitions, num_replicas)
     pt.setCell(0, sn1, CellStates.OUT_OF_DATE)
     sn1.setState(NodeStates.RUNNING)
     pt.setCell(1, sn2, CellStates.UP_TO_DATE)
     sn2.setState(NodeStates.TEMPORARILY_DOWN)
     pt.setCell(2, sn3, CellStates.UP_TO_DATE)
     sn3.setState(NodeStates.DOWN)
     pt.setCell(3, sn4, CellStates.UP_TO_DATE)
     sn4.setState(NodeStates.BROKEN)
     pt.setCell(4, sn5, CellStates.UP_TO_DATE)
     sn5.setState(NodeStates.RUNNING)
     # outdate nodes
     cells_outdated = pt.outdate()
     self.assertEqual(len(cells_outdated), 3)
     for offset, uuid, state in cells_outdated:
         self.assertTrue(offset in (1, 2, 3))
         self.assertTrue(uuid in (uuid2, uuid3, uuid4))
         self.assertEqual(state, CellStates.OUT_OF_DATE)
     # check each cell
     # part 1, already outdated
     cells = pt.getCellList(0)
     self.assertEqual(len(cells), 1)
     cell = cells[0]
     self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
     # part 2, must be outdated
     cells = pt.getCellList(1)
     self.assertEqual(len(cells), 1)
     cell = cells[0]
     self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
     # part 3, must be outdated
     cells = pt.getCellList(2)
     self.assertEqual(len(cells), 1)
     cell = cells[0]
     self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
     # part 4, already outdated
     cells = pt.getCellList(3)
     self.assertEqual(len(cells), 1)
     cell = cells[0]
     self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
     # part 5, remains running
     cells = pt.getCellList(4)
     self.assertEqual(len(cells), 1)
     cell = cells[0]
     self.assertEqual(cell.getState(), CellStates.UP_TO_DATE)
Пример #5
0
    def test_17_tweak(self):
        sn = [
            StorageNode(Mock(), None, i + 1, NodeStates.RUNNING)
            for i in xrange(5)
        ]
        pt = PartitionTable(5, 2)
        # part 0
        pt.setCell(0, sn[0], CellStates.DISCARDED)
        pt.setCell(0, sn[1], CellStates.UP_TO_DATE)
        # part 1
        pt.setCell(1, sn[0], CellStates.FEEDING)
        pt.setCell(1, sn[1], CellStates.FEEDING)
        pt.setCell(1, sn[2], CellStates.OUT_OF_DATE)
        # part 2
        pt.setCell(2, sn[0], CellStates.FEEDING)
        pt.setCell(2, sn[1], CellStates.UP_TO_DATE)
        pt.setCell(2, sn[2], CellStates.UP_TO_DATE)
        # part 3
        pt.setCell(3, sn[0], CellStates.UP_TO_DATE)
        pt.setCell(3, sn[1], CellStates.UP_TO_DATE)
        pt.setCell(3, sn[2], CellStates.UP_TO_DATE)
        pt.setCell(3, sn[3], CellStates.UP_TO_DATE)
        # part 4
        pt.setCell(4, sn[0], CellStates.UP_TO_DATE)
        pt.setCell(4, sn[4], CellStates.UP_TO_DATE)

        count_dict = defaultdict(int)
        change_list = self.tweak(pt)
        for offset, uuid, state in change_list:
            count_dict[state] += 1
        self.assertEqual(
            count_dict, {
                CellStates.DISCARDED: 3,
                CellStates.OUT_OF_DATE: 5,
                CellStates.UP_TO_DATE: 3
            })
        self.update(pt, change_list)
        self.checkPT(pt)

        self.assertRaises(PartitionTableException, pt.dropNodeList, sn[1:4])
        self.assertEqual(6, len(pt.dropNodeList(sn[1:3], True)))
        self.assertEqual(3, len(pt.dropNodeList([sn[1]])))
        pt.addNodeList([sn[1]])
        change_list = self.tweak(pt)
        self.assertEqual(3, len(change_list))
        self.update(pt, change_list)
        self.checkPT(pt)

        for np, i in (12, 0), (12, 1), (13, 2):
            pt = PartitionTable(np, i)
            i += 1
            pt.make(sn[:i])
            for n in sn[i:i + 3]:
                self.assertEqual([n], pt.addNodeList([n]))
                self.update(pt, self.tweak(pt))
                self.checkPT(pt)
            pt.clear()
            pt.make(sn[:i])
            for n in sn[i:i + 3]:
                self.assertEqual([n], pt.addNodeList([n]))
                self.tweak(pt)
            self.update(pt)
            self.checkPT(pt)

        pt = PartitionTable(7, 0)
        pt.make(sn[:1])
        pt.addNodeList(sn[1:3])
        self.update(pt, self.tweak(pt, sn[:1]))
        self.checkPT(pt, True)
Пример #6
0
    def test_15_dropNodeList(self):
        sn = [
            StorageNode(Mock(), None, i + 1, NodeStates.RUNNING)
            for i in xrange(3)
        ]
        pt = PartitionTable(3, 0)
        pt.setCell(0, sn[0], CellStates.OUT_OF_DATE)
        pt.setCell(1, sn[1], CellStates.FEEDING)
        pt.setCell(1, sn[2], CellStates.OUT_OF_DATE)
        pt.setCell(2, sn[0], CellStates.OUT_OF_DATE)
        pt.setCell(2, sn[1], CellStates.FEEDING)
        pt.setCell(2, sn[2], CellStates.UP_TO_DATE)

        self.assertEqual(sorted(pt.dropNodeList(sn[:1], True)),
                         [(0, 1, CellStates.DISCARDED),
                          (2, 1, CellStates.DISCARDED),
                          (2, 2, CellStates.UP_TO_DATE)])

        self.assertEqual(sorted(pt.dropNodeList(sn[2:], True)),
                         [(1, 2, CellStates.UP_TO_DATE),
                          (1, 3, CellStates.DISCARDED),
                          (2, 2, CellStates.UP_TO_DATE),
                          (2, 3, CellStates.DISCARDED)])

        self.assertRaises(PartitionTableException, pt.dropNodeList, sn[1:2])
        pt.setCell(1, sn[2], CellStates.UP_TO_DATE)
        self.assertEqual(sorted(pt.dropNodeList(sn[1:2])),
                         [(1, 2, CellStates.DISCARDED),
                          (2, 2, CellStates.DISCARDED)])

        self.assertEqual(self.tweak(pt), [(2, 3, CellStates.FEEDING)])