コード例 #1
0
ファイル: StatsTests.cs プロジェクト: mcquaiga/Exceptionless
        public async Task CanGetEventStatsAsync()
        {
            // capture start date before generating data to make sure that our time range for stats includes all items
            var       startDate  = DateTime.UtcNow.SubtractDays(60);
            const int eventCount = 100;

            await RemoveDataAsync();
            await CreateDataAsync(eventCount, false);

            _metricsClient.DisplayStats();
            var result = await _stats.GetOccurrenceStatsAsync(startDate, DateTime.UtcNow, null, userFilter : "project:" + TestConstants.ProjectId);

            Assert.Equal(eventCount, result.Total);
            Assert.Equal(eventCount, result.Timeline.Sum(t => t.Total));
            Assert.Equal(await _stackRepository.CountAsync(), result.Unique);
            Assert.Equal(await _stackRepository.CountAsync(), result.Timeline.Sum(t => t.New));

            var stacks = await _stackRepository.GetByOrganizationIdAsync(TestConstants.OrganizationId, new PagingOptions().WithLimit(100));

            foreach (var stack in stacks.Documents)
            {
                result = await _stats.GetOccurrenceStatsAsync(startDate, DateTime.UtcNow, null, userFilter : "stack:" + stack.Id);

                Console.WriteLine("{0} - {1} : {2}", stack.Id, stack.TotalOccurrences, result.Total);
                //Assert.Equal(stack.TotalOccurrences, result.Total);
                //Assert.Equal(stack.TotalOccurrences, result.Timeline.Sum(t => t.Total));
            }
        }
コード例 #2
0
        public async Task CanFindManyAsync()
        {
            Assert.Equal(0, await _repository.CountAsync());
            await _repository.AddAsync(StackData.GenerateSampleStacks());

            await RefreshDataAsync();

            var stacks = await _repository.GetByOrganizationIdAsync(TestConstants.OrganizationId, o => o.PageNumber(1).PageLimit(1));

            Assert.NotNull(stacks);
            Assert.Equal(3, stacks.Total);
            Assert.Equal(1, stacks.Documents.Count);

            var stacks2 = await _repository.GetByOrganizationIdAsync(TestConstants.OrganizationId, o => o.PageNumber(2).PageLimit(1));

            Assert.NotNull(stacks);
            Assert.Equal(1, stacks.Documents.Count);

            Assert.NotEqual(stacks.Documents.First().Id, stacks2.Documents.First().Id);

            stacks = await _repository.GetByOrganizationIdAsync(TestConstants.OrganizationId);

            Assert.NotNull(stacks);
            Assert.Equal(3, stacks.Documents.Count);

            await _repository.RemoveAsync(stacks.Documents);

            await RefreshDataAsync();

            Assert.Equal(0, await _repository.CountAsync());
        }
コード例 #3
0
ファイル: StatsTests.cs プロジェクト: zzms/Exceptionless
        public async Task CanGetNumbersAsync()
        {
            // capture start date before generating data to make sure that our time range for stats includes all items
            var       startDate  = DateTime.UtcNow.SubtractDays(60);
            const int eventCount = 100;

            await RemoveDataAsync();
            await CreateDataAsync(eventCount, false);

            var fields = FieldAggregationProcessor.Process("distinct:stack_id,term:is_first_occurrence:-F", false);

            Assert.True(fields.IsValid);
            Assert.Equal(2, fields.Aggregations.Count);

            var result = await _stats.GetNumbersTimelineStatsAsync(fields.Aggregations, startDate, DateTime.UtcNow, null, userFilter : $"project:{TestConstants.ProjectId}");

            Assert.Equal(eventCount, result.Total);
            Assert.Equal(eventCount, result.Timeline.Sum(t => t.Total));
            Assert.Equal(2, result.Numbers.Length);
            Assert.Equal(await _stackRepository.CountAsync(), result.Numbers[0]);
            Assert.Equal(await _stackRepository.CountAsync(), result.Timeline.Sum(t => t.Numbers[1]));

            var stacks = await _stackRepository.GetByOrganizationIdAsync(TestConstants.OrganizationId, new PagingOptions().WithLimit(100));

            foreach (var stack in stacks.Documents)
            {
                var nsr = await _stats.GetNumbersStatsAsync(fields.Aggregations, startDate, DateTime.UtcNow, null, userFilter : "stack:" + stack.Id);

                Assert.Equal(stack.TotalOccurrences, nsr.Total);
            }
        }
コード例 #4
0
        public async Task CanCreateUpdateRemoveAsync()
        {
            await ResetAsync();

            await _repository.RemoveAllAsync();

            await _client.RefreshAsync();

            Assert.Equal(0, await _repository.CountAsync());

            var stack = StackData.GenerateStack(projectId: TestConstants.ProjectId, organizationId: TestConstants.OrganizationId);

            Assert.Null(stack.Id);

            await _repository.AddAsync(stack);

            Assert.NotNull(stack.Id);
            await _client.RefreshAsync();

            stack = await _repository.GetByIdAsync(stack.Id);

            Assert.NotNull(stack);

            stack.Description = "New Description";
            await _repository.SaveAsync(stack);

            await _repository.RemoveAsync(stack.Id);
        }
コード例 #5
0
        public async Task CanFindManyAsync()
        {
            Assert.Equal(0, await _repository.CountAsync());
            await _repository.AddAsync(StackData.GenerateSampleStacks());

            await _configuration.Client.RefreshAsync();

            var stacks = await _repository.GetByOrganizationIdAsync(TestConstants.OrganizationId, new PagingOptions().WithPage(1).WithLimit(1));

            Assert.NotNull(stacks);
            Assert.Equal(3, stacks.Total);
            Assert.Equal(1, stacks.Documents.Count);

            var stacks2 = await _repository.GetByOrganizationIdAsync(TestConstants.OrganizationId, new PagingOptions().WithPage(2).WithLimit(1));

            Assert.NotNull(stacks);
            Assert.Equal(1, stacks.Documents.Count);

            Assert.NotEqual(stacks.Documents.First().Id, stacks2.Documents.First().Id);

            stacks = await _repository.GetByOrganizationIdAsync(TestConstants.OrganizationId);

            Assert.NotNull(stacks);
            Assert.Equal(3, stacks.Documents.Count);

            await _repository.RemoveAsync(stacks.Documents);

            await _configuration.Client.RefreshAsync();

            Assert.Equal(0, await _repository.CountAsync());
        }
コード例 #6
0
        public async Task CanGetCardinalityAggregationsAsync()
        {
            const int eventCount = 100;

            await CreateDataAsync(eventCount, false);

            Log.SetLogLevel <EventRepository>(LogLevel.Trace);

            var result = await _eventRepository.CountBySearchAsync(null, $"project:{TestConstants.ProjectId}", "cardinality:stack_id cardinality:id");

            Assert.Equal(eventCount, result.Total);
            Assert.Equal(eventCount, result.Aggregations.Cardinality("cardinality_id").Value.GetValueOrDefault());
            Assert.Equal(await _stackRepository.CountAsync(), result.Aggregations.Cardinality("cardinality_stack_id").Value.GetValueOrDefault());
        }
コード例 #7
0
        public async Task VerifyStackFilter(string filter, int expected, int?expectedInverted = null)
        {
            Log.SetLogLevel <StackRepository>(LogLevel.Trace);

            long totalStacks = await _stackRepository.CountAsync(o => o.IncludeSoftDeletes());

            var ctx         = new ElasticQueryVisitorContext();
            var stackFilter = await new EventStackFilter().GetStackFilterAsync(filter, ctx);

            _logger.LogInformation("Finding Filter: {Filter}", stackFilter.Filter);
            var stacks = await _stackRepository.FindAsync(q => q.FilterExpression(stackFilter.Filter), o => o.SoftDeleteMode(SoftDeleteQueryMode.All).PageLimit(1000));

            Assert.Equal(expected, stacks.Total);

            _logger.LogInformation("Finding Inverted Filter: {Filter}", stackFilter.InvertedFilter);
            var invertedStacks = await _stackRepository.FindAsync(q => q.FilterExpression(stackFilter.InvertedFilter), o => o.SoftDeleteMode(SoftDeleteQueryMode.All).PageLimit(1000));

            long expectedInvert = expectedInverted ?? totalStacks - expected;

            Assert.Equal(expectedInvert, invertedStacks.Total);

            var stackIds         = new HashSet <string>(stacks.Hits.Select(h => h.Id));
            var invertedStackIds = new HashSet <string>(invertedStacks.Hits.Select(h => h.Id));

            Assert.Empty(stackIds.Intersect(invertedStackIds));
        }