private void Assert_AppMetricsCollection_CorrectlyInitialized(IEnumerable <AppMetric> expectedMetrics,
                                                                      AppMetricsCollection metrics)
        {
            IEnumerable <AppMetricId> actualMetricIds = metrics
                                                        .ExportedMetrics;

            Assert.AreEqual(expectedMetrics.Count(),
                            actualMetricIds.Count());

            foreach (AppMetric expectedMetric in expectedMetrics)
            {
                CollectionAssert.Contains(actualMetricIds, expectedMetric.Id);
            }

            foreach (AppMetric m in expectedMetrics)
            {
                AppMetric metric = metrics.QueryMetric(m.Id);
                Assert.NotNull(metric);
                Assert.AreEqual(m.Value, metric.Value);
            }

            Assert.AreEqual(expectedMetrics.Count(), metrics
                            .CollectMetrics()
                            .Count());
        }
        public void Test_CanUpdateMetric_Add(int times)
        {
            Faker faker =
                new Faker();

            AppMetricId[] targetMetricIds = AppMetricId
                                            .BuiltInAppMetricIds
                                            .ToArray();

            long expectedTotal = 0;

            AppMetricsCollection metrics = new AppMetricsCollection(targetMetricIds);

            for (int i = 0; i < times; i++)
            {
                long randomValToAdd = faker.Random.Long(0, 100000);

                foreach (AppMetricId metricId in targetMetricIds)
                {
                    metrics.UpdateMetric(metricId, m => m.Add(randomValToAdd));
                }

                expectedTotal += randomValToAdd;
            }

            foreach (AppMetricId metricId in targetMetricIds)
            {
                Assert.AreEqual(expectedTotal, metrics.QueryMetric(metricId).Value);
            }
        }
        public void Test_CanUpdateMetric_Decrement(int times)
        {
            Faker faker =
                new Faker();

            AppMetricId[] targetMetricIds = AppMetricId
                                            .BuiltInAppMetricIds
                                            .ToArray();

            long initialValue = times * faker.Random
                                .Long(1, 100000);

            AppMetricsCollection metrics = new AppMetricsCollection(targetMetricIds
                                                                    .Select(mId => new AppMetric(mId, initialValue))
                                                                    .ToArray());

            for (int i = 0; i < times; i++)
            {
                foreach (AppMetricId metricId in targetMetricIds)
                {
                    metrics.UpdateMetric(metricId, m => m.Decrement());
                }
            }

            foreach (AppMetricId metricId in targetMetricIds)
            {
                Assert.AreEqual(initialValue - times, metrics.QueryMetric(metricId).Value);
            }
        }
Esempio n. 4
0
 public IEnumerable <AppMetric> CollectMetrics()
 {
     return(AppMetricsCollection.JoinCollectMetrics(mTaskBuffer,
                                                    mTaskPoller,
                                                    mTaskQueueConsumer,
                                                    mTaskResultQueue,
                                                    mExecutionPerfMon,
                                                    AppMetricsCollection.JoinProviders(mWorkers)));
 }
Esempio n. 5
0
 public AppMetric QueryMetric(AppMetricId metricId)
 {
     return(AppMetricsCollection.JoinQueryMetric(metricId,
                                                 mTaskBuffer,
                                                 mTaskPoller,
                                                 mTaskQueueConsumer,
                                                 mTaskResultQueue,
                                                 mExecutionPerfMon,
                                                 AppMetricsCollection.JoinProviders(mWorkers)));
 }
        private async Task CollectMetricsAsync()
        {
            IEnumerable <AppMetric> metrics = AppMetricsCollection
                                              .JoinCollectMetrics(mProviders.ToArray());

            if (metrics.Count() > 0)
            {
                await mWriter.WriteAsync(metrics);
            }
        }
        public void Test_CanCreateAppMetricsCollection_FromAppMetricIds_AllBuiltInAppIds()
        {
            AppMetricId[] expectedMetricIds = AppMetricId
                                              .BuiltInAppMetricIds
                                              .ToArray();

            AppMetricsCollection metrics = new AppMetricsCollection(expectedMetricIds);

            Assert_AppMetricsCollection_CorrectlyInitialized(expectedMetricIds,
                                                             metrics);
        }
        private AppMetricsCollection[] GetCollectionsFromMetricIdsBatchesWithInitialValues(List <AppMetricId>[] metricIdsBatches)
        {
            AppMetricsCollection[] collectionBatches =
                new AppMetricsCollection[metricIdsBatches.Length];

            for (int i = 0; i < metricIdsBatches.Length; i++)
            {
                collectionBatches[i] = new AppMetricsCollection(metricIdsBatches[i]
                                                                .ToArray());
            }

            return(collectionBatches);
        }
        private void Assert_CorrectJoinQueryAppMetrics(IEnumerable <AppMetricId> checkMetricIds,
                                                       AppMetricsCollection[] collectionBatches)
        {
            foreach (AppMetricId metricId in checkMetricIds)
            {
                long expectedValue = SumMetricValues(collectionBatches,
                                                     metricId);

                AppMetric metric = AppMetricsCollection.JoinQueryMetric(metricId,
                                                                        collectionBatches);

                Assert.NotNull(metric);
                Assert.AreEqual(expectedValue, metric.Value);
            }
        }
        public void Test_CanCreateAppMetricsCollection_FromAppMetrics()
        {
            int   iMetric = 0;
            Faker faker   = new Faker();

            AppMetric[] expecteMetrics = new AppMetric[AppMetricId.BuiltInAppMetricIds.Count()];

            foreach (AppMetricId mId in AppMetricId.BuiltInAppMetricIds)
            {
                expecteMetrics[iMetric++] = new AppMetric(mId, faker.Random.Long(0));
            }

            AppMetricsCollection metrics = new AppMetricsCollection(expecteMetrics);

            Assert_AppMetricsCollection_CorrectlyInitialized(expecteMetrics, metrics);
        }
        public void Test_JoinMetricsFromProviders_NoOverlappingMetricIds_DefaultInitialValues(int nCollections)
        {
            List <AppMetricId>[] metricIdsBatches =
                GetAppMetricIdsBatches(nCollections);

            List <AppMetricId> expectedMetricIds =
                GetUniqueMetricIds(metricIdsBatches);

            AppMetricsCollection[] collections =
                GetCollectionsFromMetricIdsBatchesWithInitialValues(metricIdsBatches);

            AppMetricsCollection finalCollection = AppMetricsCollection
                                                   .JoinProviders(collections);

            Assert_AppMetricsCollection_CorrectlyInitialized(expectedMetricIds,
                                                             finalCollection);
        }
        public void Test_CanJoinExportedMetrics_NoOverlappingMetricIds(int nCollections)
        {
            List <AppMetricId>[] metricIdsBatches =
                GetAppMetricIdsBatches(nCollections);

            List <AppMetricId> expectedMetricIds =
                GetUniqueMetricIds(metricIdsBatches);

            AppMetricsCollection[] collections =
                GetCollectionsFromMetricIdsBatchesWithInitialValues(metricIdsBatches);

            IEnumerable <AppMetricId> metricIds = AppMetricsCollection
                                                  .JoinExportedMetrics(collections);

            Assert.NotNull(metricIds);
            CollectionAssert.AreEquivalent(expectedMetricIds,
                                           metricIds);
        }
        public void Test_CanCreateAppMetricsCollection_FromAppMetricIds_SpecificAppIds()
        {
            AppMetricId[] expectedMetricIds = new AppMetricId[]
            {
                AppMetricId.BufferMaxCount,
                AppMetricId.BufferMinCount,
                AppMetricId.BufferTimesEmptied,
                AppMetricId.BufferTimesFilled,
                AppMetricId.ListenerNotificationWaitTimeoutCount,
                AppMetricId.ListenerReconnectCount,
                AppMetricId.ListenerTaskNotificationCount
            };

            AppMetricsCollection metrics = new AppMetricsCollection(expectedMetricIds);

            Assert_AppMetricsCollection_CorrectlyInitialized(expectedMetricIds,
                                                             metrics);
        }
        public void Test_JoinMetricsFromProviders_WithOverlappingMetricIds_CustomInitialValues(int nCollections)
        {
            List <AppMetricId>[] metricIdsBatches =
                GetAppMetricIdsBatches(nCollections);

            metricIdsBatches = InterleaveAppMetricIdsBatches(metricIdsBatches);

            AppMetricsCollection[] collections =
                GetCollectionsFromMetricIdsBatchesWithCustomValues(metricIdsBatches);

            List <AppMetric> expectedMetrics =
                MergeAppMetrics(collections);

            AppMetricsCollection finalCollection = AppMetricsCollection
                                                   .JoinProviders(collections);

            Assert_AppMetricsCollection_CorrectlyInitialized(expectedMetrics,
                                                             finalCollection);
        }
        public void Test_JoinMetricsFromProviders_SameMetricIds_CustomInitialValues(int nCollections)
        {
            AppMetricId[] allMetricIds = AllBuiltInMetricIds;

            List <AppMetricId>[] metricIdsBatches = allMetricIds
                                                    .MultiplyCollection(nCollections);

            AppMetricsCollection[] collections =
                GetCollectionsFromMetricIdsBatchesWithCustomValues(metricIdsBatches);

            List <AppMetric> expectedMetrics =
                MergeAppMetrics(collections);

            AppMetricsCollection finalCollection = AppMetricsCollection
                                                   .JoinProviders(collections);

            Assert_AppMetricsCollection_CorrectlyInitialized(expectedMetrics,
                                                             finalCollection);
        }
        private AppMetricsCollection[] GetCollectionsFromMetricIdsBatchesWithCustomValues(List <AppMetricId>[] metricIdsBatches)
        {
            Faker faker =
                new Faker();

            AppMetricsCollection[] collectionBatches =
                new AppMetricsCollection[metricIdsBatches.Length];

            for (int i = 0; i < metricIdsBatches.Length; i++)
            {
                List <AppMetric> metrics = faker.RandomAppMetrics(metricIdsBatches[i],
                                                                  minValue: 0,
                                                                  maxValue: 100000);

                collectionBatches[i] = new AppMetricsCollection(metrics
                                                                .ToArray());
            }

            return(collectionBatches);
        }
        public void Test_CanJoinExportedMetrics_SameMetricIds(int nCollections)
        {
            AppMetricId[] allMetricIds = AllBuiltInMetricIds;

            List <AppMetricId> expectedMetricIds =
                new List <AppMetricId>(allMetricIds);

            List <AppMetricId>[] metricIdsBatches = allMetricIds
                                                    .MultiplyCollection(nCollections);

            AppMetricsCollection[] collections =
                GetCollectionsFromMetricIdsBatchesWithInitialValues(metricIdsBatches);

            IEnumerable <AppMetricId> metricIds = AppMetricsCollection
                                                  .JoinExportedMetrics(collections);

            Assert.NotNull(metricIds);
            CollectionAssert.AreEquivalent(expectedMetricIds,
                                           metricIds);
        }
        public void Test_CanUpdateMetric_Increment(int times)
        {
            AppMetricId[] targetMetricIds = AppMetricId
                                            .BuiltInAppMetricIds
                                            .ToArray();

            AppMetricsCollection metrics = new AppMetricsCollection(targetMetricIds);

            for (int i = 0; i < times; i++)
            {
                foreach (AppMetricId metricId in targetMetricIds)
                {
                    metrics.UpdateMetric(metricId, m => m.Increment());
                }
            }

            foreach (AppMetricId metricId in targetMetricIds)
            {
                Assert.AreEqual(times, metrics.QueryMetric(metricId).Value);
            }
        }
        public void Test_CanJoinQueryMetric_AbsentFromAllProviders(int nCollections)
        {
            AppMetricId[] allMetricIds = AllBuiltInMetricIds;

            foreach (AppMetricId testMetricId in allMetricIds)
            {
                AppMetricId[] metricIds = AllBuiltInMetricIds
                                          .Where(m => !m.Equals(testMetricId))
                                          .ToArray();

                List <AppMetricId>[] metricIdsBatches = metricIds
                                                        .MultiplyCollection(nCollections);

                AppMetricsCollection[] collections =
                    GetCollectionsFromMetricIdsBatchesWithCustomValues(metricIdsBatches);

                AppMetric testMetric = AppMetricsCollection.JoinQueryMetric(testMetricId,
                                                                            collections);

                Assert.IsNull(testMetric);
            }
        }
        public void Test_CanUpdateMetric_ReplaceValue(int times)
        {
            Faker faker =
                new Faker();

            AppMetricId[] targetMetricIds = AppMetricId
                                            .BuiltInAppMetricIds
                                            .ToArray();

            AppMetricsCollection metrics = new AppMetricsCollection(targetMetricIds);

            for (int i = 0; i < times; i++)
            {
                foreach (AppMetricId metricId in targetMetricIds)
                {
                    long randomNewVal = faker.Random.Long();
                    metrics.UpdateMetric(metricId, m => m.Update(randomNewVal));

                    Assert.AreEqual(randomNewVal, metrics
                                    .QueryMetric(metricId)
                                    .Value);
                }
            }
        }
 public AppMetric QueryMetric(AppMetricId metricId)
 {
     return(AppMetricsCollection.JoinQueryMetric(metricId,
                                                 mMetrics,
                                                 mNotificationListener));
 }
 public IEnumerable <AppMetric> CollectMetrics()
 {
     return(AppMetricsCollection.JoinCollectMetrics(mMetrics,
                                                    mNotificationListener));
 }