public void MeasureAggregatorAggregatesCorrectlyWhenMultipleThreadsUpdatesLong() { // create an aggregator MeasureMinMaxSumCountAggregator <long> aggregator = new MeasureMinMaxSumCountAggregator <long>(); var summary = aggregator.ToMetricData() as SummaryData <long>; // we start with 0. Assert.Equal(0, summary.Sum); Assert.Equal(0, summary.Count); // setup args to threads. var mre = new ManualResetEvent(false); var mreToEnsureAllThreadsStart = new ManualResetEvent(false); var argToThread = new UpdateThreadArguments <long>(); argToThread.minMaxSumCountAggregator = aggregator; argToThread.threadsStartedCount = 0; argToThread.mreToBlockUpdateThread = mre; argToThread.mreToEnsureAllThreadsStart = mreToEnsureAllThreadsStart; Thread[] t = new Thread[10]; for (int i = 0; i < 10; i++) { t[i] = new Thread(LongMetricUpdateThread); t[i].Start(argToThread); } // Block until all 10 threads started. mreToEnsureAllThreadsStart.WaitOne(); // kick-off all the threads. mre.Set(); for (int i = 0; i < 10; i++) { // wait for all threads to complete t[i].Join(); } // check point. aggregator.Checkpoint(); summary = aggregator.ToMetricData() as SummaryData <long>; // 1000000 times (10+50+100) by each thread. times 10 as there are 10 threads Assert.Equal(1600000000, summary.Sum); // 1000000 times 3 by each thread, times 10 as there are 10 threads. Assert.Equal(30000000, summary.Count); // Min and Max are 10 and 100 Assert.Equal(10, summary.Min); Assert.Equal(100, summary.Max); }
public void MeasureAggregatorSupportsDouble() { MeasureMinMaxSumCountAggregator <double> aggregator = new MeasureMinMaxSumCountAggregator <double>(); }
public void MeasureAggregatorSupportsLong() { MeasureMinMaxSumCountAggregator <long> aggregator = new MeasureMinMaxSumCountAggregator <long>(); }