public void testMockStorageMany()
        {
            var s = new MockStorage();

            Assert.AreEqual(s.TotalItems, 0);

            s.Put("hello world");
            s.Put("hello world 2");
            s.Put("hello world 3");

            Assert.AreEqual(3, s.TotalItems);

            var i = s.TakeLast(3);

            Assert.AreEqual(3, i.Count);
            Assert.AreEqual("hello world", i[2].Item);
            Assert.AreEqual("hello world 2", i[1].Item);
            Assert.AreEqual("hello world 3", i[0].Item);
            Assert.AreEqual(3, s.TotalItems);

            var del = s.Delete(new List <string> {
                "0", "1", "2"
            });

            Assert.IsTrue(del);
            Assert.AreEqual(0, s.TotalItems);
        }
        public void testMultipleConsumers()
        {
            var mockStorage = new MockStorage();

            var q = new PersistentBlockingQueue(mockStorage, new PayloadToJsonString());

            int expectedRecordCount = 1000;

            var producer = new MockProducer(expectedRecordCount, q);

            var producerThread = new Thread(new ThreadStart(producer.Produce));

            producerThread.Start();

            var threads   = new List <Thread>();
            var consumers = new List <MockConsumer>();

            for (int i = 0; i < expectedRecordCount; i++)
            {
                var consumer       = new MockConsumer(1, q);
                var consumerThread = new Thread(new ThreadStart(consumer.Consume));
                consumerThread.Start();
                threads.Add(consumerThread);
                consumers.Add(consumer);
            }

            threads.ForEach(t => { t.Join(100); });

            var  total = (from c in consumers select c.Consumed.Count).Sum();
            bool allConsumedOneItem = !consumers.Any(item => { return(item.Consumed.Count != 1); });

            Assert.IsTrue(allConsumedOneItem);
            Assert.AreEqual(expectedRecordCount, total);
        }
        public void testAddRemoveThreaded()
        {
            var mockStorage = new MockStorage();

            var q = new PersistentBlockingQueue(mockStorage, new PayloadToJsonString());

            int expectedRecordCount = 1000;

            var consumer = new MockConsumer(expectedRecordCount, q);

            var producer       = new MockProducer(expectedRecordCount / 2, q);
            var secondProducer = new MockProducer(expectedRecordCount / 2, q);

            var consumerThread = new Thread(new ThreadStart(consumer.Consume));

            consumerThread.Start();

            var producerThread = new Thread(new ThreadStart(producer.Produce));

            producerThread.Start();

            var secondProducerThread = new Thread(new ThreadStart(secondProducer.Produce));

            secondProducerThread.Start();

            consumerThread.Join(1000); // time out if errors

            Assert.AreEqual(expectedRecordCount, consumer.Consumed.Count);
        }
        public void testConsumerTimeout()
        {
            var mockStorage = new MockStorage();

            var q = new PersistentBlockingQueue(mockStorage, new PayloadToJsonString());

            var consumer       = new MockConsumer(1, q, 10);
            var consumerThread = new Thread(new ThreadStart(consumer.Consume));

            consumerThread.Start();

            consumerThread.Join(500);

            Assert.AreEqual(0, consumer.Consumed.Count);
        }
        public void testAddRemoveOne()
        {
            var storage = new MockStorage();
            var queue   = new PersistentBlockingQueue(storage, new PayloadToJsonString());

            var dict = new Dictionary <string, string>();

            dict.Add("hello", "world");
            var samplePayload = new Payload();

            samplePayload.AddDict(dict);

            var payload = new List <Payload>();

            payload.Add(samplePayload);

            queue.Enqueue(payload);
            var actualPayload = queue.Peek(1);

            Assert.AreEqual(1, actualPayload.Count);
            CollectionAssert.AreEqual(samplePayload.Payload, actualPayload[0].Item2.Payload);
        }
        public void testMockStorageOne()
        {
            var s = new MockStorage();

            Assert.AreEqual(s.TotalItems, 0);

            s.Put("hello world");

            Assert.AreEqual(1, s.TotalItems);

            var i = s.TakeLast(1);

            Assert.AreEqual(1, i.Count);
            Assert.AreEqual("hello world", i[0].Item);
            Assert.AreEqual(1, s.TotalItems);

            var del = s.Delete(new List <string> {
                "0"
            });

            Assert.IsTrue(del);
            Assert.AreEqual(0, s.TotalItems);
        }