public void TailTest() { const string data = "One Two Three One Three"; var queue = data.Split().Aggregate(BatchedQueue <string> .Empty, BatchedQueue <string> .Snoc); var tail = BatchedQueue <string> .Tail(queue); Assert.AreEqual("[[Two, Three, One, Three], null]", DumpQueue(tail)); }
public void HeadTest() { const string data = "One Two Three One Three"; var queue = data.Split().Aggregate(BatchedQueue <string> .Empty, BatchedQueue <string> .Snoc); var head = BatchedQueue <string> .Head(queue); Assert.AreEqual("One", head); }
public void Tests() { var batchSize = 2; var maxCapacity = 5; var q = new BatchedQueue <int>(batchSize, maxCapacity); q.AsString().Should().Be("[()]"); q.Enqueue(1); q.AsString().Should().Be("[(1)]"); q.Enqueue(2); q.AsString().Should().Be("[(1,2)]"); q.Enqueue(3); q.AsString().Should().Be("[(1,2)(3)]"); q.Enqueue(4); q.AsString().Should().Be("[(1,2)(3,4)]"); q.Enqueue(5); q.AsString().Should().Be("[(1,2)(3,4)(5)]"); q.Count().Should().Be(5); q.Enqueue(6); q.AsString().Should().Be("[(1,2)(3,4)(5)]"); var firstBatch = q.DequeueBatch(); firstBatch.AsString().Should().BeEquivalentTo("(1,2)"); q.AsString().Should().Be("[(3,4)(5)]"); q.Enqueue(new[] { 7, 8, 9 }); q.AsString().Should().Be("[(3,4)(5,7)(8)]"); q.EnqueueToFront(firstBatch); q.AsString().Should().Be("[(1,2)(3,4)(5)]"); q.EnqueueToFront(L(8, 9, 10)); q.AsString().Should().Be("[(8,9,10)(1,2)]"); // dequeue empty list firstBatch = q.DequeueBatch(); firstBatch.AsString().Should().BeEquivalentTo("(8,9,10)"); q.AsString().Should().Be("[(1,2)]"); firstBatch = q.DequeueBatch(); firstBatch.AsString().Should().BeEquivalentTo("(1,2)"); q.AsString().Should().Be("[()]"); firstBatch = q.DequeueBatch(); firstBatch.AsString().Should().BeEquivalentTo("()"); q.AsString().Should().Be("[()]"); }
private static string DumpQueue <T>(BatchedQueue <T> .Queue queue) { var builder = new StringBuilder(); builder.Append("["); builder.Append(queue.F?.ToReadableString() ?? "null"); builder.Append(", "); builder.Append(queue.R?.ToReadableString() ?? "null"); builder.Append("]"); return(builder.ToString()); }
public void EmptyTest() { var queue = BatchedQueue <string> .Empty; Assert.IsTrue(BatchedQueue <string> .IsEmpty(queue)); queue = BatchedQueue <string> .Snoc(queue, "Item"); Assert.IsFalse(BatchedQueue <string> .IsEmpty(queue)); queue = BatchedQueue <string> .Tail(queue); Assert.IsTrue(BatchedQueue <string> .IsEmpty(queue)); }
public void PushPopTest() { const string data = "One Two Three One Three"; var queue = data.Split().Aggregate(BatchedQueue <string> .Empty, BatchedQueue <string> .Snoc); foreach (var expected in data.Split()) { var actual = BatchedQueue <string> .Head(queue); Assert.AreEqual(expected, actual); queue = BatchedQueue <string> .Tail(queue); } Assert.IsTrue(BatchedQueue <string> .IsEmpty(queue)); }
public Table(string connectionString, string databaseName, MetricsWriterSettings writerSettings) { _connectionString = connectionString; _databaseName = databaseName; _queue = new BatchedQueue <object[]>(writerSettings.BatchSize, writerSettings.MaxQueuedRows); }
public void EmptyTailTest() { var queue = BatchedQueue <string> .Empty; AssertThrows <ArgumentNullException>(() => BatchedQueue <string> .Tail(queue)); }
public void EmptySnocTest() { AssertThrows <NullReferenceException>(() => BatchedQueue <string> .Snoc(null, "Item")); }
public BufferedSender(MetricsWriterSettings settings, string uri, Func <IList <T>, MetricsModel> builder) { _uri = uri; _builder = builder; _queue = new BatchedQueue <T>(settings.BatchSize, settings.MaxQueuedRows); }