public async Task QueryToPoco() { MockServer.Given(Request.Create().WithPath("/api/v2/query").UsingPost()) .RespondWith(CreateResponse()); var result = await FluxClient.QueryAsync <Free>("from(bucket:\"telegraf\")"); Assert.That(result.Count == 4); // 1 Assert.AreEqual("A", result[0].Host); Assert.AreEqual("west", result[0].Region); Assert.AreEqual(10L, result[0].Mem); // 2 Assert.AreEqual("B", result[1].Host); Assert.AreEqual("west", result[1].Region); Assert.AreEqual(20L, result[1].Mem); // 3 Assert.AreEqual("A", result[2].Host); Assert.AreEqual("west", result[2].Region); Assert.AreEqual(11L, result[2].Mem); // 4 Assert.AreEqual("B", result[3].Host); Assert.AreEqual("west", result[3].Region); Assert.AreEqual(22L, result[3].Mem); }
public async Task Query() { MockServer.Given(Request.Create().WithPath("/api/v2/query").UsingPost()) .RespondWith(CreateResponse()); var result = await FluxClient.QueryAsync("from(bucket:\"telegraf\")"); AssertSuccessResult(result); }
public async Task QueryCallbackError() { MockServer.Given(Request.Create().WithPath("/api/v2/query").UsingPost()) .RespondWith(CreateErrorResponse("Flux query is not valid")); await FluxClient.QueryAsync("from(bucket:\"telegraf\")", (cancellable, result) => Assert.Fail("Unreachable"), error => CountdownEvent.Signal()); WaitToCallback(); }
public async Task UserAgentHeader() { MockServer.Given(Request.Create().WithPath("/api/v2/query").UsingPost()) .RespondWith(CreateResponse()); await FluxClient.QueryAsync("from(bucket:\"telegraf\")"); var request = MockServer.LogEntries.Last(); StringAssert.StartsWith("influxdb-client-csharp/1.", request.RequestMessage.Headers["User-Agent"].First()); StringAssert.EndsWith(".0.0", request.RequestMessage.Headers["User-Agent"].First()); }
public async Task WithAuthentication() { FluxClient = FluxClientFactory.Create(new FluxConnectionOptions(MockServerUrl, "my-user", "my-password".ToCharArray())); MockServer.Given(Request.Create() .WithPath("/api/v2/query") .WithParam("u", new ExactMatcher("my-user")) .WithParam("p", new ExactMatcher("my-password")) .UsingPost()) .RespondWith(CreateResponse()); var result = await FluxClient.QueryAsync("from(bucket:\"telegraf\")"); AssertSuccessResult(result); }
public async Task ChunkedOneTable() { await PrepareChunkRecords(); var flux = FromFluxDatabase + "\n" + "\t|> filter(fn: (r) => r[\"_measurement\"] == \"chunked\")\n" + "\t|> range(start: 1970-01-01T00:00:00.000000000Z)"; await FluxClient.QueryAsync(flux, (cancellable, fluxRecord) => { // +1 record CountdownEvent.Signal(); if (CountdownEvent.CurrentCount % 100_000 == 0) { Trace.WriteLine($"Remaining parsed: {CountdownEvent.CurrentCount} records"); } });
public async Task WithBasicAuthentication() { FluxClient = FluxClientFactory.Create(new FluxConnectionOptions(MockServerUrl, "my-user", "my-password".ToCharArray(), FluxConnectionOptions.AuthenticationType.BasicAuthentication)); var auth = System.Text.Encoding.UTF8.GetBytes("my-user:my-password"); MockServer.Given(Request.Create() .WithPath("/api/v2/query") .WithHeader("Authorization", new ExactMatcher("Basic " + Convert.ToBase64String(auth))) .UsingPost()) .RespondWith(CreateResponse()); var result = await FluxClient.QueryAsync("from(bucket:\"telegraf\")"); AssertSuccessResult(result); }
public async Task QueryCallback() { CountdownEvent = new CountdownEvent(4); MockServer.Given(Request.Create().WithPath("/api/v2/query").UsingPost()) .RespondWith(CreateResponse()); var records = new List <FluxRecord>(); await FluxClient.QueryAsync("from(bucket:\"telegraf\")", (cancellable, result) => { records.Add(result); CountdownEvent.Signal(); }); WaitToCallback(); AssertRecords(records); }
public async Task QueryErrorSuccessResponseWithoutReference() { var error = "#datatype,string,string\n" + "#group,true,true\n" + "#default,,\n" + ",error,reference\n" + ",failed to create physical plan: invalid time bounds from procedure from: bounds contain zero time,"; MockServer.Given(Request.Create().WithPath("/api/v2/query").UsingPost()) .RespondWith(CreateResponse(error)); try { await FluxClient.QueryAsync("from(bucket:\"telegraf\")"); Assert.Fail(); } catch (InfluxException e) { Assert.That(e.Message.Equals("failed to create physical plan: invalid time bounds from procedure from: bounds contain zero time")); } }
public async Task ErrorAsStream() { var response = Response.Create() .WithStatusCode(403) .WithBody("Flux query service disabled. Verify flux-enabled=true in the [http] section of the InfluxDB config."); MockServer.Given(Request.Create().WithPath("/api/v2/query").UsingPost()) .RespondWith(response); try { await FluxClient.QueryAsync("from(bucket:\"telegraf\")"); Assert.Fail(); } catch (InfluxException e) { Assert.AreEqual(e.Status, 403); Assert.AreEqual(e.Message, "Flux query service disabled. Verify flux-enabled=true in the [http] section of the InfluxDB config."); } }