public async Task CountByQueryAsync() { Assert.Equal(0, await _identityRepository.CountAsync()); var identity = IdentityGenerator.Default; var result = await _identityRepository.AddAsync(identity, o => o.ImmediateConsistency()); Assert.Equal(identity, result); Assert.Equal(0, await _identityRepository.CountBySearchAsync(null, "id:test")); Assert.Equal(1, await _identityRepository.CountBySearchAsync(null, $"id:{identity.Id}")); }
public async Task CountByQuery() { Assert.Equal(0, await _identityRepository.CountAsync()); var identity = IdentityGenerator.Default; var result = await _identityRepository.AddAsync(identity); Assert.Equal(identity, result); await _client.RefreshAsync(); Assert.Equal(0, await _identityRepository.CountBySearchAsync(null, "id:test")); Assert.Equal(1, await _identityRepository.CountBySearchAsync(null, $"id:{identity.Id}")); }
public async Task RemoveAllWithDeleteByQueryAsync() { const int COUNT = 10000; Log.SetLogLevel <IdentityWithNoCachingRepository>(LogLevel.Information); await _identityRepositoryWithNoCaching.AddAsync(IdentityGenerator.GenerateIdentities(COUNT), o => o.ImmediateConsistency()); Log.SetLogLevel <IdentityWithNoCachingRepository>(LogLevel.Trace); var disposables = new List <IDisposable>(2); var countdownEvent = new AsyncCountdownEvent(1); try { disposables.Add(_identityRepositoryWithNoCaching.DocumentsRemoving.AddSyncHandler((o, args) => { countdownEvent.Signal(); })); disposables.Add(_identityRepositoryWithNoCaching.DocumentsRemoved.AddSyncHandler((o, args) => { countdownEvent.Signal(); })); var sw = Stopwatch.StartNew(); Assert.Equal(COUNT, await _identityRepositoryWithNoCaching.RemoveAllAsync(o => o.ImmediateConsistency(true))); sw.Stop(); _logger.LogInformation($"Deleted {COUNT} documents in {sw.ElapsedMilliseconds}ms"); await countdownEvent.WaitAsync(new CancellationTokenSource(TimeSpan.FromMilliseconds(250)).Token); Assert.Equal(0, countdownEvent.CurrentCount); Assert.Equal(0, await _identityRepositoryWithNoCaching.CountAsync()); } finally { foreach (var disposable in disposables) { disposable.Dispose(); } disposables.Clear(); } }
public async Task RemoveAllWithDeleteByQuery() { const int COUNT = 10000; Log.SetLogLevel <IdentityWithNoCachingRepository>(LogLevel.Information); await _identityRepositoryWithNoCaching.AddAsync(IdentityGenerator.GenerateIdentities(COUNT)); await _client.RefreshAsync(); Log.SetLogLevel <IdentityWithNoCachingRepository>(LogLevel.Trace); var sw = Stopwatch.StartNew(); Assert.Equal(COUNT, await _identityRepositoryWithNoCaching.RemoveAllAsync()); sw.Stop(); _logger.Info($"Deleted {COUNT} documents in {sw.ElapsedMilliseconds}ms"); await _client.RefreshAsync(); Assert.Equal(0, await _identityRepositoryWithNoCaching.CountAsync()); // TODO: Ensure only one removed notification is sent out. }
public async Task InvalidateCache() { var identity = await _identityRepository.AddAsync(IdentityGenerator.Default, addToCache : true); Assert.NotNull(identity?.Id); Assert.Equal(1, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(0, _cache.Misses); await _identityRepository.InvalidateCacheAsync(identity); Assert.Equal(0, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(0, _cache.Misses); await _identityRepository.SaveAsync(identity, addToCache : true); Assert.Equal(1, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(1, _cache.Misses); // Save will attempt to lookup the original document using the cache. await _identityRepository.InvalidateCacheAsync(new List <Identity> { identity }); Assert.Equal(0, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(1, _cache.Misses); await _identityRepository.SaveAsync(new List <Identity> { identity }, addToCache : true); Assert.Equal(1, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(2, _cache.Misses); // Save will attempt to lookup the original document using the cache. await _identityRepository.InvalidateCacheAsync(new List <Identity> { identity }); Assert.Equal(0, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(2, _cache.Misses); await _identityRepository.SaveAsync(new List <Identity> { identity }, addToCache : true); Assert.Equal(1, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(3, _cache.Misses); await _identityRepository.InvalidateCacheAsync(identity); Assert.Equal(0, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(3, _cache.Misses); await _identityRepository.InvalidateCacheAsync(new List <Identity> { identity }); Assert.Equal(0, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(3, _cache.Misses); }
public async Task AddAsync() { var identity1 = await _identityRepository.AddAsync(IdentityGenerator.Generate()); Assert.NotNull(identity1?.Id); var disposables = new List <IDisposable>(2); var countdownEvent = new AsyncCountdownEvent(2); try { var identity2 = IdentityGenerator.Default; disposables.Add(_identityRepository.DocumentsAdding.AddSyncHandler((o, args) => { Assert.Equal(identity2, args.Documents.First()); countdownEvent.Signal(); })); disposables.Add(_identityRepository.DocumentsAdded.AddSyncHandler((o, args) => { Assert.Equal(identity2, args.Documents.First()); countdownEvent.Signal(); })); var result = await _identityRepository.AddAsync(identity2); Assert.Equal(IdentityGenerator.Default.Id, result.Id); await countdownEvent.WaitAsync(new CancellationTokenSource(TimeSpan.FromMilliseconds(250)).Token); Assert.Equal(0, countdownEvent.CurrentCount); } finally { foreach (var disposable in disposables) { disposable.Dispose(); } disposables.Clear(); } }
public async Task InvalidateCacheAsync() { var identity = await _identityRepository.AddAsync(IdentityGenerator.Default, o => o.Cache()); Assert.NotNull(identity?.Id); Assert.Equal(1, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(0, _cache.Misses); await _identityRepository.InvalidateCacheAsync(identity); Assert.Equal(0, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(0, _cache.Misses); await _identityRepository.SaveAsync(identity, o => o.Cache()); Assert.Equal(1, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(0, _cache.Misses); await _identityRepository.InvalidateCacheAsync(new List <Identity> { identity }); Assert.Equal(0, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(0, _cache.Misses); await _identityRepository.SaveAsync(new List <Identity> { identity }, o => o.Cache()); Assert.Equal(1, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(0, _cache.Misses); await _identityRepository.InvalidateCacheAsync(new List <Identity> { identity }); Assert.Equal(0, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(0, _cache.Misses); await _identityRepository.SaveAsync(new List <Identity> { identity }, o => o.Cache()); Assert.Equal(1, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(0, _cache.Misses); await _identityRepository.InvalidateCacheAsync(identity); Assert.Equal(0, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(0, _cache.Misses); await _identityRepository.InvalidateCacheAsync(new List <Identity> { identity }); Assert.Equal(0, _cache.Count); Assert.Equal(0, _cache.Hits); Assert.Equal(0, _cache.Misses); }