public async Task TestPostPointsAsync_FromObject_AutogenRetention() { try { var client = new InfluxDBClient(influxUrl, dbUName, dbpwd); var retention = new InfluxRetentionPolicy() { Name = "autogen", DBName = dbName, Duration = TimeSpan.FromMinutes(0), IsDefault = true }; var points = Enumerable.Range(0, 10).Select(i => new PointObjectWithObjectRetention { Measurement = "RetentionTest", Time = DateTime.UtcNow.AddDays(-i), Retention = retention, Precision = TimePrecision.Milliseconds, StringTag = "FromObject", IntTag = DataGen.RandomInt(), StringField = DataGen.RandomString(), DoubleField = DataGen.RandomDouble(), IntField = DataGen.RandomInt(), BoolField = i % 2 == 0, }); var r = await client.PostPointsAsync(dbName, points); Assert.IsTrue(r, "PostPointsAsync returned false"); } catch (Exception e) { Assert.Fail($"Unexpected exception of type {e.GetType()} caught: {e.Message}"); return; } }
public async Task TestPostObjectPointAsync() { try { var client = new InfluxDBClient(influxUrl, dbUName, dbpwd); var point = new PointObjectWithStringRetention { Time = DateTime.UtcNow, Measurement = measurementName, Precision = TimePrecision.Seconds, StringTag = "FromObject", IntTag = DataGen.RandomInt(), StringField = DataGen.RandomString(), DoubleField = DataGen.RandomDouble(), IntField = DataGen.RandomInt(), BoolField = true, }; var r = await client.PostPointAsync(dbName, point); Assert.IsTrue(r, "PostPointAsync returned false"); } catch (Exception e) { Assert.Fail($"Unexpected exception of type {e.GetType()} caught: {e.Message}"); return; } }
public async Task TestPostPointsAsync_PartialWrite() { var client = new InfluxDBClient(influxUrl, dbUName, dbpwd); var time = DateTime.Now; var today = DateTime.Now.ToShortDateString(); var now = DateTime.Now.ToShortTimeString(); var points = new List <IInfluxDatapoint>(); var valDouble = new InfluxDatapoint <double>(); valDouble.UtcTimestamp = DateTime.UtcNow; valDouble.Tags.Add("TestDate", today); valDouble.Tags.Add("TestTime", now); valDouble.Fields.Add("Doublefield", DataGen.RandomDouble()); valDouble.Fields.Add("Doublefield2", Double.NaN); valDouble.MeasurementName = measurementName; valDouble.Precision = TimePrecision.Seconds; points.Add(valDouble); for (int i = 0; i < 5; i++) { var valInt = new InfluxDatapoint <int>(); valInt.UtcTimestamp = DateTime.UtcNow.AddSeconds(-1 * DataGen.RandomInt(3600)); valInt.Tags.Add("TestDate", today); valInt.Tags.Add("TestTime", now); valInt.Fields.Add("Intfield", DataGen.RandomInt()); valInt.Fields.Add("Intfield2", DataGen.RandomInt()); valInt.MeasurementName = measurementName; valInt.Precision = TimePrecision.Seconds; points.Add(valInt); } valDouble = new InfluxDatapoint <double>(); valDouble.UtcTimestamp = DateTime.UtcNow; valDouble.Tags.Add("TestDate", today); valDouble.Tags.Add("TestTime", now); valDouble.Fields.Add("Doublefield", DataGen.RandomDouble()); valDouble.Fields.Add("Doublefield2", Double.NaN); valDouble.MeasurementName = measurementName; valDouble.Precision = TimePrecision.Seconds; points.Add(valDouble); var r = await AssertEx.ThrowsAsync <InfluxDBException>(() => client.PostPointsAsync(dbName, points)); }
public async Task TestPartialResponseBecauseOfMaxRowLimit() { try { var client = new InfluxDBClient(influxUrl, dbUName, dbpwd); var points = new List <IInfluxDatapoint>(); var today = DateTime.Now.ToShortDateString(); var now = DateTime.UtcNow; var nowString = DateTime.Now.ToShortTimeString(); var measurement = "Partialtest"; for (int i = 0; i < 200000; i++) { var valMixed = new InfluxDatapoint <InfluxValueField>(); valMixed.Tags.Add("TestDate", today); valMixed.Tags.Add("TestTime", nowString); valMixed.UtcTimestamp = now + TimeSpan.FromMilliseconds(i * 100); valMixed.Fields.Add("Open", new InfluxValueField(DataGen.RandomDouble())); valMixed.Fields.Add("High", new InfluxValueField(DataGen.RandomDouble())); valMixed.Fields.Add("Low", new InfluxValueField(DataGen.RandomDouble())); valMixed.Fields.Add("Close", new InfluxValueField(DataGen.RandomDouble())); valMixed.Fields.Add("Volume", new InfluxValueField(DataGen.RandomDouble())); valMixed.MeasurementName = measurement; valMixed.Precision = TimePrecision.Nanoseconds; points.Add(valMixed); } Assert.IsTrue(await client.PostPointsAsync(dbName, points, 25000), "PostPointsAsync retunred false"); var r = await client.QueryMultiSeriesAsync(dbName, "SELECT * FROM Partialtest"); Assert.IsTrue(r.All(s => s.Partial), "Not all influx series returned by the query contained the flag 'partial=true'"); r = await client.QueryMultiSeriesAsync(dbName, "SELECT * FROM Partialtest limit 50000"); Assert.IsTrue(!r.Any(s => s.Partial), "At least one of the influx series returned by the query contained the flag 'partial=true'"); } catch (Exception e) { Assert.Fail($"Unexpected exception of type {e.GetType()} caught: {e.Message}"); return; } }
public async Task TestQueryMultiSeriesAsync_ToObject() { var client = new InfluxDBClient(influxUrl, dbUName, dbpwd); var tagId = DataGen.RandomString(); var points = Enumerable.Range(0, 3).Select(i => new PointObjectWithStringRetention { Time = DateTime.UtcNow, Measurement = measurementName, Precision = TimePrecision.Nanoseconds, StringTag = tagId, IntTag = i, StringField = DataGen.RandomString(), DoubleField = DataGen.RandomDouble(), IntField = DataGen.RandomInt(), BoolField = i % 2 == 0, } ).ToList(); var postResult = await client.PostPointsAsync(dbName, points); Assert.IsTrue(postResult, "PostPointsAsync returned false"); Stopwatch s = new Stopwatch(); s.Start(); var queryResult = await client.QueryMultiSeriesAsync <PointObjectWithStringRetention>(dbName, $"SELECT * from {measurementName} WHERE StringTag='{tagId}'"); s.Stop(); Debug.WriteLine($"Elapsed {s.ElapsedMilliseconds}ms"); Assert.IsTrue(queryResult != null, "QueryMultiSeriesAsync returned null or invalid data"); Assert.IsTrue(queryResult.Count == 1, "QueryMultiSeriesAsync returned invalid number of series"); foreach (var point in points) { var matching = queryResult[0].Entries.FirstOrDefault(e => e.IntTag == point.IntTag); Assert.IsTrue(matching != null, $"Missing record corresponding to record {point.IntTag}"); Assert.IsTrue(matching.StringField == point.StringField, $"Mismatching string field on record {point.IntTag}"); Assert.IsTrue(Math.Abs(matching.DoubleField - point.DoubleField) < .0000001, $"Mismatching double field on record {point.IntTag}"); Assert.IsTrue(matching.IntField == point.IntField, $"Mismatching int field on record {point.IntTag}"); Assert.IsTrue(matching.BoolField == point.BoolField, $"Mismatching bool field on record {point.IntTag}"); } }
public async Task TestPerformance() { try { var client = new InfluxDBClient(influxUrl, dbUName, dbpwd); var points = new List <IInfluxDatapoint>(); var today = DateTime.Now.ToShortDateString(); var now = DateTime.Now.ToShortTimeString(); var start = DateTime.Now.AddDays(-5); var end = DateTime.Now; var measurement = "Perftest"; for (int i = 0; i < 1000000; i++) { var valMixed = new InfluxDatapoint <InfluxValueField>(); valMixed.Tags.Add("TestDate", today); valMixed.Tags.Add("TestTime", now); valMixed.UtcTimestamp = DateTime.UtcNow; valMixed.Fields.Add("Open", new InfluxValueField(DataGen.RandomDouble())); valMixed.Fields.Add("High", new InfluxValueField(DataGen.RandomDouble())); valMixed.Fields.Add("Low", new InfluxValueField(DataGen.RandomDouble())); valMixed.Fields.Add("Close", new InfluxValueField(DataGen.RandomDouble())); valMixed.Fields.Add("Volume", new InfluxValueField(DataGen.RandomDouble())); valMixed.MeasurementName = measurement; valMixed.Precision = TimePrecision.Nanoseconds; points.Add(valMixed); } Stopwatch s = new Stopwatch(); s.Start(); var r = await client.PostPointsAsync(dbName, points, 10000); s.Stop(); Debug.WriteLine($"Elapsed{s.ElapsedMilliseconds}"); Assert.IsTrue(points.TrueForAll(p => p.Saved == true), "PostPointsAsync did not save all points"); Assert.IsTrue(s.Elapsed.TotalSeconds < 120, "PostPointsAsync took more than 120 sec"); } catch (Exception e) { Assert.Fail($"Unexpected exception of type {e.GetType()} caught: {e.Message}"); return; } }
public async Task TestPostPointAsync_InvalidReq() { var client = new InfluxDBClient(influxUrl, dbUName, dbpwd); var time = DateTime.Now; var today = DateTime.Now.ToShortDateString(); var now = DateTime.Now.ToShortTimeString(); var valDouble = new InfluxDatapoint <double>(); valDouble.UtcTimestamp = DateTime.UtcNow; valDouble.Tags.Add("TestDate", today); valDouble.Tags.Add("TestTime", now); valDouble.Fields.Add("Doublefield", DataGen.RandomDouble()); valDouble.Fields.Add("Doublefield2", Double.NaN); valDouble.MeasurementName = measurementName; valDouble.Precision = TimePrecision.Seconds; var r = await AssertEx.ThrowsAsync <InfluxDBException>(() => client.PostPointAsync(dbName, valDouble)); }
public async Task TestPostPointsAsync_Batch() { try { var client = new InfluxDBClient(influxUrl, dbUName, dbpwd); var points = new List <IInfluxDatapoint>(); var today = DateTime.Now.ToShortDateString(); var now = DateTime.Now.ToShortTimeString(); var start = DateTime.Now.AddDays(-5); var end = DateTime.Now; for (int i = 0; i < 5000; i++) { var valMixed = new InfluxDatapoint <InfluxValueField>(); valMixed.UtcTimestamp = DataGen.RandomDate(start, end); valMixed.Tags.Add("TestDate", today); valMixed.Tags.Add("TestTime", now); valMixed.UtcTimestamp = DateTime.UtcNow; valMixed.Fields.Add("Doublefield", new InfluxValueField(DataGen.RandomDouble())); valMixed.Fields.Add("Stringfield", new InfluxValueField(DataGen.RandomString())); valMixed.Fields.Add("Boolfield", new InfluxValueField(DateTime.Now.Ticks % 2 == 0)); valMixed.Fields.Add("Int Field", new InfluxValueField(DataGen.RandomInt())); valMixed.MeasurementName = measurementName; valMixed.Precision = (TimePrecision)(DataGen.RandomInt() % 6) + 1; points.Add(valMixed); } var r = await client.PostPointsAsync(dbName, points); Assert.IsTrue(points.TrueForAll(p => p.Saved == true), "PostPointsAsync did not save all points"); } catch (Exception e) { Assert.Fail($"Unexpected exception of type {e.GetType()} caught: {e.Message}"); return; } }
public async Task TestPostPointsAsync() { try { var client = new InfluxDBClient(influxUrl, dbUName, dbpwd); var time = DateTime.Now; var today = DateTime.Now.ToShortDateString(); var now = DateTime.Now.ToShortTimeString(); var points = new List <IInfluxDatapoint>(); var valDouble = new InfluxDatapoint <double>(); valDouble.UtcTimestamp = DateTime.UtcNow; valDouble.Tags.Add("TestDate", today); valDouble.Tags.Add("TestTime", now); valDouble.Fields.Add("Doublefield", DataGen.RandomDouble()); valDouble.Fields.Add("Doublefield2", DataGen.RandomDouble()); valDouble.MeasurementName = measurementName; valDouble.Precision = TimePrecision.Nanoseconds; points.Add(valDouble); valDouble = new InfluxDatapoint <double>(); valDouble.UtcTimestamp = DateTime.UtcNow; valDouble.Tags.Add("TestDate", today); valDouble.Tags.Add("TestTime", now); valDouble.Fields.Add("Doublefield", DataGen.RandomDouble()); valDouble.Fields.Add("Doublefield2", DataGen.RandomDouble()); valDouble.MeasurementName = measurementName; valDouble.Precision = TimePrecision.Microseconds; points.Add(valDouble); var valInt = new InfluxDatapoint <int>(); valInt.UtcTimestamp = DateTime.UtcNow; valInt.Tags.Add("TestDate", today); valInt.Tags.Add("TestTime", now); valInt.Fields.Add("Intfield", DataGen.RandomInt()); valInt.Fields.Add("Intfield2", DataGen.RandomInt()); valInt.MeasurementName = measurementName; valInt.Precision = TimePrecision.Milliseconds; points.Add(valInt); valInt = new InfluxDatapoint <int>(); valInt.UtcTimestamp = DateTime.UtcNow; valInt.Tags.Add("TestDate", today); valInt.Tags.Add("TestTime", now); valInt.Fields.Add("Intfield", DataGen.RandomInt()); valInt.Fields.Add("Intfield2", DataGen.RandomInt()); valInt.MeasurementName = measurementName; valInt.Precision = TimePrecision.Seconds; points.Add(valInt); var valBool = new InfluxDatapoint <bool>(); valBool.UtcTimestamp = DateTime.UtcNow; valBool.Tags.Add("TestDate", today); valBool.Tags.Add("TestTime", now); valBool.Fields.Add("Booleanfield", time.Ticks % 2 == 0); valBool.MeasurementName = measurementName; valBool.Precision = TimePrecision.Minutes; points.Add(valBool); var valString = new InfluxDatapoint <string>(); valString.UtcTimestamp = DateTime.UtcNow; valString.Tags.Add("TestDate", today); valString.Tags.Add("TestTime", now); valString.Fields.Add("Stringfield", DataGen.RandomString()); valString.MeasurementName = measurementName; valString.Precision = TimePrecision.Hours; points.Add(valString); var r = await client.PostPointsAsync(dbName, points); Assert.IsTrue(r, "PostPointsAsync retunred false"); } catch (Exception e) { Assert.Fail($"Unexpected exception of type {e.GetType()} caught: {e.Message}"); return; } }