public void ExecuteGetWithoutResults() { //Arrange var baseUrl = "https://sdk-aws-staging.split.io/api/"; var headers = new Dictionary <string, string> { { "SplitSDKMachineIP", "1.0.0.0" }, { "SplitSDKMachineName", "localhost" }, { "SplitSDKVersion", "1" } }; var telemetryStorage = new InMemoryTelemetryStorage(); var sdkApiClient = new SplitSdkApiClient("0", headers, baseUrl, 10000, 10000, telemetryStorage); var apiSplitChangeFetcher = new ApiSplitChangeFetcher(sdkApiClient); var sdkSegmentApiClient = new SegmentSdkApiClient("0", headers, baseUrl, 10000, 10000, telemetryStorage); var apiSegmentChangeFetcher = new ApiSegmentChangeFetcher(sdkSegmentApiClient); var gates = new InMemoryReadinessGatesCache(); var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>()); var segmentTaskQueue = new SegmentTaskQueue(); var wrapperAdapter = new WrapperAdapter(); var selfRefreshingSegmentFetcher = new SelfRefreshingSegmentFetcher(apiSegmentChangeFetcher, gates, 30, segmentCache, 4, segmentTaskQueue, new TasksManager(wrapperAdapter), wrapperAdapter); var splitParser = new InMemorySplitParser(selfRefreshingSegmentFetcher, segmentCache); var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); var selfRefreshingSplitFetcher = new SelfRefreshingSplitFetcher(apiSplitChangeFetcher, splitParser, gates, 30, new TasksManager(wrapperAdapter), splitCache); selfRefreshingSplitFetcher.Start(); //Act gates.WaitUntilReady(10); var result = splitCache.GetSplit("condition_and"); //Assert Assert.IsNull(result); }
public void ExecuteGetSuccessfulWithResultsFromJSONFileIncludingTrafficAllocation() { //Arrange var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>()); var splitParser = new InMemorySplitParser(new JSONFileSegmentFetcher("segment_payed.json", segmentCache), segmentCache); var splitChangeFetcher = new JSONFileSplitChangeFetcher("splits_staging_4.json"); var splitChangesResult = splitChangeFetcher.Fetch(-1); var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); var gates = new InMemoryReadinessGatesCache(); var selfRefreshingSplitFetcher = new SelfRefreshingSplitFetcher(splitChangeFetcher, splitParser, gates, 30, splitCache); selfRefreshingSplitFetcher.Start(); gates.IsSDKReady(1000); //Act ParsedSplit result = (ParsedSplit)splitCache.GetSplit("Traffic_Allocation_UI"); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.name == "Traffic_Allocation_UI"); Assert.IsTrue(result.trafficAllocation == 100); Assert.IsTrue(result.trafficAllocationSeed == 0); Assert.IsTrue(result.conditions.Count > 0); Assert.IsNotNull(result.conditions.Find(x => x.conditionType == ConditionType.ROLLOUT)); }
public void ExecuteGetWithoutResults() { //Arrange var baseUrl = "https://sdk-aws-staging.split.io/api/"; var httpHeader = new HTTPHeader() { authorizationApiKey = "0", splitSDKMachineIP = "1.0.0.0", splitSDKMachineName = "localhost", splitSDKVersion = "net-0.0.0", splitSDKSpecVersion = "1.2", }; var sdkApiClient = new SplitSdkApiClient(httpHeader, baseUrl, 10000, 10000); var apiSplitChangeFetcher = new ApiSplitChangeFetcher(sdkApiClient); var sdkSegmentApiClient = new SegmentSdkApiClient(httpHeader, baseUrl, 10000, 10000); var apiSegmentChangeFetcher = new ApiSegmentChangeFetcher(sdkSegmentApiClient); var gates = new InMemoryReadinessGatesCache(); var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>()); var selfRefreshingSegmentFetcher = new SelfRefreshingSegmentFetcher(apiSegmentChangeFetcher, gates, 30, segmentCache, 4); var splitParser = new InMemorySplitParser(selfRefreshingSegmentFetcher, segmentCache); var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); var selfRefreshingSplitFetcher = new SelfRefreshingSplitFetcher(apiSplitChangeFetcher, splitParser, gates, 30, splitCache); selfRefreshingSplitFetcher.Start(); //Act gates.IsSDKReady(10); var result = splitCache.GetSplit("condition_and"); //Assert Assert.IsNull(result); }
public void SplitsReturnWithNoRolloutConditionSuccessfully() { //Arrange var conditionsWithLogic = new List <ConditionWithLogic>(); var conditionWithLogic = new ConditionWithLogic() { conditionType = ConditionType.WHITELIST, partitions = new List <PartitionDefinition>() { new PartitionDefinition() { size = 100, treatment = "on" } } }; conditionsWithLogic.Add(conditionWithLogic); var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); splitCache.AddSplit("test1", new ParsedSplit() { name = "test1", changeNumber = 10000, killed = false, trafficTypeName = "user", seed = -1, conditions = conditionsWithLogic }); splitCache.AddSplit("test2", new ParsedSplit() { name = "test2", conditions = conditionsWithLogic }); splitCache.AddSplit("test3", new ParsedSplit() { name = "test3", conditions = conditionsWithLogic }); splitCache.AddSplit("test4", new ParsedSplit() { name = "test4", conditions = conditionsWithLogic }); splitCache.AddSplit("test5", new ParsedSplit() { name = "test5", conditions = conditionsWithLogic }); splitCache.AddSplit("test6", new ParsedSplit() { name = "test6", conditions = conditionsWithLogic }); var manager = new SplitManager(splitCache); //Act var result = manager.Splits(); //Assert Assert.IsNotNull(result); Assert.AreEqual(6, result.Count); var firstResult = result.Find(x => x.name == "test1"); Assert.AreEqual(firstResult.name, "test1"); Assert.AreEqual(firstResult.changeNumber, 10000); Assert.AreEqual(firstResult.killed, false); Assert.AreEqual(firstResult.trafficType, "user"); Assert.AreEqual(firstResult.treatments.Count, 0); }
public void AddDuplicateSplitTest() { //Arrange var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); var splitName = "test1"; //Act var parsedSplit1 = new ParsedSplit() { name = splitName }; splitCache.AddSplit(splitName, parsedSplit1); var parsedSplit2 = new ParsedSplit() { name = splitName }; splitCache.AddSplit(splitName, parsedSplit2); var result = splitCache.GetAllSplits(); //Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.Count); Assert.AreEqual(result[0], parsedSplit1); Assert.AreNotEqual(result[0], parsedSplit2); }
public void SplitReturnDefaultTreatmentsWhenNoRolloutCondition() { //Arrange var conditionsWithLogic = new List <ConditionWithLogic>(); var conditionWithLogic = new ConditionWithLogic() { conditionType = ConditionType.WHITELIST, partitions = new List <PartitionDefinition>() { new PartitionDefinition() { size = 100, treatment = "on" }, } }; conditionsWithLogic.Add(conditionWithLogic); var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); splitCache.AddSplit("test1", new ParsedSplit() { name = "test1", changeNumber = 10000, killed = false, trafficTypeName = "user", seed = -1, conditions = conditionsWithLogic }); splitCache.AddSplit("test2", new ParsedSplit() { name = "test2", conditions = conditionsWithLogic }); splitCache.AddSplit("test3", new ParsedSplit() { name = "test3", conditions = conditionsWithLogic }); splitCache.AddSplit("test4", new ParsedSplit() { name = "test4", conditions = conditionsWithLogic }); splitCache.AddSplit("test5", new ParsedSplit() { name = "test5", conditions = conditionsWithLogic }); splitCache.AddSplit("test6", new ParsedSplit() { name = "test6", conditions = conditionsWithLogic }); _blockUntilReadyService .Setup(mock => mock.IsSdkReady()) .Returns(true); var manager = new SplitManager(splitCache, _blockUntilReadyService.Object); //Act var result = manager.Split("test1"); //Assert Assert.IsNotNull(result); Assert.AreEqual(result.name, "test1"); Assert.AreEqual(conditionWithLogic.partitions.Count, result.treatments.Count); }
public void GetInexistentSplitTest() { //Arrange var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); var splitName = "test1"; //Act var result = splitCache.GetSplit(splitName); //Assert Assert.IsNull(result); }
public void SplitNamessWhenCacheIsEmptyShouldReturnEmptyList() { //Arrange var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); var manager = new SplitManager(splitCache); //Act var result = manager.SplitNames(); //Assert Assert.IsNotNull(result); Assert.AreEqual(0, result.Count); }
public void SplitReturnsNullWhenInexistent() { //Arrange var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); var manager = new SplitManager(splitCache); //Act var result = manager.Split("test1"); //Assert Assert.IsNull(result); }
public void SetAndGetChangeNumberTest() { //Arrange var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); var changeNumber = 1234; //Act splitCache.SetChangeNumber(changeNumber); var result = splitCache.GetChangeNumber(); //Assert Assert.AreEqual(changeNumber, result); }
private void BuildSplitFetcher() { var segmentRefreshRate = RandomizeRefreshRates ? Random(SegmentRefreshRate) : SegmentRefreshRate; var splitsRefreshRate = RandomizeRefreshRates ? Random(SplitsRefreshRate) : SplitsRefreshRate; segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>(ConcurrencyLevel, InitialCapacity)); var segmentChangeFetcher = new ApiSegmentChangeFetcher(segmentSdkApiClient); selfRefreshingSegmentFetcher = new SelfRefreshingSegmentFetcher(segmentChangeFetcher, gates, segmentRefreshRate, segmentCache, NumberOfParalellSegmentTasks); var splitChangeFetcher = new ApiSplitChangeFetcher(splitSdkApiClient); var splitParser = new InMemorySplitParser(selfRefreshingSegmentFetcher, segmentCache); splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>(ConcurrencyLevel, InitialCapacity)); splitFetcher = new SelfRefreshingSplitFetcher(splitChangeFetcher, splitParser, gates, splitsRefreshRate, splitCache); }
public void AddAndGetSplitTest() { //Arrange var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); var splitName = "test1"; //Act splitCache.AddSplit(splitName, new ParsedSplit() { name = splitName }); var result = splitCache.GetSplit(splitName); //Assert Assert.IsNotNull(result); }
public void SplitWithNullNameShouldReturnNull() { //Arrange _blockUntilReadyService .Setup(mock => mock.IsSdkReady()) .Returns(true); var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); var manager = new SplitManager(splitCache, _blockUntilReadyService.Object); //Act var result = manager.Split(null); //Assert Assert.IsNull(result); }
public LocalhostClient(string filePath, Splitter splitter = null) { fullPath = LookupFilePath(filePath); var directoryPath = Path.GetDirectoryName(fullPath); watcher = new FileSystemWatcher(directoryPath != String.Empty ? directoryPath : Directory.GetCurrentDirectory(), Path.GetFileName(fullPath)); watcher.NotifyFilter = NotifyFilters.LastWrite; watcher.Changed += new FileSystemEventHandler(OnFileChanged); watcher.EnableRaisingEvents = true; var splits = ParseSplitFile(fullPath); splitCache = new InMemorySplitCache(splits); BuildSplitter(splitter); manager = new SplitManager(splitCache); }
public void SplitNamessWhenCacheIsEmptyShouldReturnEmptyList() { //Arrange _blockUntilReadyService .Setup(mock => mock.IsSdkReady()) .Returns(true); var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); var manager = new SplitManager(splitCache, _blockUntilReadyService.Object); //Act var result = manager.SplitNames(); //Assert Assert.IsNotNull(result); Assert.AreEqual(0, result.Count); }
public void SplitReturnsNullWhenInexistent() { //Arrange var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); _blockUntilReadyService .Setup(mock => mock.IsSdkReady()) .Returns(true); var manager = new SplitManager(splitCache, _blockUntilReadyService.Object); //Act var result = manager.Split("test1"); //Assert Assert.IsNull(result); }
private void BuildSplitFetcher() { var segmentRefreshRate = _config.RandomizeRefreshRates ? Random(_config.SegmentRefreshRate) : _config.SegmentRefreshRate; var splitsRefreshRate = _config.RandomizeRefreshRates ? Random(_config.SplitsRefreshRate) : _config.SplitsRefreshRate; _segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>(_config.ConcurrencyLevel, InitialCapacity)); var segmentChangeFetcher = new ApiSegmentChangeFetcher(_segmentSdkApiClient); _selfRefreshingSegmentFetcher = new SelfRefreshingSegmentFetcher(segmentChangeFetcher, _gates, segmentRefreshRate, _segmentCache, _config.NumberOfParalellSegmentTasks); var splitChangeFetcher = new ApiSplitChangeFetcher(_splitSdkApiClient); _splitParser = new InMemorySplitParser((SelfRefreshingSegmentFetcher)_selfRefreshingSegmentFetcher, _segmentCache); _splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>(_config.ConcurrencyLevel, InitialCapacity)); _splitFetcher = new SelfRefreshingSplitFetcher(splitChangeFetcher, _splitParser, _gates, splitsRefreshRate, _splitCache); _trafficTypeValidator = new TrafficTypeValidator(_splitCache); }
public void RemoveSplitTest() { //Arrange var splitName = "test1"; var splits = new ConcurrentDictionary <string, ParsedSplit>(); splits.TryAdd(splitName, new ParsedSplit() { name = splitName }); var splitCache = new InMemorySplitCache(splits); //Act splitCache.RemoveSplit(splitName); var result = splitCache.GetSplit(splitName); //Assert Assert.IsNull(result); }
public LocalhostClient(string filePath, ISplitLogger log = null) : base(GetLogger(log)) { _fullPath = LookupFilePath(filePath); if (_fullPath.ToLower().EndsWith(SplitFileYaml) || _fullPath.ToLower().EndsWith(SplitFileYml)) { _localhostFileService = new YamlLocalhostFileService(); } else { _log.Warn("Localhost mode: .split/.splits mocks will be deprecated soon in favor of YAML files, which provide more targeting power. Take a look in our documentation."); _localhostFileService = new LocalhostFileService(); } var directoryPath = Path.GetDirectoryName(_fullPath); _watcher = new FileSystemWatcher(directoryPath != string.Empty ? directoryPath : Directory.GetCurrentDirectory(), Path.GetFileName(_fullPath)) { NotifyFilter = NotifyFilters.LastWrite }; _watcher.Changed += new FileSystemEventHandler(OnFileChanged); _watcher.EnableRaisingEvents = true; var splits = ParseSplitFile(_fullPath); _splitCache = new InMemorySplitCache(splits); _blockUntilReadyService = new NoopBlockUntilReadyService(); _manager = new SplitManager(_splitCache, _blockUntilReadyService); ApiKey = "localhost"; Destroyed = false; _trafficTypeValidator = new TrafficTypeValidator(_splitCache); BuildEvaluator(); _impressionsManager = new ImpressionsManager(null, null, null, false, ImpressionsMode.Debug); }
public void ExecuteGetSuccessfulWithResults() { //Arrange var baseUrl = "https://sdk-aws-staging.split.io/api/"; //var baseUrl = "http://localhost:3000/api/"; var headers = new Dictionary <string, string> { { "SplitSDKMachineIP", "1.0.0.0" }, { "SplitSDKMachineName", "localhost" }, { "SplitSDKVersion", "1" } }; var telemetryStorage = new InMemoryTelemetryStorage(); var sdkApiClient = new SplitSdkApiClient("///PUT API KEY HERE///", headers, baseUrl, 10000, 10000, telemetryStorage); var apiSplitChangeFetcher = new ApiSplitChangeFetcher(sdkApiClient); var sdkSegmentApiClient = new SegmentSdkApiClient("///PUT API KEY HERE///", headers, baseUrl, 10000, 10000, telemetryStorage); var apiSegmentChangeFetcher = new ApiSegmentChangeFetcher(sdkSegmentApiClient); var gates = new InMemoryReadinessGatesCache(); var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>()); var segmentTaskQueue = new SegmentTaskQueue(); var wrapperAdapter = new WrapperAdapter(); var selfRefreshingSegmentFetcher = new SelfRefreshingSegmentFetcher(apiSegmentChangeFetcher, gates, 30, segmentCache, 4, segmentTaskQueue, new TasksManager(wrapperAdapter), wrapperAdapter); var splitParser = new InMemorySplitParser(selfRefreshingSegmentFetcher, segmentCache); var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); var selfRefreshingSplitFetcher = new SelfRefreshingSplitFetcher(apiSplitChangeFetcher, splitParser, gates, 30, new TasksManager(wrapperAdapter), splitCache); selfRefreshingSplitFetcher.Start(); //Act gates.WaitUntilReady(1000); selfRefreshingSplitFetcher.Stop(); ParsedSplit result = (ParsedSplit)splitCache.GetSplit("Pato_Test_1"); ParsedSplit result2 = (ParsedSplit)splitCache.GetSplit("Manu_Test_1"); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.name == "Pato_Test_1"); Assert.IsTrue(result.conditions.Count > 0); }
public void ExecuteGetSuccessfulWithResultsFromJSONFile() { //Arrange var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>()); var splitParser = new InMemorySplitParser(new JSONFileSegmentFetcher("segment_payed.json", segmentCache), segmentCache); var splitChangeFetcher = new JSONFileSplitChangeFetcher("splits_staging.json"); var splitChangesResult = splitChangeFetcher.Fetch(-1); var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); var gates = new InMemoryReadinessGatesCache(); var selfRefreshingSplitFetcher = new SelfRefreshingSplitFetcher(splitChangeFetcher, splitParser, gates, 30, splitCache); selfRefreshingSplitFetcher.Start(); gates.IsSDKReady(1000); //Act ParsedSplit result = (ParsedSplit)splitCache.GetSplit("Pato_Test_1"); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.name == "Pato_Test_1"); Assert.IsTrue(result.conditions.Count > 0); }
public void ExecuteGetSuccessfulWithResults() { //Arrange var baseUrl = "https://sdk-aws-staging.split.io/api/"; //var baseUrl = "http://localhost:3000/api/"; var httpHeader = new HTTPHeader() { authorizationApiKey = "///PUT API KEY HERE///", splitSDKMachineIP = "1.0.0.0", splitSDKMachineName = "localhost", splitSDKVersion = "net-0.0.0", splitSDKSpecVersion = "1.2", encoding = "gzip" }; var sdkApiClient = new SplitSdkApiClient(httpHeader, baseUrl, 10000, 10000); var apiSplitChangeFetcher = new ApiSplitChangeFetcher(sdkApiClient); var sdkSegmentApiClient = new SegmentSdkApiClient(httpHeader, baseUrl, 10000, 10000); var apiSegmentChangeFetcher = new ApiSegmentChangeFetcher(sdkSegmentApiClient); var gates = new InMemoryReadinessGatesCache(); var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>()); var selfRefreshingSegmentFetcher = new SelfRefreshingSegmentFetcher(apiSegmentChangeFetcher, gates, 30, segmentCache, 4); var splitParser = new InMemorySplitParser(selfRefreshingSegmentFetcher, segmentCache); var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); var selfRefreshingSplitFetcher = new SelfRefreshingSplitFetcher(apiSplitChangeFetcher, splitParser, gates, 30, splitCache); selfRefreshingSplitFetcher.Start(); //Act gates.IsSDKReady(1000); selfRefreshingSplitFetcher.Stop(); ParsedSplit result = (ParsedSplit)splitCache.GetSplit("Pato_Test_1"); ParsedSplit result2 = (ParsedSplit)splitCache.GetSplit("Manu_Test_1"); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.name == "Pato_Test_1"); Assert.IsTrue(result.conditions.Count > 0); }
public void GetAllSplitsTest() { //Arrange var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); var splitName = "test1"; var splitName2 = "test2"; //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); }
public void AddOrUpdate_WhenUpdateTraffictType_ReturnsTrue() { // Arrange var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); var splitName = "split_1"; var splitName2 = "split_2"; var split = new ParsedSplit { name = splitName, trafficTypeName = "traffic_type_1" }; var split2 = new ParsedSplit { name = splitName, trafficTypeName = "traffic_type_2" }; var split3 = new ParsedSplit { name = splitName, trafficTypeName = "traffic_type_3" }; var split4 = new ParsedSplit { name = splitName2, trafficTypeName = "traffic_type_4" }; splitCache.AddOrUpdate(splitName, split); splitCache.AddOrUpdate(splitName, split2); splitCache.AddOrUpdate(splitName, split3); splitCache.AddOrUpdate(splitName2, split4); // Act var result1 = splitCache.TrafficTypeExists("traffic_type_1"); var result2 = splitCache.TrafficTypeExists("traffic_type_2"); var result3 = splitCache.TrafficTypeExists("traffic_type_3"); // Assert Assert.IsFalse(result1); Assert.IsFalse(result2); Assert.IsTrue(result3); }
public void SplitReturnRolloutConditionTreatmentsSuccessfully() { //Arrange var conditionsWithLogic = new List <ConditionWithLogic>(); var conditionWithLogic = new ConditionWithLogic() { conditionType = ConditionType.WHITELIST, partitions = new List <PartitionDefinition>() { new PartitionDefinition() { size = 100, treatment = "on" }, } }; conditionsWithLogic.Add(conditionWithLogic); var conditionWithLogic2 = new ConditionWithLogic() { conditionType = ConditionType.ROLLOUT, partitions = new List <PartitionDefinition>() { new PartitionDefinition() { size = 90, treatment = "on" }, new PartitionDefinition() { size = 10, treatment = "off" }, } }; conditionsWithLogic.Add(conditionWithLogic2); var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); splitCache.AddSplit("test1", new ParsedSplit() { name = "test1", changeNumber = 10000, killed = false, trafficTypeName = "user", seed = -1, conditions = conditionsWithLogic }); splitCache.AddSplit("test2", new ParsedSplit() { name = "test2", conditions = conditionsWithLogic }); splitCache.AddSplit("test3", new ParsedSplit() { name = "test3", conditions = conditionsWithLogic }); splitCache.AddSplit("test4", new ParsedSplit() { name = "test4", conditions = conditionsWithLogic }); splitCache.AddSplit("test5", new ParsedSplit() { name = "test5", conditions = conditionsWithLogic }); splitCache.AddSplit("test6", new ParsedSplit() { name = "test6", conditions = conditionsWithLogic }); var manager = new SplitManager(splitCache); //Act var result = manager.Split("test1"); //Assert Assert.IsNotNull(result); Assert.AreEqual(result.name, "test1"); Assert.AreEqual(result.treatments.Count, 2); var firstTreatment = result.treatments[0]; Assert.AreEqual(firstTreatment, "on"); var secondTreatment = result.treatments[1]; Assert.AreEqual(secondTreatment, "off"); }
public void SplitReturnSuccessfully() { //Arrange var conditionsWithLogic = new List <ConditionWithLogic>(); var conditionWithLogic = new ConditionWithLogic() { conditionType = ConditionType.ROLLOUT, partitions = new List <PartitionDefinition>() { new PartitionDefinition() { size = 90, treatment = "on" }, new PartitionDefinition() { size = 10, treatment = "off" } } }; conditionsWithLogic.Add(conditionWithLogic); var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); splitCache.AddSplit("test1", new ParsedSplit() { name = "test1", changeNumber = 10000, killed = false, trafficTypeName = "user", seed = -1, conditions = conditionsWithLogic }); splitCache.AddSplit("test2", new ParsedSplit() { name = "test2", conditions = conditionsWithLogic }); splitCache.AddSplit("test3", new ParsedSplit() { name = "test3", conditions = conditionsWithLogic }); splitCache.AddSplit("test4", new ParsedSplit() { name = "test4", conditions = conditionsWithLogic }); splitCache.AddSplit("test5", new ParsedSplit() { name = "test5", conditions = conditionsWithLogic }); splitCache.AddSplit("test6", new ParsedSplit() { name = "test6", conditions = conditionsWithLogic }); _blockUntilReadyService .Setup(mock => mock.IsSdkReady()) .Returns(true); var manager = new SplitManager(splitCache, _blockUntilReadyService.Object); //Act var result = manager.Split("test1"); //Assert Assert.IsNotNull(result); Assert.AreEqual(result.name, "test1"); Assert.AreEqual(result.changeNumber, 10000); Assert.AreEqual(result.killed, false); Assert.AreEqual(result.trafficType, "user"); Assert.AreEqual(result.treatments.Count, 2); var firstTreatment = result.treatments[0]; Assert.AreEqual(firstTreatment, "on"); var secondTreatment = result.treatments[1]; Assert.AreEqual(secondTreatment, "off"); }
public void Split_WithConfigs_ReturnSuccessfully() { //Arrange var configurations = new Dictionary <string, string> { { "On", "\"Name = \"Test Config\"" } }; var conditionsWithLogic = new List <ConditionWithLogic>(); var conditionWithLogic = new ConditionWithLogic() { partitions = new List <PartitionDefinition>() { new PartitionDefinition() { size = 100, treatment = "on" } } }; conditionsWithLogic.Add(conditionWithLogic); var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); splitCache.AddSplit("test1", new ParsedSplit() { name = "test1", changeNumber = 10000, killed = false, trafficTypeName = "user", seed = -1, conditions = conditionsWithLogic, configurations = configurations }); splitCache.AddSplit("test2", new ParsedSplit() { name = "test2", conditions = conditionsWithLogic, configurations = configurations }); splitCache.AddSplit("test3", new ParsedSplit() { name = "test3", conditions = conditionsWithLogic }); splitCache.AddSplit("test4", new ParsedSplit() { name = "test4", conditions = conditionsWithLogic }); splitCache.AddSplit("test5", new ParsedSplit() { name = "test5", conditions = conditionsWithLogic }); splitCache.AddSplit("test6", new ParsedSplit() { name = "test6", conditions = conditionsWithLogic }); _blockUntilReadyService .Setup(mock => mock.IsSdkReady()) .Returns(true); var manager = new SplitManager(splitCache, _blockUntilReadyService.Object); manager.BlockUntilReady(1000); //Act var result1 = manager.Split("test1"); var result2 = manager.Split("test2"); var result3 = manager.Split("test3"); //Assert Assert.IsNotNull(result1); Assert.IsNotNull(result1.configs); Assert.IsNotNull(result2); Assert.IsNotNull(result2.configs); Assert.IsNotNull(result3); Assert.IsNull(result3.configs); }
private void BuildSplitCache() { _splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>(_config.ConcurrencyLevel, InitialCapacity)); }
private void OnFileChanged(object sender, FileSystemEventArgs e) { var splits = ParseSplitFile(FullPath); splitCache = new InMemorySplitCache(splits); }
public void SplitNamesReturnSuccessfully() { //Arrange var conditionsWithLogic = new List <ConditionWithLogic>(); var conditionWithLogic = new ConditionWithLogic() { partitions = new List <PartitionDefinition>() { new PartitionDefinition() { size = 100, treatment = "on" } } }; conditionsWithLogic.Add(conditionWithLogic); var splitCache = new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>()); splitCache.AddSplit("test1", new ParsedSplit() { name = "test1", changeNumber = 10000, killed = false, trafficTypeName = "user", seed = -1, conditions = conditionsWithLogic }); splitCache.AddSplit("test2", new ParsedSplit() { name = "test2", conditions = conditionsWithLogic }); splitCache.AddSplit("test3", new ParsedSplit() { name = "test3", conditions = conditionsWithLogic }); splitCache.AddSplit("test4", new ParsedSplit() { name = "test4", conditions = conditionsWithLogic }); splitCache.AddSplit("test5", new ParsedSplit() { name = "test5", conditions = conditionsWithLogic }); splitCache.AddSplit("test6", new ParsedSplit() { name = "test6", conditions = conditionsWithLogic }); _blockUntilReadyService .Setup(mock => mock.IsSdkReady()) .Returns(true); var manager = new SplitManager(splitCache, _blockUntilReadyService.Object); manager.BlockUntilReady(1000); //Act var result = manager.SplitNames(); //Assert Assert.IsNotNull(result); Assert.AreEqual(6, result.Count); var firstResult = result.Find(x => x == "test1"); Assert.AreEqual(firstResult, "test1"); }