public void Returns_empty_uniform_snapshot_when_zero_size()
        {
            var reservoir = new DefaultSlidingWindowReservoir(0);

            reservoir.GetSnapshot().Should().BeOfType <UniformSnapshot>();
            reservoir.GetSnapshot().Size.Should().Be(0);
            reservoir.GetSnapshot().Values.Should().BeEmpty();
        }
        public void can_store_small_sample()
        {
            _reservoir.Update(1L);
            _reservoir.Update(2L);

            _reservoir.GetSnapshot().Values.Should().ContainInOrder(1L, 2L);
        }
        public void Can_reset()
        {
            _reservoir.Update(1L);
            _reservoir.Reset();
            _reservoir.Update(2L);
            _reservoir.Update(3L);

            _reservoir.GetSnapshot().Values.Should().NotContain(1L);
            _reservoir.GetSnapshot().Values.Should().ContainInOrder(2L, 3L);
        }
Beispiel #4
0
        public void SlidingWindowReservoir()
        {
            var reservoir = new DefaultSlidingWindowReservoir(Constants.ReservoirSampling.DefaultSampleSize);

            foreach (var sample in _samples)
            {
                reservoir.Update(sample);
            }

            var snapshot = reservoir.GetSnapshot();

            AssertValues(snapshot);
        }
Beispiel #5
0
        public override void Setup()
        {
            _fixture = new MetricsCoreTestFixture();

            _reservoir = new DefaultSlidingWindowReservoir();

            _scheduler = new DefaultTaskScheduler();

            _scheduler.Interval(
                TimeSpan.FromMilliseconds(10),
                TaskCreationOptions.None,
                () =>
            {
                _reservoir.GetSnapshot();
                _reservoir.Reset();
            });
        }
        private Task Tick()
        {
            try
            {
                _reservoir.GetSnapshot();
                _reservoir.Reset();
            }
            catch (Exception)
            {
            }
            finally
            {
                lock (_syncLock)
                {
                    if (!_disposing)
                    {
                        SetScheduler();
                    }
                }
            }

            return(Task.CompletedTask);
        }