Example #1
0
        public void Start_InvalidState_NoInitiatingObject()
        {
            var heartbeat = new hb.Heartbeat();

            heartbeat.PulseCountInterval = 10;
            heartbeat.Start();
        }
Example #2
0
        public void Start_NoIntervals_NoText()
        {
            var heartbeat = new hb.Heartbeat(this);

            heartbeat.Start();
            heartbeat.SetComplete();
        }
Example #3
0
        public void Start_NoIntervals_NoText_Failed()
        {
            var heartbeat = new hb.Heartbeat(this);

            heartbeat.Start();
            heartbeat.SetFailed();
        }
Example #4
0
        public void Start_NoIntervals()
        {
            var heartbeat = new hb.Heartbeat(this);

            heartbeat.Start("Start_NoIntervals started");
            heartbeat.SetComplete("Start_NoIntervals completed");
        }
Example #5
0
        public void RunCountAndTimer_NoHandler_MultiThreaded()
        {
            long   countInterval = 7000;
            long   countTo       = RandomValueGenerator.GetRandomInt(10000, 30000);
            double timerInterval = 300; //0.3 seconds
            var    runTime       = RandomValueGenerator.GetRandomInt(3 * 1000, 10 * 1000);

            _heartbeat = new hb.Heartbeat(this, countInterval, timerInterval);
            _heartbeat.Start("RunCountAndTimer_NoHandler_MultiThreaded, countInterval: {0}, countTo: {1}, timerInterval: {2}, runTime: {3}"
                             .FormatWith(countInterval, countTo, timerInterval, runTime));
            List <Thread> threads = new List <Thread>();

            for (int i = 0; i < countTo; i++)
            {
                Thread thread = new Thread(Increment);
                thread.Start();
            }
            // Wait for the threads.
            foreach (Thread thread in threads)
            {
                thread.Join();
            }
            threads.Clear();
            _heartbeat.SetComplete("RunCountAndTimer_NoHandler_MultiThreaded finished");
        }
Example #6
0
 public void RunTimer_NoHandler()
 {
     double timerInterval = 3 * 1000; //3 seconds
     var runTime = RandomValueGenerator.GetRandomInt(3 * 1000, 10 * 1000);
     var heartbeat = new hb.Heartbeat(this, 0, timerInterval);
     heartbeat.Start("RunTimer_NoHandler started, timerInterval: {0}, runTime: {1}".FormatWith(timerInterval, runTime));
     Thread.Sleep(runTime);
     heartbeat.SetComplete("RunTimer_NoHandler finished");
 }
Example #7
0
        public void RunTimer_NoHandler()
        {
            double timerInterval = 3 * 1000; //3 seconds
            var    runTime       = RandomValueGenerator.GetRandomInt(3 * 1000, 10 * 1000);
            var    heartbeat     = new hb.Heartbeat(this, 0, timerInterval);

            heartbeat.Start("RunTimer_NoHandler started, timerInterval: {0}, runTime: {1}".FormatWith(timerInterval, runTime));
            Thread.Sleep(runTime);
            heartbeat.SetComplete("RunTimer_NoHandler finished");
        }
Example #8
0
     public void RunCount_NoHandler()
     {
         long countInterval = 5000;
         long countTo = RandomValueGenerator.GetRandomInt(1000, 50000);
         var heartbeat = new hb.Heartbeat(this, countInterval, 0);
 heartbeat.Start("RunCount_NoHandler, countInterval: {0}, countTo: {1}".FormatWith(countInterval, countTo));
         for (int i = 0; i < countTo; i++)
         {
             heartbeat.IncrementCount();
         }
         heartbeat.SetComplete("RunCount_NoHandler finished");
     }
Example #9
0
        public void RunCount_NoHandler()
        {
            long countInterval = 5000;
            long countTo       = RandomValueGenerator.GetRandomInt(1000, 50000);
            var  heartbeat     = new hb.Heartbeat(this, countInterval, 0);

            heartbeat.Start("RunCount_NoHandler, countInterval: {0}, countTo: {1}".FormatWith(countInterval, countTo));
            for (int i = 0; i < countTo; i++)
            {
                heartbeat.IncrementCount();
            }
            heartbeat.SetComplete("RunCount_NoHandler finished");
        }
Example #10
0
        public void RunCount_NoCompletion()
        {
            long countInterval = 5000;
            long countTo       = RandomValueGenerator.GetRandomInt(1000, 50000);

            using (var heartbeat = new hb.Heartbeat(this, countInterval, 0))
            {
                heartbeat.Start("RunCount_NoCompletion, countInterval: {0}, countTo: {1}".FormatWith(countInterval, countTo));
                for (int i = 0; i < countTo; i++)
                {
                    heartbeat.IncrementCount();
                }
            }
        }
Example #11
0
        public void RunCountAndTimer_NoHandler_ThreadPool()
        {
            long   countInterval = 7000;
            long   countTo       = RandomValueGenerator.GetRandomInt(10000, 30000);
            double timerInterval = 300; //0.3 seconds
            var    runTime       = RandomValueGenerator.GetRandomInt(3 * 1000, 10 * 1000);

            _heartbeat = new hb.Heartbeat(this, countInterval, timerInterval);
            _heartbeat.Start("RunCountAndTimer_NoHandler_ThreadPool, countInterval: {0}, countTo: {1}, timerInterval: {2}, runTime: {3}"
                             .FormatWith(countInterval, countTo, timerInterval, runTime));
            for (int i = 0; i < countTo; i++)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(Increment), null);
            }
            _heartbeat.SetComplete("RunCountAndTimer_NoHandler_ThreadPool finished");
        }
Example #12
0
        public void RunCount()
        {
            long countInterval = 5000;
            long countTo       = RandomValueGenerator.GetRandomInt(1000, 50000);

            using (var heartbeat = new hb.Heartbeat(this, countInterval, 0))
            {
                heartbeat.OnPulse += new Sixeyed.Heartbeat.Heartbeat.OnPulseEventHanlder(RunCount_OnPulse);
                heartbeat.Start("RunCount, countInterval: {0}, countTo: {1}".FormatWith(countInterval, countTo));
                for (int i = 0; i < countTo; i++)
                {
                    heartbeat.IncrementCount();
                }
                heartbeat.SetComplete("RunCount finished");
            }
        }
Example #13
0
        public void RunCountAndTimer_NoHandler()
        {
            long   countInterval = 1000;
            long   countTo       = RandomValueGenerator.GetRandomInt(1000, 10000);
            double timerInterval = 800; //0.8 seconds
            var    runTime       = RandomValueGenerator.GetRandomInt(3 * 1000, 10 * 1000);
            var    heartbeat     = new hb.Heartbeat(this, countInterval, timerInterval);

            heartbeat.Start("RunCountAndTimer_NoHandler, countInterval: {0}, countTo: {1}, timerInterval: {2}, runTime: {3}"
                            .FormatWith(countInterval, countTo, timerInterval, runTime));
            for (int i = 0; i < countTo; i++)
            {
                heartbeat.IncrementCount();
                if (RandomValueGenerator.GetRandomBool())
                {
                    Thread.Sleep(RandomValueGenerator.GetRandomInt(2));
                }
            }
            heartbeat.SetComplete("RunCountAndTimer_NoHandler finished");
        }
Example #14
0
        public void RunCount_Failure()
        {
            long countInterval = 5000;
            long countTo       = RandomValueGenerator.GetRandomInt(1000, 50000);
            var  heartbeat     = new hb.Heartbeat(this, countInterval, 0);

            heartbeat.Start("RunCount_NoHandler, countInterval: {0}, countTo: {1}".FormatWith(countInterval, countTo));
            try
            {
                for (int i = 0; i < countTo; i++)
                {
                    heartbeat.IncrementCount();
                }
                var zero = 0;
                var dbz  = 1 / zero;
                heartbeat.SetComplete("RunCount_NoHandler finished");
            }
            catch (Exception ex)
            {
                heartbeat.SetFailed("RunCount_NoHandler failed, message: {0}".FormatWith(ex.FullMessage()));
            }
        }
Example #15
0
 public void RunCount()
 {
     long countInterval = 5000;
     long countTo = RandomValueGenerator.GetRandomInt(1000, 50000);
     using (var heartbeat = new hb.Heartbeat(this, countInterval, 0))
     {
         heartbeat.OnPulse += new Sixeyed.Heartbeat.Heartbeat.OnPulseEventHanlder(RunCount_OnPulse);
         heartbeat.Start("RunCount, countInterval: {0}, countTo: {1}".FormatWith(countInterval, countTo));
         for (int i = 0; i < countTo; i++)
         {
             heartbeat.IncrementCount();
         }
         heartbeat.SetComplete("RunCount finished");
     }
 }
Example #16
0
 public void Start_NoIntervals_NoText_Failed()
 {
     var heartbeat = new hb.Heartbeat(this);
     heartbeat.Start();
     heartbeat.SetFailed();
 }
Example #17
0
 public void Start_InvalidState_NoInitiatingObject()
 {
     var heartbeat = new hb.Heartbeat();
     heartbeat.PulseCountInterval = 10;
     heartbeat.Start();
 }
Example #18
0
 private void DoWork(Heartbeat heartbeat, long taskIndex, long finalTaskIndex)
 {
     heartbeat.IncrementCount();
     //fake work:
     if (RandomValueGenerator.GetRandomBool())
     {
         Thread.Sleep(RandomValueGenerator.GetRandomInt(2));
     }            
     if (taskIndex == finalTaskIndex)
     {
         heartbeat.SetComplete("RunCountAndTimer_NoHandler_WithTasks finished");
     }
 }
Example #19
0
 public void Start_NoIntervals_NoText()
 {
     var heartbeat = new hb.Heartbeat(this);
     heartbeat.Start();
     heartbeat.SetComplete();
 }
Example #20
0
        public void RunCountAndTimer_NoHandler_WithTasks()
        {

            long countTo = RandomValueGenerator.GetRandomInt(20000, 50000);
            long countInterval = 7000;
            double timerInterval = 300; //0.3 seconds
            var heartbeat = new Heartbeat(this, countInterval, timerInterval);
            heartbeat.Start("RunCountAndTimer_NoHandler_WithTasks, countInterval: {0}, countTo: {1}, timerInterval: {2}"
                                .FormatWith(countInterval, countTo, timerInterval));
            var tasks = new Task[countTo];
            long finalTaskIndex = countTo - 1;
            for (long i = 0; i < countTo; i++)
            {
                var taskIndex = i;
                tasks[i] = Task.Factory.StartNew(() => DoWork(heartbeat, taskIndex, finalTaskIndex));
            }
            //for long-running async calls, this wouldn't be used, but
            //the unit test will not allow all threads to complete otherwise:
            Task.WaitAll(tasks);
        }
Example #21
0
 public void RunCountAndTimer_NoHandler_MultiThreaded()
 {
     long countInterval = 7000;
     long countTo = RandomValueGenerator.GetRandomInt(10000, 30000);
     double timerInterval = 300; //0.3 seconds
     var runTime = RandomValueGenerator.GetRandomInt(3 * 1000, 10 * 1000);
     _heartbeat = new hb.Heartbeat(this, countInterval, timerInterval);
     _heartbeat.Start("RunCountAndTimer_NoHandler_MultiThreaded, countInterval: {0}, countTo: {1}, timerInterval: {2}, runTime: {3}"
                         .FormatWith(countInterval, countTo, timerInterval, runTime));
     List<Thread> threads = new List<Thread>();
     for (int i = 0; i < countTo; i++)
     {
         Thread thread = new Thread(Increment);
         thread.Start();
     }
     // Wait for the threads.
     foreach (Thread thread in threads)
     {
         thread.Join();
     }
     threads.Clear();
     _heartbeat.SetComplete("RunCountAndTimer_NoHandler_MultiThreaded finished");
 }
Example #22
0
 public void RunCountAndTimer_NoHandler_ThreadPool()
 {
     long countInterval = 7000;
     long countTo = RandomValueGenerator.GetRandomInt(10000, 30000);
     double timerInterval = 300; //0.3 seconds
     var runTime = RandomValueGenerator.GetRandomInt(3 * 1000, 10 * 1000);
     _heartbeat = new hb.Heartbeat(this, countInterval, timerInterval);
     _heartbeat.Start("RunCountAndTimer_NoHandler_ThreadPool, countInterval: {0}, countTo: {1}, timerInterval: {2}, runTime: {3}"
                         .FormatWith(countInterval, countTo, timerInterval, runTime));
     for (int i = 0; i < countTo; i++)
     {
         ThreadPool.QueueUserWorkItem(new WaitCallback(Increment), null);
     }
     _heartbeat.SetComplete("RunCountAndTimer_NoHandler_ThreadPool finished");
 }
Example #23
0
 public void Start_NoIntervals()
 {
     var heartbeat = new hb.Heartbeat(this);
     heartbeat.Start("Start_NoIntervals started");
     heartbeat.SetComplete("Start_NoIntervals completed");
 }
Example #24
0
 public void RunCountAndTimer_NoHandler()
 {
     long countInterval = 1000;
     long countTo = RandomValueGenerator.GetRandomInt(1000, 10000);
     double timerInterval = 800; //0.8 seconds
     var runTime = RandomValueGenerator.GetRandomInt(3 * 1000, 10 * 1000);
     var heartbeat = new hb.Heartbeat(this, countInterval, timerInterval);
     heartbeat.Start("RunCountAndTimer_NoHandler, countInterval: {0}, countTo: {1}, timerInterval: {2}, runTime: {3}"
                         .FormatWith(countInterval, countTo, timerInterval, runTime));
     for (int i = 0; i < countTo; i++)
     {
         heartbeat.IncrementCount();
         if (RandomValueGenerator.GetRandomBool())
         {
             Thread.Sleep(RandomValueGenerator.GetRandomInt(2));
         }
     }
     heartbeat.SetComplete("RunCountAndTimer_NoHandler finished");
 }
Example #25
0
     public void RunCount_Failure()
     {
         long countInterval = 5000;
         long countTo = RandomValueGenerator.GetRandomInt(1000, 50000);
 var heartbeat = new hb.Heartbeat(this, countInterval, 0);
 heartbeat.Start("RunCount_NoHandler, countInterval: {0}, countTo: {1}".FormatWith(countInterval, countTo));
 try
 {
     for (int i = 0; i < countTo; i++)
     {
         heartbeat.IncrementCount();
     }
     var zero = 0;
     var dbz = 1 / zero;
     heartbeat.SetComplete("RunCount_NoHandler finished");
 }
 catch (Exception ex)
 {
     heartbeat.SetFailed("RunCount_NoHandler failed, message: {0}".FormatWith(ex.FullMessage()));
 }
     }
Example #26
0
 public void RunCount_NoCompletion()
 {
     long countInterval = 5000;
     long countTo = RandomValueGenerator.GetRandomInt(1000, 50000);
     using (var heartbeat = new hb.Heartbeat(this, countInterval, 0))
     {
         heartbeat.Start("RunCount_NoCompletion, countInterval: {0}, countTo: {1}".FormatWith(countInterval, countTo));
         for (int i = 0; i < countTo; i++)
         {
             heartbeat.IncrementCount();
         }
     }
 }