public void Callback_in_delay_time() { var dispatcher = new MockUpdateRecordDispatcher(1); var queue = new UpdateDelayQueue(TimeSpan.FromSeconds(1), dispatcher); XDoc queued = new XDoc("deki-event") .Attr("wikiid", "abc") .Elem("channel", "event://abc/deki/pages/update") .Elem("pageid", "1") .Elem("path", "bar"); DateTime queueTime = DateTime.Now; queue.Enqueue(queued); Assert.AreEqual(0, dispatcher.Dispatches.Count); if (!dispatcher.ResetEvent.WaitOne(5000, true)) { Assert.Fail("callback didn't happen"); } Assert.AreEqual(1, dispatcher.Dispatches.Count); Assert.AreEqual(1, dispatcher.Dispatches[0].Item2.Id); Assert.AreEqual("abc", dispatcher.Dispatches[0].Item2.WikiId); Assert.AreEqual("bar", dispatcher.Dispatches[0].Item2.Path); Assert.AreEqual(RecordType.Page, dispatcher.Dispatches[0].Item2.Type); Assert.GreaterOrEqual(dispatcher.Dispatches[0].Item1, queueTime.Add(TimeSpan.FromMilliseconds(1000))); }
public void Multiple_events_for_same_page_update_path_in_dispatched_callback() { var dispatcher = new MockUpdateRecordDispatcher(1); var queue = new UpdateDelayQueue(TimeSpan.FromSeconds(1), dispatcher); XDoc queued = new XDoc("deki-event") .Attr("wikiid", "abc") .Elem("channel", "event://abc/deki/pages/create") .Elem("pageid", "1") .Elem("path", "bar"); DateTime queueTime = DateTime.Now; queue.Enqueue(queued); Assert.AreEqual(0, dispatcher.Dispatches.Count); Thread.Sleep(100); queued = new XDoc("deki-event") .Attr("wikiid", "abc") .Elem("channel", "event://abc/deki/pages/update") .Elem("pageid", "1") .Elem("path", "baz"); queue.Enqueue(queued); Assert.AreEqual(0, dispatcher.Dispatches.Count); if (!dispatcher.ResetEvent.WaitOne(2000, true)) { Assert.Fail("callbacks didn't happen"); } Assert.AreEqual(1, dispatcher.Dispatches.Count); Assert.AreEqual(1, dispatcher.Dispatches[0].Item2.Id); Assert.AreEqual("abc", dispatcher.Dispatches[0].Item2.WikiId); Assert.AreEqual("baz", dispatcher.Dispatches[0].Item2.Path); Assert.AreEqual(RecordType.Page, dispatcher.Dispatches[0].Item2.Type); }
public void QueueSize_queries_dispatcher_QueueSize() { var dispatcher = new MockUpdateRecordDispatcher(1); var queue = new UpdateDelayQueue(TimeSpan.FromSeconds(1), dispatcher); Assert.AreEqual(1, queue.QueueSize); Assert.AreEqual(1, dispatcher.QueueSizeCalled); }
public void Multiple_events_for_different_types_fire_for_each_type() { var dispatcher = new MockUpdateRecordDispatcher(3); var queue = new UpdateDelayQueue(TimeSpan.FromSeconds(1), dispatcher); XDoc queued = new XDoc("deki-event") .Attr("wikiid", "abc") .Elem("channel", "event://abc/deki/pages/create") .Elem("pageid", "1") .Elem("path", "bar"); DateTime queueTime = DateTime.Now; queue.Enqueue(queued); Assert.AreEqual(0, dispatcher.Dispatches.Count); Thread.Sleep(100); queued = new XDoc("deki-event") .Attr("wikiid", "abd") .Elem("channel", "event://abc/deki/pages/update") .Elem("pageid", "2") .Elem("path", "baz"); queue.Enqueue(queued); Assert.AreEqual(0, dispatcher.Dispatches.Count); Thread.Sleep(100); queued = new XDoc("deki-event") .Attr("wikiid", "abf") .Elem("channel", "event://abc/deki/files/foop") .Elem("fileid", "1"); queue.Enqueue(queued); Assert.AreEqual(0, dispatcher.Dispatches.Count); if (!dispatcher.ResetEvent.WaitOne(2000, true)) { Assert.Fail("callbacks didn't happen"); } Assert.AreEqual(3, dispatcher.Dispatches.Count); Assert.AreEqual(1, dispatcher.Dispatches[0].Item2.Id); Assert.AreEqual("abc", dispatcher.Dispatches[0].Item2.WikiId); Assert.AreEqual("bar", dispatcher.Dispatches[0].Item2.Path); Assert.AreEqual(RecordType.Page, dispatcher.Dispatches[0].Item2.Type); Assert.AreEqual(2, dispatcher.Dispatches[1].Item2.Id); Assert.AreEqual("abd", dispatcher.Dispatches[1].Item2.WikiId); Assert.AreEqual("baz", dispatcher.Dispatches[1].Item2.Path); Assert.AreEqual(RecordType.Page, dispatcher.Dispatches[1].Item2.Type); Assert.AreEqual(1, dispatcher.Dispatches[2].Item2.Id); Assert.AreEqual("abf", dispatcher.Dispatches[2].Item2.WikiId); Assert.IsTrue(string.IsNullOrEmpty(dispatcher.Dispatches[2].Item2.Path)); Assert.AreEqual(RecordType.File, dispatcher.Dispatches[2].Item2.Type); }
public void Multiple_events_for_same_page_fire_once_on_first_plus_delay() { var dispatcher = new MockUpdateRecordDispatcher(1); var queue = new UpdateDelayQueue(TimeSpan.FromSeconds(2), dispatcher); XDoc queued = new XDoc("deki-event") .Attr("wikiid", "abc") .Elem("channel", "event://abc/deki/pages/create") .Elem("pageid", "1") .Elem("path", "bar"); DateTime queueTime = DateTime.Now; queue.Enqueue(queued); Assert.AreEqual(0, dispatcher.Dispatches.Count); Thread.Sleep(300); queued = new XDoc("deki-event") .Attr("wikiid", "abc") .Elem("channel", "event://abc/deki/pages/update") .Elem("pageid", "1") .Elem("path", "bar"); queue.Enqueue(queued); Assert.AreEqual(0, dispatcher.Dispatches.Count); Thread.Sleep(300); queued = new XDoc("deki-event") .Attr("wikiid", "abc") .Elem("channel", "event://abc/deki/pages/foop") .Elem("pageid", "1") .Elem("path", "bar"); queue.Enqueue(queued); Assert.AreEqual(0, dispatcher.Dispatches.Count); if (!dispatcher.ResetEvent.WaitOne(3000, true)) { Assert.Fail("callback didn't happen"); } Assert.AreEqual(1, dispatcher.Dispatches.Count); Assert.AreEqual(1, dispatcher.Dispatches[0].Item2.Id); Assert.AreEqual("abc", dispatcher.Dispatches[0].Item2.WikiId); Assert.AreEqual("bar", dispatcher.Dispatches[0].Item2.Path); Assert.AreEqual(RecordType.Page, dispatcher.Dispatches[0].Item2.Type); Assert.GreaterOrEqual(dispatcher.Dispatches[0].Item1, queueTime.Add(TimeSpan.FromMilliseconds(2000))); Assert.LessOrEqual(dispatcher.Dispatches[0].Item1, queueTime.Add(TimeSpan.FromMilliseconds(2200))); Thread.Sleep(1000); Assert.AreEqual(1, dispatcher.Dispatches.Count); }
public void Callback_in_delay_time() { var dispatcher = new MockUpdateRecordDispatcher(1); var queue = new UpdateDelayQueue(TimeSpan.FromSeconds(1), dispatcher); XDoc queued = new XDoc("deki-event") .Attr("wikiid", "abc") .Elem("channel", "event://abc/deki/pages/update") .Elem("pageid", "1") .Elem("path", "bar"); DateTime queueTime = DateTime.Now; queue.Enqueue(queued); Assert.AreEqual(0, dispatcher.Dispatches.Count); if(!dispatcher.ResetEvent.WaitOne(5000, true)) { Assert.Fail("callback didn't happen"); } Assert.AreEqual(1, dispatcher.Dispatches.Count); Assert.AreEqual(1, dispatcher.Dispatches[0].Item2.Id); Assert.AreEqual("abc", dispatcher.Dispatches[0].Item2.WikiId); Assert.AreEqual("bar", dispatcher.Dispatches[0].Item2.Path); Assert.AreEqual(RecordType.Page, dispatcher.Dispatches[0].Item2.Type); Assert.GreaterOrEqual(dispatcher.Dispatches[0].Item1, queueTime.Add(TimeSpan.FromMilliseconds(1000))); }
public void Multiple_events_for_same_page_fire_once_on_first_plus_delay() { var dispatcher = new MockUpdateRecordDispatcher(1); var queue = new UpdateDelayQueue(TimeSpan.FromSeconds(2), dispatcher); XDoc queued = new XDoc("deki-event") .Attr("wikiid", "abc") .Elem("channel", "event://abc/deki/pages/create") .Elem("pageid", "1") .Elem("path", "bar"); DateTime queueTime = DateTime.Now; queue.Enqueue(queued); Assert.AreEqual(0, dispatcher.Dispatches.Count); Thread.Sleep(300); queued = new XDoc("deki-event") .Attr("wikiid", "abc") .Elem("channel", "event://abc/deki/pages/update") .Elem("pageid", "1") .Elem("path", "bar"); queue.Enqueue(queued); Assert.AreEqual(0, dispatcher.Dispatches.Count); Thread.Sleep(300); queued = new XDoc("deki-event") .Attr("wikiid", "abc") .Elem("channel", "event://abc/deki/pages/foop") .Elem("pageid", "1") .Elem("path", "bar"); queue.Enqueue(queued); Assert.AreEqual(0, dispatcher.Dispatches.Count); if(!dispatcher.ResetEvent.WaitOne(3000, true)) { Assert.Fail("callback didn't happen"); } Assert.AreEqual(1, dispatcher.Dispatches.Count); Assert.AreEqual(1, dispatcher.Dispatches[0].Item2.Id); Assert.AreEqual("abc", dispatcher.Dispatches[0].Item2.WikiId); Assert.AreEqual("bar", dispatcher.Dispatches[0].Item2.Path); Assert.AreEqual(RecordType.Page, dispatcher.Dispatches[0].Item2.Type); Assert.GreaterOrEqual(dispatcher.Dispatches[0].Item1, queueTime.Add(TimeSpan.FromMilliseconds(2000))); Assert.LessOrEqual(dispatcher.Dispatches[0].Item1, queueTime.Add(TimeSpan.FromMilliseconds(2200))); Thread.Sleep(1000); Assert.AreEqual(1, dispatcher.Dispatches.Count); }
public void Multiple_events_for_same_page_update_path_in_dispatched_callback() { var dispatcher = new MockUpdateRecordDispatcher(1); var queue = new UpdateDelayQueue(TimeSpan.FromSeconds(1), dispatcher); XDoc queued = new XDoc("deki-event") .Attr("wikiid", "abc") .Elem("channel", "event://abc/deki/pages/create") .Elem("pageid", "1") .Elem("path", "bar"); DateTime queueTime = DateTime.Now; queue.Enqueue(queued); Assert.AreEqual(0, dispatcher.Dispatches.Count); Thread.Sleep(100); queued = new XDoc("deki-event") .Attr("wikiid", "abc") .Elem("channel", "event://abc/deki/pages/update") .Elem("pageid", "1") .Elem("path", "baz"); queue.Enqueue(queued); Assert.AreEqual(0, dispatcher.Dispatches.Count); if(!dispatcher.ResetEvent.WaitOne(2000, true)) { Assert.Fail("callbacks didn't happen"); } Assert.AreEqual(1, dispatcher.Dispatches.Count); Assert.AreEqual(1, dispatcher.Dispatches[0].Item2.Id); Assert.AreEqual("abc", dispatcher.Dispatches[0].Item2.WikiId); Assert.AreEqual("baz", dispatcher.Dispatches[0].Item2.Path); Assert.AreEqual(RecordType.Page, dispatcher.Dispatches[0].Item2.Type); }
public void Multiple_events_for_different_types_fire_for_each_type() { var dispatcher = new MockUpdateRecordDispatcher(3); var queue = new UpdateDelayQueue(TimeSpan.FromSeconds(1), dispatcher); XDoc queued = new XDoc("deki-event") .Attr("wikiid", "abc") .Elem("channel", "event://abc/deki/pages/create") .Elem("pageid", "1") .Elem("path", "bar"); DateTime queueTime = DateTime.Now; queue.Enqueue(queued); Assert.AreEqual(0, dispatcher.Dispatches.Count); Thread.Sleep(100); queued = new XDoc("deki-event") .Attr("wikiid", "abd") .Elem("channel", "event://abc/deki/pages/update") .Elem("pageid", "2") .Elem("path", "baz"); queue.Enqueue(queued); Assert.AreEqual(0, dispatcher.Dispatches.Count); Thread.Sleep(100); queued = new XDoc("deki-event") .Attr("wikiid", "abf") .Elem("channel", "event://abc/deki/files/foop") .Elem("fileid", "1"); queue.Enqueue(queued); Assert.AreEqual(0, dispatcher.Dispatches.Count); if(!dispatcher.ResetEvent.WaitOne(2000, true)) { Assert.Fail("callbacks didn't happen"); } Assert.AreEqual(3, dispatcher.Dispatches.Count); Assert.AreEqual(1, dispatcher.Dispatches[0].Item2.Id); Assert.AreEqual("abc", dispatcher.Dispatches[0].Item2.WikiId); Assert.AreEqual("bar", dispatcher.Dispatches[0].Item2.Path); Assert.AreEqual(RecordType.Page, dispatcher.Dispatches[0].Item2.Type); Assert.AreEqual(2, dispatcher.Dispatches[1].Item2.Id); Assert.AreEqual("abd", dispatcher.Dispatches[1].Item2.WikiId); Assert.AreEqual("baz", dispatcher.Dispatches[1].Item2.Path); Assert.AreEqual(RecordType.Page, dispatcher.Dispatches[1].Item2.Type); Assert.AreEqual(1, dispatcher.Dispatches[2].Item2.Id); Assert.AreEqual("abf", dispatcher.Dispatches[2].Item2.WikiId); Assert.IsTrue(string.IsNullOrEmpty(dispatcher.Dispatches[2].Item2.Path)); Assert.AreEqual(RecordType.File, dispatcher.Dispatches[2].Item2.Type); }
public void Setup() { _peekQueue = new TransactionalQueue<XDoc>(new SingleFileQueueStream(new MemoryStream()), new XDocQueueItemSerializer()); _dispatcher = new MockUpdateRecordDispatcher(); _queue = new UpdateDelayQueue(TimeSpan.FromSeconds(3), _dispatcher, _peekQueue); }
public void Setup() { _peekQueue = new TransactionalQueue <XDoc>(new SingleFileQueueStream(new MemoryStream()), new XDocQueueItemSerializer()); _dispatcher = new MockUpdateRecordDispatcher(); _queue = new UpdateDelayQueue(TimeSpan.FromSeconds(3), _dispatcher, _peekQueue); }