コード例 #1
0
class TestGetToleratingRequestCount(unittest.TestCase):

    def setUp(self):

        self.begin_at = datetime(2016, 1, 1)
        self.end_at = datetime(2016, 1, 2)
        self.aq = ApdexQuery(self.begin_at, self.end_at, 0.1)

    def mock_get_es(self):

        self.aq.get_es = MagicMock()
        return self.aq.get_es.return_value

    def test_call(self):

        mock_es = self.mock_get_es()
        mock_es.count.return_value = {'count': 100}

        self.assertEqual(self.aq.get_tolerating_request_count(), 100)

        clauses = [
            TimeRangeClause(begin_time=self.begin_at, end_time=self.end_at),
            RangeClause('backend_processing_time', min_val=0.1, max_val=0.4)
        ]
        clauses = map(lambda c: c.get_clause(), clauses)

        mock_es.count.assert_called_with(
            index='logstash-2016.01.01',
            body={'filter': {'bool': {'filter': clauses}}}
        )
コード例 #2
0
class TestQuery(unittest.TestCase):
    def setUp(self):

        self.begin_at = datetime(2016, 1, 1)
        self.end_at = datetime(2016, 1, 2)
        self.aq = ApdexQuery(self.begin_at, self.end_at, 0.1)

    def test_call(self):

        self.aq.get_satisfied_request_count = MagicMock(return_value=1)
        self.aq.get_tolerating_request_count = MagicMock(return_value=2)
        self.aq.get_request_count = MagicMock(return_value=3)
        self.assertAlmostEqual(self.aq.query(), (1 + 1) / 3.0)
コード例 #3
0
class TestGetRequestCount(unittest.TestCase):
    def setUp(self):

        self.begin_at = datetime(2016, 1, 1)
        self.end_at = datetime(2016, 1, 2)
        self.aq = ApdexQuery(self.begin_at, self.end_at, 0.1)

    @patch(module + '.RequestCountQuery')
    def test_call(self, mock_req_cnt_query):

        mock_req_cnt_query.return_value.query.return_value = 100
        self.assertEqual(self.aq.get_request_count(), 100)
        mock_req_cnt_query.assert_called_with(self.begin_at, self.end_at)
コード例 #4
0
class TestQuery(unittest.TestCase):

    def setUp(self):

        self.begin_at = datetime(2016, 1, 1)
        self.end_at = datetime(2016, 1, 2)
        self.aq = ApdexQuery(self.begin_at, self.end_at, 0.1)

    def test_call(self):

        self.aq.get_satisfied_request_count = MagicMock(return_value=1)
        self.aq.get_tolerating_request_count = MagicMock(return_value=2)
        self.aq.get_request_count = MagicMock(return_value=3)
        self.assertAlmostEqual(self.aq.query(), (1 + 1) / 3.0)
コード例 #5
0
class TestGetRequestCount(unittest.TestCase):

    def setUp(self):

        self.begin_at = datetime(2016, 1, 1)
        self.end_at = datetime(2016, 1, 2)
        self.aq = ApdexQuery(self.begin_at, self.end_at, 0.1)

    @patch(module + '.RequestCountQuery')
    def test_call(self, mock_req_cnt_query):

        mock_req_cnt_query.return_value.query.return_value = 100
        self.assertEqual(self.aq.get_request_count(), 100)
        mock_req_cnt_query.assert_called_with(self.begin_at, self.end_at)
コード例 #6
0
class TestGetToleratingRequestCount(unittest.TestCase):
    def setUp(self):

        self.begin_at = datetime(2016, 1, 1)
        self.end_at = datetime(2016, 1, 2)
        self.aq = ApdexQuery(self.begin_at, self.end_at, 0.1)

    def mock_get_es(self):

        self.aq.get_es = MagicMock()
        return self.aq.get_es.return_value

    def test_call(self):

        mock_es = self.mock_get_es()
        mock_es.count.return_value = {'count': 100}

        self.assertEqual(self.aq.get_tolerating_request_count(), 100)
        mock_es.count.assert_called_with(
            index='logstash-2016.01.01',
            body={
                'query': {
                    'bool': {
                        'filter': [{
                            'range': {
                                'timestamp': {
                                    'gte': 1451606400000,
                                    'lt': 1451692800000
                                }
                            }
                        }, {
                            'exists': {
                                'field': 'rails.controller#action'
                            }
                        }, {
                            'term': {
                                'domain_name': 'api.thekono.com'
                            }
                        }, {
                            'range': {
                                'backend_processing_time': {
                                    'gte': 0.1,
                                    'lt': 0.4
                                }
                            }
                        }]
                    }
                }
            })
コード例 #7
0
    def get_apdex(self):

        aq = ApdexQuery(self.begin_at, self.end_at, self.APDEX_THRESHOLD)
        return aq.query()
コード例 #8
0
    def setUp(self):

        self.begin_at = datetime(2016, 1, 1)
        self.end_at = datetime(2016, 1, 2)
        self.aq = ApdexQuery(self.begin_at, self.end_at, 0.1)
コード例 #9
0
    def setUp(self):

        self.begin_at = datetime(2016, 1, 1)
        self.end_at = datetime(2016, 1, 2)
        self.aq = ApdexQuery(self.begin_at, self.end_at, 0.1)
コード例 #10
0
    def get_apdex(self):

        aq = ApdexQuery(self.begin_at, self.end_at, self.APDEX_THRESHOLD)
        return aq.query()