public async Task WriteMeasurementsWithoutFields() { _writeApi = Client.GetWriteApi(); var listener = new WriteApiTest.EventListener(_writeApi); var bucketName = _bucket.Name; var time = DateTime.UtcNow; var measurement1 = new H20Measurement { Location = "coyote_creek", Level = 2.927, Time = time.Add(-TimeSpan.FromSeconds(30)) }; var measurement2 = new H20Measurement { Location = "coyote_creek", Level = null, Time = time }; _writeApi.WriteMeasurements(bucketName, _organization.Id, WritePrecision.S, measurement1, measurement2); _writeApi.Flush(); listener.WaitToSuccess(); var measurements = await _queryApi.QueryAsync <H20Measurement>( $"from(bucket:\"{bucketName}\") |> range(start: 0) |> rename(columns:{{_value: \"level\"}})", _organization.Id); Assert.AreEqual(1, measurements.Count); Assert.AreEqual(2.927, measurements[0].Level); Assert.AreEqual("coyote_creek", measurements[0].Location); Assert.AreEqual(time.AddTicks(-(time.Ticks % TimeSpan.TicksPerSecond)).Add(-TimeSpan.FromSeconds(30)), measurements[0].Time); }
public async Task WriteMeasurements() { _writeApi = Client.GetWriteApi(); var bucketName = _bucket.Name; var time = DateTime.UtcNow.Add(-TimeSpan.FromSeconds(10)); var measurement1 = new H20Measurement { Location = "coyote_creek", Level = 2.927, Time = time.Add(-TimeSpan.FromSeconds(30)) }; var measurement2 = new H20Measurement { Location = "coyote_creek", Level = 1.927, Time = time }; _writeApi.WriteMeasurements(bucketName, _organization.Id, WritePrecision.S, measurement1, measurement2); _writeApi.Dispose(); var measurements = await _queryApi.QueryAsync <H20Measurement>( $"from(bucket:\"{bucketName}\") |> range(start: 1970-01-01T00:00:00.000000001Z) |> rename(columns:{{_value: \"level\"}})", _organization.Id); Assert.AreEqual(2, measurements.Count); Assert.AreEqual(2.927, measurements[0].Level); Assert.AreEqual("coyote_creek", measurements[0].Location); Assert.AreEqual(time.AddTicks(-(time.Ticks % TimeSpan.TicksPerSecond)).Add(-TimeSpan.FromSeconds(30)), measurements[0].Time); Assert.AreEqual(1.927, measurements[1].Level); Assert.AreEqual("coyote_creek", measurements[1].Location); Assert.AreEqual(time.AddTicks(-(time.Ticks % TimeSpan.TicksPerSecond)), measurements[1].Time); }
public async Task WriteTooManyData() { _writeApi?.Dispose(); const int count = 500_000; const int batchSize = 50_000; var measurements = new List <H20Measurement>(); for (var i = 0; i < count; i++) { measurements.Add(new H20Measurement { Level = i, Time = DateTime.UnixEpoch.Add(TimeSpan.FromSeconds(i)), Location = "Europe" }); } var successEvents = new List <WriteSuccessEvent>(); _writeApi = Client.GetWriteApi(WriteOptions.CreateNew().BatchSize(batchSize).FlushInterval(10_000).Build()); _writeApi.EventHandler += (sender, args) => { successEvents.Add(args as WriteSuccessEvent); }; var start = 0; for (;;) { var history = measurements.Skip(start).Take(batchSize).ToArray(); if (history.Length == 0) { break; } if (start != 0) { Trace.WriteLine("Delaying..."); await Task.Delay(100); } start += batchSize; Trace.WriteLine( $"Add measurement to buffer From: {history.First().Time}, To: {history.Last().Time}. Remaining {count - start}"); _writeApi.WriteMeasurements(_bucket.Name, _organization.Name, WritePrecision.S, history); } Trace.WriteLine("Flushing data..."); Client.Dispose(); Trace.WriteLine("Finished"); Assert.AreEqual(10, successEvents.Count); foreach (var successEvent in successEvents) { Assert.AreEqual(50_000, successEvent.LineProtocol.Split("\n").Length); } }