public async Task GetByCreatedDate() { var log = await _dailyRepository.AddAsync(LogEventGenerator.Generate(companyId: "1234567890", message: "test", createdUtc: SystemClock.UtcNow), o => o.ImmediateConsistency()); Assert.NotNull(log?.Id); var results = await _dailyRepository.GetByDateRange(SystemClock.UtcNow.SubtractDays(1), SystemClock.UtcNow.AddDays(1)); Assert.Equal(log, results.Documents.Single()); results = await _dailyRepository.GetByDateRange(SystemClock.UtcNow.SubtractDays(1), DateTime.MaxValue); Assert.Equal(log, results.Documents.Single()); results = await _dailyRepository.GetByDateRange(DateTime.MinValue, SystemClock.UtcNow.AddDays(1)); Assert.Equal(log, results.Documents.Single()); results = await _dailyRepository.GetByDateRange(DateTime.MinValue, DateTime.MaxValue); Assert.Equal(log, results.Documents.Single()); results = await _dailyRepository.GetByDateRange(SystemClock.UtcNow.AddDays(1), DateTime.MaxValue); Assert.Empty(results.Documents); }
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); } }
public async Task CanHandleIncludeWithWrongCasing() { var log = await _dailyRepository.AddAsync(LogEventGenerator.Generate(companyId: "1234567890", message: "test"), o => o.ImmediateConsistency()); Assert.NotNull(log?.Id); var results = await _dailyRepository.FindAsync(q => q.Include(e => e.Id).Include("CreatedUtc")); 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); results = await _dailyRepository.FindAsync(q => q.Include(e => e.Id).Include("createdUtc")); Assert.Equal(1, results.Documents.Count); 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 Task RemoveUnsavedDocumentsAsync() { return(_dailyRepository.RemoveAsync(new List <LogEvent> { LogEventGenerator.Generate(ObjectId.GenerateNewId().ToString(), createdUtc: SystemClock.UtcNow), LogEventGenerator.Generate(ObjectId.GenerateNewId().ToString(), createdUtc: SystemClock.UtcNow) })); }
public async Task SearchByQueryWithTimeSeriesAsync() { var utcNow = SystemClock.UtcNow; var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(ObjectId.GenerateNewId(utcNow.AddDays(-1)).ToString(), createdUtc: utcNow.AddDays(-1), companyId: "1234567890"), o => o.ImmediateConsistency()); Assert.NotNull(yesterdayLog?.Id); var nowLog = await _dailyRepository.AddAsync(LogEventGenerator.Default, o => o.ImmediateConsistency()); Assert.NotNull(nowLog?.Id); var results = await _dailyRepository.GetByIdsAsync(new[] { yesterdayLog.Id, nowLog.Id }); Assert.NotNull(results); Assert.Equal(2, results.Count); var searchResults = await _dailyRepository.SearchAsync(new RepositoryQuery().Company("test")); Assert.Equal(0, searchResults.Total); searchResults = await _dailyRepository.SearchAsync(new RepositoryQuery().Company(yesterdayLog.CompanyId)); Assert.Equal(1, searchResults.Total); searchResults = await _dailyRepository.SearchAsync(new RepositoryQuery().Company(yesterdayLog.CompanyId).DateRange(utcNow.Subtract(TimeSpan.FromHours(1)), utcNow, "created")); Assert.Equal(0, searchResults.Total); searchResults = await _dailyRepository.SearchAsync(new RepositoryQuery().Id(yesterdayLog.Id)); Assert.Equal(1, searchResults.Total); }
public async Task AddWithTimeSeriesAsync() { var log = await _dailyRepository.AddAsync(LogEventGenerator.Generate()); Assert.NotNull(log?.Id); Assert.Equal(log, await _dailyRepository.GetByIdAsync(log.Id)); }
public async Task GetByIdWithOutOfSyncIndex() { var utcNow = SystemClock.UtcNow; var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(ObjectId.GenerateNewId().ToString(), createdUtc: utcNow.AddDays(-1))); Assert.NotNull(yesterdayLog?.Id); Assert.Equal(yesterdayLog, await _dailyRepository.GetByIdAsync(yesterdayLog.Id)); }
public async Task RemoveWithTimeSeriesAsync() { var log = LogEventGenerator.Generate(ObjectId.GenerateNewId().ToString()); await _dailyRepository.AddAsync(log, o => o.ImmediateConsistency()); Assert.Equal(1, await _dailyRepository.CountAsync()); await _dailyRepository.RemoveAsync(log, o => o.ImmediateConsistency()); Assert.Equal(0, await _dailyRepository.CountAsync()); }
public async Task GetByIdsWithOutOfSyncIndexAsync() { var utcNow = SystemClock.UtcNow; var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(ObjectId.GenerateNewId().ToString(), createdUtc: utcNow.AddDays(-1))); Assert.NotNull(yesterdayLog?.Id); var results = await _dailyRepository.GetByIdsAsync(new[] { yesterdayLog.Id }); Assert.NotNull(results); Assert.Equal(1, results.Count); }
public async Task AddAndSave() { var log = await _dailyRepository.AddAsync(LogEventGenerator.Default, sendNotification : false); Assert.NotNull(log?.Id); var disposables = new List <IDisposable>(4); var countdownEvent = new AsyncCountdownEvent(5); // Save requires an id to be set. var addedLog = LogEventGenerator.Generate(id: ObjectId.GenerateNewId().ToString()); try { disposables.Add(_dailyRepository.DocumentsAdding.AddSyncHandler((o, args) => { Assert.Equal(addedLog, args.Documents.First()); countdownEvent.Signal(); })); disposables.Add(_dailyRepository.DocumentsAdded.AddSyncHandler((o, args) => { Assert.Equal(addedLog, args.Documents.First()); countdownEvent.Signal(); })); disposables.Add(_dailyRepository.DocumentsSaving.AddSyncHandler((o, args) => { Assert.Equal(log, args.Documents.First().Value); countdownEvent.Signal(); })); disposables.Add(_dailyRepository.DocumentsSaved.AddSyncHandler((o, args) => { Assert.Equal(log, args.Documents.First().Value); countdownEvent.Signal(); })); _messgeBus.Subscribe <EntityChanged>((msg, ct) => { Assert.Equal(nameof(LogEvent), msg.Type); Assert.Equal(log.Id, msg.Id); Assert.Equal(ChangeType.Saved, msg.ChangeType); countdownEvent.Signal(); return(Task.CompletedTask); }); log.CompanyId = ObjectId.GenerateNewId().ToString(); await _dailyRepository.SaveAsync(new List <LogEvent> { log, addedLog }); await countdownEvent.WaitAsync(new CancellationTokenSource(TimeSpan.FromSeconds(2)).Token); Assert.Equal(0, countdownEvent.CurrentCount); } finally { foreach (var disposable in disposables) { disposable.Dispose(); } disposables.Clear(); } }
public async Task RemoveWithOutOfSyncIndexAsync() { 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()); await _dailyRepository.RemoveAsync(yesterdayLog, o => o.ImmediateConsistency()); Assert.Equal(1, await _dailyRepository.CountAsync()); }
public async Task GetByIdWithTimeSeries() { var utcNow = SystemClock.UtcNow; var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(createdUtc: utcNow.AddDays(-1))); Assert.NotNull(yesterdayLog?.Id); var nowLog = await _dailyRepository.AddAsync(LogEventGenerator.Default); Assert.NotNull(nowLog?.Id); Assert.Equal(yesterdayLog, await _dailyRepository.GetByIdAsync(yesterdayLog.Id)); Assert.Equal(nowLog, await _dailyRepository.GetByIdAsync(nowLog.Id)); }
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 RemoveWithTimeSeries() { var log = LogEventGenerator.Generate(ObjectId.GenerateNewId().ToString()); await _dailyRepository.AddAsync(log); await _client.RefreshAsync(); Assert.Equal(1, await _dailyRepository.CountAsync()); await _dailyRepository.RemoveAsync(log); await _client.RefreshAsync(); Assert.Equal(0, await _dailyRepository.CountAsync()); }
public async Task ExistsWithTimeSeriesAsync() { Assert.False(await _dailyRepository.ExistsAsync(Id.Null)); var utcNow = SystemClock.UtcNow; var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(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.True(await _dailyRepository.ExistsAsync(yesterdayLog.Id)); Assert.True(await _dailyRepository.ExistsAsync(nowLog.Id)); }
public async Task GetByIdsWithTimeSeriesAsync() { var utcNow = SystemClock.UtcNow; var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(createdUtc: utcNow.AddDays(-1))); Assert.NotNull(yesterdayLog?.Id); var nowLog = await _dailyRepository.AddAsync(LogEventGenerator.Default); Assert.NotNull(nowLog?.Id); var results = await _dailyRepository.GetByIdsAsync(new[] { yesterdayLog.Id, nowLog.Id }); Assert.NotNull(results); Assert.Equal(2, results.Count); }
public async Task RemoveCollectionWithTimeSeriesAsync() { var utcNow = SystemClock.UtcNow; var yesterdayLog = LogEventGenerator.Generate(ObjectId.GenerateNewId(utcNow.AddDays(-1)).ToString(), createdUtc: utcNow.AddDays(-1)); var nowLog = LogEventGenerator.Default; var logs = new List <LogEvent> { yesterdayLog, nowLog }; await _dailyRepository.AddAsync(logs, o => o.ImmediateConsistency()); Assert.Equal(2, await _dailyRepository.CountAsync()); await _dailyRepository.RemoveAsync(logs, o => o.ImmediateConsistency()); Assert.Equal(0, await _dailyRepository.CountAsync()); }
public async Task ScriptPatchAll() { 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 _dailyRepository.AddAsync(logs, addToCache : true); Assert.Equal(5, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(0, _cache.Misses); await _client.RefreshAsync(); Assert.Equal(3, await _dailyRepository.IncrementValueAsync(logs.Select(l => l.Id).ToArray())); Assert.Equal(2, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(0, _cache.Misses); await _client.RefreshAsync(); var results = await _dailyRepository.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 _dailyRepository.SaveAsync(logs, addToCache : true); await _client.RefreshAsync(); results = await _dailyRepository.GetAllByCompanyAsync("1"); Assert.Equal(2, results.Documents.Count); foreach (var document in results.Documents) { Assert.Equal("1", document.CompanyId); Assert.Equal(0, document.Value); } }
public async Task CanRoundTripById() { using var _ = TestSystemClock.Install(); TestSystemClock.SetFrozenTime(new DateTime(2020, 6, 16, 20, 0, 0, DateTimeKind.Local)); Assert.Equal(0, await _dailyRepository.CountAsync()); var utcNow = SystemClock.UtcNow; var logEvent = await _dailyRepository.AddAsync(LogEventGenerator.Generate(createdUtc: utcNow, date: utcNow.SubtractDays(1)), o => o.ImmediateConsistency()); Assert.NotNull(logEvent?.Id); var ev = await _dailyRepository.GetByIdAsync(logEvent.Id); Assert.NotNull(ev); Assert.Equal(ev.Date, ObjectId.Parse(ev.Id).CreationTime); Assert.NotEqual(ev.Date, ev.CreatedUtc); }
public async Task SaveWithOutOfSyncIndex() { var utcNow = SystemClock.UtcNow; var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(ObjectId.GenerateNewId().ToString(), createdUtc: utcNow.AddDays(-1))); Assert.NotNull(yesterdayLog?.Id); await _client.RefreshAsync(); Assert.Equal(1, await _dailyRepository.CountAsync()); yesterdayLog.Message = "updated"; await _dailyRepository.SaveAsync(yesterdayLog); await _client.RefreshAsync(); Assert.Equal(1, await _dailyRepository.CountAsync()); }
public async Task ExistsWithTimeSeries() { Assert.False(await _dailyRepository.ExistsAsync(null)); var utcNow = SystemClock.UtcNow; var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(createdUtc: utcNow.AddDays(-1))); Assert.NotNull(yesterdayLog?.Id); var nowLog = await _dailyRepository.AddAsync(LogEventGenerator.Default); Assert.NotNull(nowLog?.Id); await _client.RefreshAsync(); Assert.True(await _dailyRepository.ExistsAsync(yesterdayLog.Id)); Assert.True(await _dailyRepository.ExistsAsync(nowLog.Id)); }
public async Task RemoveCollectionWithOutOfSyncIndex() { var utcNow = SystemClock.UtcNow; var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(ObjectId.GenerateNewId().ToString(), createdUtc: utcNow.AddDays(-1))); Assert.NotNull(yesterdayLog?.Id); await _client.RefreshAsync(); Assert.Equal(1, await _dailyRepository.CountAsync()); await _dailyRepository.RemoveAsync(new List <LogEvent> { yesterdayLog }); await _client.RefreshAsync(); Assert.Equal(1, 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.CountAsync(q => q.FilterExpression("id:test"))); Assert.Equal(1, await _dailyRepository.CountAsync(q => q.FilterExpression($"id:{nowLog.Id}"))); Assert.Equal(1, await _dailyRepository.CountAsync(q => q.DateRange(utcNow.AddHours(-1), utcNow.AddHours(1), "createdUtc").FilterExpression($"id:{nowLog.Id}"))); Assert.Equal(0, await _dailyRepository.CountAsync(q => q.DateRange(utcNow.AddDays(-1), utcNow.AddHours(-12), (LogEvent l) => l.CreatedUtc).FilterExpression($"id:{nowLog.Id}"))); Assert.Equal(1, await _dailyRepository.CountAsync(q => q.DateRange(utcNow.AddDays(-1), utcNow.AddHours(-12), "created"))); Assert.Equal(1, await _dailyRepository.CountAsync(q => q.DateRange(utcNow.AddHours(-1), utcNow.AddHours(1), "createdUtc"))); }
public async Task CanGetAggregationsAsync() { 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); var result = await _dailyRepository.CountBySearchAsync(null, aggregations : "cardinality:companyId max:createdUtc"); Assert.Equal(2, result.Aggregations.Count); var cardinalityAgg = result.Aggregations.Cardinality("cardinality_companyId"); Assert.NotNull(cardinalityAgg); Assert.Equal(1, cardinalityAgg.Value.GetValueOrDefault()); var maxAgg = result.Aggregations.Max <DateTime>("max_createdUtc"); Assert.NotNull(maxAgg); Assert.True(yesterdayLog.CreatedUtc.Subtract(maxAgg.Value).TotalSeconds < 1); }
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 RemoveAllWithTimeSeries() { var utcNow = SystemClock.UtcNow; var yesterdayLog = LogEventGenerator.Generate(ObjectId.GenerateNewId(utcNow.AddDays(-1)).ToString(), createdUtc: utcNow.AddDays(-1)); var nowLog = LogEventGenerator.Default; var logs = new List <LogEvent> { yesterdayLog, nowLog }; await _dailyRepository.AddAsync(logs); await _client.RefreshAsync(); Assert.Equal(2, await _dailyRepository.CountAsync()); await _dailyRepository.RemoveAllAsync(); await _client.RefreshAsync(); Assert.Equal(0, await _dailyRepository.CountAsync()); }
public async Task AddCollectionWithTimeSeriesAsync() { var utcNow = SystemClock.UtcNow; var yesterdayLog = LogEventGenerator.Generate(ObjectId.GenerateNewId(utcNow.AddDays(-1)).ToString(), createdUtc: utcNow.AddDays(-1)); var nowLog = LogEventGenerator.Default; var logs = new List <LogEvent> { yesterdayLog, nowLog }; await _dailyRepository.AddAsync(logs, o => o.ImmediateConsistency()); var results = await _dailyRepository.GetByIdsAsync(new List <string> { yesterdayLog.Id, nowLog.Id }); Assert.Equal(logs, results.OrderBy(d => d.CreatedUtc).ToList()); var getAllResults = await _dailyRepository.GetAllAsync(); Assert.Equal(logs, getAllResults.Documents.OrderBy(d => d.CreatedUtc).ToList()); }
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 CanGetAggregations() { var utcNow = SystemClock.UtcNow; var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(ObjectId.GenerateNewId().ToString(), createdUtc: utcNow.AddDays(-1))); Assert.NotNull(yesterdayLog?.Id); await _client.RefreshAsync(); var result = await _dailyRepository.CountBySearchAsync(null, aggregations : "cardinality:companyId max:createdUtc"); Assert.Equal(2, result.Aggregations.Count); var cardinalityAgg = result.Aggregations.FirstOrDefault(a => a.Key == "cardinality_companyId"); Assert.NotNull(cardinalityAgg); Assert.Equal(1, cardinalityAgg.Value.Value); var maxAgg = result.Aggregations.FirstOrDefault(a => a.Key == "max_createdUtc"); Assert.NotNull(maxAgg); Assert.True(maxAgg.Value.Value.HasValue); Assert.True(yesterdayLog.CreatedUtc.Subtract(__unixEpoch.AddMilliseconds(maxAgg.Value.Value.Value)).TotalSeconds < 1); }