def test_non_local_filtered_data(): env = Env() with env.getClusterConnectionIfNeeded() as r: r.execute_command('TS.ADD', '{host1}_metric_1', 1, 100, 'LABELS', 'metric', 'cpu') r.execute_command('TS.ADD', '{host1}_metric_2', 2, 40, 'LABELS', 'metric', 'cpu') r.execute_command('TS.ADD', '{host1}_metric_1', 2, 95) r.execute_command('TS.ADD', '{host1}_metric_1', 10, 99) previous_results = [] # ensure that initiating the query on different shards always replies with the same series for shard in range(0, env.shardsCount): shard_conn = env.getConnection(shard) # send undordered timestamps to test for sorting actual_result = shard_conn.execute_command( 'TS.MRANGE - + FILTER_BY_TS 11 5 25 55 101 18 9 1900 2 FILTER metric=cpu' ) env.assertEqual(len(actual_result), 2) # ensure reply is properly filtered by TS for serie in actual_result: serie_ts = serie[2] # ensure only timestamp 2 is present on reply env.assertEqual(len(serie_ts), 1) env.assertEqual(serie_ts[0][0], 2) for previous_result in previous_results: ensure_replies_series_match(env, previous_result, actual_result) previous_results.append(actual_result)
def testLibmrFail(): env = Env() if env.shardsCount < 3: env.skip() if (not env.isCluster): env.skip() env.skipOnSlave() # There can't be 2 rdb save at the same time env.skipOnAOF() start_ts = 1 samples_count = 10 with env.getClusterConnectionIfNeeded() as r: assert r.execute_command('TS.CREATE', 'tester1{1}', 'LABELS', 'name', 'bob') _insert_data(r, 'tester1{1}', start_ts, samples_count, 1) try: env.envRunner.shards[2].stopEnv() except Exception as e: pass Refresh_Cluster(env) try: actual_result = env.getConnection(1).execute_command( 'TS.mrange', start_ts, start_ts + samples_count, 'WITHLABELS', 'FILTER', 'name=bob') assert (False) except Exception as e: env.assertResponseError(e, "multi shard cmd failed") env.envRunner.shards[2].startEnv() Refresh_Cluster(env) expected_res = [[ b'tester1{1}', [[b'name', b'bob']], [[1, b'1'], [2, b'1'], [3, b'1'], [4, b'1'], [5, b'1'], [6, b'1'], [7, b'1'], [8, b'1'], [9, b'1'], [10, b'1']] ]] actual_result = env.getConnection(1).execute_command( 'TS.mrange', start_ts, start_ts + samples_count, 'WITHLABELS', 'FILTER', 'name=bob') env.assertEqual(actual_result, expected_res)
def test_mrange_expire_issue549(): Env().skipOnDebugger() env = Env() set_hertz(env) with Env().getClusterConnectionIfNeeded() as r: assert r.execute_command('ts.add', 'k1', 1, 10, 'LABELS', 'l', '1') == 1 assert r.execute_command('ts.add', 'k2', 2, 20, 'LABELS', 'l', '1') == 2 assert r.execute_command('expire', 'k1', '1') == 1 for i in range(0, 5000): assert env.getConnection().execute_command( 'ts.mrange - + aggregation avg 10 withlabels filter l=1' ) is not None
def test_non_local_data(): env = Env() with env.getClusterConnectionIfNeeded() as r: r.execute_command('TS.ADD', '{host1}_metric_1', 1, 100, 'LABELS', 'metric', 'cpu') r.execute_command('TS.ADD', '{host1}_metric_2', 2, 40, 'LABELS', 'metric', 'cpu') r.execute_command('TS.ADD', '{host1}_metric_1', 2, 95) r.execute_command('TS.ADD', '{host1}_metric_1', 10, 99) previous_results = [] # ensure that initiating the query on different shards always replies with the same series for shard in range(0, env.shardsCount): shard_conn = env.getConnection(shard) actual_result = shard_conn.execute_command( 'TS.MRANGE - + FILTER metric=cpu') env.assertEqual(len(actual_result), 2) for previous_result in previous_results: ensure_replies_series_match(env, previous_result, actual_result) previous_results.append(actual_result)