コード例 #1
0
    def test__prepare_data(self):
        def assertAlmostEqualLists(l1, l2, places=1):
            self.assertEqual(len(l1), len(l2), "List sizes differs")
            for vals in zip(l1, l2):
                self.assertAlmostEqual(*vals, places=places)

        data = []
        for i in range(100):
            atomic_actions = [
                {
                    "action": "a1",
                    "duration": i + 0.1
                },
                {
                    "action": "a2",
                    "duration": i + 0.8
                },
            ]
            row = {
                "duration": i * 3.14,
                "idle_duration": i * 0.2,
                "error": [],
                "atomic_actions": atomic_actions,
            }
            data.append(row)
        data.insert(42, {"error": ["error"]})
        data.insert(52, {"error": ["error"]})

        new_data = plot._prepare_data({"result": data}, reduce_rows=10)
        self.assertEqual(2, new_data["num_errors"])

        expected_durations = [
            0.0, 31.4, 65.9, 100.5, 127.2, 161.6, 201.0, 238.6, 273.2, 307.7
        ]
        total_durations = new_data["total_durations"]["duration"]
        assertAlmostEqualLists(expected_durations, total_durations)

        expected_durations = [
            0.0, 2.0, 4.2, 6.4, 8.1, 10.3, 12.8, 15.2, 17.4, 19.6
        ]
        idle_durations = new_data["total_durations"]["idle_duration"]
        assertAlmostEqualLists(expected_durations, idle_durations)

        expected_durations = [
            0.1, 10.1, 21.1, 32.1, 40.6, 51.6, 64.1, 76.1, 87.1, 98.1
        ]
        atomic_a1 = new_data["atomic_durations"]["a1"]
        assertAlmostEqualLists(expected_durations, atomic_a1)

        expected_durations = [
            0.8, 10.8, 21.8, 32.8, 41.3, 52.2, 64.8, 76.8, 87.8, 98.8
        ]
        atomic_a2 = new_data["atomic_durations"]["a2"]
        assertAlmostEqualLists(expected_durations, atomic_a2)
コード例 #2
0
ファイル: test_plot.py プロジェクト: sahanasj/rally
    def test__prepare_data(self, mock_compress):

        mock_compress.side_effect = lambda i, **kv: i
        rows_range = 100
        limit = 10

        data = []
        for i in range(rows_range):
            atomic_actions = {
                "a1": i + 0.1,
                "a2": i + 0.8,
            }
            row = {
                "duration": i * 3.1,
                "idle_duration": i * 0.2,
                "error": [],
                "atomic_actions": atomic_actions,
            }
            data.append(row)

        data[42]["error"] = "foo error"
        data[52]["error"] = "bar error"

        values_atomic_a1 = [i + 0.1 for i in range(rows_range)]
        values_atomic_a2 = [i + 0.8 for i in range(rows_range)]
        values_duration = [i * 3.1 for i in range(rows_range)]
        values_idle = [i * 0.2 for i in range(rows_range)]
        num_errors = 2

        prepared_data = plot._prepare_data({"result": data}, reduce_rows=limit)
        self.assertEqual(num_errors, prepared_data["num_errors"])

        calls = [
            mock.call(values_atomic_a1, limit=limit),
            mock.call(values_atomic_a2, limit=limit),
            mock.call(values_duration, limit=limit),
            mock.call(values_idle, limit=limit)
        ]
        mock_compress.assert_has_calls(calls)

        self.assertEqual(
            {
                "total_durations": {
                    "duration": values_duration,
                    "idle_duration": values_idle
                },
                "atomic_durations": {
                    "a1": values_atomic_a1,
                    "a2": values_atomic_a2
                },
                "num_errors": num_errors
            }, prepared_data)
コード例 #3
0
ファイル: test_plot.py プロジェクト: danielmellado/rally
    def test__prepare_data(self, mock_compress):

        mock_compress.side_effect = lambda i, **kv: i
        rows_range = 100
        limit = 10

        data = []
        for i in range(rows_range):
            atomic_actions = {
                "a1": i + 0.1,
                "a2": i + 0.8,
            }
            row = {
                "duration": i * 3.1,
                "idle_duration": i * 0.2,
                "error": [],
                "atomic_actions": atomic_actions,
            }
            data.append(row)

        data[42]["error"] = "foo error"
        data[52]["error"] = "bar error"

        values_atomic_a1 = [i + 0.1 for i in range(rows_range)]
        values_atomic_a2 = [i + 0.8 for i in range(rows_range)]
        values_duration = [i * 3.1 for i in range(rows_range)]
        values_idle = [i * 0.2 for i in range(rows_range)]
        num_errors = 2

        prepared_data = plot._prepare_data({"result": data},
                                           reduce_rows=limit)
        self.assertEqual(num_errors, prepared_data["num_errors"])

        calls = [mock.call(values_atomic_a1, limit=limit),
                 mock.call(values_atomic_a2, limit=limit),
                 mock.call(values_duration, limit=limit),
                 mock.call(values_idle, limit=limit)]
        mock_compress.assert_has_calls(calls)

        self.assertEqual({
            "total_durations": {"duration": values_duration,
                                "idle_duration": values_idle},
            "atomic_durations": {"a1": values_atomic_a1,
                                 "a2": values_atomic_a2},
            "num_errors": num_errors
        }, prepared_data)
コード例 #4
0
ファイル: test_plot.py プロジェクト: bluejayKR/rally
    def test__prepare_data(self):

        def assertAlmostEqualLists(l1, l2, places=1):
            self.assertEqual(len(l1), len(l2), "List sizes differs")
            for vals in zip(l1, l2):
                self.assertAlmostEqual(*vals, places=places)

        data = []
        for i in range(100):
            atomic_actions = [
                    {"action": "a1", "duration": i + 0.1},
                    {"action": "a2", "duration": i + 0.8},
            ]
            row = {
                    "duration": i * 3.14,
                    "idle_duration": i * 0.2,
                    "error": [],
                    "atomic_actions": atomic_actions,
            }
            data.append(row)
        data.insert(42, {"error": ["error"]})
        data.insert(52, {"error": ["error"]})

        new_data = plot._prepare_data({"result": data}, reduce_rows=10)
        self.assertEqual(2, new_data["num_errors"])

        expected_durations = [0.0, 31.4, 65.9, 100.5, 127.2,
                              161.6, 201.0, 238.6, 273.2, 307.7]
        total_durations = new_data["total_durations"]["duration"]
        assertAlmostEqualLists(expected_durations, total_durations)

        expected_durations = [0.0, 2.0, 4.2, 6.4, 8.1, 10.3,
                              12.8, 15.2, 17.4, 19.6]
        idle_durations = new_data["total_durations"]["idle_duration"]
        assertAlmostEqualLists(expected_durations, idle_durations)

        expected_durations = [0.1, 10.1, 21.1, 32.1, 40.6,
                              51.6, 64.1, 76.1, 87.1, 98.1]
        atomic_a1 = new_data["atomic_durations"]["a1"]
        assertAlmostEqualLists(expected_durations, atomic_a1)

        expected_durations = [0.8, 10.8, 21.8, 32.8, 41.3,
                              52.2, 64.8, 76.8, 87.8, 98.8]
        atomic_a2 = new_data["atomic_durations"]["a2"]
        assertAlmostEqualLists(expected_durations, atomic_a2)
コード例 #5
0
ファイル: test_plot.py プロジェクト: linhuacheng/rally
    def test__prepare_data(self, mock_compress):

        mock_compress.side_effect = lambda i, **kv: i
        rows_num = 100
        load_duration = 1234.5
        full_duration = 6789.1
        sla = [{"foo": "bar"}]
        data = []
        for i in range(rows_num):
            atomic_actions = {
                "a1": i + 0.1,
                "a2": i + 0.8,
            }
            row = {
                "duration": i * 3.1,
                "idle_duration": i * 0.2,
                "error": [],
                "atomic_actions": atomic_actions,
                "scenario_output": {"errors": ["err"],
                                    "data": {"out_key": "out_value"}}
            }
            data.append(row)

        data[42]["error"] = ["foo", "bar", "spam"]
        data[52]["error"] = ["spam", "bar", "foo"]

        values_atomic_a1 = [i + 0.1 for i in range(rows_num)]
        values_atomic_a2 = [i + 0.8 for i in range(rows_num)]
        values_duration = [i * 3.1 for i in range(rows_num)]
        values_duration[42] = 0
        values_duration[52] = 0
        values_idle = [i * 0.2 for i in range(rows_num)]
        values_idle[42] = 0
        values_idle[52] = 0

        prepared_data = plot._prepare_data({"result": data,
                                            "load_duration": load_duration,
                                            "full_duration": full_duration,
                                            "sla": sla,
                                            "key": "foo_key"})
        self.assertEqual(2, len(prepared_data["errors"]))

        calls = [mock.call(values_atomic_a1),
                 mock.call(values_atomic_a2),
                 mock.call(values_duration),
                 mock.call(values_idle)]
        mock_compress.assert_has_calls(calls)

        expected_output = [{"key": "out_key",
                            "values": ["out_value"] * rows_num}]
        expected_output_errors = [(i, [e])
                                  for i, e in enumerate(["err"] * rows_num)]
        self.assertEqual({
            "total_durations": {"duration": values_duration,
                                "idle_duration": values_idle},
            "atomic_durations": {"a1": values_atomic_a1,
                                 "a2": values_atomic_a2},
            "errors": [{"iteration": 42,
                        "message": "bar",
                        "traceback": "spam",
                        "type": "foo"},
                       {"iteration": 52,
                        "message": "bar",
                        "traceback": "foo",
                        "type": "spam"}],
            "output": expected_output,
            "output_errors": expected_output_errors,
            "load_duration": load_duration,
            "full_duration": full_duration,
            "sla": sla,
        }, prepared_data)
コード例 #6
0
ファイル: test_plot.py プロジェクト: linhuacheng/rally
    def test__process_main_time(self):
        result = {
            "result": [
                {
                    "error": [],
                    "duration": 1,
                    "idle_duration": 2,
                    "atomic_actions": {},
                    "scenario_output": {"errors": [], "data": {}}
                },
                {
                    "error": ["some", "error", "occurred"],
                    "duration": 1,
                    "idle_duration": 1,
                    "atomic_actions": {},
                    "scenario_output": {"errors": [], "data": {}}
                },
                {
                    "error": [],
                    "duration": 2,
                    "idle_duration": 3,
                    "atomic_actions": {},
                    "scenario_output": {"errors": [], "data": {}}
                }
            ],
            "sla": "foo_sla",
            "load_duration": 1234.5,
            "full_duration": 6789.1
        }

        output = plot._process_main_duration(result,
                                             plot._prepare_data(result))

        self.assertEqual(output, {
            "pie": [
                {"key": "success", "value": 2},
                {"key": "errors", "value": 1}
            ],
            "iter": [
                {
                    "key": "duration",
                    "values": [(1, 1.0), (2, 0), (3, 2.0)]
                },
                {
                    "key": "idle_duration",
                    "values": [(1, 2.0), (2, 0), (3, 3.0)]
                }
            ],
            "histogram": [
                {
                    "key": "task",
                    "method": "Square Root Choice",
                    "values": [{"x": 1.0, "y": 1.0}, {"x": 1.0, "y": 0.0}]
                },
                {
                    "key": "task",
                    "method": "Sturges Formula",
                    "values": [{"x": 1.0, "y": 1.0}, {"x": 1.0, "y": 0.0}]
                },
                {
                    "key": "task",
                    "method": "Rice Rule",
                    "values": [{"x": 1.0, "y": 1.0}, {"x": 1.0, "y": 0.0},
                               {"x": 1.0, "y": 0.0}]
                },
                {
                    "key": "task",
                    "method": "One Half",
                    "values": [{"x": 2.0, "y": 2.0}]
                }
            ]
        })
コード例 #7
0
    def test__prepare_data(self, mock_compress):

        mock_compress.side_effect = lambda i, **kv: i
        rows_num = 100
        load_duration = 1234.5
        full_duration = 6789.1
        sla = [{"foo": "bar"}]
        data = []
        for i in range(rows_num):
            atomic_actions = {
                "a1": i + 0.1,
                "a2": i + 0.8,
            }
            row = {
                "duration": i * 3.1,
                "idle_duration": i * 0.2,
                "error": [],
                "atomic_actions": atomic_actions,
                "scenario_output": {
                    "errors": ["err"],
                    "data": {
                        "out_key": "out_value"
                    }
                }
            }
            data.append(row)

        data[42]["error"] = ["foo", "bar", "spam"]
        data[52]["error"] = ["spam", "bar", "foo"]

        values_atomic_a1 = [i + 0.1 for i in range(rows_num)]
        values_atomic_a2 = [i + 0.8 for i in range(rows_num)]
        values_duration = [i * 3.1 for i in range(rows_num)]
        values_duration[42] = 0
        values_duration[52] = 0
        values_idle = [i * 0.2 for i in range(rows_num)]
        values_idle[42] = 0
        values_idle[52] = 0

        prepared_data = plot._prepare_data({
            "result": data,
            "load_duration": load_duration,
            "full_duration": full_duration,
            "sla": sla,
            "key": "foo_key"
        })
        self.assertEqual(2, len(prepared_data["errors"]))

        calls = [
            mock.call(values_atomic_a1),
            mock.call(values_atomic_a2),
            mock.call(values_duration),
            mock.call(values_idle)
        ]
        mock_compress.assert_has_calls(calls)

        expected_output = [{
            "key": "out_key",
            "values": ["out_value"] * rows_num
        }]
        expected_output_errors = [(i, [e])
                                  for i, e in enumerate(["err"] * rows_num)]
        self.assertEqual(
            {
                "total_durations": {
                    "duration": values_duration,
                    "idle_duration": values_idle
                },
                "atomic_durations": {
                    "a1": values_atomic_a1,
                    "a2": values_atomic_a2
                },
                "errors": [{
                    "iteration": 42,
                    "message": "bar",
                    "traceback": "spam",
                    "type": "foo"
                }, {
                    "iteration": 52,
                    "message": "bar",
                    "traceback": "foo",
                    "type": "spam"
                }],
                "output":
                expected_output,
                "output_errors":
                expected_output_errors,
                "load_duration":
                load_duration,
                "full_duration":
                full_duration,
                "sla":
                sla,
            }, prepared_data)
コード例 #8
0
    def test__process_main_time(self):
        result = {
            "result": [{
                "error": [],
                "duration": 1,
                "idle_duration": 2,
                "atomic_actions": {},
                "scenario_output": {
                    "errors": [],
                    "data": {}
                }
            }, {
                "error": ["some", "error", "occurred"],
                "duration": 1,
                "idle_duration": 1,
                "atomic_actions": {},
                "scenario_output": {
                    "errors": [],
                    "data": {}
                }
            }, {
                "error": [],
                "duration": 2,
                "idle_duration": 3,
                "atomic_actions": {},
                "scenario_output": {
                    "errors": [],
                    "data": {}
                }
            }],
            "sla":
            "foo_sla",
            "load_duration":
            1234.5,
            "full_duration":
            6789.1
        }

        output = plot._process_main_duration(result,
                                             plot._prepare_data(result))

        self.assertEqual(
            {
                "pie": [{
                    "key": "success",
                    "value": 2
                }, {
                    "key": "errors",
                    "value": 1
                }],
                "iter": [{
                    "key": "duration",
                    "values": [(1, 1.0), (2, 0), (3, 2.0)]
                }, {
                    "key": "idle_duration",
                    "values": [(1, 2.0), (2, 0), (3, 3.0)]
                }],
                "histogram": [
                    {
                        "key": "task",
                        "method": "Square Root Choice",
                        "values": [{
                            "x": 1.0,
                            "y": 1.0
                        }, {
                            "x": 1.0,
                            "y": 0.0
                        }]
                    }, {
                        "key": "task",
                        "method": "Sturges Formula",
                        "values": [{
                            "x": 1.0,
                            "y": 1.0
                        }, {
                            "x": 1.0,
                            "y": 0.0
                        }]
                    }, {
                        "key":
                        "task",
                        "method":
                        "Rice Rule",
                        "values": [{
                            "x": 1.0,
                            "y": 1.0
                        }, {
                            "x": 1.0,
                            "y": 0.0
                        }, {
                            "x": 1.0,
                            "y": 0.0
                        }]
                    }, {
                        "key": "task",
                        "method": "One Half",
                        "values": [{
                            "x": 2.0,
                            "y": 2.0
                        }]
                    }
                ]
            }, output)
コード例 #9
0
ファイル: test_plot.py プロジェクト: sahanasj/rally
    def test__process_main_time(self):
        result = {
            "result": [{
                "error": [],
                "duration": 1,
                "idle_duration": 2,
                "atomic_actions": {}
            }, {
                "error": True,
                "duration": 1,
                "idle_duration": 1,
                "atomic_actions": {}
            }, {
                "error": [],
                "duration": 2,
                "idle_duration": 3,
                "atomic_actions": {}
            }]
        }

        output = plot._process_main_duration(result,
                                             plot._prepare_data(result))

        self.assertEqual(
            output, {
                "pie": [{
                    "key": "success",
                    "value": 2
                }, {
                    "key": "errors",
                    "value": 1
                }],
                "iter": [{
                    "key": "duration",
                    "values": [(1, 1.0), (2, 1.0), (3, 2.0)]
                }, {
                    "key": "idle_duration",
                    "values": [(1, 2.0), (2, 1.0), (3, 3.0)]
                }],
                "histogram": [
                    {
                        "key": "task",
                        "method": "Square Root Choice",
                        "values": [{
                            "x": 1.0,
                            "y": 1.0
                        }, {
                            "x": 1.0,
                            "y": 0.0
                        }]
                    }, {
                        "key": "task",
                        "method": "Sturges Formula",
                        "values": [{
                            "x": 1.0,
                            "y": 1.0
                        }, {
                            "x": 1.0,
                            "y": 0.0
                        }]
                    }, {
                        "key":
                        "task",
                        "method":
                        "Rice Rule",
                        "values": [{
                            "x": 1.0,
                            "y": 1.0
                        }, {
                            "x": 1.0,
                            "y": 0.0
                        }, {
                            "x": 1.0,
                            "y": 0.0
                        }]
                    }, {
                        "key": "task",
                        "method": "One Half",
                        "values": [{
                            "x": 2.0,
                            "y": 2.0
                        }]
                    }
                ]
            })
コード例 #10
0
ファイル: test_plot.py プロジェクト: danielmellado/rally
    def test__process_main_time(self):
        result = {
            "result": [
                {
                    "error": [],
                    "duration": 1,
                    "idle_duration": 2,
                    "atomic_actions": {}
                },
                {
                    "error": True,
                    "duration": 1,
                    "idle_duration": 1,
                    "atomic_actions": {}
                },
                {
                    "error": [],
                    "duration": 2,
                    "idle_duration": 3,
                    "atomic_actions": {}
                }
            ]
        }

        output = plot._process_main_duration(result,
                                             plot._prepare_data(result))

        self.assertEqual(output, {
            "pie": [
                {"key": "success", "value": 2},
                {"key": "errors", "value": 1}
            ],
            "iter": [
                {
                    "key": "duration",
                    "values": [(1, 1.0), (2, 1.0), (3, 2.0)]
                },
                {
                    "key": "idle_duration",
                    "values": [(1, 2.0), (2, 1.0), (3, 3.0)]
                }
            ],
            "histogram": [
                {
                    "key": "task",
                    "method": "Square Root Choice",
                    "values": [{"x": 1.0, "y": 1.0}, {"x": 1.0, "y": 0.0}]
                },
                {
                    "key": "task",
                    "method": "Sturges Formula",
                    "values": [{"x": 1.0, "y": 1.0}, {"x": 1.0, "y": 0.0}]
                },
                {
                    "key": "task",
                    "method": "Rice Rule",
                    "values": [{"x": 1.0, "y": 1.0}, {"x": 1.0, "y": 0.0},
                               {"x": 1.0, "y": 0.0}]
                },
                {
                    "key": "task",
                    "method": "One Half",
                    "values": [{"x": 2.0, "y": 2.0}]
                }
            ]
        })