1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Diagnostics ;
4
+ using System . Linq ;
5
+ using System . Threading . Tasks ;
6
+ using InfluxDB . Client . Core ;
7
+ using InfluxDB . Client . Core . Flux . Domain ;
8
+ using InfluxDB . Client . Core . Test ;
9
+ using NUnit . Framework ;
10
+ using WireMock . RequestBuilders ;
11
+
12
+ namespace InfluxDB . Client . Test
13
+ {
14
+ [ TestFixture ]
15
+ public class QueryApiTest : AbstractMockServerTest
16
+ {
17
+ private InfluxDBClient _influxDbClient ;
18
+ private QueryApi _queryApi ;
19
+
20
+ private const string Data =
21
+ "#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,string,string,string,string,double\n "
22
+ + "#group,false,false,false,false,false,false,false,false,false,false\n "
23
+ + "#default,_result,,,,,,,,,\n "
24
+ + ",result,table,_start,_stop,_time,id,_field,_measurement,host,_value\n "
25
+ + ",,0,1970-01-01T00:00:10Z,1970-01-01T00:00:20Z,1970-01-01T00:00:10Z,ab,free,mem,A,12.25\n "
26
+ + ",,0,1970-01-01T00:00:10Z,1970-01-01T00:00:20Z,1970-01-01T00:00:10Z,cd,free,mem,A,13.00\n " ;
27
+
28
+ [ SetUp ]
29
+ public new void SetUp ( )
30
+ {
31
+ var options = InfluxDBClientOptions . Builder
32
+ . CreateNew ( )
33
+ . Url ( MockServerUrl )
34
+ . AuthenticateToken ( "token" )
35
+ . Org ( "my-org" )
36
+ . Build ( ) ;
37
+
38
+ _influxDbClient = InfluxDBClientFactory . Create ( options ) ;
39
+ _influxDbClient . SetLogLevel ( LogLevel . Body ) ;
40
+ _queryApi = _influxDbClient . GetQueryApi ( ) ;
41
+ }
42
+
43
+ [ Test ]
44
+ public async Task ParallelRequest ( )
45
+ {
46
+ MockServer
47
+ . Given ( Request . Create ( ) . WithPath ( "/api/v2/query" ) . UsingPost ( ) )
48
+ . RespondWith ( CreateResponse ( Data ) ) ;
49
+
50
+ var stopWatch = new Stopwatch ( ) ;
51
+ stopWatch . Start ( ) ;
52
+
53
+ var tasks = new List < Task < List < FluxTable > > > ( ) ;
54
+ foreach ( var _ in Enumerable . Range ( 0 , 100 ) )
55
+ {
56
+ tasks . Add ( _queryApi . QueryAsync ( "from(bucket:\" my-bucket\" ) |> range(start: 0)" , "my-org" ) ) ;
57
+ }
58
+ await Task . WhenAll ( tasks ) ;
59
+
60
+ var ts = stopWatch . Elapsed ;
61
+ Assert . LessOrEqual ( ts . TotalSeconds , 10 , $ "Elapsed time: { ts } ") ;
62
+ }
63
+ }
64
+ }
0 commit comments