Exemple #1
0
        public void Start_NoIntervals_NoText_Failed()
        {
            var heartbeat = new hb.Heartbeat(this);

            heartbeat.Start();
            heartbeat.SetFailed();
        }
Exemple #2
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");
        }
Exemple #3
0
        public void Start_NoIntervals()
        {
            var heartbeat = new hb.Heartbeat(this);

            heartbeat.Start("Start_NoIntervals started");
            heartbeat.SetComplete("Start_NoIntervals completed");
        }
Exemple #4
0
        public void Start_InvalidState_NoInitiatingObject()
        {
            var heartbeat = new hb.Heartbeat();

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

            heartbeat.Start();
            heartbeat.SetComplete();
        }
 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");
 }
Exemple #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");
        }
Exemple #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");
        }
Exemple #9
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();
                }
            }
        }
Exemple #10
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");
            }
        }
Exemple #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");
        }
Exemple #12
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");
        }
Exemple #13
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()));
            }
        }
 public void Start_InvalidState_NoInitiatingObject()
 {
     var heartbeat = new hb.Heartbeat();
     heartbeat.PulseCountInterval = 10;
     heartbeat.Start();
 }
 public void Start_NoIntervals_NoText_Failed()
 {
     var heartbeat = new hb.Heartbeat(this);
     heartbeat.Start();
     heartbeat.SetFailed();
 }
 public void Start_NoIntervals_NoText()
 {
     var heartbeat = new hb.Heartbeat(this);
     heartbeat.Start();
     heartbeat.SetComplete();
 }
        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);
        }
 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");
 }
 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");
 }
 public void Start_NoIntervals()
 {
     var heartbeat = new hb.Heartbeat(this);
     heartbeat.Start("Start_NoIntervals started");
     heartbeat.SetComplete("Start_NoIntervals completed");
 }
 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");
 }
 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();
         }
     }
 }
     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");
     }
     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()));
 }
     }
 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");
     }
 }