Exemple #1
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));
        }
        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);
        }
Exemple #3
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);
        }
Exemple #4
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";
        }
Exemple #5
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);
        }