Exemplo n.º 1
0
        public void testFlushStopsAfterFirstFailure()
        {
            var storage      = new MockStorage();
            var queue        = new PersistentBlockingQueue(storage, new PayloadToJsonString());
            var mockEndpoint = new MockEndpoint()
            {
                Response = false
            };
            AsyncEmitter e = new AsyncEmitter(mockEndpoint, queue, sendLimit: 1);

            for (int i = 0; i < 100; i++)
            {
                var p = new Payload();
                p.AddDict(new Dictionary <string, string>()
                {
                    { "foo", "bar" }
                });
                e.Input(p);
            }

            Assert.AreEqual(100, storage.TotalItems);
            Assert.IsFalse(e.Running);

            e.Flush(true);

            Assert.IsFalse(e.Running);
            Assert.AreEqual(1, mockEndpoint.CallCount);
            Assert.AreEqual(0, mockEndpoint.Result.SuccessIds.Count);
            Assert.AreEqual(1, mockEndpoint.Result.FailureIds.Count);
            Assert.AreEqual(100, storage.TotalItems);
        }
Exemplo n.º 2
0
        public void testFailedItemsEnqueuedAgain()
        {
            var          q = new PersistentBlockingQueue(new MockStorage(), new PayloadToJsonString());
            AsyncEmitter e = new AsyncEmitter(new MockEndpoint()
            {
                Response = false
            }, q);

            // no events will send, and so they should be at the start of the queue

            e.Start();

            var p = new Payload();

            p.AddDict(new Dictionary <string, string>()
            {
                { "foo", "bar" }
            });

            e.Input(p);
            Thread.Sleep(100); // this could be done better with triggers of some kind
            e.Stop();

            var inQueue = q.Peek(1);

            Assert.AreEqual(1, inQueue.Count);
        }
Exemplo n.º 3
0
        public void testBackoffInterval()
        {
            // because of the back off period (5sec +), this event should only be sent once
            var q            = new PersistentBlockingQueue(new MockStorage(), new PayloadToJsonString());
            var mockEndpoint = new MockEndpoint()
            {
                Response = false
            };
            AsyncEmitter e = new AsyncEmitter(mockEndpoint, q);

            e.Start();
            var p = new Payload();

            p.AddDict(new Dictionary <string, string>()
            {
                { "foo", "bar" }
            });
            e.Input(p);
            Thread.Sleep(100);
            e.Stop();

            Assert.AreEqual(1, mockEndpoint.CallCount);
        }