forked from influxdata/influxdb-client-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeasurementMapperTest.cs
122 lines (99 loc) · 3.73 KB
/
MeasurementMapperTest.cs
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
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using InfluxDB.Client.Api.Domain;
using InfluxDB.Client.Core;
using InfluxDB.Client.Internal;
using NodaTime.Text;
using NUnit.Framework;
namespace InfluxDB.Client.Test
{
[TestFixture]
public class MeasurementMapperTest
{
private MeasurementMapper _mapper;
[SetUp]
public void SetUp()
{
_mapper = new MeasurementMapper();
}
[Test]
public void Precision()
{
var timeStamp = InstantPattern.ExtendedIso.Parse("1970-01-01T00:00:10.999999999Z").Value;
var poco = new Poco
{
Tag = "value",
Value = "val",
Timestamp = timeStamp
};
Assert.AreEqual("poco,tag=value value=\"val\" 10", _mapper.ToPoint(poco, WritePrecision.S).ToLineProtocol());
Assert.AreEqual("poco,tag=value value=\"val\" 10999", _mapper.ToPoint(poco, WritePrecision.Ms).ToLineProtocol());
Assert.AreEqual("poco,tag=value value=\"val\" 10999999", _mapper.ToPoint(poco, WritePrecision.Us).ToLineProtocol());
Assert.AreEqual("poco,tag=value value=\"val\" 10999999999", _mapper.ToPoint(poco, WritePrecision.Ns).ToLineProtocol());
}
[Test]
public void ColumnWithoutName()
{
var poco = new Poco
{
Tag = "tag val",
Value = 15.444,
ValueWithoutDefaultName = 20,
ValueWithEmptyName = 25d,
Timestamp = TimeSpan.FromDays(10)
};
var lineProtocol = _mapper.ToPoint(poco, WritePrecision.S).ToLineProtocol();
Assert.AreEqual("poco,tag=tag\\ val value=15.444,ValueWithEmptyName=25,ValueWithoutDefaultName=20i 864000", lineProtocol);
}
[Test]
public void DefaultToString()
{
var poco = new Poco
{
Tag = "value",
Value = new MyClass()
};
var lineProtocol = _mapper.ToPoint(poco, WritePrecision.S).ToLineProtocol();
Assert.AreEqual("poco,tag=value value=\"to-string\"", lineProtocol);
}
[Test]
public void HeavyLoad()
{
var measurements = new List<Poco>();
for (var i = 0; i < 500_000; i++)
{
measurements.Add(new Poco{Value = i, Tag = "Europe", Timestamp = DateTime.UnixEpoch.Add(TimeSpan.FromSeconds(i))});
}
var stopWatch = new Stopwatch();
stopWatch.Start();
var enumerable = measurements.Select(it => _mapper.ToPoint(it, WritePrecision.S).ToLineProtocol());
var _ = string.Join("\n", enumerable);
var ts = stopWatch.Elapsed;
var elapsedTime = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds / 10:00}";
Assert.LessOrEqual(ts.Seconds, 10, $"Elapsed time: {elapsedTime}");
}
private class MyClass
{
public override string ToString()
{
return "to-string";
}
}
[Measurement("poco")]
private class Poco
{
[Column("tag", IsTag = true)]
public string Tag { get; set; }
[Column("value")]
public Object Value { get; set; }
[Column]
public int? ValueWithoutDefaultName { get; set; }
[Column("")]
public Double? ValueWithEmptyName { get; set; }
[Column(IsTimestamp = true)]
public Object Timestamp { get; set; }
}
}
}