public void TheSecondTakeIsBlockedUntilTheKeyCooledDown() { var timeSource = new ControllableTime(); using (var q = new ConcurrentBufferedQueue <int, string>(timeSource)) { q.Add(1, "Hallo 1"); q.Add(1, "Hallo new"); var r = q.Take(); bool clockWasSet = false; r.Key.Should().Be(1); r.Value.Should().Be("Hallo new"); q.Count.Should().Be(0); q.Add(1, "Hallo after cooldown"); Task.Factory.StartNew(() => { Thread.Sleep(50); clockWasSet = true; timeSource.Add(100); }); r = q.Take(); clockWasSet.Should().BeTrue(); r.Key.Should().Be(1); r.Value.Should().Be("Hallo after cooldown"); } }
public void CompleteAddingPropertiesWorkAsExpected() { using var q = new ConcurrentBufferedQueue <int, string>(); q.Add(1, "Hallo 1"); q.Add(2, "Hallo 2"); q.CompleteAdding(); q.IsAddingCompleted.Should().BeTrue(); q.IsCompleted.Should().BeFalse(); _ = q.Take(); _ = q.Take(); q.IsCompleted.Should().BeTrue(); }
public void TakingAnElementRetrievesTheFirstOne() { using (var q = new ConcurrentBufferedQueue <int, string>(NullTime.Source)) { q.Add(3, "Hallo 3"); q.Add(7, "Hallo 7"); q.Add(1, "Hallo 1"); var result = q.Take(); result.Key.Should().Be(3); result.Value.Should().Be("Hallo 3"); result = q.Take(); result.Key.Should().Be(7); result.Value.Should().Be("Hallo 7"); result = q.Take(); result.Key.Should().Be(1); result.Value.Should().Be("Hallo 1"); } }
public void CallTakeAfterCompletingThrowsAnException() { using (var q = new ConcurrentBufferedQueue <int, string>(NullTime.Source)) { var takeAction = new Action(() => { var result = q.Take(); }); q.CompleteAdding(); takeAction.Should().Throw <InvalidOperationException>(); } }
public void CallTakeAfterCompletingThrowsAnException() { using var q = new ConcurrentBufferedQueue <int, string>(); bool?success = null; var takeAction = new Action(() => (success, _, _) = q.Take()); q.CompleteAdding(); takeAction(); success.HasValue.Should().BeTrue(); success.Value.Should().BeFalse(); }
public void CompletingTheBufferWhileTakeIsWaitingThrowsAnException() { using var q = new ConcurrentBufferedQueue <int, string>(); Task.Factory.StartNew(() => { Thread.Sleep(50); // Make sure Take is called before the next line is executed q.CompleteAdding(); }); var(success, _, _) = q.Take(); success.Should().BeFalse(); }
public void OverrideQueueElementWithSameKey() { using (var q = new ConcurrentBufferedQueue <int, string>(NullTime.Source)) { q.Add(1, "Hallo 1"); q.Add(2, "Hallo 2"); q.Add(1, "Hallo NEW"); var r = q.Take(); r.Key.Should().Be(1); r.Value.Should().Be("Hallo NEW"); } }
public void OverrideQueueElementWithSameKey() { using var q = new ConcurrentBufferedQueue <int, string>(); q.Add(1, "Hallo 1"); q.Add(2, "Hallo 2"); q.Add(1, "Hallo NEW"); var(success, key, value) = q.Take(); success.Should().BeTrue(); key.Should().Be(1); value.Should().Be("Hallo NEW"); }
public void TakingAnElementBlocksUnitAnElementIsAvailable() { using (var q = new ConcurrentBufferedQueue <int, string>(NullTime.Source)) { Task.Factory.StartNew(() => { Thread.Sleep(50); //Make sure Take is called before the next line is executed q.Add(3, "Hallo"); }); var result = q.Take(); result.Key.Should().Be(3); result.Value.Should().Be("Hallo"); } }
public void TakingAnElementBlocksUnitAnElementIsAvailable() { using var q = new ConcurrentBufferedQueue <int, string>(); Task.Factory.StartNew(() => { Thread.Sleep(50); // Make sure Take is called before the next line is executed q.Add(3, "Hallo"); }); var(success, key, value) = q.Take(); success.Should().BeTrue(); key.Should().Be(3); value.Should().Be("Hallo"); }
public void CompletingTheBufferWhileTakeIsWaitingThrowsAnException() { using (var q = new ConcurrentBufferedQueue <int, string>(NullTime.Source)) { Task.Factory.StartNew(() => { Thread.Sleep(50); //Make sure Take is called before the next line is executed q.CompleteAdding(); }); var takeAction = new Action(() => { var result = q.Take(); }); takeAction.Should().Throw <InvalidOperationException>(); } }