public void TestRulesAdditionDeletion()
        {
            IDatabase db = redisFixture.Redis.GetDatabase();

            db.TimeSeriesCreate(srcKey);
            foreach (var destKey in destKeys.Values)
            {
                db.TimeSeriesCreate(destKey);
            }
            long timeBucket = 50;
            var  rules      = new List <TimeSeriesRule>();
            var  rulesMap   = new Dictionary <Aggregation, TimeSeriesRule>();

            foreach (var aggregation in destKeys.Keys)
            {
                var rule = new TimeSeriesRule(destKeys[aggregation], timeBucket, aggregation);
                rules.Add(rule);
                rulesMap[aggregation] = rule;
                Assert.True(db.TimeSeriesCreateRule(srcKey, rule));
                TimeSeriesInformation info = db.TimeSeriesInfo(srcKey);
                Assert.Equal(rules, info.Rules);
            }
            foreach (var aggregation in destKeys.Keys)
            {
                var rule = rulesMap[aggregation];
                rules.Remove(rule);
                Assert.True(db.TimeSeriesDeleteRule(srcKey, rule.DestKey));
                TimeSeriesInformation info = db.TimeSeriesInfo(srcKey);
                Assert.Equal(rules, info.Rules);
            }
        }
 private static void AddRule(this IList <object> args, TimeSeriesRule rule)
 {
     args.Add(rule.DestKey);
     args.Add(CommandArgs.AGGREGATION);
     args.Add(rule.Aggregation.Name);
     args.Add(rule.TimeBucket);
 }
        public void TestRuleConstructor()
        {
            TimeSeriesRule rule = new TimeSeriesRule("key", 50, Aggregation.AVG);

            Assert.Equal("key", rule.DestKey);
            Assert.Equal(Aggregation.AVG, rule.Aggregation);
            Assert.Equal(50, rule.TimeBucket);
        }
Exemple #4
0
        /// <summary>
        /// Example for create and delete RedisTimeSeries rules.
        /// </summary>
        public static void  RulesCreateDeleteExample()
        {
            ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
            IDatabase             db    = redis.GetDatabase();
            // Create you rule with destination key, time bucket and aggregation type.
            TimeSeriesRule rule = new TimeSeriesRule("dest_ts", 50, TsAggregation.Avg);

            db.TimeSeriesCreateRule("my_ts", rule);
            db.TimeSeriesDeleteRule("my_ts", "dest");
            redis.Close();
        }
Exemple #5
0
        /// <summary>
        /// Example for create and delete RedisTimeSeries rules.
        /// </summary>
        public static async Task RulesCreateDeleteAsyncExample()
        {
            ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
            IDatabase             db    = redis.GetDatabase();
            // Create your rule with destination key, time bucket and aggregation type.
            TimeSeriesRule rule = new TimeSeriesRule("dest_ts", 50, Aggregation.AVG);
            await db.TimeSeriesCreateRuleAsync("my_ts", rule);

            await db.TimeSeriesDeleteRuleAsync("my_ts", "dest");

            redis.Close();
        }
        public void TestNonExisitingDestinaion()
        {
            IDatabase db      = redisFixture.Redis.GetDatabase();
            string    destKey = "RULES_DEST_" + Aggregation.AVG;

            db.TimeSeriesCreate(srcKey);
            TimeSeriesRule rule = new TimeSeriesRule(destKey, 50, Aggregation.AVG);
            var            ex   = Assert.Throws <RedisServerException>(() => db.TimeSeriesCreateRule(srcKey, rule));

            Assert.Equal("ERR TSDB: the key does not exist", ex.Message);
            ex = Assert.Throws <RedisServerException>(() => db.TimeSeriesDeleteRule(srcKey, destKey));
            Assert.Equal("ERR TSDB: compaction rule does not exist", ex.Message);
        }
        public void TestRuleHashCode()
        {
            TimeSeriesRule rule = new TimeSeriesRule("key", 50, Aggregation.AVG);

            TimeSeriesRule rule1 = new TimeSeriesRule("key", 50, Aggregation.AVG);
            TimeSeriesRule rule2 = new TimeSeriesRule("key2", 50, Aggregation.AVG);
            TimeSeriesRule rule3 = new TimeSeriesRule("key", 51, Aggregation.AVG);
            TimeSeriesRule rule4 = new TimeSeriesRule("key", 50, Aggregation.COUNT);

            Assert.Equal(rule.GetHashCode(), rule1.GetHashCode());
            Assert.NotEqual(rule.GetHashCode(), rule2.GetHashCode());
            Assert.NotEqual(rule.GetHashCode(), rule3.GetHashCode());
            Assert.NotEqual(rule.GetHashCode(), rule4.GetHashCode());
        }
        public void TestRuleEquals()
        {
            TimeSeriesRule rule = new TimeSeriesRule("key", 50, Aggregation.AVG);

            TimeSeriesRule rule1 = new TimeSeriesRule("key", 50, Aggregation.AVG);
            TimeSeriesRule rule2 = new TimeSeriesRule("key2", 50, Aggregation.AVG);
            TimeSeriesRule rule3 = new TimeSeriesRule("key", 51, Aggregation.AVG);
            TimeSeriesRule rule4 = new TimeSeriesRule("key", 50, Aggregation.COUNT);

            Assert.Equal(rule, rule1);
            Assert.NotEqual(rule, rule2);
            Assert.NotEqual(rule, rule3);
            Assert.NotEqual(rule, rule4);
        }
Exemple #9
0
        public async Task TestNonExisitingDestinaion()
        {
            var key    = CreateKeyName();
            var aggKey = $"{key}:{TsAggregation.Avg}";
            var db     = redisFixture.Redis.GetDatabase();
            await db.TimeSeriesCreateAsync(key);

            var rule = new TimeSeriesRule(aggKey, 50, TsAggregation.Avg);
            var ex   = await Assert.ThrowsAsync <RedisServerException>(async() => await db.TimeSeriesCreateRuleAsync(key, rule));

            Assert.Equal("ERR TSDB: the key does not exist", ex.Message);

            ex = await Assert.ThrowsAsync <RedisServerException>(async() => await db.TimeSeriesDeleteRuleAsync(key, aggKey));

            Assert.Equal("ERR TSDB: compaction rule does not exist", ex.Message);
        }
Exemple #10
0
        public async Task TestRulesAdditionDeletion()
        {
            var key = CreateKeyName();
            var db  = redisFixture.Redis.GetDatabase();
            await db.TimeSeriesCreateAsync(key);

            var aggregations = (TsAggregation[])Enum.GetValues(typeof(TsAggregation));

            foreach (var aggregation in aggregations)
            {
                await db.TimeSeriesCreateAsync($"{key}:{aggregation}");
            }

            var timeBucket = 50L;
            var rules      = new List <TimeSeriesRule>();
            var rulesMap   = new Dictionary <TsAggregation, TimeSeriesRule>();

            foreach (var aggregation in aggregations)
            {
                var rule = new TimeSeriesRule($"{key}:{aggregation}", timeBucket, aggregation);
                rules.Add(rule);
                rulesMap[aggregation] = rule;
                Assert.True(await db.TimeSeriesCreateRuleAsync(key, rule));

                var info = await db.TimeSeriesInfoAsync(key);

                Assert.Equal(rules, info.Rules);
            }

            foreach (var aggregation in aggregations)
            {
                var rule = rulesMap[aggregation];
                rules.Remove(rule);
                Assert.True(await db.TimeSeriesDeleteRuleAsync(key, rule.DestKey));

                var info = await db.TimeSeriesInfoAsync(key);

                Assert.Equal(rules, info.Rules);
            }

            await db.KeyDeleteAsync(aggregations.Select(i => (RedisKey)$"{key}:{i}").ToArray());
        }
        public void TestRuleToString()
        {
            TimeSeriesRule rule = new TimeSeriesRule("key", 50, TsAggregation.Avg);

            Assert.Equal("DestinationKey: key, TimeBucket: 50, Aggregation: AVG", (string)rule);
        }