def test_agg_count():
    with Env().getConnection() as r:
        agg_key = _insert_agg_data(r, 'tester', 'count')

        expected_result = [[10, b'10'], [20, b'10'], [30, b'10'], [40, b'10']]
        actual_result = r.execute_command('TS.RANGE', agg_key, 10, 50)
        assert expected_result == actual_result
Beispiel #2
0
def test_agg_range():
    with Env().getClusterConnectionIfNeeded() as r:
        agg_key = _insert_agg_data(r, 'tester{a}', 'range')

        expected_result = [[10, b'74'], [20, b'74'], [30, b'74'], [40, b'74']]
        actual_result = r.execute_command('TS.RANGE', agg_key, 10, 50)
        assert expected_result == actual_result
Beispiel #3
0
def test_agg_var_s():
    with Env().getClusterConnectionIfNeeded() as r:
        agg_key = _insert_agg_data(r, 'tester{a}', 'var.s')

        expected_result = [[10, b'743.611'], [20, b'743.611'],
                           [30, b'743.611'], [40, b'743.611']]
        actual_result = r.execute_command('TS.RANGE', agg_key, 10, 50)
        for i in range(len(expected_result)):
            assert abs(
                float(expected_result[i][1]) -
                float(actual_result[i][1])) < ALLOWED_ERROR
def test_agg_var_p():
    with Env().getConnection() as r:
        agg_key = _insert_agg_data(r, 'tester', 'var.p')

        expected_result = [[10, b'669.25'], [20, b'669.25'], [30, b'669.25'],
                           [40, b'669.25']]
        actual_result = r.execute_command('TS.RANGE', agg_key, 10, 50)
        for i in range(len(expected_result)):
            assert abs(
                float(expected_result[i][1]) -
                float(actual_result[i][1])) < ALLOWED_ERROR
def test_downsampling_extensive():
    with Env().getClusterConnectionIfNeeded() as r:
        key = 'tester{abc}'
        fromTS = 10
        toTS = 10000
        type_list = ['', 'uncompressed']
        for chunk_type in type_list:
            agg_list = [
                'avg', 'sum', 'min', 'max', 'count', 'range', 'first', 'last',
                'std.p', 'std.s', 'var.p', 'var.s'
            ]  # more
            for agg in agg_list:
                agg_key = _insert_agg_data(
                    r,
                    key,
                    agg,
                    chunk_type,
                    fromTS,
                    toTS,
                    key_create_args=['DUPLICATE_POLICY', 'LAST'])

                # sanity + check result have changed
                expected_result1 = r.execute_command('TS.RANGE', key, fromTS,
                                                     toTS, 'aggregation', agg,
                                                     10)
                actual_result1 = r.execute_command('TS.RANGE', agg_key, fromTS,
                                                   toTS)
                assert expected_result1 == actual_result1
                assert len(expected_result1) == 999

                for i in range(fromTS + 5, toTS - 4, 10):
                    assert r.execute_command('TS.ADD', key, i, 42)

                expected_result2 = r.execute_command('TS.RANGE', key, fromTS,
                                                     toTS, 'aggregation', agg,
                                                     10)
                actual_result2 = r.execute_command('TS.RANGE', agg_key, fromTS,
                                                   toTS)
                assert expected_result2 == actual_result2

                # remove aggs with identical results
                compare_list = [
                    'avg', 'sum', 'min', 'range', 'std.p', 'std.s', 'var.p',
                    'var.s'
                ]
                if agg in compare_list:
                    assert expected_result1 != expected_result2
                    assert actual_result1 != actual_result2

                r.execute_command('DEL', key)
                r.execute_command('DEL', agg_key)
def test_backfill_downsampling(self):
    with Env().getClusterConnectionIfNeeded() as r:
        key = 'tester{a}'
        type_list = ['', 'uncompressed']
        for chunk_type in type_list:
            agg_list = ['sum', 'min', 'max', 'count', 'first', 'last']  # more
            for agg in agg_list:
                agg_key = _insert_agg_data(
                    r,
                    key,
                    agg,
                    chunk_type,
                    key_create_args=['DUPLICATE_POLICY', 'LAST'])

                expected_result = r.execute_command('TS.RANGE', key, 10, 50,
                                                    'aggregation', agg, 10)
                actual_result = r.execute_command('TS.RANGE', agg_key, 10, 50)
                assert expected_result == actual_result
                assert r.execute_command('TS.ADD', key, 15, 50) == 15
                expected_result = r.execute_command('TS.RANGE', key, 10, 50,
                                                    'aggregation', agg, 10)
                actual_result = r.execute_command('TS.RANGE', agg_key, 10, 50)
                assert expected_result == actual_result

                # add in latest window
                r.execute_command('TS.ADD', key, 1055, 50) == 1055
                r.execute_command('TS.ADD', key, 1053, 55) == 1053
                r.execute_command('TS.ADD', key, 1062, 60) == 1062
                expected_result = r.execute_command('TS.RANGE', key, 10, 1060,
                                                    'aggregation', agg, 10)
                actual_result = r.execute_command('TS.RANGE', agg_key, 10,
                                                  1060)
                assert expected_result == actual_result

                # update in latest window
                r.execute_command('TS.ADD', key, 1065, 65) == 1065
                r.execute_command('TS.ADD', key, 1066, 66) == 1066
                r.execute_command('TS.ADD', key, 1001, 42) == 1001
                r.execute_command('TS.ADD', key, 1075, 50) == 1075
                expected_result = r.execute_command('TS.RANGE', key, 10, 1070,
                                                    'aggregation', agg, 10)
                actual_result = r.execute_command('TS.RANGE', agg_key, 10,
                                                  1070)
                assert expected_result == actual_result

                r.execute_command('DEL', key)
                r.execute_command('DEL', agg_key)
def test_agg_avg():
    with Env().getClusterConnectionIfNeeded() as r:
        agg_key = _insert_agg_data(r, 'tester{a}', 'avg')

        expected_result = [[10, b'156.5'], [20, b'256.5'], [30, b'356.5'],
                           [40, b'456.5']]
        actual_result = r.execute_command('TS.RANGE', agg_key, 10, 50)
        assert expected_result == actual_result

        #test overflow
        MAX_DOUBLE = 1.7976931348623157E+308
        assert r.execute_command('TS.CREATE', 'ts1')
        assert r.execute_command('TS.ADD', 'ts1', 1, MAX_DOUBLE - 10)
        assert r.execute_command('TS.ADD', 'ts1', 2, MAX_DOUBLE - 8)
        assert r.execute_command('TS.ADD', 'ts1', 3, MAX_DOUBLE - 6)

        actual_result = r.execute_command('TS.RANGE', 'ts1', 0, 3,
                                          'AGGREGATION', 'avg', 5)
        #MAX_DOUBLE - 10 equals MAX_DOUBLE cause of precision limit

        # If this test fails in the future it means
        # it run on an OS/compiler that doesn't support long double need to remove the comment below
        if (VALGRIND or (sizeof(c_longdouble) == 8)):
            assert actual_result == [[0, b'1.7976931348623155E308']]
        else:
            assert actual_result == [[0, b'1.7976931348623157E308']]

        MIN_DOUBLE = -1.7976931348623157E+308
        assert r.execute_command('TS.CREATE', 'ts2')
        assert r.execute_command('TS.ADD', 'ts2', 1, MIN_DOUBLE + 10)
        assert r.execute_command('TS.ADD', 'ts2', 2, MIN_DOUBLE + 8)
        assert r.execute_command('TS.ADD', 'ts2', 3, MIN_DOUBLE + 6)

        actual_result = r.execute_command('TS.RANGE', 'ts2', 0, 3,
                                          'AGGREGATION', 'avg', 5)
        #MIN_DOUBLE + 10 equals MIN_DOUBLE cause of precision limit
        if (VALGRIND or (sizeof(c_longdouble) == 8)):
            assert actual_result == [[0, b'-1.7976931348623155E308']]
        else:
            assert actual_result == [[0, b'-1.7976931348623157E308']]