Пример #1
0
    def test_rdbs(self):
        with self.redis() as current_r:
            load_into_redis(current_r)

            for rdb_file in os.listdir('rdbs'):
                with self.redis(dir=os.path.realpath('rdbs'), dbfilename=rdb_file) as r:
                    for key in current_r.keys():
                        assert r.execute_command('ts.range', key, "-", "+") == \
                               current_r.execute_command('ts.range', key, "-", "+"), "data in key '{}' is not correct (rdb {})".format(key, rdb_file)
                        loaded_info = r.execute_command('ts.info', key)
                        current_info = current_r.execute_command('ts.info', key)

                        assert self.normalize_info(loaded_info) == self.normalize_info(current_info), \
                            "info for key '{}' is not correct (rdb {})".format(key, rdb_file)
Пример #2
0
def testRDBCompatibility():
    env = Env()
    env.skipOnCluster()
    skip_on_rlec()
    RDBS = os.listdir('rdbs')

    # Current RDB version check
    TSRANGE_RESULTS = {}
    TSINFO_RESULTS = {}
    KEYS = None

    current_r = env.getConnection()
    load_into_redis(current_r)
    KEYS = current_r.keys()
    KEYS.sort()
    for key in KEYS:
        TSRANGE_RESULTS[key] = current_r.execute_command(
            'ts.range', key, "-", "+")
        TSINFO_RESULTS[key] = normalize_info(
            current_r.execute_command('ts.info', key))

    # Compatibility check
    for fileName in RDBS:
        filePath = os.path.abspath(os.path.join("rdbs", fileName))
        dbFileName = env.cmd('config', 'get', 'dbfilename')[1].decode('ascii')
        dbDir = env.cmd('config', 'get', 'dir')[1].decode('ascii')
        rdbFilePath = os.path.join(dbDir, dbFileName)
        env.stop()
        try:
            os.remove(rdbFilePath)
        except FileNotFoundError:
            pass
        os.symlink(filePath, rdbFilePath)
        env.start()

        r = env.getConnection()
        OLD_KEYS = r.keys()
        newDbFileName = r.execute_command('config', 'get',
                                          'dbfilename')[1].decode('ascii')
        env.assertEqual(newDbFileName, dbFileName)
        OLD_KEYS.sort()
        env.assertEqual(OLD_KEYS, KEYS)
        for key in OLD_KEYS:
            assert r.execute_command('ts.range', key, "-",
                                     "+") == TSRANGE_RESULTS[key]
            assert normalize_info(r.execute_command(
                'ts.info', key)) == TSINFO_RESULTS[key]
def test_filterby():
    env = Env()
    high_temps = defaultdict(lambda: defaultdict(lambda: 0))
    specific_days = defaultdict(lambda: defaultdict(lambda: 0))
    days = [1335830400000, 1338508800000]
    for row in create_test_rdb_file.read_from_disk():
        timestamp = create_test_rdb_file.parse_timestamp(row[0])
        country = row[create_test_rdb_file.Country].replace('(', '[').replace(
            ')', ']')
        if timestamp in days:
            specific_days[country][timestamp] += 1

        if row[1] and float(row[1]) >= 30:
            if timestamp > 0:
                high_temps[country][timestamp] += 1

    with env.getClusterConnectionIfNeeded() as r:
        create_test_rdb_file.load_into_redis(r)

        def assert_results(results, expected_results):
            for row in results:
                country = row[1][0][1].decode()
                points = dict([(point[0], int(point[1])) for point in row[2]])
                for k in points:
                    env.assertEqual(points[k],
                                    expected_results[country][k],
                                    message="timestamp {} not equal".format(k))
                env.assertEqual(points,
                                expected_results[country],
                                message="country {} not eq".format(country))

        results = r.execute_command("TS.MRANGE", "-", "+", "withlabels",
                                    "FILTER_BY_VALUE", 30, 100, "AGGREGATION",
                                    "count", 3600000, "filter",
                                    "metric=temperature", "groupby", "country",
                                    "reduce", "sum")
        assert_results(results, high_temps)

        results = r.execute_command("TS.MRANGE", "-", "+", "withlabels",
                                    "FILTER_BY_TS", 1335830400000,
                                    1338508800000, "AGGREGATION", "count",
                                    3600000, "filter", "metric=temperature",
                                    "groupby", "country", "reduce", "sum")
        assert_results(results, specific_days)
Пример #4
0
def testRDBCompatibility():
    env = Env()
    env.skipOnCluster()
    skip_on_rlec()
    env.skipOnAOF()
    RDBS = os.listdir('rdbs')

    # Current RDB version check
    TSRANGE_RESULTS = {}
    TSINFO_RESULTS = {}
    KEYS = None

    current_r = env.getConnection()
    load_into_redis(current_r)
    KEYS = current_r.keys()
    KEYS.sort()
    for key in KEYS:
        TSRANGE_RESULTS[key] = current_r.execute_command(
            'ts.range', key, "-", "+")
        TSINFO_RESULTS[key] = normalize_info(
            current_r.execute_command('ts.info', key))

    # Compatibility check
    for fileName in RDBS:
        filePath = os.path.abspath(os.path.join("rdbs", fileName))
        dbFileName = env.cmd('config', 'get', 'dbfilename')[1].decode('ascii')
        dbDir = env.cmd('config', 'get', 'dir')[1].decode('ascii')
        rdbFilePath = os.path.join(dbDir, dbFileName)
        env.stop()
        try:
            os.remove(rdbFilePath)
        except FileNotFoundError:
            pass
        os.symlink(filePath, rdbFilePath)
        env.start()

        r = env.getConnection()
        OLD_KEYS = r.keys()
        newDbFileName = r.execute_command('config', 'get',
                                          'dbfilename')[1].decode('ascii')
        env.assertEqual(newDbFileName, dbFileName)
        OLD_KEYS.sort()

        if (fileName == "1.4.9_with_avg_ctx.rdb"):
            keys = r.keys()
            keys.sort()
            assert keys == [b'ts1', b'ts2']
            assert r.execute_command('ts.info', 'ts1') == [
                b'totalSamples', 2, b'memoryUsage', 4240, b'firstTimestamp',
                100, b'lastTimestamp', 120, b'retentionTime', 0, b'chunkCount',
                1, b'chunkSize', 4096, b'chunkType', b'compressed',
                b'duplicatePolicy', None, b'labels', [], b'sourceKey', None,
                b'rules', [[b'ts2', 1000, b'AVG']]
            ]
            assert r.execute_command('ts.info', 'ts2') == [
                b'totalSamples', 0, b'memoryUsage', 4184, b'firstTimestamp', 0,
                b'lastTimestamp', 0, b'retentionTime', 0, b'chunkCount', 1,
                b'chunkSize', 4096, b'chunkType', b'compressed',
                b'duplicatePolicy', None, b'labels', [], b'sourceKey', b'ts1',
                b'rules', []
            ]
            assert r.execute_command('ts.range', 'ts1', '-',
                                     '+') == [[100, b'3'], [120, b'5']]
            assert r.execute_command('ts.range', 'ts2', '-', '+') == []
            assert r.execute_command('ts.add', 'ts1', 1500, 100)
            assert r.execute_command('ts.range', 'ts2', '-',
                                     '+') == [[0, b'4']]

            continue

        env.assertEqual(OLD_KEYS, KEYS)
        for key in OLD_KEYS:
            assert r.execute_command('ts.range', key, "-",
                                     "+") == TSRANGE_RESULTS[key]
            assert normalize_info(r.execute_command(
                'ts.info', key)) == TSINFO_RESULTS[key]