public async Task CanAddAndGetByCachedAsync() { var organization = new Organization { Name = "Test Organization", PlanId = BillingManager.FreePlan.Id }; Assert.Null(organization.Id); Assert.Equal(0, _cache.Count); await _repository.AddAsync(organization, true); await _configuration.Client.RefreshAsync(); Assert.NotNull(organization.Id); Assert.Equal(1, _cache.Count); await _cache.RemoveAllAsync(); Assert.Equal(0, _cache.Count); await _repository.GetByIdAsync(organization.Id, true); Assert.NotNull(organization.Id); Assert.Equal(1, _cache.Count); await _repository.RemoveAllAsync(); await _configuration.Client.RefreshAsync(); Assert.Equal(0, _cache.Count); }
protected virtual async Task RemoveDataAsync(bool configureIndexes = true) { var minimumLevel = Log.MinimumLevel; Log.MinimumLevel = LogLevel.Warning; var sw = Stopwatch.StartNew(); _logger.LogInformation("Starting remove data"); await _workItemQueue.DeleteQueueAsync(); await _configuration.DeleteIndexesAsync(); if (configureIndexes) { await _configuration.ConfigureIndexesAsync(null, false); } await _cache.RemoveAllAsync(); _cache.ResetStats(); await _client.Indices.RefreshAsync(Indices.All); _messageBus.ResetMessagesSent(); sw.Stop(); _logger.LogInformation("Done removing data {Duration}", sw.Elapsed); Log.MinimumLevel = minimumLevel; }
public async Task CanAddAndGetByCachedAsync() { var organization = new Organization { Name = "Test Organization", PlanId = _plans.FreePlan.Id }; Assert.Null(organization.Id); Assert.Equal(0, _cache.Count); await _repository.AddAsync(organization, o => o.Cache()); await RefreshDataAsync(); Assert.NotNull(organization.Id); Assert.Equal(1, _cache.Count); await _cache.RemoveAllAsync(); Assert.Equal(0, _cache.Count); await _repository.GetByIdAsync(organization.Id, o => o.Cache()); Assert.NotNull(organization.Id); Assert.Equal(1, _cache.Count); await _repository.RemoveAllAsync(); await RefreshDataAsync(); Assert.Equal(0, _cache.Count); }
private async Task RemoveDataAsync() { await _cache.RemoveAllAsync(); _configuration.DeleteIndexes(_client); _configuration.ConfigureIndexes(_client); await _client.RefreshAsync(); }
protected virtual async Task RemoveDataAsync(bool configureIndexes = true) { var minimumLevel = Log.MinimumLevel; Log.MinimumLevel = LogLevel.Warning; await _workItemQueue.DeleteQueueAsync(); await _configuration.DeleteIndexesAsync(); if (configureIndexes) { await _configuration.ConfigureIndexesAsync(null, false); } await _cache.RemoveAllAsync(); await _client.RefreshAsync(); Log.MinimumLevel = minimumLevel; }
public async Task CanSetMaxItems() { Log.MinimumLevel = LogLevel.Trace; // run in tight loop so that the code is warmed up and we can catch timing issues for (int x = 0; x < 5; x++) { var cache = new InMemoryCacheClient(o => o.MaxItems(10).CloneValues(true)); using (cache) { await cache.RemoveAllAsync(); for (int i = 0; i < cache.MaxItems; i++) { await cache.SetAsync("test" + i, i); } _logger.LogTrace(String.Join(",", cache.Keys)); Assert.Equal(10, cache.Count); await cache.SetAsync("next", 1); _logger.LogTrace(String.Join(",", cache.Keys)); Assert.Equal(10, cache.Count); Assert.False((await cache.GetAsync <int>("test0")).HasValue); Assert.Equal(1, cache.Misses); await SystemClock.SleepAsync(50); // keep the last access ticks from being the same for all items Assert.NotNull(await cache.GetAsync <int?>("test1")); Assert.Equal(1, cache.Hits); await cache.SetAsync("next2", 2); _logger.LogTrace(String.Join(",", cache.Keys)); Assert.False((await cache.GetAsync <int>("test2")).HasValue); Assert.Equal(2, cache.Misses); Assert.True((await cache.GetAsync <int>("test1")).HasValue); Assert.Equal(2, cache.Misses); } } }