1
+ using System . Collections . Generic ;
2
+ using System . Linq ;
3
+ using System . Threading . Tasks ;
4
+ using InfluxDB . Client . Api . Domain ;
5
+ using InfluxDB . Client . Core . Test ;
6
+ using InfluxDB . Client . Writes ;
7
+ using NUnit . Framework ;
8
+ using WireMock . RequestBuilders ;
9
+
10
+ namespace InfluxDB . Client . Test
11
+ {
12
+ [ TestFixture ]
13
+ public class WriteApiAsyncTest : AbstractMockServerTest
14
+ {
15
+ private InfluxDBClient _influxDbClient ;
16
+
17
+ [ SetUp ]
18
+ public new void SetUp ( )
19
+ {
20
+ _influxDbClient = InfluxDBClientFactory . Create ( MockServerUrl , "token" . ToCharArray ( ) ) ;
21
+ }
22
+
23
+ [ TearDown ]
24
+ public new void ResetServer ( )
25
+ {
26
+ _influxDbClient . Dispose ( ) ;
27
+ }
28
+
29
+ [ Test ]
30
+ public async Task GroupPointsByPrecisionSame ( )
31
+ {
32
+ MockServer
33
+ . Given ( Request . Create ( ) . WithPath ( "/api/v2/write" ) . UsingPost ( ) )
34
+ . RespondWith ( CreateResponse ( "{}" ) ) ;
35
+
36
+ var writeApi = _influxDbClient . GetWriteApiAsync ( ) ;
37
+ await writeApi . WritePointsAsync ( "my-bucket" , "my-org" , new List < PointData >
38
+ {
39
+ PointData . Measurement ( "h2o" ) . Tag ( "location" , "coyote_creek" ) . Field ( "water_level" , 9.0D )
40
+ . Timestamp ( 9L , WritePrecision . S ) ,
41
+ PointData . Measurement ( "h2o" ) . Tag ( "location" , "coyote_creek" ) . Field ( "water_level" , 10.0D )
42
+ . Timestamp ( 10L , WritePrecision . S )
43
+ } ) ;
44
+
45
+ Assert . AreEqual ( 1 , MockServer . LogEntries . Count ( ) ) ;
46
+
47
+ var request = MockServer . LogEntries . Last ( ) ;
48
+ Assert . AreEqual ( MockServerUrl + "/api/v2/write?org=my-org&bucket=my-bucket&precision=s" ,
49
+ request . RequestMessage . AbsoluteUrl ) ;
50
+ Assert . AreEqual ( "h2o,location=coyote_creek water_level=9 9\n h2o,location=coyote_creek water_level=10 10" ,
51
+ request . RequestMessage . Body ) ;
52
+ }
53
+
54
+ [ Test ]
55
+ public async Task GroupPointsByPrecisionDifferent ( )
56
+ {
57
+ MockServer
58
+ . Given ( Request . Create ( ) . WithPath ( "/api/v2/write" ) . UsingPost ( ) )
59
+ . RespondWith ( CreateResponse ( "{}" ) ) ;
60
+
61
+ var writeApi = _influxDbClient . GetWriteApiAsync ( ) ;
62
+ await writeApi . WritePointsAsync ( "my-bucket" , "my-org" , new List < PointData >
63
+ {
64
+ PointData . Measurement ( "h2o" ) . Tag ( "location" , "coyote_creek" ) . Field ( "water_level" , 9.0D )
65
+ . Timestamp ( 9L , WritePrecision . S ) ,
66
+ PointData . Measurement ( "h2o" ) . Tag ( "location" , "coyote_creek" ) . Field ( "water_level" , 10.0D )
67
+ . Timestamp ( 10L , WritePrecision . Ms )
68
+ } ) ;
69
+
70
+ Assert . AreEqual ( 2 , MockServer . LogEntries . Count ( ) ) ;
71
+
72
+ var request = MockServer . LogEntries . ToList ( ) [ 0 ] ;
73
+ Assert . AreEqual ( MockServerUrl + "/api/v2/write?org=my-org&bucket=my-bucket&precision=s" ,
74
+ request . RequestMessage . AbsoluteUrl ) ;
75
+ Assert . AreEqual ( "h2o,location=coyote_creek water_level=9 9" ,
76
+ request . RequestMessage . Body ) ;
77
+
78
+ request = MockServer . LogEntries . ToList ( ) [ 1 ] ;
79
+ Assert . AreEqual ( MockServerUrl + "/api/v2/write?org=my-org&bucket=my-bucket&precision=ms" ,
80
+ request . RequestMessage . AbsoluteUrl ) ;
81
+ Assert . AreEqual ( "h2o,location=coyote_creek water_level=10 10" ,
82
+ request . RequestMessage . Body ) ;
83
+ }
84
+ }
85
+ }
0 commit comments