|
@@ -1,6 +1,9 @@
|
|
using System;
|
|
using System;
|
|
using System.Net.Http;
|
|
using System.Net.Http;
|
|
using System.Threading;
|
|
using System.Threading;
|
|
|
|
+using DotNet.Testcontainers.Containers.Builders;
|
|
|
|
+using DotNet.Testcontainers.Containers.Modules;
|
|
|
|
+using DotNet.Testcontainers.Containers.WaitStrategies;
|
|
using Xunit;
|
|
using Xunit;
|
|
|
|
|
|
namespace OhmGraphite.Test
|
|
namespace OhmGraphite.Test
|
|
@@ -10,32 +13,41 @@ namespace OhmGraphite.Test
|
|
[Fact, Trait("Category", "integration")]
|
|
[Fact, Trait("Category", "integration")]
|
|
public async void CanInsertIntoInflux()
|
|
public async void CanInsertIntoInflux()
|
|
{
|
|
{
|
|
- var config = new InfluxConfig(new Uri("http://influx:8086"), "mydb", "my_user", "my_pass");
|
|
|
|
- using (var writer = new InfluxWriter(config, "my-pc"))
|
|
|
|
- using (var client = new HttpClient())
|
|
|
|
|
|
+ var testContainersBuilder = new TestcontainersBuilder<TestcontainersContainer>()
|
|
|
|
+ .WithImage("influxdb:1.8-alpine")
|
|
|
|
+ .WithEnvironment("INFLUXDB_DB", "mydb")
|
|
|
|
+ .WithEnvironment("INFLUXDB_USER", "my_user")
|
|
|
|
+ .WithEnvironment("INFLUXDB_USER_PASSWORD", "my_pass")
|
|
|
|
+ .WithPortBinding(8086, assignRandomHostPort: true)
|
|
|
|
+ .WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(8086));
|
|
|
|
+
|
|
|
|
+ await using var container = testContainersBuilder.Build();
|
|
|
|
+ await container.StartAsync();
|
|
|
|
+ var baseUrl = $"http://{container.Hostname}:{container.GetMappedPublicPort(8086)}";
|
|
|
|
+ var config = new InfluxConfig(new Uri(baseUrl), "mydb", "my_user", "my_pass");
|
|
|
|
+ using var writer = new InfluxWriter(config, "my-pc");
|
|
|
|
+ using var client = new HttpClient();
|
|
|
|
+ for (int attempts = 0; ; attempts++)
|
|
{
|
|
{
|
|
- for (int attempts = 0; ; attempts++)
|
|
|
|
|
|
+ try
|
|
{
|
|
{
|
|
- try
|
|
|
|
- {
|
|
|
|
- await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values());
|
|
|
|
|
|
+ await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values());
|
|
|
|
|
|
- var resp = await client.GetAsync(
|
|
|
|
- "http://influx:8086/query?pretty=true&db=mydb&q=SELECT%20*%20FROM%20Temperature");
|
|
|
|
- Assert.True(resp.IsSuccessStatusCode);
|
|
|
|
- var content = await resp.Content.ReadAsStringAsync();
|
|
|
|
- Assert.Contains("/intelcpu/0/temperature/0", content);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- catch (Exception)
|
|
|
|
|
|
+ var resp = await client.GetAsync(
|
|
|
|
+ $"{baseUrl}/query?pretty=true&db=mydb&q=SELECT%20*%20FROM%20Temperature");
|
|
|
|
+ Assert.True(resp.IsSuccessStatusCode);
|
|
|
|
+ var content = await resp.Content.ReadAsStringAsync();
|
|
|
|
+ Assert.Contains("/intelcpu/0/temperature/0", content);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ catch (Exception)
|
|
|
|
+ {
|
|
|
|
+ if (attempts >= 10)
|
|
{
|
|
{
|
|
- if (attempts >= 10)
|
|
|
|
- {
|
|
|
|
- throw;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Thread.Sleep(TimeSpan.FromSeconds(1));
|
|
|
|
|
|
+ throw;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ Thread.Sleep(TimeSpan.FromSeconds(1));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -43,35 +55,76 @@ namespace OhmGraphite.Test
|
|
[Fact, Trait("Category", "integration")]
|
|
[Fact, Trait("Category", "integration")]
|
|
public async void CanInsertIntoPasswordLessInfluxdb()
|
|
public async void CanInsertIntoPasswordLessInfluxdb()
|
|
{
|
|
{
|
|
- var config = new InfluxConfig(new Uri("http://influx-passwordless:8086"), "mydb", "my_user", null);
|
|
|
|
- using (var writer = new InfluxWriter(config, "my-pc"))
|
|
|
|
- using (var client = new HttpClient())
|
|
|
|
|
|
+ var testContainersBuilder = new TestcontainersBuilder<TestcontainersContainer>()
|
|
|
|
+ .WithImage("influxdb:1.8-alpine")
|
|
|
|
+ .WithEnvironment("INFLUXDB_DB", "mydb")
|
|
|
|
+ .WithEnvironment("INFLUXDB_USER", "my_user")
|
|
|
|
+ .WithEnvironment("INFLUXDB_HTTP_AUTH_ENABLED", "false")
|
|
|
|
+ .WithPortBinding(8086, assignRandomHostPort: true)
|
|
|
|
+ .WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(8086));
|
|
|
|
+
|
|
|
|
+ await using var container = testContainersBuilder.Build();
|
|
|
|
+ await container.StartAsync();
|
|
|
|
+ var baseUrl = $"http://{container.Hostname}:{container.GetMappedPublicPort(8086)}";
|
|
|
|
+ var config = new InfluxConfig(new Uri(baseUrl), "mydb", "my_user", null);
|
|
|
|
+ using var writer = new InfluxWriter(config, "my-pc");
|
|
|
|
+ using var client = new HttpClient();
|
|
|
|
+ for (int attempts = 0; ; attempts++)
|
|
{
|
|
{
|
|
- for (int attempts = 0; ; attempts++)
|
|
|
|
|
|
+ try
|
|
{
|
|
{
|
|
- try
|
|
|
|
- {
|
|
|
|
- await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values());
|
|
|
|
|
|
+ await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values());
|
|
|
|
|
|
- var resp = await client.GetAsync(
|
|
|
|
- "http://influx-passwordless:8086/query?pretty=true&db=mydb&q=SELECT%20*%20FROM%20Temperature");
|
|
|
|
- Assert.True(resp.IsSuccessStatusCode);
|
|
|
|
- var content = await resp.Content.ReadAsStringAsync();
|
|
|
|
- Assert.Contains("/intelcpu/0/temperature/0", content);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- catch (Exception)
|
|
|
|
|
|
+ var resp = await client.GetAsync(
|
|
|
|
+ $"{baseUrl}/query?pretty=true&db=mydb&q=SELECT%20*%20FROM%20Temperature");
|
|
|
|
+ Assert.True(resp.IsSuccessStatusCode);
|
|
|
|
+ var content = await resp.Content.ReadAsStringAsync();
|
|
|
|
+ Assert.Contains("/intelcpu/0/temperature/0", content);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ catch (Exception)
|
|
|
|
+ {
|
|
|
|
+ if (attempts >= 10)
|
|
{
|
|
{
|
|
- if (attempts >= 10)
|
|
|
|
- {
|
|
|
|
- throw;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Thread.Sleep(TimeSpan.FromSeconds(1));
|
|
|
|
|
|
+ throw;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ Thread.Sleep(TimeSpan.FromSeconds(1));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //[Fact, Trait("Category", "integration")]
|
|
|
|
+ //public async void CanInsertIntoInflux2()
|
|
|
|
+ //{
|
|
|
|
+ // var config = new InfluxConfig(new Uri("http://influx2:8086"), "mydb", "my_user", "my_pass");
|
|
|
|
+ // using (var writer = new InfluxWriter(config, "my-pc"))
|
|
|
|
+ // using (var client = new HttpClient())
|
|
|
|
+ // {
|
|
|
|
+ // for (int attempts = 0; ; attempts++)
|
|
|
|
+ // {
|
|
|
|
+ // try
|
|
|
|
+ // {
|
|
|
|
+ // await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values());
|
|
|
|
+
|
|
|
|
+ // var resp = await client.GetAsync(
|
|
|
|
+ // "http://influx2:8086/query?pretty=true&db=mydb&q=SELECT%20*%20FROM%20Temperature");
|
|
|
|
+ // Assert.True(resp.IsSuccessStatusCode);
|
|
|
|
+ // var content = await resp.Content.ReadAsStringAsync();
|
|
|
|
+ // Assert.Contains("/intelcpu/0/temperature/0", content);
|
|
|
|
+ // break;
|
|
|
|
+ // }
|
|
|
|
+ // catch (Exception)
|
|
|
|
+ // {
|
|
|
|
+ // if (attempts >= 10)
|
|
|
|
+ // {
|
|
|
|
+ // throw;
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // Thread.Sleep(TimeSpan.FromSeconds(1));
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
}
|
|
}
|
|
}
|
|
}
|