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 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"))); }
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()); }
public async Task SaveWithOutOfSyncIndexAsync() { var utcNow = SystemClock.UtcNow; var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(ObjectId.GenerateNewId().ToString(), createdUtc: utcNow.AddDays(-1)), o => o.ImmediateConsistency()); Assert.NotNull(yesterdayLog?.Id); Assert.Equal(1, await _dailyRepository.CountAsync()); yesterdayLog.Message = "updated"; await _dailyRepository.SaveAsync(yesterdayLog, o => o.ImmediateConsistency()); Assert.Equal(1, await _dailyRepository.CountAsync()); }