public void testFlush() { var storage = new MockStorage(); var queue = new PersistentBlockingQueue(storage, new PayloadToJsonString()); var mockEndpoint = new MockEndpoint() { Response = true }; 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.IsFalse(e.Running); e.Flush(); Assert.IsTrue(e.Running); e.Stop(); Assert.AreEqual(100, mockEndpoint.CallCount); Assert.AreEqual(0, storage.TotalItems); }
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); }
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); }