Ejemplo n.º 1
0
 def test_02_PartitionTable_creation(self):
     num_partitions = 5
     num_replicas = 3
     pt = PartitionTable(num_partitions, num_replicas)
     self.assertEqual(pt.np, num_partitions)
     self.assertEqual(pt.nr, num_replicas)
     self.assertEqual(pt.num_filled_rows, 0)
     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)
     # no nodes or cells for now
     self.assertFalse(pt.getNodeSet())
     for x in xrange(num_partitions):
         self.assertEqual(len(pt.getCellList(x)), 0)
         self.assertEqual(len(pt.getCellList(x, True)), 0)
         self.assertEqual(len(pt.getRow(x)), 0)
     self.assertFalse(pt.operational())
     self.assertFalse(pt.filled())
     self.assertRaises(RuntimeError, pt.make, [])
     self.assertFalse(pt.operational())
     self.assertFalse(pt.filled())
Ejemplo n.º 2
0
 def test_02_PartitionTable_creation(self):
     num_partitions = 5
     num_replicas = 3
     pt = PartitionTable(num_partitions, num_replicas)
     self.assertEqual(pt.np, num_partitions)
     self.assertEqual(pt.nr, num_replicas)
     self.assertEqual(pt.num_filled_rows, 0)
     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)
     # no nodes or cells for now
     self.assertFalse(pt.getNodeSet())
     for x in xrange(num_partitions):
         self.assertEqual(len(pt.getCellList(x)), 0)
         self.assertEqual(len(pt.getCellList(x, True)), 0)
         self.assertEqual(len(pt.getRow(x)), 0)
     self.assertFalse(pt.operational())
     self.assertFalse(pt.filled())
     self.assertRaises(AssertionError, pt.make, [])
     self.assertFalse(pt.operational())
     self.assertFalse(pt.filled())
Ejemplo n.º 3
0
 def test_13_outdate(self):
     # create nodes
     uuid1 = self.getStorageUUID()
     server1 = ("127.0.0.1", 19001)
     sn1 = self.createStorage(server1, uuid1)
     uuid2 = self.getStorageUUID()
     server2 = ("127.0.0.2", 19002)
     sn2 = self.createStorage(server2, uuid2)
     uuid3 = self.getStorageUUID()
     server3 = ("127.0.0.3", 19003)
     sn3 = self.createStorage(server3, uuid3)
     uuid4 = self.getStorageUUID()
     server4 = ("127.0.0.4", 19004)
     sn4 = self.createStorage(server4, uuid4)
     # create partition table
     num_partitions = 4
     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.DOWN)
     pt._setCell(2, sn3, CellStates.UP_TO_DATE)
     sn3.setState(NodeStates.UNKNOWN)
     pt._setCell(3, sn4, CellStates.UP_TO_DATE)
     sn4.setState(NodeStates.RUNNING)
     # outdate nodes
     cells_outdated = pt.outdate()
     self.assertEqual(len(cells_outdated), 2)
     for offset, uuid, state in cells_outdated:
         self.assertIn(offset, (1, 2))
         self.assertIn(uuid, (uuid2, uuid3))
         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, remains running
     cells = pt.getCellList(3)
     self.assertEqual(len(cells), 1)
     cell = cells[0]
     self.assertEqual(cell.getState(), CellStates.UP_TO_DATE)
Ejemplo n.º 4
0
 def test_16_make(self):
     num_partitions = 5
     num_replicas = 1
     pt = PartitionTable(num_partitions, num_replicas)
     # add nodes
     uuid1 = self.getStorageUUID()
     server1 = ("127.0.0.1", 19001)
     sn1 = StorageNode(Mock(), server1, uuid1, NodeStates.RUNNING)
     # add not running node
     uuid2 = self.getStorageUUID()
     server2 = ("127.0.0.2", 19001)
     sn2 = StorageNode(Mock(), server2, uuid2)
     sn2.setState(NodeStates.TEMPORARILY_DOWN)
     # add node without uuid
     server3 = ("127.0.0.3", 19001)
     sn3 = StorageNode(Mock(), server3, None, NodeStates.RUNNING)
     # add clear node
     uuid4 = self.getStorageUUID()
     server4 = ("127.0.0.4", 19001)
     sn4 = StorageNode(Mock(), server4, uuid4, NodeStates.RUNNING)
     uuid5 = self.getStorageUUID()
     server5 = ("127.0.0.5", 1900)
     sn5 = StorageNode(Mock(), server5, uuid5, NodeStates.RUNNING)
     # make the table
     pt.make([sn1, sn2, sn3, sn4, sn5])
     # check it's ok, only running nodes and node with uuid
     # must be present
     for x in xrange(num_partitions):
         cells = pt.getCellList(x)
         self.assertEqual(len(cells), 2)
         nodes = [x.getNode() for x in cells]
         for node in nodes:
             self.assertTrue(node in (sn1, sn4, sn5))
             self.assertTrue(node not in (sn2, sn3))
     self.assertTrue(pt.filled())
     self.assertTrue(pt.operational())
     # create a pt with less nodes
     pt.clear()
     self.assertFalse(pt.filled())
     self.assertFalse(pt.operational())
     pt.make([sn1])
     # check it's ok
     for x in xrange(num_partitions):
         cells = pt.getCellList(x)
         self.assertEqual(len(cells), 1)
         nodes = [x.getNode() for x in cells]
         for node in nodes:
             self.assertEqual(node, sn1)
     self.assertTrue(pt.filled())
     self.assertTrue(pt.operational())
Ejemplo n.º 5
0
 def test_16_make(self):
     num_partitions = 5
     num_replicas = 1
     pt = PartitionTable(num_partitions, num_replicas)
     # add nodes
     uuid1 = self.getStorageUUID()
     server1 = ("127.0.0.1", 19001)
     sn1 = StorageNode(Mock(), server1, uuid1, NodeStates.RUNNING)
     # add not running node
     uuid2 = self.getStorageUUID()
     server2 = ("127.0.0.2", 19001)
     sn2 = StorageNode(Mock(), server2, uuid2)
     sn2.setState(NodeStates.TEMPORARILY_DOWN)
     # add node without uuid
     server3 = ("127.0.0.3", 19001)
     sn3 = StorageNode(Mock(), server3, None, NodeStates.RUNNING)
     # add clear node
     uuid4 = self.getStorageUUID()
     server4 = ("127.0.0.4", 19001)
     sn4 = StorageNode(Mock(), server4, uuid4, NodeStates.RUNNING)
     uuid5 = self.getStorageUUID()
     server5 = ("127.0.0.5", 1900)
     sn5 = StorageNode(Mock(), server5, uuid5, NodeStates.RUNNING)
     # make the table
     pt.make([sn1, sn2, sn3, sn4, sn5])
     # check it's ok, only running nodes and node with uuid
     # must be present
     for x in xrange(num_partitions):
         cells = pt.getCellList(x)
         self.assertEqual(len(cells), 2)
         nodes = [x.getNode() for x in cells]
         for node in nodes:
             self.assertTrue(node in (sn1, sn4, sn5))
             self.assertTrue(node not in (sn2, sn3))
     self.assertTrue(pt.filled())
     self.assertTrue(pt.operational())
     # create a pt with less nodes
     pt.clear()
     self.assertFalse(pt.filled())
     self.assertFalse(pt.operational())
     pt.make([sn1])
     # check it's ok
     for x in xrange(num_partitions):
         cells = pt.getCellList(x)
         self.assertEqual(len(cells), 1)
         nodes = [x.getNode() for x in cells]
         for node in nodes:
             self.assertEqual(node, sn1)
     self.assertTrue(pt.filled())
     self.assertTrue(pt.operational())
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)