Exemplo n.º 1
0
        public void Redis_Configurations_LoadWithConnectionString()
        {
            string fileName = BaseCacheManagerTest.GetCfgFileName(@"/Configuration/configuration.valid.allFeatures.config");

            RedisConfigurations.LoadConfiguration(fileName, RedisConfigurationSection.DefaultSectionName);
            var cfg = RedisConfigurations.GetConfiguration("redisConnectionString");

            cfg.ConnectionString.Should().Be("127.0.0.1:6379,allowAdmin=true,ssl=true");
        }
        public void Redis_Configurations_LoadWithConnectionString()
        {
            string fileName = TestConfigurationHelper.GetCfgFileName(@"/Configuration/configuration.valid.allFeatures.config");

            RedisConfigurations.LoadConfiguration(fileName, RedisConfigurationSection.DefaultSectionName);
            var cfg = RedisConfigurations.GetConfiguration("redisConnectionString");

            cfg.ConnectionString.ToLower().Should().Contain("127.0.0.1:6379");//,allowAdmin = true,ssl = false");
            cfg.ConnectionString.ToLower().Should().Contain("allowadmin=true");
            cfg.ConnectionString.ToLower().Should().Contain("ssl=false");
            cfg.Database.Should().Be(131);
            cfg.StrictCompatibilityModeVersion.Should().Be("2.9");
        }
Exemplo n.º 3
0
        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 = "redisConfigFromConfig";

            RedisConfigurations.LoadConfiguration(fileName, RedisConfigurationSection.DefaultSectionName);

            var cfg = (CacheManagerConfiguration)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);
                cacheA.Get(item.Key).Should().Be("something");
                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.CreateRedisAndDicCacheWithBackplane(113, true, channelName, Serializer.Json),
                cfgCache,
                TestManagers.CreateRedisCache(113, false, Serializer.Json),
                TestManagers.CreateRedisAndDicCacheWithBackplane(113, true, channelName, Serializer.Json));
        }
Exemplo n.º 4
0
        public void Redis_Valid_CfgFile_LoadWithRedisBackPlate()
        {
            // arrange
            string fileName  = BaseCacheManagerTest.GetCfgFileName(@"/Configuration/configuration.valid.allFeatures.config");
            string cacheName = "redisConfig";

            // have to load the configuration manually because the file is not avialbale to the default ConfigurtaionManager
            RedisConfigurations.LoadConfiguration(fileName, RedisConfigurationSection.DefaultSectionName);

            // act
            var cfg   = ConfigurationBuilder.LoadConfigurationFile(fileName, cacheName);
            var cache = CacheFactory.FromConfiguration <object>(cfg);

            // assert
            cache.CacheHandles.Any(p => p.Configuration.IsBackPlateSource).Should().BeTrue();
        }
Exemplo n.º 5
0
        ////[Trait("category", "Unreliable")]
        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.BackPlateChannelName = 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) =>
            {
                Thread.Sleep(12);
                var value = cache.Get(item.Key);
                value.Should().Be("new value", cache.ToString());
            },
                2,
                TestManagers.CreateRedisAndSystemCacheWithBackPlate(69, true, channelName),
                cfgCache,
                TestManagers.CreateRedisCache(69),
                TestManagers.CreateRedisAndSystemCacheWithBackPlate(69, true, channelName));
        }
Exemplo n.º 6
0
        public void Redis_Valid_CfgFile_LoadWithConnectionString()
        {
            // arrange
            string fileName  = BaseCacheManagerTest.GetCfgFileName(@"/Configuration/configuration.valid.allFeatures.config");
            string cacheName = "redisConfigFromConnectionString";

            // have to load the configuration manually because the file is not avialbale to the default ConfigurtaionManager
            RedisConfigurations.LoadConfiguration(fileName, RedisConfigurationSection.DefaultSectionName);
            var redisConfig = RedisConfigurations.GetConfiguration("redisConnectionString");

            // act
            var cfg   = ConfigurationBuilder.LoadConfigurationFile(fileName, cacheName);
            var cache = CacheFactory.FromConfiguration <object>(cfg);

            // assert
            cache.CacheHandles.Any(p => p.Configuration.IsBackplaneSource).Should().BeTrue();

            // database is the only option apart from key and connection string which must be set, database will not be set through connection string
            // to define which database should actually be used...
            redisConfig.Database.Should().Be(131);
        }
        public void Redis_Valid_CfgFile_LoadWithRedisBackplane()
        {
            // arrange
            string fileName  = TestConfigurationHelper.GetCfgFileName(@"/Configuration/configuration.valid.allFeatures.config");
            string cacheName = "redisConfigFromConfig";

            // have to load the configuration manually because the file is not avialbale to the default ConfigurtaionManager
            RedisConfigurations.LoadConfiguration(fileName, RedisConfigurationSection.DefaultSectionName);
            var redisConfig = RedisConfigurations.GetConfiguration("redisFromCfgConfigurationId");

            // act
            var cfg = ConfigurationBuilder.LoadConfigurationFile(fileName, cacheName);

            // assert
            redisConfig.Database.Should().Be(113);
            redisConfig.ConnectionTimeout.Should().Be(1200);
            redisConfig.AllowAdmin.Should().BeTrue();
            redisConfig.KeyspaceNotificationsEnabled.Should().BeTrue();
            redisConfig.TwemproxyEnabled.Should().BeTrue();
            redisConfig.StrictCompatibilityModeVersion.Should().Be("2.7");
        }
Exemplo n.º 8
0
        public void Redis_Valid_CfgFile_LoadWithRedisBackplane()
        {
            // arrange
            string fileName  = TestConfigurationHelper.GetCfgFileName(@"/Configuration/configuration.valid.allFeatures.config");
            string cacheName = "redisConfigFromConfig";

            // have to load the configuration manually because the file is not avialbale to the default ConfigurtaionManager
            RedisConfigurations.LoadConfiguration(fileName, RedisConfigurationSection.DefaultSectionName);
            var redisConfig = RedisConfigurations.GetConfiguration("redisFromCfgConfigurationId");

            // act
            var cfg   = ConfigurationBuilder.LoadConfigurationFile(fileName, cacheName);
            var cache = CacheFactory.FromConfiguration <object>(cfg);

            // assert
            cache.CacheHandles.Any(p => p.Configuration.IsBackplaneSource).Should().BeTrue();

            redisConfig.Database.Should().Be(113);
            redisConfig.ConnectionTimeout.Should().Be(1200);
            redisConfig.AllowAdmin.Should().BeTrue();
            redisConfig.KeyspaceNotificationsEnabled.Should().BeTrue();
        }
Exemplo n.º 9
0
        public void Redis_Configurations_LoadSection_SectionDoesNotExist()
        {
            Action act = () => RedisConfigurations.LoadConfiguration(Guid.NewGuid().ToString());

            act.ShouldThrow <ArgumentNullException>().WithMessage("*section*");
        }
Exemplo n.º 10
0
        public void Redis_Configurations_LoadSection_InvalidFileName()
        {
            Action act = () => RedisConfigurations.LoadConfiguration((string)null, "section");

            act.ShouldThrow <ArgumentNullException>().WithMessage("*fileName*");
        }
Exemplo n.º 11
0
 public void Redis_Configurations_LoadStandard()
 {
     RedisConfigurations.LoadConfiguration();
 }