Ejemplo n.º 1
0
        public void CanTrulyPush()
        {
            var cn = Environment.GetEnvironmentVariable("EH_CN_PSYFON");

            Action <TraceLevel, string> logger = (t, s) =>
            {
                if (t == TraceLevel.Error)
                {
                    throw new Exception(s);
                }
            };


            var bed = new BufferingEventDispatcher(cn, new DispatchSettings()
            {
                Logger = logger
            });

            bed.Start();
            for (int i = 0; i < 100; i++)
            {
                bed.Add(new EventData(new byte[10 * 1024]));
            }

            Thread.Sleep(2000);
            bed.Dispose();
            Thread.Sleep(200);
        }
Ejemplo n.º 2
0
        public async Task Event_Is_Sent_When_FlushDelay_Expires()
        {
            var sender      = new Mock <IEventSender>();
            var eventToSend = new Event("TEST", new Dictionary <string, object>());

            var sut = new BufferingEventDispatcher(sender.Object)
            {
                MaxQueueSize = 1000,
                FlushDelay   = TimeSpan.FromSeconds(1)
            };

            sut.Dispatch(eventToSend);

            sender.Verify(x => x.SendEvents(It.Is <Event[]>(array => array.Contains(eventToSend)), It.IsAny <Action <bool> >()), Times.Never);

            await Task.Delay(sut.FlushDelay);

            sender.Verify(x => x.SendEvents(It.Is <Event[]>(array => array.Contains(eventToSend)), It.IsAny <Action <bool> >()), Times.Once);
        }
Ejemplo n.º 3
0
        public void Event_Is_Sent_When_Q_Is_Full()
        {
            var sender      = new Mock <IEventSender>();
            var eventToSend = new Event("TEST", new Dictionary <string, object>());

            var sut = new BufferingEventDispatcher(sender.Object)
            {
                MaxQueueSize = 5,
                FlushDelay   = TimeSpan.FromDays(1)
            };

            sut.Dispatch(eventToSend);
            sut.Dispatch(eventToSend);
            sut.Dispatch(eventToSend);
            sut.Dispatch(eventToSend);

            sender.Verify(x => x.SendEvents(It.Is <Event[]>(array => array.Contains(eventToSend)), It.IsAny <Action <bool> >()), Times.Never);

            sut.Dispatch(eventToSend);

            sender.Verify(x => x.SendEvents(It.Is <Event[]>(array => array.Contains(eventToSend)), It.IsAny <Action <bool> >()), Times.Once);
        }
Ejemplo n.º 4
0
        public void AllItemsAreEitherSentOrInStorage()
        {
            var eventsToSend = Enumerable.Range(1, 1000)
                               .Select(i => new Event("TEST_" + i, new List <KeyValuePair <string, object> >()))
                               .ToList();
            var eventsThatWereSent = new List <Event>();

            var rnd    = new Random();
            var sender = new DelegateEventSender((e, callback) =>
            {
                if (rnd.Next(100) < 5) // 5% of events are sent successfuly
                {
                    eventsThatWereSent.AddRange(e);
                    callback(true);
                }
                else
                {
                    callback(false);
                }
            });


            var storage    = new InMemoryStorage <IList <Event> >();
            var proxy      = new StoringEventSenderProxy(sender, storage);
            var dispatcher = new BufferingEventDispatcher(proxy)
            {
                MaxQueueSize = 1
            };

            foreach (var e in eventsToSend)
            {
                dispatcher.Dispatch(e);
            }

            Assert.Equal(1000, eventsThatWereSent.Count + storage.Load().Count);
        }