Exemple #1
0
        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));
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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("[()]");
        }
Exemple #4
0
        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());
        }
Exemple #5
0
        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));
        }
Exemple #6
0
        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));
        }
Exemple #7
0
 public Table(string connectionString, string databaseName, MetricsWriterSettings writerSettings)
 {
     _connectionString = connectionString;
     _databaseName     = databaseName;
     _queue            = new BatchedQueue <object[]>(writerSettings.BatchSize, writerSettings.MaxQueuedRows);
 }
Exemple #8
0
        public void EmptyTailTest()
        {
            var queue = BatchedQueue <string> .Empty;

            AssertThrows <ArgumentNullException>(() => BatchedQueue <string> .Tail(queue));
        }
Exemple #9
0
 public void EmptySnocTest()
 {
     AssertThrows <NullReferenceException>(() => BatchedQueue <string> .Snoc(null, "Item"));
 }
Exemple #10
0
 public BufferedSender(MetricsWriterSettings settings, string uri, Func <IList <T>, MetricsModel> builder)
 {
     _uri     = uri;
     _builder = builder;
     _queue   = new BatchedQueue <T>(settings.BatchSize, settings.MaxQueuedRows);
 }