From 73c8746e47648433d0b6f846b40adb507f3c9906 Mon Sep 17 00:00:00 2001 From: Bill Al Date: Wed, 17 Dec 2025 15:41:19 -0800 Subject: [PATCH 01/15] added event notification to segments and rbsegments cache --- src/Splitio/Constants/Constants.cs | 2 + .../Classes/InMemoryRuleBasedSegmentCache.cs | 13 +++- .../Cache/Classes/InMemorySegmentCache.cs | 16 ++++- .../Services/Client/Classes/JSONFileClient.cs | 5 +- .../Client/Classes/LocalhostClient.cs | 5 +- .../Client/Classes/SelfRefreshingClient.cs | 4 +- .../SelfRefreshingSegmentFetcherTests.cs | 4 +- .../TargetingRulesFetcherTests.cs | 18 ++--- .../InMemory/RuleBasedSegmentCacheTests.cs | 44 ++++++++++++- .../Cache/InMemory/SegmentCacheAsyncTests.cs | 41 +++++++++++- .../Cache/InMemory/SegmentCacheTests.cs | 65 +++++++++++++++++-- .../UserDefinedSegmentMatcherAsyncTests.cs | 25 ++++--- .../UserDefinedSegmentMatcherTests.cs | 25 ++++--- .../SelfRefreshingSegmentFetcherUnitTests.cs | 4 +- .../SelfRefreshingSegmentUnitTests.cs | 7 +- 15 files changed, 230 insertions(+), 48 deletions(-) diff --git a/src/Splitio/Constants/Constants.cs b/src/Splitio/Constants/Constants.cs index f728b179d..318606c6e 100644 --- a/src/Splitio/Constants/Constants.cs +++ b/src/Splitio/Constants/Constants.cs @@ -65,5 +65,7 @@ public static class ApiVersions public static class EventMetadataKeys { public static string Flags => "flags"; + public static string Segments => "segments"; + public static string RuleBasedSegments => "ruleBasedSegments"; } } diff --git a/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs b/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs index 554e20358..2517fc699 100644 --- a/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs @@ -1,5 +1,7 @@ -using Splitio.Domain; +using Splitio.Constants; +using Splitio.Domain; using Splitio.Services.Cache.Interfaces; +using Splitio.Services.Common; using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading.Tasks; @@ -10,12 +12,15 @@ public class InMemoryRuleBasedSegmentCache : IRuleBasedSegmentCache { private readonly ConcurrentDictionary _cache; private long _changeNumber; + private readonly EventsManager _eventsManager; public InMemoryRuleBasedSegmentCache(ConcurrentDictionary cache, + EventsManager eventsManger, long changeNumber = -1) { _cache = cache; _changeNumber = changeNumber; + _eventsManager = eventsManger; } #region Sync Methods @@ -45,9 +50,11 @@ public long GetChangeNumber() // Producer public void Update(List toAdd, List toRemove, long till) { + List toNotify = new List(); foreach (var rbSegment in toAdd) { _cache.AddOrUpdate(rbSegment.Name, rbSegment, (key, oldValue) => rbSegment); + toNotify.Add(rbSegment.Name); } foreach (var name in toRemove) @@ -56,6 +63,10 @@ public void Update(List toAdd, List toRemove, long til } SetChangeNumber(till); + _eventsManager.NotifyInternalEvent(SdkInternalEvent.RuleBasedSegmentsUpdated, + new EventMetadata(new Dictionary { { EventMetadataKeys.RuleBasedSegments, toNotify } }), + Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.RuleBasedSegmentsUpdated, + _eventsManager)); } public void SetChangeNumber(long changeNumber) diff --git a/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs b/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs index f94a3d51f..7655a6e61 100644 --- a/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs @@ -1,5 +1,7 @@ -using Splitio.Domain; +using Splitio.Constants; +using Splitio.Domain; using Splitio.Services.Cache.Interfaces; +using Splitio.Services.Common; using Splitio.Services.Logger; using Splitio.Services.Shared.Classes; using System.Collections.Concurrent; @@ -13,10 +15,12 @@ public class InMemorySegmentCache : ISegmentCache private readonly ISplitLogger _log = WrapperAdapter.Instance().GetLogger(typeof(InMemorySegmentCache)); private readonly ConcurrentDictionary _segments; + private readonly EventsManager _eventsManager; - public InMemorySegmentCache(ConcurrentDictionary segments) + public InMemorySegmentCache(ConcurrentDictionary segments, EventsManager eventsManger) { _segments = segments; + _eventsManager = eventsManger; } #region Methods Sync @@ -31,6 +35,10 @@ public void AddToSegment(string segmentName, List segmentKeys) } segment.AddKeys(segmentKeys); + _eventsManager.NotifyInternalEvent(SdkInternalEvent.SegmentsUpdated, + new EventMetadata(new Dictionary { { EventMetadataKeys.Segments, segmentName } }), + Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SegmentsUpdated, + _eventsManager)); } public void RemoveFromSegment(string segmentName, List segmentKeys) @@ -38,6 +46,10 @@ public void RemoveFromSegment(string segmentName, List segmentKeys) if (_segments.TryGetValue(segmentName, out Segment segment)) { segment.RemoveKeys(segmentKeys); + _eventsManager.NotifyInternalEvent(SdkInternalEvent.SegmentsUpdated, + new EventMetadata(new Dictionary { { EventMetadataKeys.Segments, segmentName } }), + Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SegmentsUpdated, + _eventsManager)); } } diff --git a/src/Splitio/Services/Client/Classes/JSONFileClient.cs b/src/Splitio/Services/Client/Classes/JSONFileClient.cs index 36a5897aa..2ef9df660 100644 --- a/src/Splitio/Services/Client/Classes/JSONFileClient.cs +++ b/src/Splitio/Services/Client/Classes/JSONFileClient.cs @@ -21,7 +21,6 @@ public class JSONFileClient : SplitClient { private readonly IFeatureFlagCache _featureFlagCache; private readonly ISegmentCache _segmentCache; - private EventsManager _eventsManager; public JSONFileClient(string splitsFilePath, string segmentsFilePath, @@ -55,9 +54,9 @@ public JSONFileClient(string splitsFilePath, } BuildFlagSetsFilter(new HashSet()); - _eventsManager = new EventsManager(new EventsManagerConfig()); + var eventsManager = new EventsManager(new EventsManagerConfig()); - _featureFlagCache = featureFlagCacheInstance ?? new InMemorySplitCache(new ConcurrentDictionary(parsedSplits), _flagSetsFilter, _eventsManager); + _featureFlagCache = featureFlagCacheInstance ?? new InMemorySplitCache(new ConcurrentDictionary(parsedSplits), _flagSetsFilter, eventsManager); _impressionsLog = impressionsLog; _eventsLog = eventsLog; _trafficTypeValidator = trafficTypeValidator; diff --git a/src/Splitio/Services/Client/Classes/LocalhostClient.cs b/src/Splitio/Services/Client/Classes/LocalhostClient.cs index deb1bda15..1afea359d 100644 --- a/src/Splitio/Services/Client/Classes/LocalhostClient.cs +++ b/src/Splitio/Services/Client/Classes/LocalhostClient.cs @@ -25,7 +25,6 @@ public class LocalhostClient : SplitClient private readonly IFeatureFlagCache _featureFlagCache; private readonly ILocalhostFileSync _localhostFileSync; private readonly string _fullPath; - private EventsManager _eventsManager; private readonly object _lock = new object(); @@ -48,9 +47,9 @@ public LocalhostClient(ConfigurationOptions configurationOptions, FallbackTreatm BuildFlagSetsFilter(new HashSet()); - _eventsManager = new EventsManager(new EventsManagerConfig()); + var eventsManager = new EventsManager(new EventsManagerConfig()); var splits = _localhostFileService.ParseSplitFile(_fullPath); - _featureFlagCache = new InMemorySplitCache(splits, _flagSetsFilter, _eventsManager); + _featureFlagCache = new InMemorySplitCache(splits, _flagSetsFilter, eventsManager); if (configs.FileSync != null) diff --git a/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs b/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs index 04594e4de..33141a74c 100644 --- a/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs +++ b/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs @@ -101,12 +101,12 @@ private void BuildSplitCache() private void BuildSegmentCache() { - _segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(_config.ConcurrencyLevel, InitialCapacity)); + _segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(_config.ConcurrencyLevel, InitialCapacity), _eventsManager); } private void BuildRuleBasedSegmentCache() { - _ruleBasedSegmentCache = new InMemoryRuleBasedSegmentCache(new ConcurrentDictionary(_config.ConcurrencyLevel, InitialCapacity)); + _ruleBasedSegmentCache = new InMemoryRuleBasedSegmentCache(new ConcurrentDictionary(_config.ConcurrencyLevel, InitialCapacity), _eventsManager); } private void BuildTelemetryStorage() diff --git a/tests/Splitio-tests/Integration Tests/SelfRefreshingSegmentFetcherTests.cs b/tests/Splitio-tests/Integration Tests/SelfRefreshingSegmentFetcherTests.cs index 10cf92515..bde1a5696 100644 --- a/tests/Splitio-tests/Integration Tests/SelfRefreshingSegmentFetcherTests.cs +++ b/tests/Splitio-tests/Integration Tests/SelfRefreshingSegmentFetcherTests.cs @@ -1,6 +1,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Splitio.Domain; using Splitio.Services.Cache.Classes; +using Splitio.Services.Common; using Splitio.Services.SegmentFetcher.Classes; using System.Collections.Concurrent; @@ -26,7 +27,8 @@ public SelfRefreshingSegmentFetcherTests() public void ExecuteGetSuccessfulWithResultsFromJSONFile() { //Arrange - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var segmentFetcher = new JSONFileSegmentFetcher($"{rootFilePath}segment_payed.json", segmentCache); diff --git a/tests/Splitio-tests/Integration Tests/TargetingRulesFetcherTests.cs b/tests/Splitio-tests/Integration Tests/TargetingRulesFetcherTests.cs index 52c5cb4f1..f2b7dfe7c 100644 --- a/tests/Splitio-tests/Integration Tests/TargetingRulesFetcherTests.cs +++ b/tests/Splitio-tests/Integration Tests/TargetingRulesFetcherTests.cs @@ -38,13 +38,13 @@ public TargetingRulesFetcherTests() public async Task ExecuteGetSuccessfulWithResultsFromJSONFile() { //Arrange - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); - var rbsCache = new InMemoryRuleBasedSegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + var rbsCache = new InMemoryRuleBasedSegmentCache(new ConcurrentDictionary(), eventsManager); var segmentFetcher = new JSONFileSegmentFetcher($"{rootFilePath}segment_payed.json", segmentCache); var splitParser = new FeatureFlagParser(segmentCache, segmentFetcher); var splitChangeFetcher = new JSONFileSplitChangeFetcher($"{rootFilePath}splits_staging.json"); var flagSetsFilter = new FlagSetsFilter(new HashSet()); - var eventsManager = new EventsManager(new EventsManagerConfig()); var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), flagSetsFilter, eventsManager); var gates = new InMemoryReadinessGatesCache(); var taskManager = new TasksManager(gates); @@ -84,13 +84,13 @@ public async Task ExecuteGetSuccessfulWithResultsFromJSONFile() public async Task ExecuteGetSuccessfulWithResultsFromJSONFileIncludingTrafficAllocation() { //Arrange - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); - var rbsCache = new InMemoryRuleBasedSegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + var rbsCache = new InMemoryRuleBasedSegmentCache(new ConcurrentDictionary(), eventsManager); var segmentFetcher = new JSONFileSegmentFetcher($"{rootFilePath}segment_payed.json", segmentCache); var splitParser = new FeatureFlagParser(segmentCache, segmentFetcher); var splitChangeFetcher = new JSONFileSplitChangeFetcher($"{rootFilePath}splits_staging_4.json"); var flagSetsFilter = new FlagSetsFilter(new HashSet()); - var eventsManager = new EventsManager(new EventsManagerConfig()); var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), flagSetsFilter, eventsManager); var gates = new InMemoryReadinessGatesCache(); var taskManager = new TasksManager(gates); @@ -142,16 +142,16 @@ public async Task ExecuteGetWithoutResults() var sdkSegmentApiClient = new SegmentSdkApiClient(httpClient, telemetryStorage, baseUrl); var apiSegmentChangeFetcher = new ApiSegmentChangeFetcher(sdkSegmentApiClient); var gates = new InMemoryReadinessGatesCache(); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var segmentsQueue = new SplitQueue(); var taskManager = new TasksManager(gates); var worker = new SegmentTaskWorker(4, segmentsQueue); segmentsQueue.AddObserver(worker); var segmentsTask = taskManager.NewPeriodicTask(Splitio.Enums.Task.SegmentsFetcher, 3000); var segmentFetcher = new SelfRefreshingSegmentFetcher(apiSegmentChangeFetcher, segmentCache, segmentsQueue, segmentsTask, gates); - var rbsCache = new InMemoryRuleBasedSegmentCache(new ConcurrentDictionary()); + var rbsCache = new InMemoryRuleBasedSegmentCache(new ConcurrentDictionary(), eventsManager); var splitParser = new FeatureFlagParser(segmentCache, segmentFetcher); - var eventsManager = new EventsManager(new EventsManagerConfig()); var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), flagSetsFilter, eventsManager); var task = taskManager.NewPeriodicTask(Splitio.Enums.Task.FeatureFlagsFetcher, 3000); var featureFlagSyncService = new FeatureFlagUpdater(splitParser, splitCache, flagSetsFilter, rbsCache); diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs index 763ac6ebe..e3ba2df2a 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs @@ -1,6 +1,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Splitio.Domain; using Splitio.Services.Cache.Classes; +using Splitio.Services.Common; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading.Tasks; @@ -11,12 +13,17 @@ namespace Splitio_Tests.Unit_Tests.Cache.InMemory public class RuleBasedSegmentCacheTests { private InMemoryRuleBasedSegmentCache _segmentCache; + private EventsManager _eventsManager; + private bool SdkUpdate = false; + private EventMetadata eMetadata = null; + public event EventHandler PublicSdkUpdateHandler; [TestInitialize] public void Setup() { var cache = new ConcurrentDictionary(); - _segmentCache = new InMemoryRuleBasedSegmentCache(cache); + _eventsManager = new EventsManager(new EventsManagerConfig()); + _segmentCache = new InMemoryRuleBasedSegmentCache(cache, _eventsManager); } [TestMethod] @@ -142,5 +149,40 @@ public void Contains_ShouldReturnTrue() Assert.IsFalse(_segmentCache.Contains(new List { "segment1", "segment3" })); Assert.IsTrue(_segmentCache.Contains(new List { "segment1", "segment2" })); } + + [TestMethod] + public void Update_ShouldNotifyEvent() + { + // Arrange + Splitio.Util.Helper.BuildInternalSdkEventStatus(_eventsManager); + + var segmentToAdd = new RuleBasedSegment { Name = "segment-to-add" }; + var segmentToRemove = new RuleBasedSegment { Name = "segment-to-remove" }; + var till = 67890; + var toNotify = new List { { "segment-to-add" } }; + PublicSdkUpdateHandler += sdkUpdate_callback; + _eventsManager.Register(SdkEvent.SdkUpdate, sdkUpdate_callback); + _eventsManager.Register(SdkEvent.SdkReady, sdkUpdate_callback); + _eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(new Dictionary()), + Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkReady, _eventsManager)); + + // Act + SdkUpdate = false; + _segmentCache.Update(new List { segmentToAdd, segmentToRemove }, new List { segmentToRemove.Name }, till); + + // Assert + Assert.IsTrue(SdkUpdate); + Assert.IsTrue(eMetadata.ContainKey(Splitio.Constants.EventMetadataKeys.RuleBasedSegments)); + List rbsegments = (List)eMetadata.GetData()[Splitio.Constants.EventMetadataKeys.RuleBasedSegments]; + Assert.IsTrue(rbsegments.Count == 2); + Assert.IsTrue(rbsegments.Contains("segment-to-add")); + Assert.IsTrue(rbsegments.Contains("segment-to-remove")); + } + + private void sdkUpdate_callback(object sender, EventMetadata metadata) + { + SdkUpdate = true; + eMetadata = metadata; + } } } diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheAsyncTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheAsyncTests.cs index c08a7515c..806d67b2b 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheAsyncTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheAsyncTests.cs @@ -2,9 +2,12 @@ using Splitio.Domain; using Splitio.Services.Cache.Classes; using Splitio.Services.Cache.Interfaces; +using Splitio.Services.Common; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading.Tasks; +using WireMock.Pact.Models.V2; namespace Splitio_Tests.Unit_Tests.Cache { @@ -12,12 +15,16 @@ namespace Splitio_Tests.Unit_Tests.Cache public class SegmentCacheAsyncTests { private readonly ISegmentCache _cache; + private EventsManager _eventsManager; + private bool SdkUpdate = false; + private EventMetadata eMetadata = null; + public event EventHandler PublicSdkUpdateHandler; public SegmentCacheAsyncTests() { var segments = new ConcurrentDictionary(); - - _cache = new InMemorySegmentCache(segments); + _eventsManager = new EventsManager(new EventsManagerConfig()); + _cache = new InMemorySegmentCache(segments, _eventsManager); } [TestMethod] @@ -47,5 +54,35 @@ public async Task IsInSegmentAsyncTestTrue() //Assert Assert.IsTrue(result); } + + [TestMethod] + public async Task NotifyEventsTest() + { + //Arrange + var segmentName = "segment_test"; + Splitio.Util.Helper.BuildInternalSdkEventStatus(_eventsManager); + var toNotify = new List { { segmentName } }; + PublicSdkUpdateHandler += sdkUpdate_callback; + _eventsManager.Register(SdkEvent.SdkUpdate, sdkUpdate_callback); + _eventsManager.Register(SdkEvent.SdkReady, sdkUpdate_callback); + _eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(new Dictionary()), + Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkReady, _eventsManager)); + + //Act + SdkUpdate = false; + _cache.AddToSegment(segmentName, new List { "abcd", "zzzzf" }); + + //Assert + Assert.IsTrue(SdkUpdate); + Assert.IsTrue(eMetadata.ContainKey(Splitio.Constants.EventMetadataKeys.Segments)); + string segment = (string)eMetadata.GetData()[Splitio.Constants.EventMetadataKeys.Segments]; + Assert.AreEqual(segmentName, segment); + } + + private void sdkUpdate_callback(object sender, EventMetadata metadata) + { + SdkUpdate = true; + eMetadata = metadata; + } } } diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheTests.cs index 287f18750..b81611a4e 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheTests.cs @@ -1,6 +1,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Splitio.Domain; using Splitio.Services.Cache.Classes; +using Splitio.Services.Common; +using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -9,11 +11,16 @@ namespace Splitio_Tests.Unit_Tests.Cache [TestClass] public class SegmentCacheTests { + private bool SdkUpdate = false; + private EventMetadata eMetadata = null; + public event EventHandler PublicSdkUpdateHandler; + [TestMethod] public void RegisterSegmentTest() { //Arrange - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var keys = new List { "abcd", "1234" }; var segmentName = "test"; @@ -29,7 +36,8 @@ public void RegisterSegmentTest() public void IsNotInSegmentTest() { //Arrange - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var keys = new List { "1234" }; var segmentName = "test"; @@ -45,7 +53,8 @@ public void IsNotInSegmentTest() public void IsInSegmentWithInexistentSegmentTest() { //Arrange - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); //Act var result = segmentCache.IsInSegment("test", "abcd"); @@ -58,7 +67,8 @@ public void IsInSegmentWithInexistentSegmentTest() public void RemoveKeyFromSegmentTest() { //Arrange - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var keys = new List { "1234" }; var segmentName = "test"; @@ -77,7 +87,8 @@ public void RemoveKeyFromSegmentTest() public void SetAndGetChangeNumberTest() { //Arrange - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var segmentName = "test"; //Act @@ -88,5 +99,49 @@ public void SetAndGetChangeNumberTest() //Assert Assert.AreEqual(1234, result); } + + [TestMethod] + public void NotifyEventsTest() + { + //Arrange + var eventsManager = new EventsManager(new EventsManagerConfig()); + Splitio.Util.Helper.BuildInternalSdkEventStatus(eventsManager); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + var keys = new List { "1234" }; + var segmentName = "test"; + var toNotify = new List { { segmentName } }; + PublicSdkUpdateHandler += sdkUpdate_callback; + eventsManager.Register(SdkEvent.SdkUpdate, sdkUpdate_callback); + eventsManager.Register(SdkEvent.SdkReady, sdkUpdate_callback); + eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(new Dictionary()), + Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkReady, eventsManager)); + + // Act + SdkUpdate = false; + segmentCache.AddToSegment(segmentName, keys); + + //Assert + Assert.IsTrue(SdkUpdate); + Assert.IsTrue(eMetadata.ContainKey(Splitio.Constants.EventMetadataKeys.Segments)); + string segment = (string) eMetadata.GetData()[Splitio.Constants.EventMetadataKeys.Segments]; + Assert.AreEqual(segmentName, segment); + + // Act + SdkUpdate = false; + eMetadata = null; + segmentCache.RemoveFromSegment(segmentName, keys); + + //Assert + Assert.IsTrue(SdkUpdate); + Assert.IsTrue(eMetadata.ContainKey(Splitio.Constants.EventMetadataKeys.Segments)); + segment = (string)eMetadata.GetData()[Splitio.Constants.EventMetadataKeys.Segments]; + Assert.AreEqual(segmentName, segment); + } + + private void sdkUpdate_callback(object sender, EventMetadata metadata) + { + SdkUpdate = true; + eMetadata = metadata; + } } } diff --git a/tests/Splitio-tests/Unit Tests/Matchers/UserDefinedSegmentMatcherAsyncTests.cs b/tests/Splitio-tests/Unit Tests/Matchers/UserDefinedSegmentMatcherAsyncTests.cs index 1a7a087ff..e870361b2 100644 --- a/tests/Splitio-tests/Unit Tests/Matchers/UserDefinedSegmentMatcherAsyncTests.cs +++ b/tests/Splitio-tests/Unit Tests/Matchers/UserDefinedSegmentMatcherAsyncTests.cs @@ -1,6 +1,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Splitio.Domain; using Splitio.Services.Cache.Classes; +using Splitio.Services.Common; using Splitio.Services.Parsing; using System.Collections.Concurrent; using System.Collections.Generic; @@ -22,7 +23,8 @@ public async Task MatchAsyncShouldReturnTrueOnMatchingSegmentWithKey() }; var segmentName = "test-segment"; - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); segmentCache.AddToSegment(segmentName, keys); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -45,7 +47,8 @@ public async Task MatchAsyncShouldReturnFalseOnNonMatchingSegmentWithKey() }; var segmentName = "test-segment"; - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); segmentCache.AddToSegment(segmentName, keys); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -62,7 +65,8 @@ public async Task MatchAsyncShouldReturnFalseIfSegmentEmptyWithKey() { //Arrange var segmentName = "test-segment"; - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); segmentCache.AddToSegment(segmentName, null); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -79,7 +83,8 @@ public async Task MatchAsyncShouldReturnFalseIfCacheEmptyWithKey() { //Arrange var segmentName = "test-segment"; - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -101,7 +106,8 @@ public async Task MatchAsyncShouldReturnTrueOnMatchingSegment() }; var segmentName = "test-segment"; - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); segmentCache.AddToSegment(segmentName, keys); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -124,7 +130,8 @@ public async Task MatchAsyncShouldReturnFalseOnNonMatchingSegment() }; var segmentName = "test-segment"; - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); segmentCache.AddToSegment(segmentName, keys); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -141,7 +148,8 @@ public async Task MatchAsyncShouldReturnFalseIfSegmentEmpty() { //Arrange var segmentName = "test-segment"; - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); segmentCache.AddToSegment(segmentName, null); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -158,7 +166,8 @@ public async Task MatchAsyncShouldReturnFalseIfCacheEmpty() { //Arrange var segmentName = "test-segment"; - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); diff --git a/tests/Splitio-tests/Unit Tests/Matchers/UserDefinedSegmentMatcherTests.cs b/tests/Splitio-tests/Unit Tests/Matchers/UserDefinedSegmentMatcherTests.cs index e35113990..112399737 100644 --- a/tests/Splitio-tests/Unit Tests/Matchers/UserDefinedSegmentMatcherTests.cs +++ b/tests/Splitio-tests/Unit Tests/Matchers/UserDefinedSegmentMatcherTests.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Collections.Concurrent; using Splitio.Services.Cache.Classes; +using Splitio.Services.Common; namespace Splitio_Tests.Unit_Tests { @@ -21,7 +22,8 @@ public void MatchShouldReturnTrueOnMatchingSegmentWithKey() }; var segmentName = "test-segment"; - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); segmentCache.AddToSegment(segmentName, keys); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -44,7 +46,8 @@ public void MatchShouldReturnFalseOnNonMatchingSegmentWithKey() }; var segmentName = "test-segment"; - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); segmentCache.AddToSegment(segmentName, keys); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -61,7 +64,8 @@ public void MatchShouldReturnFalseIfSegmentEmptyWithKey() { //Arrange var segmentName = "test-segment"; - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); segmentCache.AddToSegment(segmentName, null); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -78,7 +82,8 @@ public void MatchShouldReturnFalseIfCacheEmptyWithKey() { //Arrange var segmentName = "test-segment"; - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -100,7 +105,8 @@ public void MatchShouldReturnTrueOnMatchingSegment() }; var segmentName = "test-segment"; - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); segmentCache.AddToSegment(segmentName, keys); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -123,7 +129,8 @@ public void MatchShouldReturnFalseOnNonMatchingSegment() }; var segmentName = "test-segment"; - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); segmentCache.AddToSegment(segmentName, keys); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -140,7 +147,8 @@ public void MatchShouldReturnFalseIfSegmentEmpty() { //Arrange var segmentName = "test-segment"; - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); segmentCache.AddToSegment(segmentName, null); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -157,7 +165,8 @@ public void MatchShouldReturnFalseIfCacheEmpty() { //Arrange var segmentName = "test-segment"; - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); diff --git a/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs b/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs index b2eac5b97..9e242cc83 100644 --- a/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs @@ -4,6 +4,7 @@ using Splitio.Services.Cache.Classes; using Splitio.Services.Cache.Interfaces; using Splitio.Services.Client.Classes; +using Splitio.Services.Common; using Splitio.Services.SegmentFetcher.Classes; using Splitio.Services.SegmentFetcher.Interfaces; using Splitio.Services.Shared.Classes; @@ -31,7 +32,8 @@ public void InitializeSegmentNotExistent() var apiClient = new Mock(); var apiFetcher = new ApiSegmentChangeFetcher(apiClient.Object); var segments = new ConcurrentDictionary(); - var cache = new InMemorySegmentCache(segments); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var cache = new InMemorySegmentCache(segments, eventsManager); var segmentsQueue = new SplitQueue(); var taskManager = new TasksManager(gates); var worker = new SegmentTaskWorker(5, segmentsQueue); diff --git a/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentUnitTests.cs b/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentUnitTests.cs index 228dc4c59..06f32febe 100644 --- a/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentUnitTests.cs @@ -3,6 +3,7 @@ using Splitio.Domain; using Splitio.Services.Cache.Classes; using Splitio.Services.Cache.Interfaces; +using Splitio.Services.Common; using Splitio.Services.SegmentFetcher.Classes; using Splitio.Services.SplitFetcher.Interfaces; using System; @@ -22,7 +23,8 @@ public async Task FetchSegmentNullChangesFetcherResponseShouldNotUpdateCache() var statusManager = new Mock(); var apiFetcher = new ApiSegmentChangeFetcher(apiClient.Object); var segments = new ConcurrentDictionary(); - var cache = new InMemorySegmentCache(segments); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var cache = new InMemorySegmentCache(segments, eventsManager); var segmentFetcher = new SelfRefreshingSegment("payed", apiFetcher, cache, statusManager.Object); apiClient @@ -44,7 +46,8 @@ public async Task FetchSegmentShouldUpdateSegmentsCache() var statusManager = new Mock(); var apiFetcher = new ApiSegmentChangeFetcher(apiClient.Object); var segments = new ConcurrentDictionary(); - var cache = new InMemorySegmentCache(segments); + var eventsManager = new EventsManager(new EventsManagerConfig()); + var cache = new InMemorySegmentCache(segments, eventsManager); var segmentFetcher = new SelfRefreshingSegment("payed", apiFetcher, cache, statusManager.Object); apiClient From 39fa4194d48c7e9dc09a38acb979d85a858b255f Mon Sep 17 00:00:00 2001 From: Bill Al Date: Wed, 17 Dec 2025 15:57:52 -0800 Subject: [PATCH 02/15] fixed building jsonlocal client --- src/Splitio/Services/Client/Classes/JSONFileClient.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Splitio/Services/Client/Classes/JSONFileClient.cs b/src/Splitio/Services/Client/Classes/JSONFileClient.cs index 2ef9df660..ebc40e1a6 100644 --- a/src/Splitio/Services/Client/Classes/JSONFileClient.cs +++ b/src/Splitio/Services/Client/Classes/JSONFileClient.cs @@ -35,8 +35,9 @@ public JSONFileClient(string splitsFilePath, IRuleBasedSegmentCache ruleBasedSegmentCache = null ) : base("localhost", fallbackTreatmentCalculator) { - _segmentCache = segmentCacheInstance ?? new InMemorySegmentCache(new ConcurrentDictionary()); - var rbsCache = ruleBasedSegmentCache ?? new InMemoryRuleBasedSegmentCache(new ConcurrentDictionary()); + var eventsManager = new EventsManager(new EventsManagerConfig()); + _segmentCache = segmentCacheInstance ?? new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + var rbsCache = ruleBasedSegmentCache ?? new InMemoryRuleBasedSegmentCache(new ConcurrentDictionary(), eventsManager); var segmentFetcher = new JSONFileSegmentFetcher(segmentsFilePath, _segmentCache); var splitChangeFetcher = new JSONFileSplitChangeFetcher(splitsFilePath); @@ -54,7 +55,6 @@ public JSONFileClient(string splitsFilePath, } BuildFlagSetsFilter(new HashSet()); - var eventsManager = new EventsManager(new EventsManagerConfig()); _featureFlagCache = featureFlagCacheInstance ?? new InMemorySplitCache(new ConcurrentDictionary(parsedSplits), _flagSetsFilter, eventsManager); _impressionsLog = impressionsLog; From b6d8a66ed9702817dcc85a7362c7e8fe893ac7a0 Mon Sep 17 00:00:00 2001 From: Bilal Al-Shahwany <41021307+chillaq@users.noreply.github.com> Date: Mon, 22 Dec 2025 08:45:39 -0800 Subject: [PATCH 03/15] Update src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs Co-authored-by: Mauro Sanz <51236193+sanzmauro@users.noreply.github.com> --- .../Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs b/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs index 2517fc699..555d10f4e 100644 --- a/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs @@ -15,7 +15,7 @@ public class InMemoryRuleBasedSegmentCache : IRuleBasedSegmentCache private readonly EventsManager _eventsManager; public InMemoryRuleBasedSegmentCache(ConcurrentDictionary cache, - EventsManager eventsManger, + IEventsManager eventsManger, long changeNumber = -1) { _cache = cache; From 376b7adea1aacc048a23fd3ba6b2ce02417ace98 Mon Sep 17 00:00:00 2001 From: Bilal Al-Shahwany <41021307+chillaq@users.noreply.github.com> Date: Mon, 22 Dec 2025 08:45:45 -0800 Subject: [PATCH 04/15] Update src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs Co-authored-by: Mauro Sanz <51236193+sanzmauro@users.noreply.github.com> --- .../Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs b/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs index 555d10f4e..e6410984e 100644 --- a/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs @@ -12,7 +12,7 @@ public class InMemoryRuleBasedSegmentCache : IRuleBasedSegmentCache { private readonly ConcurrentDictionary _cache; private long _changeNumber; - private readonly EventsManager _eventsManager; + private readonly IEventsManager _eventsManager; public InMemoryRuleBasedSegmentCache(ConcurrentDictionary cache, IEventsManager eventsManger, From 00f0868edf83df9c857a5b1e29c7b3f6d0af1190 Mon Sep 17 00:00:00 2001 From: Bilal Al-Shahwany <41021307+chillaq@users.noreply.github.com> Date: Mon, 22 Dec 2025 08:45:55 -0800 Subject: [PATCH 05/15] Update src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs Co-authored-by: Mauro Sanz <51236193+sanzmauro@users.noreply.github.com> --- src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs b/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs index 7655a6e61..10ec56c0a 100644 --- a/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs @@ -15,7 +15,7 @@ public class InMemorySegmentCache : ISegmentCache private readonly ISplitLogger _log = WrapperAdapter.Instance().GetLogger(typeof(InMemorySegmentCache)); private readonly ConcurrentDictionary _segments; - private readonly EventsManager _eventsManager; + private readonly IEventsManager _eventsManager; public InMemorySegmentCache(ConcurrentDictionary segments, EventsManager eventsManger) { From 5bd554e28536fa805df55252ef9e57f833bb5615 Mon Sep 17 00:00:00 2001 From: Bilal Al-Shahwany <41021307+chillaq@users.noreply.github.com> Date: Mon, 22 Dec 2025 08:46:03 -0800 Subject: [PATCH 06/15] Update src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs Co-authored-by: Mauro Sanz <51236193+sanzmauro@users.noreply.github.com> --- src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs b/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs index 10ec56c0a..cf00d483a 100644 --- a/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs @@ -17,7 +17,7 @@ public class InMemorySegmentCache : ISegmentCache private readonly ConcurrentDictionary _segments; private readonly IEventsManager _eventsManager; - public InMemorySegmentCache(ConcurrentDictionary segments, EventsManager eventsManger) + public InMemorySegmentCache(ConcurrentDictionary segments, IEventsManager eventsManger) { _segments = segments; _eventsManager = eventsManger; From 9c32ca03ebe9aa01d01dfed1267486a61e99501b Mon Sep 17 00:00:00 2001 From: Bill Al Date: Mon, 22 Dec 2025 08:53:19 -0800 Subject: [PATCH 07/15] Added notify when removing rbsegment --- .../Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs | 6 ++++-- src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs b/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs index e6410984e..1789b8e97 100644 --- a/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs @@ -2,6 +2,7 @@ using Splitio.Domain; using Splitio.Services.Cache.Interfaces; using Splitio.Services.Common; +using Splitio.Services.SegmentFetcher.Interfaces; using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading.Tasks; @@ -12,10 +13,10 @@ public class InMemoryRuleBasedSegmentCache : IRuleBasedSegmentCache { private readonly ConcurrentDictionary _cache; private long _changeNumber; - private readonly IEventsManager _eventsManager; + private readonly EventsManager _eventsManager; public InMemoryRuleBasedSegmentCache(ConcurrentDictionary cache, - IEventsManager eventsManger, + EventsManager eventsManger, long changeNumber = -1) { _cache = cache; @@ -60,6 +61,7 @@ public void Update(List toAdd, List toRemove, long til foreach (var name in toRemove) { _cache.TryRemove(name, out var _); + toNotify.Add(name); } SetChangeNumber(till); diff --git a/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs b/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs index cf00d483a..7655a6e61 100644 --- a/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs @@ -15,9 +15,9 @@ public class InMemorySegmentCache : ISegmentCache private readonly ISplitLogger _log = WrapperAdapter.Instance().GetLogger(typeof(InMemorySegmentCache)); private readonly ConcurrentDictionary _segments; - private readonly IEventsManager _eventsManager; + private readonly EventsManager _eventsManager; - public InMemorySegmentCache(ConcurrentDictionary segments, IEventsManager eventsManger) + public InMemorySegmentCache(ConcurrentDictionary segments, EventsManager eventsManger) { _segments = segments; _eventsManager = eventsManger; From 492d2e2d84d17ae69569a31228af18059945bd4d Mon Sep 17 00:00:00 2001 From: Bill Al Date: Mon, 22 Dec 2025 09:43:44 -0800 Subject: [PATCH 08/15] fixed test --- .../Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs index e3ba2df2a..eddab8b7a 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs @@ -159,7 +159,7 @@ public void Update_ShouldNotifyEvent() var segmentToAdd = new RuleBasedSegment { Name = "segment-to-add" }; var segmentToRemove = new RuleBasedSegment { Name = "segment-to-remove" }; var till = 67890; - var toNotify = new List { { "segment-to-add" } }; + var toNotify = new List { { "segment-to-add" }, { "segment-to-remove" } }; PublicSdkUpdateHandler += sdkUpdate_callback; _eventsManager.Register(SdkEvent.SdkUpdate, sdkUpdate_callback); _eventsManager.Register(SdkEvent.SdkReady, sdkUpdate_callback); @@ -174,7 +174,7 @@ public void Update_ShouldNotifyEvent() Assert.IsTrue(SdkUpdate); Assert.IsTrue(eMetadata.ContainKey(Splitio.Constants.EventMetadataKeys.RuleBasedSegments)); List rbsegments = (List)eMetadata.GetData()[Splitio.Constants.EventMetadataKeys.RuleBasedSegments]; - Assert.IsTrue(rbsegments.Count == 2); + Assert.IsTrue(rbsegments.Count == 3); Assert.IsTrue(rbsegments.Contains("segment-to-add")); Assert.IsTrue(rbsegments.Contains("segment-to-remove")); } From 015310e6cf4e0e1b1691fccdec9d198394a5ace5 Mon Sep 17 00:00:00 2001 From: Bill Al Date: Mon, 22 Dec 2025 14:44:40 -0800 Subject: [PATCH 09/15] moved helper fucntions to events manager class --- .../Classes/InMemoryRuleBasedSegmentCache.cs | 5 +- .../Cache/Classes/InMemorySegmentCache.cs | 8 +- .../Cache/Classes/InMemorySplitCache.cs | 8 +- .../Services/Client/Classes/SplitClient.cs | 3 + src/Splitio/Services/Common/EventDelivery.cs | 2 +- src/Splitio/Services/Common/EventsManager.cs | 142 ++++++++++++++++- src/Splitio/Services/Common/IEventsManager.cs | 2 +- src/Splitio/Util/Helper.cs | 146 ------------------ .../InMemory/RuleBasedSegmentCacheTests.cs | 4 +- .../Cache/InMemory/SegmentCacheAsyncTests.cs | 5 +- .../Cache/InMemory/SegmentCacheTests.cs | 4 +- .../Cache/InMemory/SplitCacheAsyncTests.cs | 4 +- .../Cache/InMemory/SplitCacheTests.cs | 4 +- .../Unit Tests/Common/EventsManagerTests.cs | 75 ++++----- 14 files changed, 180 insertions(+), 232 deletions(-) diff --git a/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs b/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs index 1789b8e97..30c1fbc90 100644 --- a/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs @@ -2,7 +2,6 @@ using Splitio.Domain; using Splitio.Services.Cache.Interfaces; using Splitio.Services.Common; -using Splitio.Services.SegmentFetcher.Interfaces; using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading.Tasks; @@ -66,9 +65,7 @@ public void Update(List toAdd, List toRemove, long til SetChangeNumber(till); _eventsManager.NotifyInternalEvent(SdkInternalEvent.RuleBasedSegmentsUpdated, - new EventMetadata(new Dictionary { { EventMetadataKeys.RuleBasedSegments, toNotify } }), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.RuleBasedSegmentsUpdated, - _eventsManager)); + new EventMetadata(new Dictionary { { EventMetadataKeys.RuleBasedSegments, toNotify } })); } public void SetChangeNumber(long changeNumber) diff --git a/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs b/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs index 7655a6e61..c0b5d8a5d 100644 --- a/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs @@ -36,9 +36,7 @@ public void AddToSegment(string segmentName, List segmentKeys) segment.AddKeys(segmentKeys); _eventsManager.NotifyInternalEvent(SdkInternalEvent.SegmentsUpdated, - new EventMetadata(new Dictionary { { EventMetadataKeys.Segments, segmentName } }), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SegmentsUpdated, - _eventsManager)); + new EventMetadata(new Dictionary { { EventMetadataKeys.Segments, segmentName } })); } public void RemoveFromSegment(string segmentName, List segmentKeys) @@ -47,9 +45,7 @@ public void RemoveFromSegment(string segmentName, List segmentKeys) { segment.RemoveKeys(segmentKeys); _eventsManager.NotifyInternalEvent(SdkInternalEvent.SegmentsUpdated, - new EventMetadata(new Dictionary { { EventMetadataKeys.Segments, segmentName } }), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SegmentsUpdated, - _eventsManager)); + new EventMetadata(new Dictionary { { EventMetadataKeys.Segments, segmentName } })); } } diff --git a/src/Splitio/Services/Cache/Classes/InMemorySplitCache.cs b/src/Splitio/Services/Cache/Classes/InMemorySplitCache.cs index bd3f53c09..d222aa129 100644 --- a/src/Splitio/Services/Cache/Classes/InMemorySplitCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemorySplitCache.cs @@ -79,9 +79,7 @@ public void Update(List toAdd, List toRemove, long till) SetChangeNumber(till); _eventsManager.NotifyInternalEvent(SdkInternalEvent.FlagsUpdated, - new EventMetadata(new Dictionary { { EventMetadataKeys.Flags, eventsFlags } }), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.FlagsUpdated, - _eventsManager)); + new EventMetadata(new Dictionary { { EventMetadataKeys.Flags, eventsFlags } })); } public void SetChangeNumber(long changeNumber) @@ -154,9 +152,7 @@ public void Kill(long changeNumber, string splitName, string defaultTreatment) _featureFlags.AddOrUpdate(featureFlag.name, featureFlag, (key, oldValue) => featureFlag); _eventsManager.NotifyInternalEvent(SdkInternalEvent.FlagKilledNotification, - new EventMetadata(new Dictionary { { EventMetadataKeys.Flags, new List { { featureFlag.name } } } }), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.FlagKilledNotification, - _eventsManager)); + new EventMetadata(new Dictionary { { EventMetadataKeys.Flags, new List { { featureFlag.name } } } })); } diff --git a/src/Splitio/Services/Client/Classes/SplitClient.cs b/src/Splitio/Services/Client/Classes/SplitClient.cs index 54297fdf8..4372c344f 100644 --- a/src/Splitio/Services/Client/Classes/SplitClient.cs +++ b/src/Splitio/Services/Client/Classes/SplitClient.cs @@ -63,6 +63,9 @@ public abstract class SplitClient : ISplitClient protected IImpressionsObserver _impressionsObserver; protected IClientExtensionService _clientExtensionService; protected IFlagSetsFilter _flagSetsFilter; + public event EventHandler PublicSdkReadyHandler; + public event EventHandler PublicSdkUpdateHandler; + public event EventHandler PublicSdkTimedOutHandler; protected SplitClient(string apikey, FallbackTreatmentCalculator fallbackTreatmentCalculator) { diff --git a/src/Splitio/Services/Common/EventDelivery.cs b/src/Splitio/Services/Common/EventDelivery.cs index be28dd36b..b97e7a32c 100644 --- a/src/Splitio/Services/Common/EventDelivery.cs +++ b/src/Splitio/Services/Common/EventDelivery.cs @@ -15,7 +15,7 @@ public virtual void Deliver(E sdkEvent, M eventMetadata, EventHandler handler _logger.Debug($"EventDelivery: Triggering handle for Sdk Event {sdkEvent}"); try { - handler(this, eventMetadata); + handler.Invoke(this, eventMetadata); } catch (Exception e) { diff --git a/src/Splitio/Services/Common/EventsManager.cs b/src/Splitio/Services/Common/EventsManager.cs index acb23688e..79ad83735 100644 --- a/src/Splitio/Services/Common/EventsManager.cs +++ b/src/Splitio/Services/Common/EventsManager.cs @@ -4,11 +4,18 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Linq; namespace Splitio.Services.Common { public class EventsManager : IEventsManager { + public struct ValidSdkEvent + { + public E SdkEvent { get; set; } + public bool Valid { get; set; } + } + private struct PublicEventProperties { public bool Triggered; @@ -19,14 +26,14 @@ private struct PublicEventProperties private readonly ISplitLogger _logger = WrapperAdapter.Instance().GetLogger("EventsManager"); private readonly EventDelivery _eventDelivery; private readonly object _lock = new object(); - public EventsManagerConfig ManagerConfig { get; private set; } + public EventManagerConfigData _managerConfig { get; private set; } - public EventsManager(EventsManagerConfig eventsManagerConfig) + public EventsManager(EventManagerConfigData eventsManagerConfig) { _activeSubscriptions = new ConcurrentDictionary(); _internalEventsStatus = new ConcurrentDictionary(); _eventDelivery = new EventDelivery(); - ManagerConfig = eventsManagerConfig; + _managerConfig = eventsManagerConfig; } #region Public Methods @@ -53,13 +60,13 @@ public void Unregister(E sdkEvent) } } - public void NotifyInternalEvent(I sdkInternalEvent, M eventMetadata, List eventsToNotify) + public void NotifyInternalEvent(I sdkInternalEvent, M eventMetadata) { lock (_lock) { _logger.Debug($"EventsManager: Handling internal event {sdkInternalEvent}"); - foreach (E sdkEvent in eventsToNotify) + foreach (E sdkEvent in GetSdkEventIfApplicable(sdkInternalEvent)) { _logger.Debug($"EventsManager: Firing Sdk event {sdkEvent}"); _eventDelivery.Deliver(sdkEvent, eventMetadata, GetEventHandler(sdkEvent)); @@ -118,6 +125,131 @@ private EventHandler GetEventHandler(E sdkEvent) return eventData.EventHandler; } + + public List GetSdkEventIfApplicable(I sdkInternalEvent) + { + ValidSdkEvent finalSdkEvent = new ValidSdkEvent + { + Valid = false +// SdkEvent = SdkEvent.SdkReady + }; + UpdateSdkInternalEventStatus(sdkInternalEvent, true); + List eventsToFire = new List(); + + ValidSdkEvent requireAnySdkEvent = CheckRequireAny(sdkInternalEvent); + if (requireAnySdkEvent.Valid) + { + if ((!EventAlreadyTriggered(requireAnySdkEvent.SdkEvent) + && ExecutionLimit(requireAnySdkEvent.SdkEvent) == 1) || ExecutionLimit(requireAnySdkEvent.SdkEvent) == -1) + { + finalSdkEvent.SdkEvent = requireAnySdkEvent.SdkEvent; + } + + finalSdkEvent.Valid = CheckPrerequisites(finalSdkEvent.SdkEvent) + && CheckSuppressedBy(finalSdkEvent.SdkEvent); + } + + if (finalSdkEvent.Valid) + { + eventsToFire.Add(finalSdkEvent.SdkEvent); + } + + foreach (E sdkEvent in CheckRequireAll()) + { + eventsToFire.Add(sdkEvent); + } + + return eventsToFire; + } + + private List CheckRequireAll() + { + List events = new List(); + foreach (KeyValuePair> kvp in _managerConfig.RequireAll) + { + bool finalStatus = true; + foreach (var val in kvp.Value) + { + finalStatus &= GetSdkInternalEventStatus(val); + } + if (finalStatus + && CheckPrerequisites(kvp.Key) + && ((ExecutionLimit(kvp.Key) == 1 && !EventAlreadyTriggered(kvp.Key)) + || (ExecutionLimit(kvp.Key) == -1)) + && kvp.Value.Count > 0) + { + events.Add(kvp.Key); + } + } + + return events; + } + + private bool CheckPrerequisites(E sdkEvent) + { + foreach (KeyValuePair> kvp in _managerConfig.Prerequisites) + { + if (kvp.Key.Equals(sdkEvent)) + { + if (kvp.Value.Any(x => !EventAlreadyTriggered(x))) + { + return false; + } + + return true; + } + } + + return true; + } + + private bool CheckSuppressedBy(E sdkEvent) + { + foreach (KeyValuePair> kvp in _managerConfig.SuppressedBy) + { + if (kvp.Key.Equals(sdkEvent)) + { + if (kvp.Value.Any(x => EventAlreadyTriggered(x))) + { + return false; + } + + return true; + } + } + + return true; + } + + private int ExecutionLimit(E sdkEvent) + { + if (!_managerConfig.ExecutionLimits.ContainsKey(sdkEvent)) + return -1; + + _managerConfig.ExecutionLimits.TryGetValue(sdkEvent, out int limit); + return limit; + } + + private ValidSdkEvent CheckRequireAny(I sdkInternalEvent) + { + ValidSdkEvent validSdkEvent = new ValidSdkEvent + { + Valid = false +// SdkEvent = SdkEvent.SdkUpdate + }; + + foreach (KeyValuePair> kvp in _managerConfig.RequireAny) + { + if (kvp.Value.Contains(sdkInternalEvent)) + { + validSdkEvent.Valid = true; + validSdkEvent.SdkEvent = kvp.Key; + return validSdkEvent; + } + } + + return validSdkEvent; + } #endregion } } diff --git a/src/Splitio/Services/Common/IEventsManager.cs b/src/Splitio/Services/Common/IEventsManager.cs index fd606b1a9..23e719c7e 100644 --- a/src/Splitio/Services/Common/IEventsManager.cs +++ b/src/Splitio/Services/Common/IEventsManager.cs @@ -6,7 +6,7 @@ namespace Splitio.Services.Common { public interface IEventsManager { - void NotifyInternalEvent(I sdkInternalEvent, M eventMetadata, List eventsToNotify); + void NotifyInternalEvent(I sdkInternalEvent, M eventMetadata); void Register(E sdkEvent, EventHandler handler); void Unregister(E sdkEvent); } diff --git a/src/Splitio/Util/Helper.cs b/src/Splitio/Util/Helper.cs index c9854f239..84dc8dda1 100644 --- a/src/Splitio/Util/Helper.cs +++ b/src/Splitio/Util/Helper.cs @@ -1,6 +1,5 @@ using Splitio.CommonLibraries; using Splitio.Domain; -using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; using Splitio.Services.Logger; using Splitio.Telemetry.Domain.Enums; @@ -12,12 +11,6 @@ namespace Splitio.Util { public class Helper { - public struct ValidSdkEvent - { - public SdkEvent SdkEvent { get; set; } - public bool Valid { get; set; } - } - public static List TakeFromList(List items, int size) { if (items == null) return new List(); @@ -91,144 +84,5 @@ public static string getFallbackConfig(FallbackTreatment fallbackTreatment) return null; } - - public static List GetSdkEventIfApplicable(SdkInternalEvent sdkInternalEvent, - EventsManager eventsManager) - { - ValidSdkEvent finalSdkEvent = new ValidSdkEvent - { - Valid = false, - SdkEvent = SdkEvent.SdkReady - }; - eventsManager.UpdateSdkInternalEventStatus(sdkInternalEvent, true); - List eventsToFire = new List(); - - ValidSdkEvent requireAnySdkEvent = CheckRequireAny(sdkInternalEvent, eventsManager.ManagerConfig); - if (requireAnySdkEvent.Valid) - { - if ((!eventsManager.EventAlreadyTriggered(requireAnySdkEvent.SdkEvent) - && ExecutionLimit(requireAnySdkEvent.SdkEvent, eventsManager.ManagerConfig) == 1) || ExecutionLimit(requireAnySdkEvent.SdkEvent, eventsManager.ManagerConfig) == -1) - { - finalSdkEvent.SdkEvent = requireAnySdkEvent.SdkEvent; - } - - finalSdkEvent.Valid = CheckPrerequisites(finalSdkEvent.SdkEvent, eventsManager) - && CheckSuppressedBy(finalSdkEvent.SdkEvent, eventsManager); - } - - if (finalSdkEvent.Valid) - { - eventsToFire.Add(finalSdkEvent.SdkEvent); - } - - foreach (SdkEvent sdkEvent in CheckRequireAll(eventsManager)) - { - eventsToFire.Add(sdkEvent); - } - - return eventsToFire; - } - - private static List CheckRequireAll( - EventsManager eventsManager) - { - List events = new List(); - foreach (KeyValuePair> kvp in eventsManager.ManagerConfig.RequireAll) - { - bool finalStatus = true; - foreach (var val in kvp.Value) - { - finalStatus &= eventsManager.GetSdkInternalEventStatus(val); - } - if (finalStatus - && CheckPrerequisites(kvp.Key, eventsManager) - && ((ExecutionLimit(kvp.Key, eventsManager.ManagerConfig) == 1 && !eventsManager.EventAlreadyTriggered(kvp.Key)) - || (ExecutionLimit(kvp.Key, eventsManager.ManagerConfig) == -1)) - && kvp.Value.Count > 0) - { - events.Add(kvp.Key); - } - } - - return events; - } - - private static bool CheckPrerequisites(SdkEvent sdkEvent, - EventsManager eventsManager) - { - foreach (KeyValuePair> kvp in eventsManager.ManagerConfig.Prerequisites) - { - if (kvp.Key == sdkEvent) - { - if (kvp.Value.Any(x => !eventsManager.EventAlreadyTriggered(x))) - { - return false; - } - - return true; - } - } - - return true; - } - - private static bool CheckSuppressedBy(SdkEvent sdkEvent, - EventsManager eventsManager) - { - foreach (KeyValuePair> kvp in eventsManager.ManagerConfig.SuppressedBy) - { - if (kvp.Key == sdkEvent) - { - if (kvp.Value.Any(x => eventsManager.EventAlreadyTriggered(x))) - { - return false; - } - - return true; - } - } - - return true; - } - - private static int ExecutionLimit(SdkEvent sdkEvent, EventsManagerConfig eventsManagerConfig) - { - if (!eventsManagerConfig.ExecutionLimits.ContainsKey(sdkEvent)) - return -1; - - eventsManagerConfig.ExecutionLimits.TryGetValue(sdkEvent, out int limit); - return limit; - } - - private static ValidSdkEvent CheckRequireAny(SdkInternalEvent sdkInternalEvent, EventsManagerConfig eventsManagerConfig) - { - ValidSdkEvent validSdkEvent = new ValidSdkEvent - { - Valid = false, - SdkEvent = SdkEvent.SdkUpdate - }; - - foreach (KeyValuePair> kvp in eventsManagerConfig.RequireAny) - { - if (kvp.Value.Contains(sdkInternalEvent)) - { - validSdkEvent.Valid = true; - validSdkEvent.SdkEvent = kvp.Key; - return validSdkEvent; - } - } - - return validSdkEvent; - } - - public static void BuildInternalSdkEventStatus(EventsManager eventsManager) - { - eventsManager.UpdateSdkInternalEventStatus(SdkInternalEvent.SdkReady, false); - eventsManager.UpdateSdkInternalEventStatus(SdkInternalEvent.RuleBasedSegmentsUpdated, false); - eventsManager.UpdateSdkInternalEventStatus(SdkInternalEvent.SdkTimedOut, false); - eventsManager.UpdateSdkInternalEventStatus(SdkInternalEvent.SegmentsUpdated, false); - eventsManager.UpdateSdkInternalEventStatus(SdkInternalEvent.FlagKilledNotification, false); - eventsManager.UpdateSdkInternalEventStatus(SdkInternalEvent.FlagsUpdated, false); - } } } diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs index eddab8b7a..d4f207c58 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs @@ -154,7 +154,6 @@ public void Contains_ShouldReturnTrue() public void Update_ShouldNotifyEvent() { // Arrange - Splitio.Util.Helper.BuildInternalSdkEventStatus(_eventsManager); var segmentToAdd = new RuleBasedSegment { Name = "segment-to-add" }; var segmentToRemove = new RuleBasedSegment { Name = "segment-to-remove" }; @@ -163,8 +162,7 @@ public void Update_ShouldNotifyEvent() PublicSdkUpdateHandler += sdkUpdate_callback; _eventsManager.Register(SdkEvent.SdkUpdate, sdkUpdate_callback); _eventsManager.Register(SdkEvent.SdkReady, sdkUpdate_callback); - _eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(new Dictionary()), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkReady, _eventsManager)); + _eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(new Dictionary())); // Act SdkUpdate = false; diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheAsyncTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheAsyncTests.cs index 806d67b2b..d44a73439 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheAsyncTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheAsyncTests.cs @@ -7,7 +7,6 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading.Tasks; -using WireMock.Pact.Models.V2; namespace Splitio_Tests.Unit_Tests.Cache { @@ -60,13 +59,11 @@ public async Task NotifyEventsTest() { //Arrange var segmentName = "segment_test"; - Splitio.Util.Helper.BuildInternalSdkEventStatus(_eventsManager); var toNotify = new List { { segmentName } }; PublicSdkUpdateHandler += sdkUpdate_callback; _eventsManager.Register(SdkEvent.SdkUpdate, sdkUpdate_callback); _eventsManager.Register(SdkEvent.SdkReady, sdkUpdate_callback); - _eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(new Dictionary()), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkReady, _eventsManager)); + _eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(new Dictionary())); //Act SdkUpdate = false; diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheTests.cs index b81611a4e..fd9bac22f 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheTests.cs @@ -105,7 +105,6 @@ public void NotifyEventsTest() { //Arrange var eventsManager = new EventsManager(new EventsManagerConfig()); - Splitio.Util.Helper.BuildInternalSdkEventStatus(eventsManager); var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var keys = new List { "1234" }; var segmentName = "test"; @@ -113,8 +112,7 @@ public void NotifyEventsTest() PublicSdkUpdateHandler += sdkUpdate_callback; eventsManager.Register(SdkEvent.SdkUpdate, sdkUpdate_callback); eventsManager.Register(SdkEvent.SdkReady, sdkUpdate_callback); - eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(new Dictionary()), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkReady, eventsManager)); + eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(new Dictionary())); // Act SdkUpdate = false; diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheAsyncTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheAsyncTests.cs index 5d3b4c18f..9fb65e658 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheAsyncTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheAsyncTests.cs @@ -27,7 +27,6 @@ public SplitCacheAsyncTests() _flagSetsFilter = new FlagSetsFilter(new HashSet()); var splits = new ConcurrentDictionary(); _eventsManager = new EventsManager(new EventsManagerConfig()); - Splitio.Util.Helper.BuildInternalSdkEventStatus(_eventsManager); _cache = new InMemorySplitCache(splits, _flagSetsFilter, _eventsManager); } @@ -197,8 +196,7 @@ public async Task NotifyUpdateEventTest() PublicSdkUpdateHandler += sdkUpdate_callback; _eventsManager.Register(SdkEvent.SdkUpdate, sdkUpdate_callback); _eventsManager.Register(SdkEvent.SdkReady, sdkUpdate_callback); - _eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(new Dictionary()), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkReady, _eventsManager)); + _eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(new Dictionary())); SdkUpdate = false; _cache.Update(toAdd, new List(), -1); diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheTests.cs index 35a59f451..3d5450670 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheTests.cs @@ -245,7 +245,6 @@ public void NotifyUpdateEventTest() { // Arrange. var eventsManager = new EventsManager(new EventsManagerConfig()); - Splitio.Util.Helper.BuildInternalSdkEventStatus(eventsManager); var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), _flagSetsFilter.Object, eventsManager); var splitName = "test1"; @@ -253,8 +252,7 @@ public void NotifyUpdateEventTest() PublicSdkUpdateHandler += sdkUpdate_callback; eventsManager.Register(SdkEvent.SdkUpdate, sdkUpdate_callback); eventsManager.Register(SdkEvent.SdkReady, sdkUpdate_callback); - eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(new Dictionary()), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkReady, eventsManager)); + eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(new Dictionary())); // Act. SdkUpdate = false; diff --git a/tests/Splitio-tests/Unit Tests/Common/EventsManagerTests.cs b/tests/Splitio-tests/Unit Tests/Common/EventsManagerTests.cs index 558fa68cf..3c1a25d9d 100644 --- a/tests/Splitio-tests/Unit Tests/Common/EventsManagerTests.cs +++ b/tests/Splitio-tests/Unit Tests/Common/EventsManagerTests.cs @@ -10,6 +10,7 @@ namespace Splitio_Tests.Unit_Tests.Common public class EventsManagerTests { private bool SdkReady = false; + private bool SdkReady2 = false; private bool SdkTimedOut = false; private bool SdkUpdate = false; private EventMetadata eMetadata = null; @@ -23,49 +24,36 @@ public void TestFiringEvents() //Act EventsManagerConfig config = new EventsManagerConfig(); EventsManager eventsManager = new EventsManager(config); - Splitio.Util.Helper.BuildInternalSdkEventStatus(eventsManager); PublicSdkReadyHandler += sdkReady_callback; + PublicSdkReadyHandler += sdkReady_callback2; PublicSdkUpdateHandler += sdkUpdate_callback; PublicSdkTimedOutHandler += sdkTimedOut_callback; - Dictionary metaData = new Dictionary { { "flags", new List {{ "flag1" }} } }; - eventsManager.Register(SdkEvent.SdkReady, sdkReady_callback); - eventsManager.Register(SdkEvent.SdkUpdate, sdkUpdate_callback); - - eventsManager.NotifyInternalEvent(SdkInternalEvent.RuleBasedSegmentsUpdated, new EventMetadata(metaData), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.RuleBasedSegmentsUpdated, - eventsManager)); - eventsManager.NotifyInternalEvent(SdkInternalEvent.FlagKilledNotification, new EventMetadata(metaData), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.FlagKilledNotification, - eventsManager)); - eventsManager.NotifyInternalEvent(SdkInternalEvent.SegmentsUpdated, new EventMetadata(metaData), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SegmentsUpdated, - eventsManager)); - eventsManager.NotifyInternalEvent(SdkInternalEvent.FlagsUpdated, new EventMetadata(metaData), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.FlagsUpdated, - eventsManager)); + eventsManager.Register(SdkEvent.SdkReady, PublicSdkReadyHandler); + eventsManager.Register(SdkEvent.SdkUpdate, PublicSdkUpdateHandler); + + eventsManager.NotifyInternalEvent(SdkInternalEvent.RuleBasedSegmentsUpdated, new EventMetadata(metaData)); + eventsManager.NotifyInternalEvent(SdkInternalEvent.FlagKilledNotification, new EventMetadata(metaData)); + eventsManager.NotifyInternalEvent(SdkInternalEvent.SegmentsUpdated, new EventMetadata(metaData)); + eventsManager.NotifyInternalEvent(SdkInternalEvent.FlagsUpdated, new EventMetadata(metaData)); Assert.IsFalse(SdkReady); Assert.IsFalse(SdkUpdate); Assert.IsFalse(SdkTimedOut); ResetAllVariables(); - eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkTimedOut, new EventMetadata(metaData), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkTimedOut, - eventsManager)); + eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkTimedOut, new EventMetadata(metaData)); System.Threading.SpinWait.SpinUntil(() => SdkTimedOut, TimeSpan.FromMilliseconds(500)); Assert.IsFalse(SdkReady); Assert.IsFalse(SdkUpdate); Assert.IsFalse(SdkTimedOut); // not fired as it is not registered yet - eventsManager.Register(SdkEvent.SdkReadyTimeout, sdkTimedOut_callback); - eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkTimedOut, new EventMetadata(metaData), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkTimedOut, - eventsManager)); + eventsManager.Register(SdkEvent.SdkReadyTimeout, PublicSdkTimedOutHandler); + eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkTimedOut, new EventMetadata(metaData)); System.Threading.SpinWait.SpinUntil(() => SdkTimedOut, TimeSpan.FromMilliseconds(500)); Assert.IsFalse(SdkReady); Assert.IsFalse(SdkUpdate); @@ -73,30 +61,24 @@ public void TestFiringEvents() VerifyMetadata(eMetadata); ResetAllVariables(); - List eventsToNotify = Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkReady, - eventsManager); - eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(metaData), - eventsToNotify); + eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(metaData)); System.Threading.SpinWait.SpinUntil(() => SdkReady, TimeSpan.FromMilliseconds(500)); Assert.IsTrue(SdkReady); + Assert.IsTrue(SdkReady2); Assert.IsFalse(SdkUpdate); Assert.IsFalse(SdkTimedOut); VerifyMetadata(eMetadata); ResetAllVariables(); - eventsManager.Register(SdkEvent.SdkReadyTimeout, sdkTimedOut_callback); - eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkTimedOut, new EventMetadata(metaData), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkTimedOut, - eventsManager)); + eventsManager.Register(SdkEvent.SdkReadyTimeout, PublicSdkTimedOutHandler); + eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkTimedOut, new EventMetadata(metaData)); System.Threading.SpinWait.SpinUntil(() => SdkTimedOut, TimeSpan.FromMilliseconds(500)); Assert.IsFalse(SdkReady); Assert.IsFalse(SdkUpdate); Assert.IsFalse(SdkTimedOut); // not fired as suppressed by sdkReady ResetAllVariables(); - eventsManager.NotifyInternalEvent(SdkInternalEvent.FlagKilledNotification, new EventMetadata(metaData), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.FlagKilledNotification, - eventsManager)); + eventsManager.NotifyInternalEvent(SdkInternalEvent.FlagKilledNotification, new EventMetadata(metaData)); System.Threading.SpinWait.SpinUntil(() => SdkUpdate, TimeSpan.FromMilliseconds(500)); Assert.IsFalse(SdkTimedOut); Assert.IsFalse(SdkReady); @@ -104,9 +86,7 @@ public void TestFiringEvents() VerifyMetadata(eMetadata); ResetAllVariables(); - eventsManager.NotifyInternalEvent(SdkInternalEvent.SegmentsUpdated, new EventMetadata(metaData), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SegmentsUpdated, - eventsManager)); + eventsManager.NotifyInternalEvent(SdkInternalEvent.SegmentsUpdated, new EventMetadata(metaData)); System.Threading.SpinWait.SpinUntil(() => SdkUpdate, TimeSpan.FromMilliseconds(500)); Assert.IsFalse(SdkTimedOut); Assert.IsFalse(SdkReady); @@ -114,9 +94,7 @@ public void TestFiringEvents() VerifyMetadata(eMetadata); ResetAllVariables(); - eventsManager.NotifyInternalEvent(SdkInternalEvent.RuleBasedSegmentsUpdated, new EventMetadata(metaData), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.RuleBasedSegmentsUpdated, - eventsManager)); + eventsManager.NotifyInternalEvent(SdkInternalEvent.RuleBasedSegmentsUpdated, new EventMetadata(metaData)); System.Threading.SpinWait.SpinUntil(() => SdkUpdate, TimeSpan.FromMilliseconds(500)); Assert.IsFalse(SdkTimedOut); Assert.IsFalse(SdkReady); @@ -124,9 +102,7 @@ public void TestFiringEvents() VerifyMetadata(eMetadata); ResetAllVariables(); - eventsManager.NotifyInternalEvent(SdkInternalEvent.FlagsUpdated, new EventMetadata(metaData), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.FlagsUpdated, - eventsManager)); + eventsManager.NotifyInternalEvent(SdkInternalEvent.FlagsUpdated, new EventMetadata(metaData)); System.Threading.SpinWait.SpinUntil(() => SdkUpdate, TimeSpan.FromMilliseconds(500)); Assert.IsFalse(SdkTimedOut); Assert.IsFalse(SdkReady); @@ -136,9 +112,7 @@ public void TestFiringEvents() eventsManager.Unregister(SdkEvent.SdkUpdate); eventsManager.Unregister(SdkEvent.SdkUpdate); // should not cause exception ResetAllVariables(); - eventsManager.NotifyInternalEvent(SdkInternalEvent.FlagsUpdated, new EventMetadata(metaData), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.FlagsUpdated, - eventsManager)); + eventsManager.NotifyInternalEvent(SdkInternalEvent.FlagsUpdated, new EventMetadata(metaData)); System.Threading.SpinWait.SpinUntil(() => SdkUpdate, TimeSpan.FromMilliseconds(500)); Assert.IsFalse(SdkTimedOut); Assert.IsFalse(SdkReady); @@ -148,6 +122,7 @@ public void TestFiringEvents() void ResetAllVariables() { SdkReady = false; + SdkReady2 = false; SdkTimedOut = false; eMetadata = null; SdkUpdate = false; @@ -173,6 +148,12 @@ private void sdkReady_callback(object sender, EventMetadata metadata) eMetadata = metadata; } + private void sdkReady_callback2(object sender, EventMetadata metadata) + { + SdkReady2 = true; + eMetadata = metadata; + } + private void sdkTimedOut_callback(object sender, EventMetadata metadata) { SdkTimedOut = true; From 4af93a3f90195e9d1c5620340d40362243101919 Mon Sep 17 00:00:00 2001 From: Bill Al Date: Mon, 22 Dec 2025 18:36:42 -0800 Subject: [PATCH 10/15] polish --- .../Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs | 4 ++-- src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs | 4 ++-- src/Splitio/Services/Cache/Classes/InMemorySplitCache.cs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs b/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs index 30c1fbc90..998e419a8 100644 --- a/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs @@ -12,10 +12,10 @@ public class InMemoryRuleBasedSegmentCache : IRuleBasedSegmentCache { private readonly ConcurrentDictionary _cache; private long _changeNumber; - private readonly EventsManager _eventsManager; + private readonly IEventsManager _eventsManager; public InMemoryRuleBasedSegmentCache(ConcurrentDictionary cache, - EventsManager eventsManger, + IEventsManager eventsManger, long changeNumber = -1) { _cache = cache; diff --git a/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs b/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs index c0b5d8a5d..1a687722a 100644 --- a/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs @@ -15,9 +15,9 @@ public class InMemorySegmentCache : ISegmentCache private readonly ISplitLogger _log = WrapperAdapter.Instance().GetLogger(typeof(InMemorySegmentCache)); private readonly ConcurrentDictionary _segments; - private readonly EventsManager _eventsManager; + private readonly IEventsManager _eventsManager; - public InMemorySegmentCache(ConcurrentDictionary segments, EventsManager eventsManger) + public InMemorySegmentCache(ConcurrentDictionary segments, IEventsManager eventsManger) { _segments = segments; _eventsManager = eventsManger; diff --git a/src/Splitio/Services/Cache/Classes/InMemorySplitCache.cs b/src/Splitio/Services/Cache/Classes/InMemorySplitCache.cs index d222aa129..73bddb5d6 100644 --- a/src/Splitio/Services/Cache/Classes/InMemorySplitCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemorySplitCache.cs @@ -20,12 +20,12 @@ public class InMemorySplitCache : IFeatureFlagCache private readonly ConcurrentDictionary _featureFlags; private readonly ConcurrentDictionary _trafficTypes; private readonly ConcurrentDictionary> _flagSets; - private readonly EventsManager _eventsManager; + private readonly IEventsManager _eventsManager; private long _changeNumber; public InMemorySplitCache(ConcurrentDictionary featureFlags, - IFlagSetsFilter flagSetsFilter, EventsManager eventsManger, + IFlagSetsFilter flagSetsFilter, IEventsManager eventsManger, long changeNumber = -1) { _featureFlags = featureFlags; From 6d5071550da63254d7d0acd4ba86fa55a53f003c Mon Sep 17 00:00:00 2001 From: Bill Al Date: Mon, 22 Dec 2025 20:34:21 -0800 Subject: [PATCH 11/15] polish --- src/Splitio/Services/Common/EventsManager.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Splitio/Services/Common/EventsManager.cs b/src/Splitio/Services/Common/EventsManager.cs index 79ad83735..d08a57b97 100644 --- a/src/Splitio/Services/Common/EventsManager.cs +++ b/src/Splitio/Services/Common/EventsManager.cs @@ -131,7 +131,6 @@ public List GetSdkEventIfApplicable(I sdkInternalEvent) ValidSdkEvent finalSdkEvent = new ValidSdkEvent { Valid = false -// SdkEvent = SdkEvent.SdkReady }; UpdateSdkInternalEventStatus(sdkInternalEvent, true); List eventsToFire = new List(); @@ -147,11 +146,11 @@ public List GetSdkEventIfApplicable(I sdkInternalEvent) finalSdkEvent.Valid = CheckPrerequisites(finalSdkEvent.SdkEvent) && CheckSuppressedBy(finalSdkEvent.SdkEvent); - } - if (finalSdkEvent.Valid) - { - eventsToFire.Add(finalSdkEvent.SdkEvent); + if (finalSdkEvent.Valid) + { + eventsToFire.Add(finalSdkEvent.SdkEvent); + } } foreach (E sdkEvent in CheckRequireAll()) @@ -235,7 +234,6 @@ private ValidSdkEvent CheckRequireAny(I sdkInternalEvent) ValidSdkEvent validSdkEvent = new ValidSdkEvent { Valid = false -// SdkEvent = SdkEvent.SdkUpdate }; foreach (KeyValuePair> kvp in _managerConfig.RequireAny) From b93bdc0168ae5634e0d6fd3af34e55f8f8ec2408 Mon Sep 17 00:00:00 2001 From: Bill Al Date: Tue, 23 Dec 2025 11:49:15 -0800 Subject: [PATCH 12/15] refactor event delivery to use action callback --- .../Cache/Classes/InMemorySplitCache.cs | 1 + .../Services/Client/Classes/SplitClient.cs | 7 +- .../Client/Interfaces/ISplitClient.cs | 5 + src/Splitio/Services/Common/EventDelivery.cs | 7 +- src/Splitio/Services/Common/EventsManager.cs | 45 ++---- src/Splitio/Services/Common/IEventDelivery.cs | 2 +- src/Splitio/Services/Common/IEventsManager.cs | 7 +- .../InMemory/RuleBasedSegmentCacheTests.cs | 27 +++- .../Cache/InMemory/SegmentCacheAsyncTests.cs | 27 +++- .../Cache/InMemory/SegmentCacheTests.cs | 31 ++-- .../Cache/InMemory/SplitCacheAsyncTests.cs | 31 ++-- .../Cache/InMemory/SplitCacheTests.cs | 31 ++-- .../Unit Tests/Common/EventDeliveryTests.cs | 8 +- .../Unit Tests/Common/EventsManagerTests.cs | 142 ++++++++++-------- 14 files changed, 214 insertions(+), 157 deletions(-) diff --git a/src/Splitio/Services/Cache/Classes/InMemorySplitCache.cs b/src/Splitio/Services/Cache/Classes/InMemorySplitCache.cs index 73bddb5d6..1a99fd8cc 100644 --- a/src/Splitio/Services/Cache/Classes/InMemorySplitCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemorySplitCache.cs @@ -74,6 +74,7 @@ public void Update(List toAdd, List toRemove, long till) { DecreaseTrafficTypeCount(removedSplit); RemoveFromFlagSets(removedSplit.name, removedSplit.Sets); + eventsFlags.Add(featureFlagName); } } diff --git a/src/Splitio/Services/Client/Classes/SplitClient.cs b/src/Splitio/Services/Client/Classes/SplitClient.cs index 4372c344f..c8d383f9d 100644 --- a/src/Splitio/Services/Client/Classes/SplitClient.cs +++ b/src/Splitio/Services/Client/Classes/SplitClient.cs @@ -63,9 +63,10 @@ public abstract class SplitClient : ISplitClient protected IImpressionsObserver _impressionsObserver; protected IClientExtensionService _clientExtensionService; protected IFlagSetsFilter _flagSetsFilter; - public event EventHandler PublicSdkReadyHandler; - public event EventHandler PublicSdkUpdateHandler; - public event EventHandler PublicSdkTimedOutHandler; + + public event EventHandler SdkReady; + public event EventHandler SdkUpdate; + public event EventHandler SdkTimedOut; protected SplitClient(string apikey, FallbackTreatmentCalculator fallbackTreatmentCalculator) { diff --git a/src/Splitio/Services/Client/Interfaces/ISplitClient.cs b/src/Splitio/Services/Client/Interfaces/ISplitClient.cs index 60e0b751b..a18982ddd 100644 --- a/src/Splitio/Services/Client/Interfaces/ISplitClient.cs +++ b/src/Splitio/Services/Client/Interfaces/ISplitClient.cs @@ -1,10 +1,15 @@ using Splitio.Domain; +using System; using System.Collections.Generic; namespace Splitio.Services.Client.Interfaces { public interface ISplitClient : ISplitClientAsync { + event EventHandler SdkReady; + event EventHandler SdkUpdate; + event EventHandler SdkTimedOut; + /// /// Returns the treatment to show this key for this feature flag. /// The set of treatments for a feature flag can be configured on the Split user interface. diff --git a/src/Splitio/Services/Common/EventDelivery.cs b/src/Splitio/Services/Common/EventDelivery.cs index b97e7a32c..38b04ffe9 100644 --- a/src/Splitio/Services/Common/EventDelivery.cs +++ b/src/Splitio/Services/Common/EventDelivery.cs @@ -1,4 +1,5 @@ -using Splitio.Services.Logger; +using Splitio.Domain; +using Splitio.Services.Logger; using Splitio.Services.Shared.Classes; using System; @@ -8,14 +9,14 @@ public class EventDelivery : IEventDelivery { private readonly ISplitLogger _logger = WrapperAdapter.Instance().GetLogger("EventDelivery"); - public virtual void Deliver(E sdkEvent, M eventMetadata, EventHandler handler) + public virtual void Deliver(E sdkEvent, M eventMetadata, Action handler) { if (handler != null) { _logger.Debug($"EventDelivery: Triggering handle for Sdk Event {sdkEvent}"); try { - handler.Invoke(this, eventMetadata); + handler.Invoke(eventMetadata); } catch (Exception e) { diff --git a/src/Splitio/Services/Common/EventsManager.cs b/src/Splitio/Services/Common/EventsManager.cs index d08a57b97..d891e883e 100644 --- a/src/Splitio/Services/Common/EventsManager.cs +++ b/src/Splitio/Services/Common/EventsManager.cs @@ -19,12 +19,12 @@ public struct ValidSdkEvent private struct PublicEventProperties { public bool Triggered; - public EventHandler EventHandler; + public Action EventHandler; } private readonly ConcurrentDictionary _activeSubscriptions; private readonly ConcurrentDictionary _internalEventsStatus; private readonly ISplitLogger _logger = WrapperAdapter.Instance().GetLogger("EventsManager"); - private readonly EventDelivery _eventDelivery; + public readonly EventDelivery _eventDelivery; private readonly object _lock = new object(); public EventManagerConfigData _managerConfig { get; private set; } @@ -37,7 +37,7 @@ public EventsManager(EventManagerConfigData eventsManagerConfig) } #region Public Methods - public void Register(E sdkEvent, EventHandler handler) + public void Register(E sdkEvent, Action handler) { if (_activeSubscriptions.TryGetValue(sdkEvent, out var _)) { @@ -116,7 +116,7 @@ private void SetSdkEventTriggered(E sdkEvent) _activeSubscriptions.TryUpdate(sdkEvent, newEventData, eventData); } - private EventHandler GetEventHandler(E sdkEvent) + private Action GetEventHandler(E sdkEvent) { if (!_activeSubscriptions.TryGetValue(sdkEvent, out var eventData)) { @@ -186,17 +186,10 @@ private List CheckRequireAll() private bool CheckPrerequisites(E sdkEvent) { - foreach (KeyValuePair> kvp in _managerConfig.Prerequisites) + foreach (var item in _managerConfig.Prerequisites.Where(kvp => kvp.Key.Equals(sdkEvent) && + kvp.Value.Any(x => !EventAlreadyTriggered(x)))) { - if (kvp.Key.Equals(sdkEvent)) - { - if (kvp.Value.Any(x => !EventAlreadyTriggered(x))) - { - return false; - } - - return true; - } + return false; } return true; @@ -204,17 +197,10 @@ private bool CheckPrerequisites(E sdkEvent) private bool CheckSuppressedBy(E sdkEvent) { - foreach (KeyValuePair> kvp in _managerConfig.SuppressedBy) + foreach (var item in _managerConfig.SuppressedBy.Where(kvp => kvp.Key.Equals(sdkEvent) && + kvp.Value.Any(x => EventAlreadyTriggered(x)))) { - if (kvp.Key.Equals(sdkEvent)) - { - if (kvp.Value.Any(x => EventAlreadyTriggered(x))) - { - return false; - } - - return true; - } + return false; } return true; @@ -236,14 +222,11 @@ private ValidSdkEvent CheckRequireAny(I sdkInternalEvent) Valid = false }; - foreach (KeyValuePair> kvp in _managerConfig.RequireAny) + foreach (var item in _managerConfig.RequireAny.Where(kvp => kvp.Value.Contains(sdkInternalEvent))) { - if (kvp.Value.Contains(sdkInternalEvent)) - { - validSdkEvent.Valid = true; - validSdkEvent.SdkEvent = kvp.Key; - return validSdkEvent; - } + validSdkEvent.Valid = true; + validSdkEvent.SdkEvent = item.Key; + return validSdkEvent; } return validSdkEvent; diff --git a/src/Splitio/Services/Common/IEventDelivery.cs b/src/Splitio/Services/Common/IEventDelivery.cs index 550cfbbf2..69ae709f5 100644 --- a/src/Splitio/Services/Common/IEventDelivery.cs +++ b/src/Splitio/Services/Common/IEventDelivery.cs @@ -5,6 +5,6 @@ namespace Splitio.Services.Common { public interface IEventDelivery { - void Deliver(E sdkEvent, M eventMetadata, EventHandler handler); + void Deliver(E sdkEvent, M eventMetadata, Action handler); } } diff --git a/src/Splitio/Services/Common/IEventsManager.cs b/src/Splitio/Services/Common/IEventsManager.cs index 23e719c7e..ac5f37396 100644 --- a/src/Splitio/Services/Common/IEventsManager.cs +++ b/src/Splitio/Services/Common/IEventsManager.cs @@ -1,13 +1,12 @@ -using Splitio.Domain; -using System; -using System.Collections.Generic; +using System; namespace Splitio.Services.Common { public interface IEventsManager { void NotifyInternalEvent(I sdkInternalEvent, M eventMetadata); - void Register(E sdkEvent, EventHandler handler); + void Register(E sdkEvent, Action handler); void Unregister(E sdkEvent); + bool EventAlreadyTriggered(E sdkEvent); } } diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs index d4f207c58..b43c27cac 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs @@ -14,9 +14,10 @@ public class RuleBasedSegmentCacheTests { private InMemoryRuleBasedSegmentCache _segmentCache; private EventsManager _eventsManager; - private bool SdkUpdate = false; + private bool SdkUpdateFlag = false; private EventMetadata eMetadata = null; - public event EventHandler PublicSdkUpdateHandler; + public event EventHandler SdkUpdate; + public event EventHandler SdkReady; [TestInitialize] public void Setup() @@ -159,17 +160,17 @@ public void Update_ShouldNotifyEvent() var segmentToRemove = new RuleBasedSegment { Name = "segment-to-remove" }; var till = 67890; var toNotify = new List { { "segment-to-add" }, { "segment-to-remove" } }; - PublicSdkUpdateHandler += sdkUpdate_callback; - _eventsManager.Register(SdkEvent.SdkUpdate, sdkUpdate_callback); - _eventsManager.Register(SdkEvent.SdkReady, sdkUpdate_callback); + SdkUpdate += sdkUpdate_callback; + _eventsManager.Register(SdkEvent.SdkUpdate, TriggerSdkUpdate); + _eventsManager.Register(SdkEvent.SdkReady, TriggerSdkReady); _eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(new Dictionary())); // Act - SdkUpdate = false; + SdkUpdateFlag = false; _segmentCache.Update(new List { segmentToAdd, segmentToRemove }, new List { segmentToRemove.Name }, till); // Assert - Assert.IsTrue(SdkUpdate); + Assert.IsTrue(SdkUpdateFlag); Assert.IsTrue(eMetadata.ContainKey(Splitio.Constants.EventMetadataKeys.RuleBasedSegments)); List rbsegments = (List)eMetadata.GetData()[Splitio.Constants.EventMetadataKeys.RuleBasedSegments]; Assert.IsTrue(rbsegments.Count == 3); @@ -179,8 +180,18 @@ public void Update_ShouldNotifyEvent() private void sdkUpdate_callback(object sender, EventMetadata metadata) { - SdkUpdate = true; + SdkUpdateFlag = true; eMetadata = metadata; } + + private void TriggerSdkReady(EventMetadata metaData) + { + SdkReady?.Invoke(this, metaData); + } + + private void TriggerSdkUpdate(EventMetadata metaData) + { + SdkUpdate?.Invoke(this, metaData); + } } } diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheAsyncTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheAsyncTests.cs index d44a73439..64ff38f3e 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheAsyncTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheAsyncTests.cs @@ -15,9 +15,10 @@ public class SegmentCacheAsyncTests { private readonly ISegmentCache _cache; private EventsManager _eventsManager; - private bool SdkUpdate = false; + private bool SdkUpdateFlag = false; private EventMetadata eMetadata = null; - public event EventHandler PublicSdkUpdateHandler; + public event EventHandler SdkUpdate; + public event EventHandler SdkReady; public SegmentCacheAsyncTests() { @@ -60,17 +61,17 @@ public async Task NotifyEventsTest() //Arrange var segmentName = "segment_test"; var toNotify = new List { { segmentName } }; - PublicSdkUpdateHandler += sdkUpdate_callback; - _eventsManager.Register(SdkEvent.SdkUpdate, sdkUpdate_callback); - _eventsManager.Register(SdkEvent.SdkReady, sdkUpdate_callback); + SdkUpdate += sdkUpdate_callback; + _eventsManager.Register(SdkEvent.SdkUpdate, TriggerSdkUpdate); + _eventsManager.Register(SdkEvent.SdkReady, TriggerSdkReady); _eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(new Dictionary())); //Act - SdkUpdate = false; + SdkUpdateFlag = false; _cache.AddToSegment(segmentName, new List { "abcd", "zzzzf" }); //Assert - Assert.IsTrue(SdkUpdate); + Assert.IsTrue(SdkUpdateFlag); Assert.IsTrue(eMetadata.ContainKey(Splitio.Constants.EventMetadataKeys.Segments)); string segment = (string)eMetadata.GetData()[Splitio.Constants.EventMetadataKeys.Segments]; Assert.AreEqual(segmentName, segment); @@ -78,8 +79,18 @@ public async Task NotifyEventsTest() private void sdkUpdate_callback(object sender, EventMetadata metadata) { - SdkUpdate = true; + SdkUpdateFlag = true; eMetadata = metadata; } + + private void TriggerSdkReady(EventMetadata metaData) + { + SdkReady?.Invoke(this, metaData); + } + + private void TriggerSdkUpdate(EventMetadata metaData) + { + SdkUpdate?.Invoke(this, metaData); + } } } diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheTests.cs index fd9bac22f..235d9408d 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheTests.cs @@ -11,9 +11,10 @@ namespace Splitio_Tests.Unit_Tests.Cache [TestClass] public class SegmentCacheTests { - private bool SdkUpdate = false; + private bool SdkUpdateFlag = false; private EventMetadata eMetadata = null; - public event EventHandler PublicSdkUpdateHandler; + public event EventHandler SdkUpdate; + public event EventHandler SdkReady; [TestMethod] public void RegisterSegmentTest() @@ -109,28 +110,28 @@ public void NotifyEventsTest() var keys = new List { "1234" }; var segmentName = "test"; var toNotify = new List { { segmentName } }; - PublicSdkUpdateHandler += sdkUpdate_callback; - eventsManager.Register(SdkEvent.SdkUpdate, sdkUpdate_callback); - eventsManager.Register(SdkEvent.SdkReady, sdkUpdate_callback); + SdkUpdate += sdkUpdate_callback; + eventsManager.Register(SdkEvent.SdkUpdate, TriggerSdkUpdate); + eventsManager.Register(SdkEvent.SdkReady, TriggerSdkReady); eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(new Dictionary())); // Act - SdkUpdate = false; + SdkUpdateFlag = false; segmentCache.AddToSegment(segmentName, keys); //Assert - Assert.IsTrue(SdkUpdate); + Assert.IsTrue(SdkUpdateFlag); Assert.IsTrue(eMetadata.ContainKey(Splitio.Constants.EventMetadataKeys.Segments)); string segment = (string) eMetadata.GetData()[Splitio.Constants.EventMetadataKeys.Segments]; Assert.AreEqual(segmentName, segment); // Act - SdkUpdate = false; + SdkUpdateFlag = false; eMetadata = null; segmentCache.RemoveFromSegment(segmentName, keys); //Assert - Assert.IsTrue(SdkUpdate); + Assert.IsTrue(SdkUpdateFlag); Assert.IsTrue(eMetadata.ContainKey(Splitio.Constants.EventMetadataKeys.Segments)); segment = (string)eMetadata.GetData()[Splitio.Constants.EventMetadataKeys.Segments]; Assert.AreEqual(segmentName, segment); @@ -138,8 +139,18 @@ public void NotifyEventsTest() private void sdkUpdate_callback(object sender, EventMetadata metadata) { - SdkUpdate = true; + SdkUpdateFlag = true; eMetadata = metadata; } + + private void TriggerSdkReady(EventMetadata metaData) + { + SdkReady?.Invoke(this, metaData); + } + + private void TriggerSdkUpdate(EventMetadata metaData) + { + SdkUpdate?.Invoke(this, metaData); + } } } diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheAsyncTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheAsyncTests.cs index 9fb65e658..c02d905f5 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheAsyncTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheAsyncTests.cs @@ -18,9 +18,10 @@ public class SplitCacheAsyncTests private readonly IFlagSetsFilter _flagSetsFilter; private readonly IFeatureFlagCache _cache; private readonly EventsManager _eventsManager; - private bool SdkUpdate = false; + private bool SdkUpdateFlag = false; private EventMetadata eMetadata = null; - public event EventHandler PublicSdkUpdateHandler; + public event EventHandler SdkUpdate; + public event EventHandler SdkReady; public SplitCacheAsyncTests() { @@ -193,12 +194,12 @@ public async Task NotifyUpdateEventTest() }); toNotify.Add($"feature-flag-{i}"); } - PublicSdkUpdateHandler += sdkUpdate_callback; - _eventsManager.Register(SdkEvent.SdkUpdate, sdkUpdate_callback); - _eventsManager.Register(SdkEvent.SdkReady, sdkUpdate_callback); + SdkUpdate += sdkUpdate_callback; + _eventsManager.Register(SdkEvent.SdkUpdate, TriggerSdkUpdate); + _eventsManager.Register(SdkEvent.SdkReady, TriggerSdkReady); _eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(new Dictionary())); - SdkUpdate = false; + SdkUpdateFlag = false; _cache.Update(toAdd, new List(), -1); // Act. @@ -206,7 +207,7 @@ public async Task NotifyUpdateEventTest() // Assert. Assert.AreEqual(5, result.Count); - Assert.IsTrue(SdkUpdate); + Assert.IsTrue(SdkUpdateFlag); Assert.IsTrue(eMetadata.ContainKey(Splitio.Constants.EventMetadataKeys.Flags)); List flags = (List)eMetadata.GetData()[Splitio.Constants.EventMetadataKeys.Flags]; Assert.IsTrue(flags.Count == 5); @@ -215,11 +216,11 @@ public async Task NotifyUpdateEventTest() Assert.IsTrue(flags.Contains($"feature-flag-{i}")); } - SdkUpdate = false; + SdkUpdateFlag = false; eMetadata = null; _cache.Kill(123, "feature-flag-1", "off"); - Assert.IsTrue(SdkUpdate); + Assert.IsTrue(SdkUpdateFlag); Assert.IsTrue(eMetadata.ContainKey(Splitio.Constants.EventMetadataKeys.Flags)); flags = (List)eMetadata.GetData()[Splitio.Constants.EventMetadataKeys.Flags]; Assert.IsTrue(flags.Count == 1); @@ -228,8 +229,18 @@ public async Task NotifyUpdateEventTest() private void sdkUpdate_callback(object sender, EventMetadata metadata) { - SdkUpdate = true; + SdkUpdateFlag = true; eMetadata = metadata; } + + private void TriggerSdkReady(EventMetadata metaData) + { + SdkReady?.Invoke(this, metaData); + } + + private void TriggerSdkUpdate(EventMetadata metaData) + { + SdkUpdate?.Invoke(this, metaData); + } } } diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheTests.cs index 3d5450670..33a0889d1 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheTests.cs @@ -15,9 +15,10 @@ namespace Splitio_Tests.Unit_Tests.Cache public class SplitCacheTests { private readonly Mock _flagSetsFilter; - private bool SdkUpdate = false; + private bool SdkUpdateFlag = false; private EventMetadata eMetadata = null; - public event EventHandler PublicSdkUpdateHandler; + public event EventHandler SdkUpdate; + public event EventHandler SdkReady; public SplitCacheTests() { @@ -249,29 +250,29 @@ public void NotifyUpdateEventTest() var splitName = "test1"; var toNotify = new List { { splitName } }; - PublicSdkUpdateHandler += sdkUpdate_callback; - eventsManager.Register(SdkEvent.SdkUpdate, sdkUpdate_callback); - eventsManager.Register(SdkEvent.SdkReady, sdkUpdate_callback); + SdkUpdate += sdkUpdate_callback; + eventsManager.Register(SdkEvent.SdkUpdate, TriggerSdkUpdate); + eventsManager.Register(SdkEvent.SdkReady, TriggerSdkReady); eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(new Dictionary())); // Act. - SdkUpdate = false; + SdkUpdateFlag = false; splitCache.Update(new List { new ParsedSplit() { name = splitName } }, new List(), -1); // Assert. - Assert.IsTrue(SdkUpdate); + Assert.IsTrue(SdkUpdateFlag); Assert.IsTrue(eMetadata.ContainKey(Splitio.Constants.EventMetadataKeys.Flags)); List flags = (List)eMetadata.GetData()[Splitio.Constants.EventMetadataKeys.Flags]; Assert.IsTrue(flags.Count == 1); Assert.IsTrue(flags.Contains(splitName)); // Act. - SdkUpdate = false; + SdkUpdateFlag = false; eMetadata = null; splitCache.Kill(123, splitName, "off"); // Assert. - Assert.IsTrue(SdkUpdate); + Assert.IsTrue(SdkUpdateFlag); Assert.IsTrue(eMetadata.ContainKey(Splitio.Constants.EventMetadataKeys.Flags)); flags = (List)eMetadata.GetData()[Splitio.Constants.EventMetadataKeys.Flags]; Assert.IsTrue(flags.Count == 1); @@ -280,8 +281,18 @@ public void NotifyUpdateEventTest() private void sdkUpdate_callback(object sender, EventMetadata metadata) { - SdkUpdate = true; + SdkUpdateFlag = true; eMetadata = metadata; } + + private void TriggerSdkReady(EventMetadata metaData) + { + SdkReady?.Invoke(this, metaData); + } + + private void TriggerSdkUpdate(EventMetadata metaData) + { + SdkUpdate?.Invoke(this, metaData); + } } } diff --git a/tests/Splitio-tests/Unit Tests/Common/EventDeliveryTests.cs b/tests/Splitio-tests/Unit Tests/Common/EventDeliveryTests.cs index 807110872..1619f9d17 100644 --- a/tests/Splitio-tests/Unit Tests/Common/EventDeliveryTests.cs +++ b/tests/Splitio-tests/Unit Tests/Common/EventDeliveryTests.cs @@ -1,7 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Splitio.Domain; using Splitio.Services.Common; -using System; using System.Collections.Generic; namespace Splitio_Tests.Unit_Tests.Common @@ -11,7 +10,6 @@ public class EventDeliveryTests { private bool SdkReady = false; private EventMetadata eMetadata = null; - public event EventHandler PublicSdkReadyHandler; [TestMethod] public void TestFiringEvents() @@ -19,14 +17,12 @@ public void TestFiringEvents() //Act EventDelivery eventDelivery = new EventDelivery(); - PublicSdkReadyHandler += sdkReady_callback; - Dictionary metaData = new Dictionary { { "flags", new List {{ "flag1" }} } }; - eventDelivery.Deliver(SdkEvent.SdkReady, new EventMetadata(metaData), PublicSdkReadyHandler); + eventDelivery.Deliver(SdkEvent.SdkReady, new EventMetadata(metaData), sdkReady_callback); Assert.IsTrue(SdkReady); VerifyMetadata(eMetadata); @@ -40,7 +36,7 @@ void VerifyMetadata(EventMetadata eMetdata) Assert.IsTrue(flags.Contains("flag1")); } - private void sdkReady_callback(object sender, EventMetadata metadata) + private void sdkReady_callback(EventMetadata metadata) { SdkReady = true; eMetadata = metadata; diff --git a/tests/Splitio-tests/Unit Tests/Common/EventsManagerTests.cs b/tests/Splitio-tests/Unit Tests/Common/EventsManagerTests.cs index 3c1a25d9d..50c3ee78f 100644 --- a/tests/Splitio-tests/Unit Tests/Common/EventsManagerTests.cs +++ b/tests/Splitio-tests/Unit Tests/Common/EventsManagerTests.cs @@ -9,14 +9,14 @@ namespace Splitio_Tests.Unit_Tests.Common [TestClass] public class EventsManagerTests { - private bool SdkReady = false; - private bool SdkReady2 = false; - private bool SdkTimedOut = false; - private bool SdkUpdate = false; + private bool SdkReadyFlag = false; + private bool SdkReadyFlag2 = false; + private bool SdkTimedOutFlag = false; + private bool SdkUpdateFlag = false; private EventMetadata eMetadata = null; - public event EventHandler PublicSdkReadyHandler; - public event EventHandler PublicSdkUpdateHandler; - public event EventHandler PublicSdkTimedOutHandler; + public event EventHandler SdkReady; + public event EventHandler SdkUpdate; + public event EventHandler SdkTimedOut; [TestMethod] public void TestFiringEvents() @@ -25,107 +25,107 @@ public void TestFiringEvents() EventsManagerConfig config = new EventsManagerConfig(); EventsManager eventsManager = new EventsManager(config); - PublicSdkReadyHandler += sdkReady_callback; - PublicSdkReadyHandler += sdkReady_callback2; - PublicSdkUpdateHandler += sdkUpdate_callback; - PublicSdkTimedOutHandler += sdkTimedOut_callback; + SdkReady += sdkReady_callback; + SdkReady += sdkReady_callback2; + SdkUpdate += sdkUpdate_callback; + SdkTimedOut += sdkTimedOut_callback; Dictionary metaData = new Dictionary { { "flags", new List {{ "flag1" }} } }; - eventsManager.Register(SdkEvent.SdkReady, PublicSdkReadyHandler); - eventsManager.Register(SdkEvent.SdkUpdate, PublicSdkUpdateHandler); + eventsManager.Register(SdkEvent.SdkReady, TriggerSdkReady); + eventsManager.Register(SdkEvent.SdkUpdate, TriggerSdkUpdate); eventsManager.NotifyInternalEvent(SdkInternalEvent.RuleBasedSegmentsUpdated, new EventMetadata(metaData)); eventsManager.NotifyInternalEvent(SdkInternalEvent.FlagKilledNotification, new EventMetadata(metaData)); eventsManager.NotifyInternalEvent(SdkInternalEvent.SegmentsUpdated, new EventMetadata(metaData)); eventsManager.NotifyInternalEvent(SdkInternalEvent.FlagsUpdated, new EventMetadata(metaData)); - Assert.IsFalse(SdkReady); - Assert.IsFalse(SdkUpdate); - Assert.IsFalse(SdkTimedOut); + Assert.IsFalse(SdkReadyFlag); + Assert.IsFalse(SdkUpdateFlag); + Assert.IsFalse(SdkTimedOutFlag); ResetAllVariables(); eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkTimedOut, new EventMetadata(metaData)); - System.Threading.SpinWait.SpinUntil(() => SdkTimedOut, TimeSpan.FromMilliseconds(500)); - Assert.IsFalse(SdkReady); - Assert.IsFalse(SdkUpdate); - Assert.IsFalse(SdkTimedOut); // not fired as it is not registered yet + System.Threading.SpinWait.SpinUntil(() => SdkTimedOutFlag, TimeSpan.FromMilliseconds(500)); + Assert.IsFalse(SdkReadyFlag); + Assert.IsFalse(SdkUpdateFlag); + Assert.IsFalse(SdkTimedOutFlag); // not fired as it is not registered yet - eventsManager.Register(SdkEvent.SdkReadyTimeout, PublicSdkTimedOutHandler); + eventsManager.Register(SdkEvent.SdkReadyTimeout, TriggerSdkTimeout); eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkTimedOut, new EventMetadata(metaData)); - System.Threading.SpinWait.SpinUntil(() => SdkTimedOut, TimeSpan.FromMilliseconds(500)); - Assert.IsFalse(SdkReady); - Assert.IsFalse(SdkUpdate); - Assert.IsTrue(SdkTimedOut); + System.Threading.SpinWait.SpinUntil(() => SdkTimedOutFlag, TimeSpan.FromMilliseconds(500)); + Assert.IsFalse(SdkReadyFlag); + Assert.IsFalse(SdkUpdateFlag); + Assert.IsTrue(SdkTimedOutFlag); VerifyMetadata(eMetadata); ResetAllVariables(); eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, new EventMetadata(metaData)); - System.Threading.SpinWait.SpinUntil(() => SdkReady, TimeSpan.FromMilliseconds(500)); - Assert.IsTrue(SdkReady); - Assert.IsTrue(SdkReady2); - Assert.IsFalse(SdkUpdate); - Assert.IsFalse(SdkTimedOut); + System.Threading.SpinWait.SpinUntil(() => SdkReadyFlag, TimeSpan.FromMilliseconds(500)); + Assert.IsTrue(SdkReadyFlag); + Assert.IsTrue(SdkReadyFlag2); + Assert.IsFalse(SdkUpdateFlag); + Assert.IsFalse(SdkTimedOutFlag); VerifyMetadata(eMetadata); ResetAllVariables(); - eventsManager.Register(SdkEvent.SdkReadyTimeout, PublicSdkTimedOutHandler); + eventsManager.Register(SdkEvent.SdkReadyTimeout, TriggerSdkTimeout); eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkTimedOut, new EventMetadata(metaData)); - System.Threading.SpinWait.SpinUntil(() => SdkTimedOut, TimeSpan.FromMilliseconds(500)); - Assert.IsFalse(SdkReady); - Assert.IsFalse(SdkUpdate); - Assert.IsFalse(SdkTimedOut); // not fired as suppressed by sdkReady + System.Threading.SpinWait.SpinUntil(() => SdkTimedOutFlag, TimeSpan.FromMilliseconds(500)); + Assert.IsFalse(SdkReadyFlag); + Assert.IsFalse(SdkUpdateFlag); + Assert.IsFalse(SdkTimedOutFlag); // not fired as suppressed by sdkReady ResetAllVariables(); eventsManager.NotifyInternalEvent(SdkInternalEvent.FlagKilledNotification, new EventMetadata(metaData)); - System.Threading.SpinWait.SpinUntil(() => SdkUpdate, TimeSpan.FromMilliseconds(500)); - Assert.IsFalse(SdkTimedOut); - Assert.IsFalse(SdkReady); - Assert.IsTrue(SdkUpdate); + System.Threading.SpinWait.SpinUntil(() => SdkUpdateFlag, TimeSpan.FromMilliseconds(500)); + Assert.IsFalse(SdkTimedOutFlag); + Assert.IsFalse(SdkReadyFlag); + Assert.IsTrue(SdkUpdateFlag); VerifyMetadata(eMetadata); ResetAllVariables(); eventsManager.NotifyInternalEvent(SdkInternalEvent.SegmentsUpdated, new EventMetadata(metaData)); - System.Threading.SpinWait.SpinUntil(() => SdkUpdate, TimeSpan.FromMilliseconds(500)); - Assert.IsFalse(SdkTimedOut); - Assert.IsFalse(SdkReady); - Assert.IsTrue(SdkUpdate); + System.Threading.SpinWait.SpinUntil(() => SdkUpdateFlag, TimeSpan.FromMilliseconds(500)); + Assert.IsFalse(SdkTimedOutFlag); + Assert.IsFalse(SdkReadyFlag); + Assert.IsTrue(SdkUpdateFlag); VerifyMetadata(eMetadata); ResetAllVariables(); eventsManager.NotifyInternalEvent(SdkInternalEvent.RuleBasedSegmentsUpdated, new EventMetadata(metaData)); - System.Threading.SpinWait.SpinUntil(() => SdkUpdate, TimeSpan.FromMilliseconds(500)); - Assert.IsFalse(SdkTimedOut); - Assert.IsFalse(SdkReady); - Assert.IsTrue(SdkUpdate); + System.Threading.SpinWait.SpinUntil(() => SdkUpdateFlag, TimeSpan.FromMilliseconds(500)); + Assert.IsFalse(SdkTimedOutFlag); + Assert.IsFalse(SdkReadyFlag); + Assert.IsTrue(SdkUpdateFlag); VerifyMetadata(eMetadata); ResetAllVariables(); eventsManager.NotifyInternalEvent(SdkInternalEvent.FlagsUpdated, new EventMetadata(metaData)); - System.Threading.SpinWait.SpinUntil(() => SdkUpdate, TimeSpan.FromMilliseconds(500)); - Assert.IsFalse(SdkTimedOut); - Assert.IsFalse(SdkReady); - Assert.IsTrue(SdkUpdate); + System.Threading.SpinWait.SpinUntil(() => SdkUpdateFlag, TimeSpan.FromMilliseconds(500)); + Assert.IsFalse(SdkTimedOutFlag); + Assert.IsFalse(SdkReadyFlag); + Assert.IsTrue(SdkUpdateFlag); VerifyMetadata(eMetadata); eventsManager.Unregister(SdkEvent.SdkUpdate); eventsManager.Unregister(SdkEvent.SdkUpdate); // should not cause exception ResetAllVariables(); eventsManager.NotifyInternalEvent(SdkInternalEvent.FlagsUpdated, new EventMetadata(metaData)); - System.Threading.SpinWait.SpinUntil(() => SdkUpdate, TimeSpan.FromMilliseconds(500)); - Assert.IsFalse(SdkTimedOut); - Assert.IsFalse(SdkReady); - Assert.IsFalse(SdkUpdate); + System.Threading.SpinWait.SpinUntil(() => SdkUpdateFlag, TimeSpan.FromMilliseconds(500)); + Assert.IsFalse(SdkTimedOutFlag); + Assert.IsFalse(SdkReadyFlag); + Assert.IsFalse(SdkUpdateFlag); } void ResetAllVariables() { - SdkReady = false; - SdkReady2 = false; - SdkTimedOut = false; + SdkReadyFlag = false; + SdkReadyFlag2 = false; + SdkTimedOutFlag = false; eMetadata = null; - SdkUpdate = false; + SdkUpdateFlag = false; } void VerifyMetadata(EventMetadata eMetdata) @@ -138,26 +138,42 @@ void VerifyMetadata(EventMetadata eMetdata) private void sdkUpdate_callback(object sender, EventMetadata metadata) { - SdkUpdate = true; + SdkUpdateFlag = true; eMetadata = metadata; } private void sdkReady_callback(object sender, EventMetadata metadata) { - SdkReady = true; + SdkReadyFlag = true; eMetadata = metadata; } private void sdkReady_callback2(object sender, EventMetadata metadata) { - SdkReady2 = true; + SdkReadyFlag2 = true; eMetadata = metadata; } private void sdkTimedOut_callback(object sender, EventMetadata metadata) { - SdkTimedOut = true; + SdkTimedOutFlag = true; eMetadata = metadata; } + + private void TriggerSdkReady(EventMetadata metaData) + { + SdkReady?.Invoke(this, metaData); + } + + private void TriggerSdkUpdate(EventMetadata metaData) + { + SdkUpdate?.Invoke(this, metaData); + } + + private void TriggerSdkTimeout(EventMetadata metaData) + { + SdkTimedOut?.Invoke(this, metaData); + } + } } From 26a78f83e9ba8aea355471f0dfe1d86ec9e9649e Mon Sep 17 00:00:00 2001 From: Bill Al Date: Tue, 23 Dec 2025 12:35:11 -0800 Subject: [PATCH 13/15] polish --- src/Splitio/Services/Common/EventDelivery.cs | 3 +-- src/Splitio/Services/Common/EventsManager.cs | 13 +++++++------ src/Splitio/Services/Common/IEventDelivery.cs | 3 +-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Splitio/Services/Common/EventDelivery.cs b/src/Splitio/Services/Common/EventDelivery.cs index 38b04ffe9..288cb018b 100644 --- a/src/Splitio/Services/Common/EventDelivery.cs +++ b/src/Splitio/Services/Common/EventDelivery.cs @@ -1,5 +1,4 @@ -using Splitio.Domain; -using Splitio.Services.Logger; +using Splitio.Services.Logger; using Splitio.Services.Shared.Classes; using System; diff --git a/src/Splitio/Services/Common/EventsManager.cs b/src/Splitio/Services/Common/EventsManager.cs index d891e883e..483368b1e 100644 --- a/src/Splitio/Services/Common/EventsManager.cs +++ b/src/Splitio/Services/Common/EventsManager.cs @@ -186,8 +186,8 @@ private List CheckRequireAll() private bool CheckPrerequisites(E sdkEvent) { - foreach (var item in _managerConfig.Prerequisites.Where(kvp => kvp.Key.Equals(sdkEvent) && - kvp.Value.Any(x => !EventAlreadyTriggered(x)))) + if (_managerConfig.Prerequisites.Where(kvp => kvp.Key.Equals(sdkEvent) && + kvp.Value.Any(x => !EventAlreadyTriggered(x))).Count() > 0) { return false; } @@ -197,8 +197,8 @@ private bool CheckPrerequisites(E sdkEvent) private bool CheckSuppressedBy(E sdkEvent) { - foreach (var item in _managerConfig.SuppressedBy.Where(kvp => kvp.Key.Equals(sdkEvent) && - kvp.Value.Any(x => EventAlreadyTriggered(x)))) + if (_managerConfig.SuppressedBy.Where(kvp => kvp.Key.Equals(sdkEvent) && + kvp.Value.Any(x => EventAlreadyTriggered(x))).Count() > 0) { return false; } @@ -222,10 +222,11 @@ private ValidSdkEvent CheckRequireAny(I sdkInternalEvent) Valid = false }; - foreach (var item in _managerConfig.RequireAny.Where(kvp => kvp.Value.Contains(sdkInternalEvent))) + var sdkEvent = _managerConfig.RequireAny.Where(kvp => kvp.Value.Contains(sdkInternalEvent)); + if (sdkEvent.Count() > 0) { validSdkEvent.Valid = true; - validSdkEvent.SdkEvent = item.Key; + validSdkEvent.SdkEvent = sdkEvent.First().Key; return validSdkEvent; } diff --git a/src/Splitio/Services/Common/IEventDelivery.cs b/src/Splitio/Services/Common/IEventDelivery.cs index 69ae709f5..83bb4540d 100644 --- a/src/Splitio/Services/Common/IEventDelivery.cs +++ b/src/Splitio/Services/Common/IEventDelivery.cs @@ -1,5 +1,4 @@ -using Splitio.Domain; -using System; +using System; namespace Splitio.Services.Common { From 9415ac1c4332aab815f769856e39d62ef5b22dcc Mon Sep 17 00:00:00 2001 From: Bill Al Date: Tue, 23 Dec 2025 13:22:13 -0800 Subject: [PATCH 14/15] polish --- src/Splitio/Services/Common/EventsManager.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Splitio/Services/Common/EventsManager.cs b/src/Splitio/Services/Common/EventsManager.cs index 483368b1e..f50e0e814 100644 --- a/src/Splitio/Services/Common/EventsManager.cs +++ b/src/Splitio/Services/Common/EventsManager.cs @@ -24,7 +24,7 @@ private struct PublicEventProperties private readonly ConcurrentDictionary _activeSubscriptions; private readonly ConcurrentDictionary _internalEventsStatus; private readonly ISplitLogger _logger = WrapperAdapter.Instance().GetLogger("EventsManager"); - public readonly EventDelivery _eventDelivery; + private readonly EventDelivery _eventDelivery; private readonly object _lock = new object(); public EventManagerConfigData _managerConfig { get; private set; } @@ -186,8 +186,8 @@ private List CheckRequireAll() private bool CheckPrerequisites(E sdkEvent) { - if (_managerConfig.Prerequisites.Where(kvp => kvp.Key.Equals(sdkEvent) && - kvp.Value.Any(x => !EventAlreadyTriggered(x))).Count() > 0) + if (_managerConfig.Prerequisites.Any(kvp => kvp.Key.Equals(sdkEvent) && + kvp.Value.Any(x => !EventAlreadyTriggered(x)))) { return false; } @@ -197,8 +197,8 @@ private bool CheckPrerequisites(E sdkEvent) private bool CheckSuppressedBy(E sdkEvent) { - if (_managerConfig.SuppressedBy.Where(kvp => kvp.Key.Equals(sdkEvent) && - kvp.Value.Any(x => EventAlreadyTriggered(x))).Count() > 0) + if (_managerConfig.SuppressedBy.Any(kvp => kvp.Key.Equals(sdkEvent) && + kvp.Value.Any(x => EventAlreadyTriggered(x)))) { return false; } @@ -208,10 +208,11 @@ private bool CheckSuppressedBy(E sdkEvent) private int ExecutionLimit(E sdkEvent) { - if (!_managerConfig.ExecutionLimits.ContainsKey(sdkEvent)) + if (!_managerConfig.ExecutionLimits.TryGetValue(sdkEvent, out int limit)) + { return -1; + } - _managerConfig.ExecutionLimits.TryGetValue(sdkEvent, out int limit); return limit; } @@ -223,7 +224,7 @@ private ValidSdkEvent CheckRequireAny(I sdkInternalEvent) }; var sdkEvent = _managerConfig.RequireAny.Where(kvp => kvp.Value.Contains(sdkInternalEvent)); - if (sdkEvent.Count() > 0) + if (sdkEvent.Any()) { validSdkEvent.Valid = true; validSdkEvent.SdkEvent = sdkEvent.First().Key; From a1d89a9dab936c59ef23785cf899fce6b54c0b24 Mon Sep 17 00:00:00 2001 From: Bill Al Date: Tue, 23 Dec 2025 14:16:52 -0800 Subject: [PATCH 15/15] passed EventDelivery as a param to EventsManager --- .../Services/Client/Classes/JSONFileClient.cs | 2 +- .../Client/Classes/LocalhostClient.cs | 2 +- .../Client/Classes/SelfRefreshingClient.cs | 2 +- src/Splitio/Services/Common/EventsManager.cs | 6 +-- .../SelfRefreshingSegmentFetcherTests.cs | 2 +- .../TargetingRulesFetcherTests.cs | 6 +-- .../InMemory/RuleBasedSegmentCacheTests.cs | 3 +- .../Cache/InMemory/SegmentCacheAsyncTests.cs | 2 +- .../Cache/InMemory/SegmentCacheTests.cs | 23 +++++------ .../Cache/InMemory/SplitCacheAsyncTests.cs | 3 +- .../Cache/InMemory/SplitCacheTests.cs | 38 +++++++++--------- .../Unit Tests/Common/EventsManagerTests.cs | 2 +- .../UserDefinedSegmentMatcherAsyncTests.cs | 33 ++++++++-------- .../UserDefinedSegmentMatcherTests.cs | 39 ++++++++++--------- .../SelfRefreshingSegmentFetcherUnitTests.cs | 4 +- .../SelfRefreshingSegmentUnitTests.cs | 8 ++-- 16 files changed, 88 insertions(+), 87 deletions(-) diff --git a/src/Splitio/Services/Client/Classes/JSONFileClient.cs b/src/Splitio/Services/Client/Classes/JSONFileClient.cs index 371c84f42..ec5a40aa6 100644 --- a/src/Splitio/Services/Client/Classes/JSONFileClient.cs +++ b/src/Splitio/Services/Client/Classes/JSONFileClient.cs @@ -35,7 +35,7 @@ public JSONFileClient(string splitsFilePath, IRuleBasedSegmentCache ruleBasedSegmentCache = null ) : base("localhost", fallbackTreatmentCalculator) { - var eventsManager = new EventsManager(new EventsManagerConfig()); + var eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); _segmentCache = segmentCacheInstance ?? new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var rbsCache = ruleBasedSegmentCache ?? new InMemoryRuleBasedSegmentCache(new ConcurrentDictionary(), eventsManager); diff --git a/src/Splitio/Services/Client/Classes/LocalhostClient.cs b/src/Splitio/Services/Client/Classes/LocalhostClient.cs index 1afea359d..e42fca1ec 100644 --- a/src/Splitio/Services/Client/Classes/LocalhostClient.cs +++ b/src/Splitio/Services/Client/Classes/LocalhostClient.cs @@ -47,7 +47,7 @@ public LocalhostClient(ConfigurationOptions configurationOptions, FallbackTreatm BuildFlagSetsFilter(new HashSet()); - var eventsManager = new EventsManager(new EventsManagerConfig()); + var eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); var splits = _localhostFileService.ParseSplitFile(_fullPath); _featureFlagCache = new InMemorySplitCache(splits, _flagSetsFilter, eventsManager); diff --git a/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs b/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs index 33141a74c..370e6a2b8 100644 --- a/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs +++ b/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs @@ -92,7 +92,7 @@ public SelfRefreshingClient(string apiKey, ConfigurationOptions config, #region Private Methods private void BuildEventsManager() { - _eventsManager = new EventsManager(new EventsManagerConfig()); + _eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); } private void BuildSplitCache() { diff --git a/src/Splitio/Services/Common/EventsManager.cs b/src/Splitio/Services/Common/EventsManager.cs index f50e0e814..bda64bd6f 100644 --- a/src/Splitio/Services/Common/EventsManager.cs +++ b/src/Splitio/Services/Common/EventsManager.cs @@ -24,15 +24,15 @@ private struct PublicEventProperties private readonly ConcurrentDictionary _activeSubscriptions; private readonly ConcurrentDictionary _internalEventsStatus; private readonly ISplitLogger _logger = WrapperAdapter.Instance().GetLogger("EventsManager"); - private readonly EventDelivery _eventDelivery; + private readonly IEventDelivery _eventDelivery; private readonly object _lock = new object(); public EventManagerConfigData _managerConfig { get; private set; } - public EventsManager(EventManagerConfigData eventsManagerConfig) + public EventsManager(EventManagerConfigData eventsManagerConfig, IEventDelivery eventDelivery) { _activeSubscriptions = new ConcurrentDictionary(); _internalEventsStatus = new ConcurrentDictionary(); - _eventDelivery = new EventDelivery(); + _eventDelivery = eventDelivery; _managerConfig = eventsManagerConfig; } diff --git a/tests/Splitio-tests/Integration Tests/SelfRefreshingSegmentFetcherTests.cs b/tests/Splitio-tests/Integration Tests/SelfRefreshingSegmentFetcherTests.cs index bde1a5696..708396008 100644 --- a/tests/Splitio-tests/Integration Tests/SelfRefreshingSegmentFetcherTests.cs +++ b/tests/Splitio-tests/Integration Tests/SelfRefreshingSegmentFetcherTests.cs @@ -27,7 +27,7 @@ public SelfRefreshingSegmentFetcherTests() public void ExecuteGetSuccessfulWithResultsFromJSONFile() { //Arrange - var eventsManager = new EventsManager(new EventsManagerConfig()); + var eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var segmentFetcher = new JSONFileSegmentFetcher($"{rootFilePath}segment_payed.json", segmentCache); diff --git a/tests/Splitio-tests/Integration Tests/TargetingRulesFetcherTests.cs b/tests/Splitio-tests/Integration Tests/TargetingRulesFetcherTests.cs index f2b7dfe7c..c949489c5 100644 --- a/tests/Splitio-tests/Integration Tests/TargetingRulesFetcherTests.cs +++ b/tests/Splitio-tests/Integration Tests/TargetingRulesFetcherTests.cs @@ -38,7 +38,7 @@ public TargetingRulesFetcherTests() public async Task ExecuteGetSuccessfulWithResultsFromJSONFile() { //Arrange - var eventsManager = new EventsManager(new EventsManagerConfig()); + var eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var rbsCache = new InMemoryRuleBasedSegmentCache(new ConcurrentDictionary(), eventsManager); var segmentFetcher = new JSONFileSegmentFetcher($"{rootFilePath}segment_payed.json", segmentCache); @@ -84,7 +84,7 @@ public async Task ExecuteGetSuccessfulWithResultsFromJSONFile() public async Task ExecuteGetSuccessfulWithResultsFromJSONFileIncludingTrafficAllocation() { //Arrange - var eventsManager = new EventsManager(new EventsManagerConfig()); + var eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var rbsCache = new InMemoryRuleBasedSegmentCache(new ConcurrentDictionary(), eventsManager); var segmentFetcher = new JSONFileSegmentFetcher($"{rootFilePath}segment_payed.json", segmentCache); @@ -142,7 +142,7 @@ public async Task ExecuteGetWithoutResults() var sdkSegmentApiClient = new SegmentSdkApiClient(httpClient, telemetryStorage, baseUrl); var apiSegmentChangeFetcher = new ApiSegmentChangeFetcher(sdkSegmentApiClient); var gates = new InMemoryReadinessGatesCache(); - var eventsManager = new EventsManager(new EventsManagerConfig()); + var eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var segmentsQueue = new SplitQueue(); var taskManager = new TasksManager(gates); diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs index b43c27cac..023b5ce87 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs @@ -23,7 +23,7 @@ public class RuleBasedSegmentCacheTests public void Setup() { var cache = new ConcurrentDictionary(); - _eventsManager = new EventsManager(new EventsManagerConfig()); + _eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); _segmentCache = new InMemoryRuleBasedSegmentCache(cache, _eventsManager); } @@ -155,7 +155,6 @@ public void Contains_ShouldReturnTrue() public void Update_ShouldNotifyEvent() { // Arrange - var segmentToAdd = new RuleBasedSegment { Name = "segment-to-add" }; var segmentToRemove = new RuleBasedSegment { Name = "segment-to-remove" }; var till = 67890; diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheAsyncTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheAsyncTests.cs index 64ff38f3e..dcaf47d04 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheAsyncTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheAsyncTests.cs @@ -23,7 +23,7 @@ public class SegmentCacheAsyncTests public SegmentCacheAsyncTests() { var segments = new ConcurrentDictionary(); - _eventsManager = new EventsManager(new EventsManagerConfig()); + _eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); _cache = new InMemorySegmentCache(segments, _eventsManager); } diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheTests.cs index 235d9408d..689d109b0 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SegmentCacheTests.cs @@ -1,4 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; using Splitio.Domain; using Splitio.Services.Cache.Classes; using Splitio.Services.Common; @@ -20,8 +21,8 @@ public class SegmentCacheTests public void RegisterSegmentTest() { //Arrange - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); var keys = new List { "abcd", "1234" }; var segmentName = "test"; @@ -37,8 +38,8 @@ public void RegisterSegmentTest() public void IsNotInSegmentTest() { //Arrange - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); var keys = new List { "1234" }; var segmentName = "test"; @@ -54,8 +55,8 @@ public void IsNotInSegmentTest() public void IsInSegmentWithInexistentSegmentTest() { //Arrange - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); //Act var result = segmentCache.IsInSegment("test", "abcd"); @@ -68,8 +69,8 @@ public void IsInSegmentWithInexistentSegmentTest() public void RemoveKeyFromSegmentTest() { //Arrange - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); var keys = new List { "1234" }; var segmentName = "test"; @@ -88,8 +89,8 @@ public void RemoveKeyFromSegmentTest() public void SetAndGetChangeNumberTest() { //Arrange - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); var segmentName = "test"; //Act @@ -105,7 +106,7 @@ public void SetAndGetChangeNumberTest() public void NotifyEventsTest() { //Arrange - var eventsManager = new EventsManager(new EventsManagerConfig()); + var eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var keys = new List { "1234" }; var segmentName = "test"; diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheAsyncTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheAsyncTests.cs index c02d905f5..985b62755 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheAsyncTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheAsyncTests.cs @@ -27,8 +27,7 @@ public SplitCacheAsyncTests() { _flagSetsFilter = new FlagSetsFilter(new HashSet()); var splits = new ConcurrentDictionary(); - _eventsManager = new EventsManager(new EventsManagerConfig()); - + _eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); _cache = new InMemorySplitCache(splits, _flagSetsFilter, _eventsManager); } diff --git a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheTests.cs b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheTests.cs index 33a0889d1..651f66ee3 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/SplitCacheTests.cs @@ -29,8 +29,8 @@ public SplitCacheTests() public void AddAndGetSplitTest() { //Arrange - var eventsManager = new EventsManager(new EventsManagerConfig()); - var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), _flagSetsFilter.Object, eventsManager); + Mock> eventsManager = new Mock>(); + var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), _flagSetsFilter.Object, eventsManager.Object); var splitName = "test1"; //Act @@ -45,8 +45,8 @@ public void AddAndGetSplitTest() public void AddDuplicateSplitTest() { //Arrange - var eventsManager = new EventsManager(new EventsManagerConfig()); - var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), _flagSetsFilter.Object, eventsManager); + Mock> eventsManager = new Mock>(); + var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), _flagSetsFilter.Object, eventsManager.Object); var splitName = "test1"; //Act @@ -66,8 +66,8 @@ public void AddDuplicateSplitTest() public void GetInexistentSplitTest() { //Arrange - var eventsManager = new EventsManager(new EventsManagerConfig()); - var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), _flagSetsFilter.Object, eventsManager); + Mock> eventsManager = new Mock>(); + var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), _flagSetsFilter.Object, eventsManager.Object); var splitName = "test1"; //Act @@ -84,8 +84,8 @@ public void RemoveSplitTest() var splitName = "test1"; var splits = new ConcurrentDictionary(); splits.TryAdd(splitName, new ParsedSplit() { name = splitName }); - var eventsManager = new EventsManager(new EventsManagerConfig()); - var splitCache = new InMemorySplitCache(splits, _flagSetsFilter.Object, eventsManager); + Mock> eventsManager = new Mock>(); + var splitCache = new InMemorySplitCache(splits, _flagSetsFilter.Object, eventsManager.Object); //Act splitCache.Update(new List(), new List { splitName }, -1); @@ -99,8 +99,8 @@ public void RemoveSplitTest() public void SetAndGetChangeNumberTest() { //Arrange - var eventsManager = new EventsManager(new EventsManagerConfig()); - var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), _flagSetsFilter.Object, eventsManager); + Mock> eventsManager = new Mock>(); + var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), _flagSetsFilter.Object, eventsManager.Object); var changeNumber = 1234; //Act @@ -115,8 +115,8 @@ public void SetAndGetChangeNumberTest() public void GetAllSplitsTest() { //Arrange - var eventsManager = new EventsManager(new EventsManagerConfig()); - var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), _flagSetsFilter.Object, eventsManager); + Mock> eventsManager = new Mock>(); + var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), _flagSetsFilter.Object, eventsManager.Object); var splitName = "test1"; var splitName2 = "test2"; @@ -135,8 +135,8 @@ public void GetAllSplitsTest() public void AddOrUpdate_WhenUpdateTraffictType_ReturnsTrue() { // Arrange - var eventsManager = new EventsManager(new EventsManagerConfig()); - var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), _flagSetsFilter.Object, eventsManager); + Mock> eventsManager = new Mock>(); + var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), _flagSetsFilter.Object, eventsManager.Object); var splitName = "split_1"; var splitName2 = "split_2"; @@ -178,8 +178,8 @@ public void GetNamesByFlagSetsWithoutFilter() Sets = new HashSet { "set1", "set2" } }); - var eventsManager = new EventsManager(new EventsManagerConfig()); - var splitCache = new InMemorySplitCache(featureFlags, new FlagSetsFilter(new HashSet()), eventsManager); + Mock> eventsManager = new Mock>(); + var splitCache = new InMemorySplitCache(featureFlags, new FlagSetsFilter(new HashSet()), eventsManager.Object); var flagSetNames = new List { "set1", "set2", "set3", "set4" }; // Act. @@ -222,8 +222,8 @@ public void GetNamesByFlagSetsWithFilters() defaultTreatment = "on", Sets = new HashSet { "set1", "set2" } }); - var eventsManager = new EventsManager(new EventsManagerConfig()); - var splitCache = new InMemorySplitCache(featureFlags, new FlagSetsFilter(new HashSet() { "set1", "set2" }), eventsManager); + Mock> eventsManager = new Mock>(); + var splitCache = new InMemorySplitCache(featureFlags, new FlagSetsFilter(new HashSet() { "set1", "set2" }), eventsManager.Object); var flagSetNames = new List { "set1", "set2", "set3", "set4" }; // Act. @@ -245,7 +245,7 @@ public void GetNamesByFlagSetsWithFilters() public void NotifyUpdateEventTest() { // Arrange. - var eventsManager = new EventsManager(new EventsManagerConfig()); + var eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), _flagSetsFilter.Object, eventsManager); var splitName = "test1"; diff --git a/tests/Splitio-tests/Unit Tests/Common/EventsManagerTests.cs b/tests/Splitio-tests/Unit Tests/Common/EventsManagerTests.cs index 50c3ee78f..5d662d98d 100644 --- a/tests/Splitio-tests/Unit Tests/Common/EventsManagerTests.cs +++ b/tests/Splitio-tests/Unit Tests/Common/EventsManagerTests.cs @@ -23,7 +23,7 @@ public void TestFiringEvents() { //Act EventsManagerConfig config = new EventsManagerConfig(); - EventsManager eventsManager = new EventsManager(config); + EventsManager eventsManager = new EventsManager(config, new EventDelivery()); SdkReady += sdkReady_callback; SdkReady += sdkReady_callback2; diff --git a/tests/Splitio-tests/Unit Tests/Matchers/UserDefinedSegmentMatcherAsyncTests.cs b/tests/Splitio-tests/Unit Tests/Matchers/UserDefinedSegmentMatcherAsyncTests.cs index e870361b2..f3a0ff0ea 100644 --- a/tests/Splitio-tests/Unit Tests/Matchers/UserDefinedSegmentMatcherAsyncTests.cs +++ b/tests/Splitio-tests/Unit Tests/Matchers/UserDefinedSegmentMatcherAsyncTests.cs @@ -1,4 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; using Splitio.Domain; using Splitio.Services.Cache.Classes; using Splitio.Services.Common; @@ -23,8 +24,8 @@ public async Task MatchAsyncShouldReturnTrueOnMatchingSegmentWithKey() }; var segmentName = "test-segment"; - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); segmentCache.AddToSegment(segmentName, keys); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -47,8 +48,8 @@ public async Task MatchAsyncShouldReturnFalseOnNonMatchingSegmentWithKey() }; var segmentName = "test-segment"; - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); segmentCache.AddToSegment(segmentName, keys); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -65,8 +66,8 @@ public async Task MatchAsyncShouldReturnFalseIfSegmentEmptyWithKey() { //Arrange var segmentName = "test-segment"; - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); segmentCache.AddToSegment(segmentName, null); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -83,8 +84,8 @@ public async Task MatchAsyncShouldReturnFalseIfCacheEmptyWithKey() { //Arrange var segmentName = "test-segment"; - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -106,8 +107,8 @@ public async Task MatchAsyncShouldReturnTrueOnMatchingSegment() }; var segmentName = "test-segment"; - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); segmentCache.AddToSegment(segmentName, keys); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -130,8 +131,8 @@ public async Task MatchAsyncShouldReturnFalseOnNonMatchingSegment() }; var segmentName = "test-segment"; - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); segmentCache.AddToSegment(segmentName, keys); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -148,8 +149,8 @@ public async Task MatchAsyncShouldReturnFalseIfSegmentEmpty() { //Arrange var segmentName = "test-segment"; - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); segmentCache.AddToSegment(segmentName, null); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -166,8 +167,8 @@ public async Task MatchAsyncShouldReturnFalseIfCacheEmpty() { //Arrange var segmentName = "test-segment"; - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); diff --git a/tests/Splitio-tests/Unit Tests/Matchers/UserDefinedSegmentMatcherTests.cs b/tests/Splitio-tests/Unit Tests/Matchers/UserDefinedSegmentMatcherTests.cs index 112399737..f7c1245c4 100644 --- a/tests/Splitio-tests/Unit Tests/Matchers/UserDefinedSegmentMatcherTests.cs +++ b/tests/Splitio-tests/Unit Tests/Matchers/UserDefinedSegmentMatcherTests.cs @@ -1,10 +1,11 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using Splitio.Services.Parsing; +using Moq; using Splitio.Domain; -using System.Collections.Generic; -using System.Collections.Concurrent; using Splitio.Services.Cache.Classes; using Splitio.Services.Common; +using Splitio.Services.Parsing; +using System.Collections.Concurrent; +using System.Collections.Generic; namespace Splitio_Tests.Unit_Tests { @@ -22,8 +23,8 @@ public void MatchShouldReturnTrueOnMatchingSegmentWithKey() }; var segmentName = "test-segment"; - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); segmentCache.AddToSegment(segmentName, keys); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -46,8 +47,8 @@ public void MatchShouldReturnFalseOnNonMatchingSegmentWithKey() }; var segmentName = "test-segment"; - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); segmentCache.AddToSegment(segmentName, keys); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -64,8 +65,8 @@ public void MatchShouldReturnFalseIfSegmentEmptyWithKey() { //Arrange var segmentName = "test-segment"; - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); segmentCache.AddToSegment(segmentName, null); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -82,8 +83,8 @@ public void MatchShouldReturnFalseIfCacheEmptyWithKey() { //Arrange var segmentName = "test-segment"; - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -105,8 +106,8 @@ public void MatchShouldReturnTrueOnMatchingSegment() }; var segmentName = "test-segment"; - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); segmentCache.AddToSegment(segmentName, keys); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -129,8 +130,8 @@ public void MatchShouldReturnFalseOnNonMatchingSegment() }; var segmentName = "test-segment"; - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); segmentCache.AddToSegment(segmentName, keys); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -147,8 +148,8 @@ public void MatchShouldReturnFalseIfSegmentEmpty() { //Arrange var segmentName = "test-segment"; - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); segmentCache.AddToSegment(segmentName, null); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); @@ -165,8 +166,8 @@ public void MatchShouldReturnFalseIfCacheEmpty() { //Arrange var segmentName = "test-segment"; - var eventsManager = new EventsManager(new EventsManagerConfig()); - var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); + Mock> eventsManager = new Mock>(); + var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager.Object); var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache); diff --git a/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs b/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs index 9e242cc83..e16e8ca3d 100644 --- a/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs @@ -32,8 +32,8 @@ public void InitializeSegmentNotExistent() var apiClient = new Mock(); var apiFetcher = new ApiSegmentChangeFetcher(apiClient.Object); var segments = new ConcurrentDictionary(); - var eventsManager = new EventsManager(new EventsManagerConfig()); - var cache = new InMemorySegmentCache(segments, eventsManager); + Mock> eventsManager = new Mock>(); + var cache = new InMemorySegmentCache(segments, eventsManager.Object); var segmentsQueue = new SplitQueue(); var taskManager = new TasksManager(gates); var worker = new SegmentTaskWorker(5, segmentsQueue); diff --git a/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentUnitTests.cs b/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentUnitTests.cs index 06f32febe..830745586 100644 --- a/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentUnitTests.cs @@ -23,8 +23,8 @@ public async Task FetchSegmentNullChangesFetcherResponseShouldNotUpdateCache() var statusManager = new Mock(); var apiFetcher = new ApiSegmentChangeFetcher(apiClient.Object); var segments = new ConcurrentDictionary(); - var eventsManager = new EventsManager(new EventsManagerConfig()); - var cache = new InMemorySegmentCache(segments, eventsManager); + Mock> eventsManager = new Mock>(); + var cache = new InMemorySegmentCache(segments, eventsManager.Object); var segmentFetcher = new SelfRefreshingSegment("payed", apiFetcher, cache, statusManager.Object); apiClient @@ -46,8 +46,8 @@ public async Task FetchSegmentShouldUpdateSegmentsCache() var statusManager = new Mock(); var apiFetcher = new ApiSegmentChangeFetcher(apiClient.Object); var segments = new ConcurrentDictionary(); - var eventsManager = new EventsManager(new EventsManagerConfig()); - var cache = new InMemorySegmentCache(segments, eventsManager); + Mock> eventsManager = new Mock>(); + var cache = new InMemorySegmentCache(segments, eventsManager.Object); var segmentFetcher = new SelfRefreshingSegment("payed", apiFetcher, cache, statusManager.Object); apiClient