Example #1
0
        public void update_multi_archive()
        {
            var retention_schema = new List <ArchiveInfo>()
            {
                new ArchiveInfo(1, 60), new ArchiveInfo(60, 60)
            };
            var data = update(schema: retention_schema);

            var fetch       = Whipser.Fetch(db, DateTime.UtcNow.ToUnixTime() - 25, now: DateTime.UtcNow.ToUnixTime() + 5).Value;
            var fetchedData = fetch.ValueList;

            foreach (var item in data)
            {
                Debug.WriteLine("wrote point ({0},{1})", item.Timestamp, item.value);
            }
            foreach (var item in fetchedData)
            {
                Debug.WriteLine("read point ({0},{1})", item.Timestamp, item.value);
            }

            // in future
            Assert.Throws <TimestampNotCoveredException>(() => Whipser.Update(db, 1.337, DateTime.UtcNow.ToUnixTime() + 1, now));

            // before the past
            Assert.Throws <TimestampNotCoveredException>(() => Whipser.Update(db, 1.337, DateTime.UtcNow.ToUnixTime() - retention_schema[1].Retention - 1, now));

            RemoveDb();
        }
Example #2
0
        public void fetch()
        {
            Assert.Throws <FileNotFoundException>(() => Whipser.Fetch("does_not_exist", 0));

            var retention = new List <ArchiveInfo>()
            {
                new ArchiveInfo(1, 60), new ArchiveInfo(60, 60), new ArchiveInfo(3600, 24), new ArchiveInfo(86400, 365)
            };

            Whipser.Create(db, retention);

            Assert.Throws <InvalidTimeIntervalException>(() => Whipser.Fetch(db, DateTime.Now.Ticks, DateTime.Now.Ticks - 60000));

            var fetch = Whipser.Fetch(db, 0).Value;

            // check time range
            Assert.AreEqual(retention.Last().Retention, fetch.TimeInfo.UntilInterval - fetch.TimeInfo.FromInterval);

            // check number of points
            Assert.AreEqual(retention.Last().Points, fetch.ValueList.Count);

            // check step size
            Assert.AreEqual(retention.Last().SecondsPerPoint, fetch.TimeInfo.Step);

            RemoveDb();
        }
Example #3
0
        public void update_single_archive()
        {
            var retention_schema = new List <ArchiveInfo>()
            {
                new ArchiveInfo(1, 20)
            };
            var data = update(schema: retention_schema);

            var fetch       = Whipser.Fetch(db, 0).Value;
            var fetchedData = fetch.ValueList;

            for (int i = 0; i < data.Length; i++)
            {
                Assert.AreEqual(data[i].value, fetchedData[i].value);
            }

            // in future
            Assert.Throws <TimestampNotCoveredException>(() => Whipser.Update(db, 1.337, now + 1, now));

            // before the past
            Assert.Throws <TimestampNotCoveredException>(() => Whipser.Update(db, 1.337, now - retention_schema[0].Retention - 1, now));

            RemoveDb();
        }