コード例 #1
0
ファイル: test_node.py プロジェクト: plamut/datagrid
    def test_group_value(self):
        """Test that the value of a replica group is calculated correctly.

        Group value is calculated by the following formula (from the paper):

            sum(NOR) / sum(sizes) + sum(NOR_FSTI) / FSTI +
            1 / (now - avg(last_req_time))
        """
        sim = Mock(spec=self._make_sim())
        sim.fsti = 10
        sim.now = 4

        node = self._make_instance('node_1', 1000, sim)

        replica_group = [
            self._make_replica('replica_1', size=200),
            self._make_replica('replica_2', size=400),
            self._make_replica('replica_3', size=900),
        ]

        stats_1 = Mock(nor=0, lrt=0)
        stats_1.nor_fsti.return_value = 0
        node._replica_stats['replica_1'] = stats_1

        stats_2 = Mock(nor=0, lrt=0)
        stats_2.nor_fsti.return_value = 0
        node._replica_stats['replica_2'] = stats_2

        stats_3 = Mock(nor=0, lrt=0)
        stats_3.nor_fsti.return_value = 0
        node._replica_stats['replica_3'] = stats_3

        self.assertAlmostEqual(node._GV(replica_group), 0.25)

        stats_1.nor = 15
        self.assertAlmostEqual(node._GV(replica_group), 0.26)
        stats_2.nor = 45
        self.assertAlmostEqual(node._GV(replica_group), 0.29)

        replica_group[2]._size = 2400
        self.assertAlmostEqual(node._GV(replica_group), 0.27)

        stats_1.nor_fsti.return_value = 5
        self.assertAlmostEqual(node._GV(replica_group), 0.77)
        stats_2.nor_fsti.return_value = 20
        self.assertAlmostEqual(node._GV(replica_group), 2.77)

        stats_1.lrt = 1
        stats_2.lrt = 2
        stats_3.lrt = 3
        self.assertAlmostEqual(node._GV(replica_group), 3.02)

        sim.now = 7
        self.assertAlmostEqual(node._GV(replica_group), 2.72)
コード例 #2
0
ファイル: test_node.py プロジェクト: plamut/datagrid
    def test_replica_value(self):
        """Test that the value of a replica is calculated correctly.

        Replica value is calculated by the following formula (from the paper):

            NOR / replica.size + NOR_FSTI / FSTI +
            1 / (now - repl_last_req_time)
        """
        sim = Mock(spec=self._make_sim())
        sim.fsti = 10
        sim.now = 4

        replica = self._make_replica('replica_1', size=200)
        node = self._make_instance('node_1', 1000, sim)

        repl_stats = Mock(nor=0, lrt=0)
        repl_stats.nor_fsti.return_value = 0
        node._replica_stats['replica_1'] = repl_stats

        self.assertAlmostEqual(node._RV(replica), 0.25)

        repl_stats.nor = 20
        self.assertAlmostEqual(node._RV(replica), 0.35)

        replica._size = 50
        self.assertAlmostEqual(node._RV(replica), 0.65)

        repl_stats.nor_fsti.return_value = 15
        self.assertAlmostEqual(node._RV(replica), 2.15)

        repl_stats.lrt = 3
        self.assertAlmostEqual(node._RV(replica), 2.90)

        sim.now = 8
        self.assertAlmostEqual(node._RV(replica), 2.10)