Beispiel #1
0
        private void AssertEqual(string expected, Action <LineProtocolWriter> write)
        {
            var writer = new LineProtocolWriter();

            write(writer);

            Assert.Equal(expected, writer.ToString());
        }
        public void Can_define_resolution_strategy_when_creating_the_writer()
        {
            var writer = new LineProtocolWriter(Precision.Seconds, PrecisionResolutionStrategy.Round);

            writer.Measurement("foo").Field("bar", true).Timestamp(TimeSpan.FromMilliseconds(499));
            writer.Measurement("foo").Field("bar", true).Timestamp(TimeSpan.FromMilliseconds(500));

            Assert.Equal("foo bar=t 0\nfoo bar=t 1", writer.ToString());
        }
        public void Can_round_if_wrong_precision_used(Precision precision)
        {
            var writer = new LineProtocolWriter(precision);

            writer.Measurement("foo").Field("bar", true).Timestamp(TimeSpan.FromTicks(1), PrecisionResolutionStrategy.Round);
            writer.Measurement("foo").Field("bar", true).Timestamp(TimeSpan.FromTicks(((long)precision / 100) - 1), PrecisionResolutionStrategy.Round);

            Assert.Equal("foo bar=t 0\nfoo bar=t 1", writer.ToString());
        }
        public void Can_override_resolution_strategy_when_writing_point()
        {
            var writer = new LineProtocolWriter(Precision.Seconds, PrecisionResolutionStrategy.Round);

            writer.Measurement("foo").Field("bar", true).Timestamp(TimeSpan.FromMilliseconds(700));
            writer.Measurement("foo").Field("bar", true).Timestamp(TimeSpan.FromMilliseconds(700), PrecisionResolutionStrategy.Floor);

            Assert.Equal("foo bar=t 1\nfoo bar=t 0", writer.ToString());
        }
        public void Can_ceiling_if_wrong_precision_used(Precision precision)
        {
            var writer = new LineProtocolWriter(precision);

            var timestamp = TimeSpan.FromTicks(1);

            writer.Measurement("foo").Field("bar", 1f).Timestamp(timestamp, PrecisionResolutionStrategy.Ceiling);

            Assert.Equal("foo bar=1 1", writer.ToString());
        }
        public void Will_write_timestamps_using_precision_of_writer(Precision precision, long nanoseconds, string expectedTimestamp)
        {
            var unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            var timestamp = unixEpoch.AddTicks(nanoseconds / 100); // .net tick is 100 nanoseconds.

            var writer = new LineProtocolWriter(precision);

            writer.Measurement("foo").Field("bar", 1f).Timestamp(timestamp);

            Assert.Equal($"foo bar=1 {expectedTimestamp}", writer.ToString());
        }
 public LineProtocolWriteResult Send(LineProtocolWriter lineProtocolWriter, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(OnSend(lineProtocolWriter.ToString(), lineProtocolWriter.Precision, cancellationToken));
 }
 public Task <LineProtocolWriteResult> SendAsync(LineProtocolWriter lineProtocolWriter, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(SendAsync(lineProtocolWriter.ToString(), lineProtocolWriter.Precision, cancellationToken));
 }