Ejemplo n.º 1
0
        /// [Trait(Traits.Age, Traits.Fresh)]
        //[Trait(Traits.Style, Traits.Unit)]
        public void MessageBatching_Works_Enabled()
        {
            const int MESSAGE_BATCHSIZE = 10;

            Bilge sut = TestHelper.GetBilgeAndClearDown();

            sut.SetMessageBatching(MESSAGE_BATCHSIZE, 500000);

            sut.ActiveTraceLevel = SourceLevels.Information;
            var mmh = new MockMessageHandler();

            sut.AddHandler(mmh);

            for (int i = 0; i < 100; i++)
            {
                sut.Info.Log("Dummy Message");

                if (i % 25 == 0)
                {
                    //Thread.Sleep(100);
                    // The flush forces the write, this is needed otherwise it bombs through
                    // too fast for more than one write to the handler to occur.
                    sut.Flush();
                }

                if (mmh.TotalMessagesRecieved > 0)
                {
                    // Any time that we get a batch it must be at least MESSAGE_BATCHSIZE msgs.
                    Assert.True(mmh.LastMessageBatchSize >= MESSAGE_BATCHSIZE, $"Batch Size NotBig Enough at {i} batch Size {mmh.LastMessageBatchSize}");
                }
            }
        }
Ejemplo n.º 2
0
        private void PerformMessageTestBatchLarge(int mc)
        {
            Bilge useThis = new Bilge();

            useThis.SetMessageBatching(1000, 10000);

            for (int i = 0; i < mc; i++)
            {
                useThis.Info.Log($"Tis is the message that is averagely log {i}");
            }
        }
Ejemplo n.º 3
0
        public void ExecuteTest()
        {
            clockers.Clear();

            if (Debugger.IsAttached)
            {
                MESSAGESTOSEND = 100;
            }

            Func <Bilge> defaultBilge = () => {
                return(b);
            };

            Func <Bilge> bigBatch = () => {
                var bx = new Bilge(tl: SourceLevels.Verbose);
                bx.SetMessageBatching(1000, 5000);
                return(bx);
            };

            Func <Bilge> bilgeNoBatching = () => {
                Bilge bx = new Bilge(tl: SourceLevels.Verbose);
                bx.DisableMessageBatching();
                return(bx);
            };

            Action <string, Action <Bilge>, Bilge> runPerformanceTest = (nameOfTheTest, testMethodToExecute, bilgeInstanceToUse) => {
                clockers.Add(nameOfTheTest, new Stopwatch());
                Bilge bToUse = bilgeInstanceToUse;
                clockers[nameOfTheTest].Start();

                testMethodToExecute(bToUse);

                clockers[nameOfTheTest].Stop();
            };

            clockers.Add("main", new Stopwatch());
            clockers.Add("main-noflush", new Stopwatch());

            clockers["main"].Start();
            clockers["main-noflush"].Start();

            runPerformanceTest("singleLog-default", StandardLogOnMainThread, defaultBilge());
            runPerformanceTest("singleLog-nobatch", StandardLogOnMainThread, bilgeNoBatching());
            runPerformanceTest("singleLog-bigbatch", StandardLogOnMainThread, bigBatch());
            //runPerformanceTest("standard-onelog-nobatch", StandardLogOnMainThread, bilgeNoBatching());
            runPerformanceTest("mutilog-default", MultiLogOnMainThread, defaultBilge());

            clockers["main-noflush"].Stop();
            b.Flush();
            clockers["main"].Stop();
        }
Ejemplo n.º 4
0
        /// [Trait(Traits.Age, Traits.Fresh)]
        //[Trait(Traits.Style, Traits.Unit)]
        public void MessageBatching_Works_Timed()
        {
            const int MESSAGE_BATCHSIZE = 10000;

            Bilge sut = TestHelper.GetBilgeAndClearDown();

            sut.SetMessageBatching(MESSAGE_BATCHSIZE, 250);

            sut.ActiveTraceLevel = SourceLevels.Information;
            var mmh = new MockMessageHandler();

            sut.AddHandler(mmh);

            sut.Info.Log("Dummy Message");

            Stopwatch timeSoFar = new Stopwatch();

            timeSoFar.Start();

            bool writesFound = false;

            while (timeSoFar.Elapsed.TotalMilliseconds < 750)
            {
                // This is not particularly precise because of threading and guarantees so we are using some generous margins for error.
                // With the write time of not less than 250 we shouldnt see any writes for the first 175 MS.  If we do then its a test fail.
                // Similarly if we reach 750 ms and havent seen any writes thats a test fail.

                if (timeSoFar.ElapsedMilliseconds < 175)
                {
                    Assert.Equal(0, mmh.TotalMessagesRecieved);
                }
                else
                {
                    if (mmh.TotalMessagesRecieved > 0)
                    {
                        writesFound = true;
                        break;
                    }
                }
                if (timeSoFar.ElapsedMilliseconds > 350)
                {
                    sut.Flush();
                }
            }

            if (!writesFound)
            {
                throw new InvalidOperationException("The writes never hit the listener");
            }
        }