Пример #1
0
        public RedisSplitCacheTests()
        {
            _redisAdapterMock = new Mock <IRedisAdapter>();
            _splitParserMock  = new Mock <ISplitParser>();

            _redisSplitCache = new RedisSplitCache(_redisAdapterMock.Object, _splitParserMock.Object);
        }
Пример #2
0
 private void BuildRedisCache()
 {
     redisAdapter     = new RedisAdapter(RedisHost, RedisPort, RedisPassword, RedisDatabase, RedisConnectTimeout, RedisConnectRetry, RedisSyncTimeout);
     splitCache       = new RedisSplitCache(redisAdapter, RedisUserPrefix);
     segmentCache     = new RedisSegmentCache(redisAdapter, RedisUserPrefix);
     metricsCache     = new RedisMetricsCache(redisAdapter, SdkMachineIP, SdkVersion, RedisUserPrefix);
     impressionsCache = new RedisImpressionsCache(redisAdapter, SdkMachineIP, SdkVersion, RedisUserPrefix);
 }
Пример #3
0
        public void FlushTest()
        {
            //Arrange
            var redisAdapterMock = new Mock <IRedisAdapter>();
            var splitCache       = new RedisSplitCache(redisAdapterMock.Object);

            //Act
            splitCache.Flush();

            //Assert
            redisAdapterMock.Verify(mock => mock.Flush(), Times.Once());
        }
Пример #4
0
        private void BuildRedisCache()
        {
            _redisAdapter = new RedisAdapter(_config.RedisHost, _config.RedisPort, _config.RedisPassword, _config.RedisDatabase, _config.RedisConnectTimeout, _config.RedisConnectRetry, _config.RedisSyncTimeout);

            Task.Factory.StartNew(() => _redisAdapter.Connect());

            _segmentCache         = new RedisSegmentCache(_redisAdapter, _config.RedisUserPrefix);
            _splitParser          = new RedisSplitParser(_segmentCache);
            _splitCache           = new RedisSplitCache(_redisAdapter, _splitParser, _config.RedisUserPrefix);
            _metricsCache         = new RedisMetricsCache(_redisAdapter, _config.SdkMachineIP, _config.SdkVersion, _config.SdkMachineName, _config.RedisUserPrefix);
            _trafficTypeValidator = new TrafficTypeValidator(_splitCache);
        }
Пример #5
0
        public void RemoveSplitShouldReturnFalseOnException()
        {
            //Arrange
            var splitName        = "test_split";
            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.Del(splitKeyPrefix + "test_split")).Returns(false);
            var splitCache = new RedisSplitCache(redisAdapterMock.Object);

            //Act
            var isRemoved = splitCache.RemoveSplit(splitName);

            //Assert
            Assert.IsFalse(isRemoved);
        }
Пример #6
0
        public void GetKeysTestSuccessfully()
        {
            //Arrange
            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.Keys(splitKeyPrefix + "*")).Returns(new RedisKey[] { "test_split", "test_split2" });
            var splitCache = new RedisSplitCache(redisAdapterMock.Object);

            //Act
            var result = splitCache.GetKeys();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Count);
        }
Пример #7
0
        public void GetKeysShouldReturnEmptyResultIfNoKeysOrRedisException()
        {
            //Arrange
            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.Keys(splitKeyPrefix + "*")).Returns(new RedisKey[] { });
            var splitCache = new RedisSplitCache(redisAdapterMock.Object);

            //Act
            var result = splitCache.GetKeys();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count);
        }
Пример #8
0
        private void BuildRedisCache()
        {
            _redisAdapter = new RedisAdapter(_config.RedisHost, _config.RedisPort, _config.RedisPassword, _config.RedisDatabase, _config.RedisConnectTimeout, _config.RedisConnectRetry, _config.RedisSyncTimeout, _config.TlsConfig);

            Task.Factory.StartNew(() =>
            {
                _redisAdapter.Connect();
                RecordConfigInit();
            });

            _segmentCache         = new RedisSegmentCache(_redisAdapter, _config.RedisUserPrefix);
            _splitParser          = new RedisSplitParser(_segmentCache);
            _splitCache           = new RedisSplitCache(_redisAdapter, _splitParser, _config.RedisUserPrefix);
            _trafficTypeValidator = new TrafficTypeValidator(_splitCache);
        }
Пример #9
0
        public void GetChangeNumberWhenNotSetOrRedisThrowsException()
        {
            //Arrange
            var changeNumber     = -1;
            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.Get(splitsKeyPrefix + "till")).Returns("");
            var splitCache = new RedisSplitCache(redisAdapterMock.Object);

            //Act
            var result = splitCache.GetChangeNumber();

            //Assert
            Assert.AreEqual(changeNumber, result);
        }
Пример #10
0
        public void UseSplitioAndUserPrefix()
        {
            //Arrange
            var splitName = "test_split";
            var split     = new Split
            {
                name             = splitName,
                changeNumber     = 121291,
                killed           = false,
                seed             = 4324324,
                defaultTreatment = "on",
                conditions       = new List <ConditionDefinition>(),
                status           = "ACTIVE",
                trafficTypeName  = "test"
            };

            var splitParser      = new Mock <ISplitParser>();
            var redisAdapterMock = new Mock <IRedisAdapter>();
            var splitCache       = new RedisSplitCache(redisAdapterMock.Object, splitParser.Object, "mycompany");

            redisAdapterMock
            .Setup(x => x.Get("mycompany.SPLITIO.split.test_split"))
            .Returns(JsonConvert.SerializeObject(split));

            splitParser
            .Setup(mock => mock.Parse(It.IsAny <Split>()))
            .Returns(new ParsedSplit
            {
                name             = split.name,
                changeNumber     = split.changeNumber,
                killed           = split.killed,
                seed             = split.seed,
                defaultTreatment = split.defaultTreatment,
                trafficTypeName  = split.trafficTypeName
            });

            //Act
            var result = splitCache.GetSplit(splitName);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(split.name, result.name);
            Assert.AreEqual(split.changeNumber, result.changeNumber);
            Assert.AreEqual(split.killed, result.killed);
            Assert.AreEqual(split.seed, result.seed);
            Assert.AreEqual(split.defaultTreatment, result.defaultTreatment);
            Assert.AreEqual(split.trafficTypeName, result.trafficTypeName);
        }
Пример #11
0
        public void GetInexistentSplitOrRedisExceptionShouldReturnNull()
        {
            //Arrange
            var    splitName        = "test_split";
            var    redisAdapterMock = new Mock <IRedisAdapter>();
            string value            = null;

            redisAdapterMock.Setup(x => x.Get(splitKeyPrefix + "test_split")).Returns(value);
            var splitCache = new RedisSplitCache(redisAdapterMock.Object);

            //Act
            var result = splitCache.GetSplit(splitName);

            //Assert
            Assert.IsNull(result);
        }
Пример #12
0
        private void BuildRedisCache()
        {
            redisAdapter = new RedisAdapter(RedisHost, RedisPort, RedisPassword, RedisDatabase, RedisConnectTimeout, RedisConnectRetry, RedisSyncTimeout);
            if (BlockMilisecondsUntilReady > 0 && !redisAdapter.IsConnected())
            {
                throw new TimeoutException($"SDK was not ready in {BlockMilisecondsUntilReady} miliseconds. Could not connect to Redis");
            }

            splitCache            = new RedisSplitCache(redisAdapter, RedisUserPrefix);
            segmentCache          = new RedisSegmentCache(redisAdapter, RedisUserPrefix);
            metricsCache          = new RedisMetricsCache(redisAdapter, SdkMachineIP, SdkVersion, RedisUserPrefix);
            impressionsCacheRedis = new RedisImpressionsCache(redisAdapter, SdkMachineIP, SdkVersion, RedisUserPrefix);
            eventsCache           = new RedisEventsCache(redisAdapter, SdkMachineName, SdkMachineIP, SdkVersion, RedisUserPrefix);

            _trafficTypeValidator = new TrafficTypeValidator(_log, splitCache);
        }
Пример #13
0
        public void SetAndGetChangeNumberTest()
        {
            //Arrange
            var changeNumber     = 1234;
            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.Set(splitsKeyPrefix + "till", changeNumber.ToString())).Returns(true);
            redisAdapterMock.Setup(x => x.Get(splitsKeyPrefix + "till")).Returns(changeNumber.ToString());
            var splitCache = new RedisSplitCache(redisAdapterMock.Object);

            //Act
            splitCache.SetChangeNumber(changeNumber);
            var result = splitCache.GetChangeNumber();

            //Assert
            Assert.AreEqual(changeNumber, result);
        }
Пример #14
0
        public void GetAllSplitsShouldReturnEmptyListIfGetReturnsEmpty()
        {
            //Arrange

            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.Keys(splitKeyPrefix + "*")).Returns(new RedisKey[] { });
            redisAdapterMock.Setup(x => x.Get(It.IsAny <RedisKey[]>())).Returns(new RedisValue[] { });
            var splitCache = new RedisSplitCache(redisAdapterMock.Object);

            //Act
            var result = splitCache.GetAllSplits();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count);
        }
Пример #15
0
        public void UseSplitioAndUserPrefix()
        {
            //Arrange
            var splitName = "test_split";
            var split     = new Split()
            {
                name = "test_split", changeNumber = 121291, killed = false, seed = 4324324, defaultTreatment = "on", conditions = new List <ConditionDefinition>(), status = "ACTIVE", trafficTypeName = "test"
            };
            var splitJson        = JsonConvert.SerializeObject(split);
            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.Get("mycompany.SPLITIO.split.test_split")).Returns(splitJson);
            var splitCache = new RedisSplitCache(redisAdapterMock.Object, "mycompany");

            //Act
            var result = splitCache.GetSplit(splitName);

            //Assert
            Assert.IsNotNull(result);
        }
Пример #16
0
        public void RemoveSplitTest()
        {
            //Arrange
            var splitName        = "test_split";
            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.Del(splitKeyPrefix + "test_split")).Returns(true);
            string value = null;

            redisAdapterMock.Setup(x => x.Get(splitKeyPrefix + "test_split")).Returns(value);
            var splitCache = new RedisSplitCache(redisAdapterMock.Object);

            //Act
            var isRemoved = splitCache.RemoveSplit(splitName);
            var result    = splitCache.GetSplit(splitName);

            //Assert
            Assert.IsTrue(isRemoved);
            Assert.IsNull(result);
        }
Пример #17
0
        public void GetAllSplitsSuccessfully()
        {
            //Arrange
            var splitName  = "test_split";
            var splitName2 = "test_split2";
            var split      = new Split()
            {
                name = "test_split", changeNumber = 121291, killed = false, seed = 4324324, defaultTreatment = "on", conditions = new List <ConditionDefinition>(), status = "ACTIVE", trafficTypeName = "test"
            };
            var split2 = new Split()
            {
                name = "test_split2", changeNumber = 121291, killed = false, seed = 4324324, defaultTreatment = "on", conditions = new List <ConditionDefinition>(), status = "ACTIVE", trafficTypeName = "test"
            };
            var splitJson        = JsonConvert.SerializeObject(split);
            var splitJson2       = JsonConvert.SerializeObject(split);
            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.Set(It.IsAny <string>(), splitJson)).Returns(true);
            redisAdapterMock.Setup(x => x.Set(It.IsAny <string>(), splitJson2)).Returns(true);
            redisAdapterMock.Setup(x => x.Keys(splitKeyPrefix + "*")).Returns(new RedisKey[] { "test_split", "test_split2" });
            redisAdapterMock.Setup(x => x.Get(It.IsAny <RedisKey[]>())).Returns(new RedisValue[] { splitJson, splitJson2 });
            var splitCache = new RedisSplitCache(redisAdapterMock.Object);

            //Act
            splitCache.AddSplit(splitName, new ParsedSplit()
            {
                name = splitName
            });
            splitCache.AddSplit(splitName2, new ParsedSplit()
            {
                name = splitName2
            });

            var result = splitCache.GetAllSplits();

            //Assert
            Assert.AreEqual(2, result.Count);
        }
Пример #18
0
        public void RemoveSplitsTest()
        {
            //Arrange
            var splitName        = "test_split";
            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.Del(It.IsAny <RedisKey[]>())).Returns(1);
            string value = null;

            redisAdapterMock.Setup(x => x.Get(splitKeyPrefix + "test_split")).Returns(value);
            var splitCache = new RedisSplitCache(redisAdapterMock.Object);

            //Act
            var removedCount = splitCache.RemoveSplits(new List <string>()
            {
                splitName
            });
            var result = splitCache.GetSplit(splitName);

            //Assert
            Assert.AreEqual(1, removedCount);
            Assert.IsNull(result);
        }
Пример #19
0
        public void AddAndGetSplitTest()
        {
            //Arrange
            var splitName = "test_split";
            var split     = new Split()
            {
                name = "test_split", changeNumber = 121291, killed = false, seed = 4324324, defaultTreatment = "on", conditions = new List <ConditionDefinition>(), status = "ACTIVE", trafficTypeName = "test"
            };
            var splitJson        = JsonConvert.SerializeObject(split);
            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.Set(splitKeyPrefix + "test_split", splitJson)).Returns(true);
            redisAdapterMock.Setup(x => x.Get(splitKeyPrefix + "test_split")).Returns(splitJson);
            var splitCache = new RedisSplitCache(redisAdapterMock.Object);

            //Act
            splitCache.AddSplit(splitName, split);
            var result = (Split)splitCache.GetSplit(splitName);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(splitName, result.name);
        }
Пример #20
0
        public void AddDuplicateSplitTest()
        {
            //Arrange
            var splitName = "test_split";
            var split     = new Split()
            {
                name = "test_split", changeNumber = 121291, killed = false, seed = 4324324, defaultTreatment = "on", conditions = new List <ConditionDefinition>(), status = "ACTIVE", trafficTypeName = "test"
            };
            var splitJson        = JsonConvert.SerializeObject(split);
            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.Keys(splitKeyPrefix + "*")).Returns(new RedisKey[] { "test_split" });
            redisAdapterMock.Setup(x => x.Get(It.IsAny <RedisKey[]>())).Returns(new RedisValue[] { splitJson });
            var splitCache = new RedisSplitCache(redisAdapterMock.Object);

            //Act
            var split1 = new Split()
            {
                name = splitName
            };

            splitCache.AddSplit(splitName, split1);
            var split2 = new Split()
            {
                name = "test_split_2"
            };

            splitCache.AddSplit(splitName, split2);
            var result = splitCache.GetAllSplits();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(((Split)result[0]).name, split1.name);
            Assert.AreNotEqual(((Split)result[0]).name, split2.name);
        }