public void Redis_Sliding_DoesExpire_MultiClients() { // arrange var item = new CacheItem <object>(Guid.NewGuid().ToString(), "something", ExpirationMode.Sliding, TimeSpan.FromMilliseconds(50)); var channelName = Guid.NewGuid().ToString(); var cacheA = TestManagers.CreateRedisAndSystemCacheWithBackplane(10, true, channelName); var cacheB = TestManagers.CreateRedisAndSystemCacheWithBackplane(10, true, channelName); // act/assert using (cacheA) using (cacheB) { // act var result = cacheA.Add(item); var valueB = cacheB.Get(item.Key); // assert result.Should().BeTrue(); item.Value.Should().Be(valueB); // 450ms added so absolute would be expired on the 2nd go for (int s = 0; s < 3; s++) { Thread.Sleep(40); cacheA.GetCacheItem(item.Key).Should().NotBeNull(); cacheB.GetCacheItem(item.Key).Should().NotBeNull(); } Thread.Sleep(100); cacheA.GetCacheItem(item.Key).Should().BeNull(); cacheB.GetCacheItem(item.Key).Should().BeNull(); } }
////[Trait("category", "Unreliable")] public void Redis_Multiple_PubSub_Remove() { // arrange var item = new CacheItem <object>(Guid.NewGuid().ToString(), "something"); var channelName = Guid.NewGuid().ToString(); // act/assert RedisTests.RunMultipleCaches( (cacheA, cacheB) => { cacheA.Add(item); cacheB.Get(item.Key).Should().Be(item.Value); cacheB.Remove(item.Key); Thread.Sleep(10); }, (cache) => { Thread.Sleep(200); var value = cache.GetCacheItem(item.Key); value.Should().BeNull(); }, 1, TestManagers.CreateRedisAndSystemCacheWithBackplane(6, true, channelName), TestManagers.CreateRedisAndSystemCacheWithBackplane(6, true, channelName), TestManagers.CreateRedisCache(6), TestManagers.CreateRedisAndSystemCacheWithBackplane(6, true, channelName)); }
public void Redis_Multiple_PubSub_Change() { // arrange string fileName = BaseCacheManagerTest.GetCfgFileName(@"/Configuration/configuration.valid.allFeatures.config"); var channelName = Guid.NewGuid().ToString(); // redis config name must be same for all cache handles, configured via file and via code // otherwise the pub sub channel name is different string cacheName = "redisConfig"; RedisConfigurations.LoadConfiguration(fileName, RedisConfigurationSection.DefaultSectionName); var cfg = ConfigurationBuilder.LoadConfigurationFile(fileName, cacheName); cfg.BackplaneChannelName = channelName; var cfgCache = CacheFactory.FromConfiguration <object>(cfg); var item = new CacheItem <object>(Guid.NewGuid().ToString(), "something"); // act/assert RedisTests.RunMultipleCaches( (cacheA, cacheB) => { cacheA.Put(item); Thread.Sleep(10); var value = cacheB.Get(item.Key); value.Should().Be(item.Value, cacheB.ToString()); cacheB.Put(item.Key, "new value"); }, (cache) => { int tries = 0; object value = null; do { tries++; Thread.Sleep(100); value = cache.Get(item.Key); }while (value.ToString() != "new value" && tries < 10); value.Should().Be("new value", cache.ToString()); }, 1, TestManagers.CreateRedisAndSystemCacheWithBackplane(69, true, channelName), cfgCache, TestManagers.CreateRedisCache(69), TestManagers.CreateRedisAndSystemCacheWithBackplane(69, true, channelName)); }
public void Redis_Multiple_PubSub_Clear() { // arrange var item = new CacheItem <object>(Guid.NewGuid().ToString(), "something"); var channelName = Guid.NewGuid().ToString(); // act/assert RedisTests.RunMultipleCaches( (cacheA, cacheB) => { cacheA.Add(item); cacheB.Get(item.Key).Should().Be(item.Value); cacheB.Clear(); }, (cache) => { cache.Get(item.Key).Should().BeNull(); }, 2, TestManagers.CreateRedisAndSystemCacheWithBackplane(444, true, channelName), TestManagers.CreateRedisAndSystemCacheWithBackplane(444, true, channelName), TestManagers.CreateRedisCache(444), TestManagers.CreateRedisAndSystemCacheWithBackplane(444, true, channelName)); }