public void SaveFundingTotals_GivenPublishedProfilingRequestsButProfilingAPICausesException_LogsAndThrows()
        {
            //Arrange
            IEnumerable <FundingLine> fundingLines = SetUpInput();

            ILogger logger = CreateLogger();

            IProfilingApiClient providerProfilingRepository = Substitute.For <IProfilingApiClient>();
            ValidatedApiResponse <ProviderProfilingResponseModel> providerProfilingResponseModel =
                new ValidatedApiResponse <ProviderProfilingResponseModel>(HttpStatusCode.InternalServerError);

            providerProfilingRepository
            .GetProviderProfilePeriods(Arg.Any <ProviderProfilingRequestModel>())
            .Returns(providerProfilingResponseModel);

            ProfilingService service = CreateProfilingService(
                logger: logger,
                profilingApiClient: providerProfilingRepository);

            //Act
            Func <Task> test = async() => await service.ProfileFundingLines(fundingLines, "PSG", "AY-1819");

            //Assert
            test
            .Should()
            .ThrowExactly <NonRetriableException>()
            .Which
            .Message
            .Should()
            .Be("Failed to Get Profile Periods for updating for Requested FundingPeriodId: 'AY-1819' and FundingStreamId: 'PSG'");

            logger
            .Received(1)
            .Error(Arg.Is("Failed to Get Profile Periods for updating for Requested FundingPeriodId: 'AY-1819' and FundingStreamId: 'PSG'"));
        }
        public void SaveFundingTotals_GivenPublishedProfilingRequestsButProfilingAPIReturnNoResults_LogsAndThrows()
        {
            //Arrange
            IEnumerable <FundingLine> fundingLines = SetUpInput();

            ILogger logger = CreateLogger();

            SetUpProviderProfilingResponse();

            IProfilingApiClient providerProfilingRepository = Substitute.For <IProfilingApiClient>();

            providerProfilingRepository
            .GetProviderProfilePeriods(Arg.Any <ProviderProfilingRequestModel>())
            .Returns(Task.FromResult <ValidatedApiResponse <ProviderProfilingResponseModel> >(null));

            ProfilingService serviceapi = CreateProfilingService(
                logger: logger,
                profilingApiClient: providerProfilingRepository);

            //Act
            Func <Task> test = async() => await serviceapi.ProfileFundingLines(fundingLines, "PSG", "AY-1819");

            //Assert
            logger
            .Received(0)
            .Error(Arg.Is("Failed to Get Profile Periods for updating  for Requested FundingPeriodId"));
        }
Пример #3
0
        public void Load(HeapBuddyProfilingSnapshot snapshot)
        {
            this.snapshot = snapshot;

            foreach (Type type in snapshot.Outfile.Types)
            {
                store.AppendValues("md-class", type.Name, type.LastObjectStats.AllocatedCount.ToString(),
                                   ProfilingService.PrettySize(type.LastObjectStats.AllocatedTotalBytes),
                                   String.Format("{0:0.0}", type.LastObjectStats.AllocatedAverageBytes),
                                   String.Format("{0:0.0}", type.LastObjectStats.AllocatedAverageAge),
                                   type.BacktraceCount.ToString(), type);
            }
        }
        public async Task SaveMultipleFundinglines_GivenPublishedProfilingRequests()
        {
            //Arrange
            List <FundingLine> fundingLines = new List <FundingLine>
            {
                new FundingLine {
                    Name = "Abc", FundingLineCode = "FL1", Type = FundingLineType.Payment, Value = 500, TemplateLineId = 123, DistributionPeriods = null
                },
                new FundingLine {
                    Name = "Xyz", FundingLineCode = "AB1", Type = FundingLineType.Payment, Value = 600, TemplateLineId = 123, DistributionPeriods = null
                }
            };

            ILogger logger = CreateLogger();
            ValidatedApiResponse <ProviderProfilingResponseModel> profileResponse = SetUpProviderProfilingResponse();

            IProfilingApiClient providerProfilingRepository = Substitute.For <IProfilingApiClient>();

            providerProfilingRepository
            .GetProviderProfilePeriods(Arg.Any <ProviderProfilingRequestModel>())
            .Returns(Task.FromResult(profileResponse));

            ProfilingService serviceapi = CreateProfilingService(
                logger: logger,
                profilingApiClient: providerProfilingRepository);

            //Act
            await serviceapi.ProfileFundingLines(fundingLines, "PSG", "AY-1819");

            //Assert
            fundingLines.Where(y => y.Value == 500)
            .Select(r => r.DistributionPeriods)
            .Should()
            .NotBeNullOrEmpty();

            fundingLines.Where(y => y.Value == 600)
            .Select(r => r.DistributionPeriods)
            .Should()
            .NotBeNullOrEmpty();

            await providerProfilingRepository
            .Received(1)
            .GetProviderProfilePeriods(Arg.Is <ProviderProfilingRequestModel>(m =>
                                                                              m.FundingValue == 500));

            await providerProfilingRepository
            .Received(1)
            .GetProviderProfilePeriods(Arg.Is <ProviderProfilingRequestModel>(m =>
                                                                              m.FundingValue == 600));
        }
        public void SaveFundingTotals_GivenNullPublishedProfilingFundlingTotalsRequests_ThrowsArgumentException()
        {
            //Arrange
            List <FundingLine> fundingLines = new List <FundingLine>();

            ProfilingService service = CreateProfilingService();

            //Act
            Func <Task> test = async() => await service.ProfileFundingLines(fundingLines, "PSG", "AY-1819");

            //Assert
            test
            .Should()
            .ThrowExactly <ArgumentNullException>();
        }
        public async Task SaveFundingTotals_GivenPublishedProfilingRequestsReturnProfilePatternKey()
        {
            //Arrange
            IEnumerable <FundingLine>       fundingLines       = SetUpInput();
            IEnumerable <ProfilePatternKey> profilePatternKeys = SetUpProfilePatternKeyt();

            ILogger logger = CreateLogger();

            ValidatedApiResponse <ProviderProfilingResponseModel> profileResponse = SetUpProviderProfilingResponse();

            IProfilingApiClient providerProfilingRepository = Substitute.For <IProfilingApiClient>();

            providerProfilingRepository
            .GetProviderProfilePeriods(Arg.Any <ProviderProfilingRequestModel>())
            .Returns(Task.FromResult(profileResponse));

            ProfilingService serviceapi = CreateProfilingService(
                logger: logger,
                profilingApiClient: providerProfilingRepository);

            //Act
            IEnumerable <ProfilePatternKey> result = await serviceapi.ProfileFundingLines(fundingLines, "PSG", "AY-1819",
                                                                                          profilePatternKeys, "productType", "productSubType");

            //Assert
            fundingLines.Where(y => y.Type == FundingLineType.Payment)
            .Select(r => r.DistributionPeriods)
            .Should()
            .NotBeNullOrEmpty();

            IEnumerable <FundingLine> expectedFundingLines;

            expectedFundingLines = ExpectedOutput();
            JsonConvert
            .SerializeObject(expectedFundingLines)
            .Should()
            .BeEquivalentTo(JsonConvert.SerializeObject(fundingLines));

            await providerProfilingRepository
            .Received(1)
            .GetProviderProfilePeriods(Arg.Is <ProviderProfilingRequestModel>(m =>
                                                                              m.FundingValue == 500));

            result.Select(m => m.Key)
            .Should()
            .BeEquivalentTo("ProfilePatthernKey1");
        }
Пример #7
0
        public void Load(HeapBuddyProfilingSnapshot snapshot)
        {
            this.snapshot = snapshot;

            foreach (Backtrace bt in snapshot.Outfile.Backtraces)
            {
                TreeIter iter = store.AppendValues("md-class", bt.Type.Name, bt.LastObjectStats.AllocatedCount.ToString(),
                                                   ProfilingService.PrettySize(bt.LastObjectStats.AllocatedTotalBytes),
                                                   String.Format("{0:0.0}", bt.LastObjectStats.AllocatedAverageBytes),
                                                   String.Format("{0:0.0}", bt.LastObjectStats.AllocatedAverageAge), bt);

                foreach (Frame frame in bt.Frames)
                {
                    if (!frame.MethodName.StartsWith("(wrapper"))
                    {
                        store.AppendValues(iter, "md-method", frame.MethodName, String.Empty, String.Empty,
                                           String.Empty, String.Empty, frame);
                    }
                }
            }
        }
        public void SaveFundingTotals_GivenPublishedProfilingRequestsButNoPaymentTypeinFundingTotals_LogsAndThrows()
        {
            //Arrange
            List <FundingLine> fundingLines = new List <FundingLine>
            {
                new FundingLine {
                    Name = "Abc", FundingLineCode = "FL1", Type = FundingLineType.Information, Value = 500, TemplateLineId = 123, DistributionPeriods = null
                }
            };

            ILogger logger = CreateLogger();

            ProfilingService service = CreateProfilingService(logger: logger);

            //Act
            Func <Task> test = async() => await service.ProfileFundingLines(fundingLines, "PSG", "AY-1819");

            //Assert

            logger
            .Received(0)
            .Error(Arg.Is("No Funding Values of Type Payment in the Funding Totals for updating."));
        }
        public override void DeleteItem()
        {
            IProfilingSnapshot snapshot = (IProfilingSnapshot)CurrentNode.DataItem;

            ProfilingService.RemoveSnapshot(snapshot);
        }
Пример #10
0
        public void Load(HeapBuddyProfilingSnapshot snapshot)
        {
            this.snapshot = snapshot;
            OutfileReader reader = snapshot.Outfile;

            Resize[] resizes = reader.Resizes;
            Gc[]     gcs     = reader.Gcs;

            int  i_resize  = 0;
            int  i_gc      = 0;
            long heap_size = 0;

            while (i_resize < resizes.Length || i_gc < gcs.Length)
            {
                Resize r = null;
                if (i_resize < resizes.Length)
                {
                    r = resizes [i_resize];
                }

                Gc gc = null;
                if (i_gc < gcs.Length)
                {
                    gc = gcs [i_gc];
                }

                string timestamp, tag, message;

                if (r != null && (gc == null || r.Generation <= gc.Generation))
                {
                    timestamp = string.Format("{0:HH:mm:ss}", r.Timestamp);

                    if (r.PreviousSize == 0)
                    {
                        tag     = GettextCatalog.GetString("Init");
                        message = String.Format(GettextCatalog.GetString("Initialized heap to {0}"),
                                                ProfilingService.PrettySize(r.NewSize));
                    }
                    else
                    {
                        tag     = GettextCatalog.GetString("Resize");
                        message = String.Format(GettextCatalog.GetString("Grew heap from {0} to {1}") +
                                                Environment.NewLine +
                                                GettextCatalog.GetString("{2} in {3} live objects") +
                                                Environment.NewLine +
                                                GettextCatalog.GetString("Heap went from {4:0.0}% to {5:0.0}% capacity"),
                                                ProfilingService.PrettySize(r.PreviousSize),
                                                ProfilingService.PrettySize(r.NewSize),
                                                ProfilingService.PrettySize(r.TotalLiveBytes),
                                                r.TotalLiveObjects,
                                                r.PreResizeCapacity, r.PostResizeCapacity);
                    }

                    heap_size = r.NewSize;
                    ++i_resize;
                }
                else
                {
                    timestamp = String.Format("{0:HH:mm:ss}", gc.Timestamp);
                    if (gc.Generation >= 0)
                    {
                        tag     = GettextCatalog.GetString("GC ") + gc.Generation;
                        message = String.Format(GettextCatalog.GetString("Collected {0} of {1} objects ({2:0.0}%)") +
                                                Environment.NewLine +
                                                GettextCatalog.GetString("Collected {3} of {4} ({5:0.0}%)") +
                                                Environment.NewLine +
                                                GettextCatalog.GetString("Heap went from {6:0.0}% to {7:0.0}% capacity"),
                                                gc.FreedObjects,
                                                gc.PreGcLiveObjects,
                                                gc.FreedObjectsPercentage,
                                                ProfilingService.PrettySize(gc.FreedBytes),
                                                ProfilingService.PrettySize(gc.PreGcLiveBytes),
                                                gc.FreedBytesPercentage,
                                                100.0 * gc.PreGcLiveBytes / heap_size,
                                                100.0 * gc.PostGcLiveBytes / heap_size);
                    }
                    else
                    {
                        tag     = GettextCatalog.GetString("Exit");
                        message = String.Format(GettextCatalog.GetString("{0} live objects using {1}"),
                                                gc.PreGcLiveObjects,
                                                ProfilingService.PrettySize(gc.PreGcLiveBytes));
                    }
                    ++i_gc;
                }

                store.AppendValues(timestamp, tag, message);
            }
        }