def test_hot(m_from_cache): redis_cli = MockRedis() def _fake_build_response(_b, response_kquery, _c=True): response_kquery['sample_size'] += 100 response_kquery['results'].append({'hello': 'goodbye'}) return response_kquery mts_list = [] for i in xrange(3): mts = MTS(redis_cli) mts.build_response = _fake_build_response mts_list.append(mts) m_from_cache.return_value = mts_list kq = KQuery(redis_cli) kq.cached_data = { 'mts_keys': ['kquery:mts:1', 'kquery:mts:2', 'kquery:mts:3'] } kairos_time_range = {'start_relative': {'unit': 'hours', 'value': '1'}} out = cache_calls.hot(redis_cli, kq, kairos_time_range) assert out['sample_size'] == 300 assert len(out['results']) == 3
def test_build_response_yes_trim_efficient_not_ok(m_conforms, m_efficient, m_robust): m_conforms.return_value = False m_robust.return_value = [[1234567890000, 22], [1234567900000, 23]] response_kquery = {'results': [], 'sample_size': 0} mts = MTS(MockRedis()) mts.result = {'name': 'myMetric'} mts.result['values'] = [[1234567890000, 12], [1234567900000, 13]] ktr = {'start_absolute': '1234567880000'} result = mts.build_response(ktr, response_kquery, trim=True) result = mts.build_response(ktr, response_kquery, trim=True) assert len(result) == 2 assert result['sample_size'] == 4 assert result['results'][0] == { 'name': 'myMetric', 'values': [[1234567890000, 22], [1234567900000, 23]] } assert result['results'][1] == result['results'][0] assert m_conforms.call_count == 2 assert m_robust.call_count == 2 assert m_efficient.call_count == 0 assert m_robust.call_args_list[0][0] == ( datetime.datetime.fromtimestamp(1234567880), None) assert m_robust.call_args_list[1][0] == ( datetime.datetime.fromtimestamp(1234567880), None)
def test_build_response_no_trim(): response_kquery = {'results': [], 'sample_size': 0} mts = MTS(MockRedis()) mts.result = {'name': 'myMetric'} mts.result['values'] = [[1234567890000, 12], [1234567900000, 13]] result = mts.build_response({}, response_kquery, trim=False) result = mts.build_response({}, response_kquery, trim=False) assert len(result) == 2 assert result['sample_size'] == 4 assert result['results'] == [mts.result, mts.result]
def test_build_response_yes_trim_efficient_not_ok(m_conforms, m_efficient, m_robust): m_conforms.return_value = False m_robust.return_value = [[1234567890000, 22], [1234567900000, 23]] response_kquery = {'results': [], 'sample_size': 0} mts = MTS(MockRedis()) mts.result = {'name': 'myMetric'} mts.result['values'] = [[1234567890000, 12], [1234567900000, 13]] ktr = {'start_absolute': '1234567880000'} result = mts.build_response(ktr, response_kquery, trim=True) result = mts.build_response(ktr, response_kquery, trim=True) assert len(result) == 2 assert result['sample_size'] == 4 assert result['results'][0] == {'name': 'myMetric', 'values': [[1234567890000, 22], [1234567900000, 23]]} assert result['results'][1] == result['results'][0] assert m_conforms.call_count == 2 assert m_robust.call_count == 2 assert m_efficient.call_count == 0 assert m_robust.call_args_list[0][0] == (datetime.datetime.fromtimestamp(1234567880), None) assert m_robust.call_args_list[1][0] == (datetime.datetime.fromtimestamp(1234567880), None)
def test_hot(m_from_cache): redis_cli = MockRedis() def _fake_build_response(_b, response_kquery, _c=True): response_kquery['sample_size'] += 100 response_kquery['results'].append({'hello': 'goodbye'}) return response_kquery mts_list = [] for i in xrange(3): mts = MTS(redis_cli) mts.build_response = _fake_build_response mts_list.append(mts) m_from_cache.return_value = mts_list kq = KQuery(redis_cli) kq.cached_data = {'mts_keys': ['kquery:mts:1', 'kquery:mts:2', 'kquery:mts:3']} kairos_time_range = {'start_relative': {'unit': 'hours', 'value': '1'}} out = cache_calls.hot(redis_cli, kq, kairos_time_range) assert out['sample_size'] == 300 assert len(out['results']) == 3