Esempio n. 1
0
        public async Task CountWithTimeSeriesAsync()
        {
            Assert.Equal(0, await _dailyRepository.CountAsync());

            var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(createdUtc: SystemClock.UtcNow.AddDays(-1)), o => o.ImmediateConsistency());

            Assert.NotNull(yesterdayLog?.Id);

            var nowLog = LogEventGenerator.Default;
            var result = await _dailyRepository.AddAsync(nowLog, o => o.ImmediateConsistency());

            Assert.Equal(nowLog, result);

            Assert.Equal(2, await _dailyRepository.CountAsync());
        }
        public async Task ScriptPatchAllWithNoCacheAsync()
        {
            var utcNow = SystemClock.UtcNow;
            var logs   = new List <LogEvent> {
                LogEventGenerator.Generate(ObjectId.GenerateNewId(utcNow.AddDays(-1)).ToString(), createdUtc: utcNow.AddDays(-1), companyId: "1"),
                LogEventGenerator.Generate(createdUtc: utcNow, companyId: "1"),
                LogEventGenerator.Generate(createdUtc: utcNow, companyId: "2"),
            };

            await _dailyRepositoryWithNoCaching.AddAsync(logs, o => o.ImmediateConsistency());

            Assert.Equal(3, await _dailyRepositoryWithNoCaching.IncrementValueAsync(q => q.Id(logs.Select(l => l.Id).ToArray())));

            var results = await _dailyRepositoryWithNoCaching.GetAllByCompanyAsync("1");

            Assert.Equal(2, results.Documents.Count);
            foreach (var document in results.Documents)
            {
                Assert.Equal("1", document.CompanyId);
                Assert.Equal(1, document.Value);
            }

            await _dailyRepositoryWithNoCaching.SaveAsync(logs, o => o.ImmediateConsistency());

            results = await _dailyRepositoryWithNoCaching.GetAllByCompanyAsync("1");

            Assert.Equal(2, results.Documents.Count);
            foreach (var document in results.Documents)
            {
                Assert.Equal("1", document.CompanyId);
                Assert.Equal(0, document.Value);
            }
        }
Esempio n. 3
0
        public async Task CountByQueryWithTimeSeriesAsync()
        {
            Assert.Equal(0, await _dailyRepository.CountAsync());

            var utcNow       = SystemClock.UtcNow;
            var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(ObjectId.GenerateNewId(utcNow.AddDays(-1)).ToString(), createdUtc: utcNow.AddDays(-1)), o => o.ImmediateConsistency());

            Assert.NotNull(yesterdayLog?.Id);

            var nowLog = await _dailyRepository.AddAsync(LogEventGenerator.Default, o => o.ImmediateConsistency());

            Assert.NotNull(nowLog?.Id);

            Assert.Equal(0, await _dailyRepository.CountBySearchAsync(null, "id:test"));
            Assert.Equal(1, await _dailyRepository.CountBySearchAsync(null, $"id:{nowLog.Id}"));
            Assert.Equal(1, await _dailyRepository.CountBySearchAsync(new RepositoryQuery().DateRange(utcNow.AddHours(-1), utcNow.AddHours(1), "createdUtc"), $"id:{nowLog.Id}"));
            Assert.Equal(0, await _dailyRepository.CountBySearchAsync(new RepositoryQuery().DateRange(utcNow.AddDays(-1), utcNow.AddHours(-12), (LogEvent l) => l.CreatedUtc), $"id:{nowLog.Id}"));
            Assert.Equal(1, await _dailyRepository.CountBySearchAsync(new RepositoryQuery().DateRange(utcNow.AddDays(-1), utcNow.AddHours(-12), "CREATEDUTC")));
            Assert.Equal(1, await _dailyRepository.CountBySearchAsync(new RepositoryQuery().DateRange(utcNow.AddHours(-1), utcNow.AddHours(1), "CreatedUtc")));
        }
Esempio n. 4
0
        public async Task CountByQueryWithTimeSeries()
        {
            Assert.Equal(0, await _dailyRepository.CountAsync());

            var utcNow       = SystemClock.UtcNow;
            var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(ObjectId.GenerateNewId(utcNow.AddDays(-1)).ToString(), createdUtc: utcNow.AddDays(-1)));

            Assert.NotNull(yesterdayLog?.Id);

            var nowLog = await _dailyRepository.AddAsync(LogEventGenerator.Default);

            Assert.NotNull(nowLog?.Id);

            await _client.RefreshAsync();

            Assert.Equal(0, await _dailyRepository.CountBySearchAsync(null, "id:test"));
            Assert.Equal(1, await _dailyRepository.CountBySearchAsync(null, $"id:{nowLog.Id}"));
            Assert.Equal(1, await _dailyRepository.CountBySearchAsync(new ElasticQuery().WithDateRange(utcNow.AddHours(-1), utcNow.AddHours(1), "created"), $"id:{nowLog.Id}"));
            Assert.Equal(0, await _dailyRepository.CountBySearchAsync(new ElasticQuery().WithDateRange(utcNow.AddDays(-1), utcNow.AddHours(-12), "created"), $"id:{nowLog.Id}"));
            Assert.Equal(1, await _dailyRepository.CountBySearchAsync(new ElasticQuery().WithDateRange(utcNow.AddDays(-1), utcNow.AddHours(-12), "created")));
            Assert.Equal(1, await _dailyRepository.CountBySearchAsync(new ElasticQuery().WithDateRange(utcNow.AddHours(-1), utcNow.AddHours(1), "created")));
        }
        public async Task GetByDateBasedIndexAsync()
        {
            await _configuration.DailyLogEvents.ConfigureAsync();


            // TODO: Fix this once https://github.com/elastic/elasticsearch-net/issues/3829 is fixed in beta2
            //var indexes = await _client.GetIndicesPointingToAliasAsync(_configuration.DailyLogEvents.Name);
            //Assert.Empty(indexes);

            var alias = await _client.Indices.GetAliasAsync(_configuration.DailyLogEvents.Name);

            _logger.LogRequest(alias);
            Assert.False(alias.IsValid);

            var utcNow = SystemClock.UtcNow;
            ILogEventRepository repository = new DailyLogEventRepository(_configuration);
            var logEvent = await repository.AddAsync(LogEventGenerator.Generate(createdUtc: utcNow));

            Assert.NotNull(logEvent?.Id);

            logEvent = await repository.AddAsync(LogEventGenerator.Generate(createdUtc: utcNow.SubtractDays(1)), o => o.ImmediateConsistency());

            Assert.NotNull(logEvent?.Id);

            alias = await _client.Indices.GetAliasAsync(_configuration.DailyLogEvents.Name);

            _logger.LogRequest(alias);
            Assert.True(alias.IsValid);
            Assert.Equal(2, alias.Indices.Count);

            var indexes = await _client.GetIndicesPointingToAliasAsync(_configuration.DailyLogEvents.Name);

            Assert.Equal(2, indexes.Count());

            await repository.RemoveAllAsync(o => o.ImmediateConsistency());

            Assert.Equal(0, await repository.CountAsync());
        }
        public async Task GetByDateBasedIndexAsync()
        {
            await _configuration.DailyLogEvents.ConfigureAsync();

            var indexes = await _client.GetIndicesPointingToAliasAsync(_configuration.DailyLogEvents.Name);

            Assert.Equal(0, indexes.Count());

            var alias = await _client.GetAliasAsync(descriptor => descriptor.Name(_configuration.DailyLogEvents.Name));

            _logger.Trace(() => alias.GetRequest());
            Assert.False(alias.IsValid);

            var utcNow     = SystemClock.UtcNow;
            var repository = new DailyLogEventRepository(_configuration);
            var logEvent   = await repository.AddAsync(LogEventGenerator.Generate(createdUtc: utcNow));

            Assert.NotNull(logEvent?.Id);

            logEvent = await repository.AddAsync(LogEventGenerator.Generate(createdUtc: utcNow.SubtractDays(1)), o => o.ImmediateConsistency());

            Assert.NotNull(logEvent?.Id);

            alias = await _client.GetAliasAsync(descriptor => descriptor.Name(_configuration.DailyLogEvents.Name));

            _logger.Trace(() => alias.GetRequest());
            Assert.True(alias.IsValid);
            Assert.Equal(2, alias.Indices.Count);

            indexes = await _client.GetIndicesPointingToAliasAsync(_configuration.DailyLogEvents.Name);

            Assert.Equal(2, indexes.Count());

            await repository.RemoveAllAsync(o => o.ImmediateConsistency());

            Assert.Equal(0, await repository.CountAsync());
        }
Esempio n. 7
0
        public async Task GetByCompanyWithIncludedFields()
        {
            var log = await _dailyRepository.AddAsync(LogEventGenerator.Generate(companyId: "1234567890", message: "test"), o => o.ImmediateConsistency());

            Assert.NotNull(log?.Id);

            var results = await _dailyRepository.GetByCompanyAsync(log.CompanyId);

            Assert.Equal(1, results.Documents.Count);
            Assert.Equal(log, results.Documents.First());

            results = await _dailyRepository.GetPartialByCompanyAsync(log.CompanyId);

            Assert.Equal(1, results.Documents.Count);
            var companyLog = results.Documents.First();

            Assert.Equal(log.Id, companyLog.Id);
            Assert.Equal(log.CreatedUtc, companyLog.CreatedUtc);
            Assert.Null(companyLog.Message);
            Assert.Null(companyLog.CompanyId);
        }
        public async Task AddWithTimeSeriesAsync()
        {
            var log = await _dailyRepository.AddAsync(LogEventGenerator.Generate());

            Assert.NotNull(log?.Id);

            Assert.Equal(log, await _dailyRepository.GetByIdAsync(log.Id));
        }