public async Task FlushByOne()
        {
            var bucketName = _bucket.Name;

            var writeOptions = WriteOptions.CreateNew().BatchSize(1).FlushInterval(500_000).Build();

            _writeApi = Client.GetWriteApi(writeOptions);

            var eventListener = new WriteApiTest.EventListener(_writeApi);

            const string record1 = "h2o_feet,location=coyote_creek level\\ water_level=1.0 1";
            const string record2 = "h2o_feet,location=coyote_creek level\\ water_level=2.0 2";
            const string record3 = "h2o_feet,location=coyote_creek level\\ water_level=3.0 3";
            const string record4 = "h2o_feet,location=coyote_creek level\\ water_level=4.0 4";
            const string record5 = "h2o_feet,location=coyote_creek level\\ water_level=5.0 5";

            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record1);
            Thread.Sleep(100);
            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record2);
            Thread.Sleep(100);
            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record3);
            Thread.Sleep(100);
            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record4);
            Thread.Sleep(100);
            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record5);
            Thread.Sleep(100);

            Assert.AreEqual(record1, eventListener.Get <WriteSuccessEvent>().LineProtocol);
            Assert.AreEqual(record2, eventListener.Get <WriteSuccessEvent>().LineProtocol);
            Assert.AreEqual(record3, eventListener.Get <WriteSuccessEvent>().LineProtocol);
            Assert.AreEqual(record4, eventListener.Get <WriteSuccessEvent>().LineProtocol);
            Assert.AreEqual(record5, eventListener.Get <WriteSuccessEvent>().LineProtocol);

            var query = await _queryApi.Query(
                "from(bucket:\"" + bucketName + "\") |> range(start: 1970-01-01T00:00:00.000000000Z)",
                _organization.Id);

            Assert.AreEqual(1, query.Count);

            var records = query[0].Records;

            Assert.AreEqual(5, records.Count);
            Assert.AreEqual(0, eventListener.EventCount());
        }
예제 #2
0
        public async Task PartialWrite()
        {
            var bucketName = _bucket.Name;

            _writeApi = Client.GetWriteApi(WriteOptions.CreateNew().BatchSize(2).Build());

            const string records = "h2o_feet,location=coyote_creek level\\ water_level=1.0 1\n" +
                                   "h2o_feet,location=coyote_hill level\\ water_level=2.0 2x";

            _writeApi.WriteRecords(bucketName, _organization.Id, WritePrecision.Ns, records);
            _writeApi.Flush();
            _writeApi.Dispose();

            var query = await _queryApi.QueryAsync(
                $"from(bucket:\"{bucketName}\") |> range(start: 1970-01-01T00:00:00.000000001Z) |> last()",
                _organization.Id);

            Assert.AreEqual(0, query.Count);
        }
예제 #3
0
        public async Task FlushByCount()
        {
            var bucketName = _bucket.Name;

            var writeOptions = WriteOptions.CreateNew().BatchSize(6).FlushInterval(500_000).Build();

            _writeApi = Client.GetWriteApi(writeOptions);

            var listener = new WriteApiTest.EventListener(_writeApi);

            const string record1 = "h2o_feet,location=coyote_creek level\\ water_level=1.0 1";
            const string record2 = "h2o_feet,location=coyote_creek level\\ water_level=2.0 2";
            const string record3 = "h2o_feet,location=coyote_creek level\\ water_level=3.0 3";
            const string record4 = "h2o_feet,location=coyote_creek level\\ water_level=4.0 4";
            const string record5 = "h2o_feet,location=coyote_creek level\\ water_level=5.0 5";
            const string record6 = "h2o_feet,location=coyote_creek level\\ water_level=6.0 6";

            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record1);
            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record2);
            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record3);
            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record4);
            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record5);

            var query = await _queryApi.QueryAsync(
                $"from(bucket:\"{bucketName}\") |> range(start: 1970-01-01T00:00:00.000000001Z)",
                _organization.Id);

            Assert.AreEqual(0, query.Count);

            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record6);

            listener.Get <WriteSuccessEvent>();

            query = await _queryApi.QueryAsync(
                $"from(bucket:\"{bucketName}\") |> range(start: 1970-01-01T00:00:00.000000001Z)",
                _organization.Id);

            Assert.AreEqual(1, query.Count);

            var records = query[0].Records;

            Assert.AreEqual(6, records.Count);
        }
예제 #4
0
        public void RetryOnNetworkError()
        {
            MockServer.Stop();
            _writeApi.Dispose();

            var options = WriteOptions.CreateNew()
                          .BatchSize(1)
                          .MaxRetryDelay(2_000)
                          .MaxRetries(3)
                          .Build();

            _writeApi = _influxDbClient.GetWriteApi(options);

            var listener = new EventListener(_writeApi);

            _writeApi.WriteRecord("b1", "org1", WritePrecision.Ns,
                                  "h2o_feet,location=coyote_creek level\\ description=\"feet 1\",water_level=1.0 1");

            // Three attempts
            listener.Get <WriteRetriableErrorEvent>();
            listener.Get <WriteRetriableErrorEvent>();
            listener.Get <WriteRetriableErrorEvent>();
        }
        public void MaxRetries()
        {
            var options = WriteOptions.CreateNew().MaxRetries(5).Build();

            var retry = new RetryAttempt(new HttpException("", 429), 1, _default);

            Assert.IsTrue(retry.IsRetry());

            retry = new RetryAttempt(new HttpException("", 429), 2, options);
            Assert.IsTrue(retry.IsRetry());

            retry = new RetryAttempt(new HttpException("", 429), 3, options);
            Assert.IsTrue(retry.IsRetry());

            retry = new RetryAttempt(new HttpException("", 429), 4, options);
            Assert.IsTrue(retry.IsRetry());

            retry = new RetryAttempt(new HttpException("", 429), 5, options);
            Assert.IsTrue(retry.IsRetry());

            retry = new RetryAttempt(new HttpException("", 429), 6, options);
            Assert.IsFalse(retry.IsRetry());
        }
예제 #6
0
        public static async Task Example(InfluxDBClient influxDB)
        {
            var organizationClient = influxDB.GetOrganizationsApi();

            var medicalGMBH = await organizationClient
                              .CreateOrganization("Medical Corp " +
                                                  DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff",
                                                                           CultureInfo.InvariantCulture));


            //
            // Create New Bucket with retention 1h
            //
            var temperatureBucket = await influxDB.GetBucketsApi().CreateBucket("temperature-sensors", medicalGMBH.Id);

            //
            // Add Permissions to read and write to the Bucket
            //
            var resource = new PermissionResource
            {
                Type = PermissionResource.TypeEnum.Buckets, OrgID = medicalGMBH.Id, Id = temperatureBucket.Id
            };
            var readBucket = new Permission
            {
                Resource = resource,
                Action   = Permission.ActionEnum.Read
            };

            var writeBucket = new Permission
            {
                Resource = resource,
                Action   = Permission.ActionEnum.Write
            };

            var authorization = await influxDB.GetAuthorizationsApi()
                                .CreateAuthorization(medicalGMBH, new List <Permission> {
                readBucket, writeBucket
            });

            Console.WriteLine($"The token to write to temperature-sensors bucket is: {authorization.Token}");

            influxDB.Dispose();

            //
            // Create new client with specified authorization token
            //

            influxDB = InfluxDBClientFactory.Create("http://localhost:9999", authorization.Token.ToCharArray());

            var writeOptions = WriteOptions
                               .CreateNew()
                               .BatchSize(5000)
                               .FlushInterval(1000)
                               .JitterInterval(1000)
                               .RetryInterval(5000)
                               .Build();

            //
            // Write data
            //
            using (var writeClient = influxDB.GetWriteApi(writeOptions))
            {
                //
                // Write by POCO
                //
                var temperature = new Temperature {
                    Location = "south", Value = 62D, Time = DateTime.UtcNow
                };
                writeClient.WriteMeasurement("temperature-sensors", medicalGMBH.Id, WritePrecision.Ns, temperature);

                //
                // Write by Point
                //
                var point = Point.Measurement("temperature")
                            .Tag("location", "west")
                            .Field("value", 55D)
                            .Timestamp(DateTime.UtcNow.AddSeconds(-10), WritePrecision.Ns);
                writeClient.WritePoint("temperature-sensors", medicalGMBH.Id, point);

                //
                // Write by LineProtocol
                //
                var record = "temperature,location=north value=60.0";
                writeClient.WriteRecord("temperature-sensors", medicalGMBH.Id, WritePrecision.Ns, record);

                writeClient.Flush();
                Thread.Sleep(2000);
            }

            //
            // Read data
            //
            var fluxTables = await influxDB.GetQueryApi().Query("from(bucket:\"temperature-sensors\") |> range(start: 0)", medicalGMBH.Id);

            fluxTables.ForEach(fluxTable =>
            {
                var fluxRecords = fluxTable.Records;
                fluxRecords.ForEach(fluxRecord =>
                {
                    Console.WriteLine($"{fluxRecord.GetTime()}: {fluxRecord.GetValue()}");
                });
            });


            influxDB.Dispose();
        }
예제 #7
0
 public new void SetUp()
 {
     _influxDbClient = InfluxDBClientFactory.Create(MockServerUrl, "token");
     _writeApi       = _influxDbClient.GetWriteApi(WriteOptions.CreateNew().RetryInterval(1_000).Build());
 }