@@ -10,15 +10,60 @@ namespace InfluxDB.LineProtocol.Tests.Collector
10
10
{
11
11
public class AggregationTests
12
12
{
13
+ [Fact]
14
+ public async Task PointsAreCorrectlyGrouped()
15
+ {
16
+ var written = new TaskCompletionSource<object>();
17
+ var list = new List<PointData>();
18
+
19
+ var start = DateTime.UtcNow;
20
+
21
+ var collector = new CollectorConfiguration()
22
+ .Aggregate.AtInterval(TimeSpan.FromMilliseconds(500))
23
+ .Aggregate.SumIncrements()
24
+ .WriteTo.Emitter(pts =>
25
+ {
26
+ list.AddRange(pts);
27
+ written.SetResult(0);
28
+ })
29
+ .CreateCollector();
30
+
31
+ collector.Write("foo",
32
+ new Dictionary<string, object> { { "count", 1L } },
33
+ new Dictionary<string, string> { { "tag1", "a" } },
34
+ start
35
+ );
36
+ collector.Write("foo",
37
+ new Dictionary<string, object> { { "count", 1L } },
38
+ new Dictionary<string, string> { { "tag1", "a" } },
39
+ start + TimeSpan.FromMilliseconds(200)
40
+ );
41
+ collector.Write("foo",
42
+ new Dictionary<string, object> { { "count", 1L } },
43
+ new Dictionary<string, string> { { "tag1", "a" } },
44
+ start + TimeSpan.FromMilliseconds(400)
45
+ );
46
+
47
+ await written.Task;
48
+
49
+ Assert.Equal(1, list.Count);
50
+ Assert.Equal(3L, list[0].Fields["count"]);
51
+ }
52
+
13
53
[Fact]
14
54
public async Task IncrementsCanBeSummed()
15
55
{
56
+ var written = new TaskCompletionSource<object>();
16
57
var list = new List<PointData>();
17
58
18
59
IPointEmitter collector = new CollectorConfiguration()
19
60
.Aggregate.AtInterval(TimeSpan.FromMilliseconds(500))
20
61
.Aggregate.SumIncrements()
21
- .WriteTo.Emitter(pts => list.AddRange(pts))
62
+ .WriteTo.Emitter(pts =>
63
+ {
64
+ list.AddRange(pts);
65
+ written.SetResult(0);
66
+ })
22
67
.CreateCollector();
23
68
24
69
collector.Emit(new[]
@@ -49,12 +94,17 @@ public async Task IncrementsCanBeSummed()
49
94
[Fact]
50
95
public async Task TimesCanBeAveraged()
51
96
{
97
+ var written = new TaskCompletionSource<object>();
52
98
var list = new List<PointData>();
53
99
54
100
IPointEmitter collector = new CollectorConfiguration()
55
101
.Aggregate.AtInterval(TimeSpan.FromMilliseconds(400))
56
102
.Aggregate.AggregateTimes(Enumerable.Average)
57
- .WriteTo.Emitter(pts => list.AddRange(pts))
103
+ .WriteTo.Emitter(pts =>
104
+ {
105
+ list.AddRange(pts);
106
+ written.SetResult(0);
107
+ })
58
108
.CreateCollector();
59
109
60
110
collector.Emit(new[]
@@ -85,12 +135,17 @@ public async Task TimesCanBeAveraged()
85
135
[Fact]
86
136
public async Task DifferentTagsArentAggregated()
87
137
{
138
+ var written = new TaskCompletionSource<object>();
88
139
var list = new List<PointData>();
89
140
90
141
IPointEmitter collector = new CollectorConfiguration()
91
142
.Aggregate.AtInterval(TimeSpan.FromMilliseconds(500))
92
143
.Aggregate.SumIncrements()
93
- .WriteTo.Emitter(pts => list.AddRange(pts))
144
+ .WriteTo.Emitter(pts =>
145
+ {
146
+ list.AddRange(pts);
147
+ written.SetResult(0);
148
+ })
94
149
.CreateCollector();
95
150
96
151
collector.Emit(new[]
@@ -119,12 +174,17 @@ public async Task DifferentTagsArentAggregated()
119
174
[Fact]
120
175
public async Task DifferentMeasurementsArentAggregated()
121
176
{
177
+ var written = new TaskCompletionSource<object>();
122
178
var list = new List<PointData>();
123
179
124
180
IPointEmitter collector = new CollectorConfiguration()
125
181
.Aggregate.AtInterval(TimeSpan.FromMilliseconds(500))
126
182
.Aggregate.SumIncrements()
127
- .WriteTo.Emitter(pts => list.AddRange(pts))
183
+ .WriteTo.Emitter(pts =>
184
+ {
185
+ list.AddRange(pts);
186
+ written.SetResult(0);
187
+ })
128
188
.CreateCollector();
129
189
130
190
collector.Emit(new[]
@@ -153,12 +213,17 @@ public async Task DifferentMeasurementsArentAggregated()
153
213
[Fact]
154
214
public async Task DifferentTimeSpansArentAggregated()
155
215
{
216
+ var written = new TaskCompletionSource<object>();
156
217
var list = new List<PointData>();
157
218
158
219
IPointEmitter collector = new CollectorConfiguration()
159
220
.Aggregate.AtInterval(TimeSpan.FromMilliseconds(500))
160
221
.Aggregate.SumIncrements()
161
- .WriteTo.Emitter(pts => list.AddRange(pts))
222
+ .WriteTo.Emitter(pts =>
223
+ {
224
+ list.AddRange(pts);
225
+ written.SetResult(0);
226
+ })
162
227
.CreateCollector();
163
228
164
229
collector.Emit(new[]
0 commit comments