예제 #1
0
        public void TestFlushMaxBatchSize()
        {
            var countdownEvent  = new CountdownEvent(1);
            var eventDispatcher = new TestEventDispatcher(countdownEvent)
            {
                Logger = LoggerMock.Object
            };

            SetEventProcessor(eventDispatcher);

            for (int i = 0; i < MAX_BATCH_SIZE; i++)
            {
                UserEvent userEvent = BuildConversionEvent(EventName);
                EventProcessor.Process(userEvent);
                eventDispatcher.ExpectConversion(EventName, TestUserId);
            }

            Thread.Sleep(1000);

            Assert.True(eventDispatcher.CompareEvents());
            countdownEvent.Wait();
            Assert.AreEqual(0, EventProcessor.EventQueue.Count);

            LoggerMock.Verify(l => l.Log(LogLevel.ERROR, It.IsAny <string>()), Times.Never);
        }
예제 #2
0
        public void TestFlushOnMismatchProjectId()
        {
            var countdownEvent  = new CountdownEvent(2);
            var eventDispatcher = new TestEventDispatcher(countdownEvent);

            SetEventProcessor(eventDispatcher);

            Config.Revision  = "1";
            Config.ProjectId = "X";
            var userEvent1 = BuildConversionEvent(EventName, Config);

            EventProcessor.Process(userEvent1);
            eventDispatcher.ExpectConversion(EventName, TestUserId);

            Config.Revision  = "1";
            Config.ProjectId = "Y";
            var userEvent2 = BuildConversionEvent(EventName, Config);

            EventProcessor.Process(userEvent2);
            eventDispatcher.ExpectConversion(EventName, TestUserId);

            Thread.Sleep(1500);

            Assert.True(eventDispatcher.CompareEvents());
            Assert.True(countdownEvent.Wait(TimeSpan.FromMilliseconds(MAX_DURATION_MS * 3)), "Exceeded timeout waiting for notification.");
            Assert.AreEqual(0, EventProcessor.EventQueue.Count);
        }
예제 #3
0
        public void TestDrainOnClose()
        {
            var eventDispatcher = new TestEventDispatcher();

            SetEventProcessor(eventDispatcher);

            UserEvent userEvent = BuildConversionEvent(EventName);

            EventProcessor.Process(userEvent);
            eventDispatcher.ExpectConversion(EventName, TestUserId);

            Thread.Sleep(1500);

            Assert.True(eventDispatcher.CompareEvents());
            Assert.AreEqual(0, EventProcessor.EventQueue.Count);
        }
예제 #4
0
        public void TestDispose()
        {
            var countdownEvent  = new CountdownEvent(2);
            var eventDispatcher = new TestEventDispatcher(countdownEvent);

            SetEventProcessor(eventDispatcher);

            Assert.IsTrue(EventProcessor.IsStarted);

            UserEvent userEvent = BuildConversionEvent(EventName);

            EventProcessor.Process(userEvent);
            eventDispatcher.ExpectConversion(EventName, TestUserId);

            EventProcessor.Dispose();

            Assert.True(eventDispatcher.CompareEvents());

            // make sure, isStarted is false while dispose.
            Assert.False(EventProcessor.IsStarted);
        }
예제 #5
0
        public void TestStopAndStart()
        {
            var countdownEvent  = new CountdownEvent(2);
            var eventDispatcher = new TestEventDispatcher(countdownEvent);

            SetEventProcessor(eventDispatcher);

            UserEvent userEvent = BuildConversionEvent(EventName);

            EventProcessor.Process(userEvent);
            eventDispatcher.ExpectConversion(EventName, TestUserId);
            Thread.Sleep(1500);
            Assert.True(eventDispatcher.CompareEvents());

            EventProcessor.Stop();

            EventProcessor.Process(userEvent);
            eventDispatcher.ExpectConversion(EventName, TestUserId);
            EventProcessor.Start();
            EventProcessor.Stop();

            Assert.True(countdownEvent.Wait(TimeSpan.FromMilliseconds(MAX_DURATION_MS * 3)), "Exceeded timeout waiting for notification.");
        }