public void can_records_user_value() { var reservoir = new DefaultAlgorithmRReservoir(100); reservoir.Update(2L, "B"); reservoir.Update(1L, "A"); reservoir.GetSnapshot().MinUserValue.Should().Be("A"); reservoir.GetSnapshot().MaxUserValue.Should().Be("B"); }
public void of_100_out_of_1000_elements() { var reservoir = new DefaultAlgorithmRReservoir(100); for (var i = 0; i < 1000; i++) { reservoir.Update(i); } reservoir.Size.Should().Be(100); reservoir.GetSnapshot().Size.Should().Be(100); reservoir.GetSnapshot().Values.Should().OnlyContain(v => 0 <= v && v < 1000); }
public void UniformReservoir() { var reservoir = new DefaultAlgorithmRReservoir(Constants.ReservoirSampling.DefaultSampleSize); foreach (var sample in _samples) { reservoir.Update(sample); } var snapshot = reservoir.GetSnapshot(); AssertValues(snapshot); }
public override void Setup() { _fixture = new MetricsCoreTestFixture(); _reservoir = new DefaultAlgorithmRReservoir(); _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); }