コード例 #1
0
        public void ParseSuccessfullyWhenMurmurAlgorithm()
        {
            //Arrange
            Split split = new Split();

            split.name             = "test1";
            split.seed             = 2323;
            split.status           = "ACTIVE";
            split.killed           = false;
            split.defaultTreatment = "off";
            split.changeNumber     = 232323;
            split.algo             = 2;
            split.trafficTypeName  = "user";
            split.conditions       = new List <ConditionDefinition>();

            var parser = new InMemorySplitParser(null, null);

            //Act
            var parsedSplit = parser.Parse(split);

            //Assert
            Assert.IsNotNull(parsedSplit);
            Assert.AreEqual(split.name, parsedSplit.name);
            Assert.AreEqual(split.seed, parsedSplit.seed);
            Assert.AreEqual(split.killed, parsedSplit.killed);
            Assert.AreEqual(split.defaultTreatment, parsedSplit.defaultTreatment);
            Assert.AreEqual(split.changeNumber, parsedSplit.changeNumber);
            Assert.AreEqual(AlgorithmEnum.Murmur, parsedSplit.algo);
            Assert.AreEqual(split.trafficTypeName, parsedSplit.trafficTypeName);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        private void BuildSplitFetcher()
        {
            var segmentRefreshRate   = _config.RandomizeRefreshRates ? Random(_config.SegmentRefreshRate) : _config.SegmentRefreshRate;
            var segmentChangeFetcher = new ApiSegmentChangeFetcher(_segmentSdkApiClient);
            var segmentTaskQueue     = new SegmentTaskQueue();

            _selfRefreshingSegmentFetcher = new SelfRefreshingSegmentFetcher(segmentChangeFetcher, _statusManager, segmentRefreshRate, _segmentCache, _config.NumberOfParalellSegmentTasks, segmentTaskQueue, _tasksManager, _wrapperAdapter);

            var splitChangeFetcher = new ApiSplitChangeFetcher(_splitSdkApiClient);
            var splitsRefreshRate  = _config.RandomizeRefreshRates ? Random(_config.SplitsRefreshRate) : _config.SplitsRefreshRate;

            _splitParser          = new InMemorySplitParser((SelfRefreshingSegmentFetcher)_selfRefreshingSegmentFetcher, _segmentCache);
            _splitFetcher         = new SelfRefreshingSplitFetcher(splitChangeFetcher, _splitParser, _statusManager, splitsRefreshRate, _tasksManager, _splitCache);
            _trafficTypeValidator = new TrafficTypeValidator(_splitCache);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        public JSONFileClient(string splitsFilePath,
                              string segmentsFilePath,
                              ISplitLogger log = null,
                              ISegmentCache segmentCacheInstance = null,
                              ISplitCache splitCacheInstance     = null,
                              IImpressionsLog impressionsLog     = null,
                              bool isLabelsEnabled = true,
                              IEventsLog eventsLog = null,
                              ITrafficTypeValidator trafficTypeValidator = null,
                              IImpressionsManager impressionsManager     = null) : base(GetLogger(log))
        {
            _segmentCache = segmentCacheInstance ?? new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>());

            var segmentFetcher     = new JSONFileSegmentFetcher(segmentsFilePath, _segmentCache);
            var splitChangeFetcher = new JSONFileSplitChangeFetcher(splitsFilePath);
            var task = splitChangeFetcher.Fetch(-1);

            task.Wait();

            var splitChangesResult = task.Result;
            var parsedSplits       = new ConcurrentDictionary <string, ParsedSplit>();

            _splitParser = new InMemorySplitParser(segmentFetcher, _segmentCache);

            foreach (var split in splitChangesResult.splits)
            {
                parsedSplits.TryAdd(split.name, _splitParser.Parse(split));
            }

            _splitCache = splitCacheInstance ?? new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>(parsedSplits));

            _impressionsLog = impressionsLog;

            LabelsEnabled = isLabelsEnabled;

            _eventsLog            = eventsLog;
            _trafficTypeValidator = trafficTypeValidator;

            _blockUntilReadyService = new NoopBlockUntilReadyService();
            _manager = new SplitManager(_splitCache, _blockUntilReadyService, log);

            ApiKey = "localhost";

            BuildEvaluator(log);
            _impressionsManager = impressionsManager ?? new ImpressionsManager(impressionsLog, null, null, false, ImpressionsMode.Debug);
        }
コード例 #8
0
        public JSONFileClient(string splitsFilePath, string segmentsFilePath, ISegmentCache segmentCacheInstance = null, ISplitCache splitCacheInstance = null, IImpressionListener treatmentLogInstance = null, bool isLabelsEnabled = true)
        {
            segmentCache = segmentCacheInstance ?? new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>());
            var segmentFetcher     = new JSONFileSegmentFetcher(segmentsFilePath, segmentCache);
            var splitParser        = new InMemorySplitParser(segmentFetcher, segmentCache);
            var splitChangeFetcher = new JSONFileSplitChangeFetcher(splitsFilePath);
            var splitChangesResult = splitChangeFetcher.Fetch(-1);
            var parsedSplits       = new ConcurrentDictionary <string, ParsedSplit>();

            foreach (Split split in splitChangesResult.splits)
            {
                parsedSplits.TryAdd(split.name, splitParser.Parse(split));
            }
            splitCache         = splitCacheInstance ?? new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>(parsedSplits));
            impressionListener = treatmentLogInstance;
            splitter           = new Splitter();
            LabelsEnabled      = isLabelsEnabled;
            manager            = new SplitManager(splitCache);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        public JSONFileClient(string splitsFilePath,
                              string segmentsFilePath,
                              ILog log,
                              ISegmentCache segmentCacheInstance             = null,
                              ISplitCache splitCacheInstance                 = null,
                              IListener <KeyImpression> treatmentLogInstance = null,
                              bool isLabelsEnabled = true,
                              IListener <WrappedEvent> _eventListener    = null,
                              ITrafficTypeValidator trafficTypeValidator = null)  : base(log)
        {
            segmentCache = segmentCacheInstance ?? new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>());

            var segmentFetcher     = new JSONFileSegmentFetcher(segmentsFilePath, segmentCache);
            var splitParser        = new InMemorySplitParser(segmentFetcher, segmentCache);
            var splitChangeFetcher = new JSONFileSplitChangeFetcher(splitsFilePath);
            var task = splitChangeFetcher.Fetch(-1);

            task.Wait();

            var splitChangesResult = task.Result;
            var parsedSplits       = new ConcurrentDictionary <string, ParsedSplit>();

            foreach (Split split in splitChangesResult.splits)
            {
                parsedSplits.TryAdd(split.name, splitParser.Parse(split));
            }

            splitCache         = splitCacheInstance ?? new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>(parsedSplits));
            impressionListener = treatmentLogInstance;
            splitter           = new Splitter();
            LabelsEnabled      = isLabelsEnabled;

            eventListener         = _eventListener;
            _trafficTypeValidator = trafficTypeValidator;

            _blockUntilReadyService = new NoopBlockUntilReadyService();
            manager = new SplitManager(splitCache, _blockUntilReadyService, log);

            ApiKey = "localhost";
        }
コード例 #11
0
        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);
        }
コード例 #12
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);
        }
コード例 #13
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);
        }