public async Task RemoveAll() { await _identityRepository.RemoveAllAsync(); var identities = new List <Identity> { IdentityGenerator.Default }; await _identityRepository.AddAsync(identities); await _client.RefreshAsync(); var disposables = new List <IDisposable>(2); var countdownEvent = new AsyncCountdownEvent(2); try { disposables.Add(_identityRepository.DocumentsRemoving.AddSyncHandler((o, args) => { countdownEvent.Signal(); })); disposables.Add(_identityRepository.DocumentsRemoved.AddSyncHandler((o, args) => { countdownEvent.Signal(); })); await _identityRepository.RemoveAllAsync(); await countdownEvent.WaitAsync(new CancellationTokenSource(TimeSpan.FromMilliseconds(250)).Token); Assert.Equal(0, countdownEvent.CurrentCount); } finally { foreach (var disposable in disposables) { disposable.Dispose(); } disposables.Clear(); } await _client.RefreshAsync(); Assert.Equal(0, await _identityRepository.CountAsync()); }
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. }