Repository navigation
Expand file tree
/
Copy pathTestIncrBy.cs
More file actions
111 lines (100 loc) · 3.65 KB
/
Copy pathTestIncrBy.cs
File metadata and controls
111 lines (100 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#pragma warning disable CS0618, CS0612 // allow testing obsolete methods
using NRedisStack.RedisStackCommands;
using NRedisStack.DataTypes;
using StackExchange.Redis;
using Xunit;
namespace NRedisStack.Tests.TimeSeries.TestAPI;
public class TestIncrBy(EndpointsFixture endpointsFixture) : AbstractNRedisStackTest(endpointsFixture), IDisposable
{
private readonly string key = "INCRBY_TESTS";
[Fact]
public void TestDefaultIncrBy()
{
double value = 5.5;
IDatabase db = GetCleanDatabase();
var ts = db.TS();
Assert.True(ts.IncrBy(key, value) > 0);
Assert.Equal(value, ts.Get(key)!.Val);
}
[Fact]
public void TestStarIncrBy()
{
double value = 5.5;
IDatabase db = GetCleanDatabase();
var ts = db.TS();
Assert.True(ts.IncrBy(key, value, timestamp: "*") > 0);
Assert.Equal(value, ts.Get(key)!.Val);
}
[Fact]
public void TestIncrByTimeStamp()
{
double value = 5.5;
IDatabase db = GetCleanDatabase();
var ts = db.TS();
TimeStamp timeStamp = DateTime.UtcNow;
Assert.Equal(timeStamp, ts.IncrBy(key, value, timestamp: timeStamp));
Assert.Equal(new(timeStamp, value), ts.Get(key));
}
[Fact]
public void TestDefaultIncrByWithRetentionTime()
{
double value = 5.5;
long retentionTime = 5000;
IDatabase db = GetCleanDatabase();
var ts = db.TS();
Assert.True(ts.IncrBy(key, value, retentionTime: retentionTime) > 0);
Assert.Equal(value, ts.Get(key)!.Val);
TimeSeriesInformation info = ts.Info(key);
Assert.Equal(retentionTime, info.RetentionTime);
}
[Fact]
public void TestDefaultIncrByWithLabels()
{
double value = 5.5;
TimeSeriesLabel label = new("key", "value");
IDatabase db = GetCleanDatabase();
var ts = db.TS();
var labels = new List<TimeSeriesLabel> { label };
Assert.True(ts.IncrBy(key, value, labels: labels) > 0);
Assert.Equal(value, ts.Get(key)!.Val);
TimeSeriesInformation info = ts.Info(key);
Assert.Equal(labels, info.Labels);
}
[Fact]
public void TestDefaultIncrByWithUncompressed()
{
double value = 5.5;
IDatabase db = GetCleanDatabase();
var ts = db.TS();
Assert.True(ts.IncrBy(key, value, uncompressed: true) > 0);
Assert.Equal(value, ts.Get(key)!.Val);
}
[Fact]
public void TestWrongParameters()
{
double value = 5.5;
IDatabase db = GetCleanDatabase();
var ts = db.TS();
var ex = Assert.Throws<RedisServerException>(() => ts.IncrBy(key, value, timestamp: "+"));
Assert.Equal("ERR TSDB: invalid timestamp", ex.Message);
ex = Assert.Throws<RedisServerException>(() => ts.IncrBy(key, value, timestamp: "-"));
Assert.Equal("ERR TSDB: invalid timestamp", ex.Message);
}
[SkipIfRedisTheory(Comparison.LessThan, "7.4.0")]
[MemberData(nameof(EndpointsFixture.Env.AllEnvironments), MemberType = typeof(EndpointsFixture.Env))]
public void TestIncrByAndIgnoreValues(string endpointId)
{
IDatabase db = GetCleanDatabase(endpointId);
var ts = db.TS();
var incrParameters = new TsIncrByParamsBuilder().AddValue(1).AddIgnoreValues(15, 16).build();
ts.IncrBy(key, incrParameters);
int j = -1, k = -1;
RedisResult info = TimeSeriesHelper.getInfo(db, key, out j, out k);
Assert.NotNull(info);
Assert.True(info.Length > 0);
Assert.NotEqual(-1, j);
Assert.NotEqual(-1, k);
Assert.Equal(15, (long)info[j + 1]);
Assert.Equal(16, (long)info[k + 1]);
}
}