From 2e361c1028bf6673f294b689e7f6c50ed67d0117 Mon Sep 17 00:00:00 2001 From: Bill Al Date: Thu, 18 Dec 2025 12:36:06 -0800 Subject: [PATCH 1/8] added events for ready and timedout --- .../Services/Client/Classes/RedisClient.cs | 4 +- .../Classes/InMemoryReadinessGatesCache.cs | 15 ++- .../Services/Client/Classes/JSONFileClient.cs | 4 +- .../Client/Classes/LocalhostClient.cs | 4 +- .../Client/Classes/SelfRefreshingClient.cs | 11 +-- .../Services/Client/Classes/SplitClient.cs | 6 +- .../Services/Client/Classes/SplitFactory.cs | 9 +- .../SelfRefreshingBlockUntilReadyService.cs | 14 ++- .../BaseLocalhostClientTests.cs | 31 +++--- .../Integration Tests/InMemoryClientTests.cs | 5 +- .../Integration Tests/JSONFileClientTests.cs | 97 ++++++++++--------- .../Integration Tests/RedisClientTests.cs | 51 +++++----- .../TargetingRulesFetcherTests.cs | 6 +- .../Client/LocalhostClientForTesting.cs | 6 +- .../Client/LocalhostClientUnitTests.cs | 7 +- .../Client/SdkReadinessGatesUnitTests.cs | 33 ++++++- .../Client/SplitClientForTesting.cs | 5 +- .../Impressions/ImpressionsCounterTests.cs | 10 +- .../SelfRefreshingSegmentFetcherUnitTests.cs | 2 +- ...lfRefreshingBlockUntilReadyServiceTests.cs | 52 ++++++++++ .../EventSourceClientTests.cs | 2 +- .../Splitio.TestSupport/SplitClientForTest.cs | 4 +- 22 files changed, 255 insertions(+), 123 deletions(-) create mode 100644 tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs diff --git a/Splitio.Redis/Services/Client/Classes/RedisClient.cs b/Splitio.Redis/Services/Client/Classes/RedisClient.cs index 4cfc76eac..345a546d7 100644 --- a/Splitio.Redis/Services/Client/Classes/RedisClient.cs +++ b/Splitio.Redis/Services/Client/Classes/RedisClient.cs @@ -9,6 +9,7 @@ using Splitio.Redis.Telemetry.Storages; using Splitio.Services.Cache.Interfaces; using Splitio.Services.Client.Classes; +using Splitio.Services.Common; using Splitio.Services.EngineEvaluator; using Splitio.Services.Evaluator; using Splitio.Services.Impressions.Classes; @@ -30,7 +31,8 @@ public class RedisClient : SplitClient private IFeatureFlagCacheConsumer _featureFlagCacheConsumer; private readonly new FallbackTreatmentCalculator _fallbackTreatmentCalculator; - public RedisClient(ConfigurationOptions config, string apiKey, FallbackTreatmentCalculator fallbackTreatmentCalculator) : base(apiKey, fallbackTreatmentCalculator) + public RedisClient(ConfigurationOptions config, string apiKey, FallbackTreatmentCalculator fallbackTreatmentCalculator, + EventsManager eventsManager) : base(apiKey, fallbackTreatmentCalculator, eventsManager) { _config = new RedisConfig(); _fallbackTreatmentCalculator = fallbackTreatmentCalculator; diff --git a/src/Splitio/Services/Cache/Classes/InMemoryReadinessGatesCache.cs b/src/Splitio/Services/Cache/Classes/InMemoryReadinessGatesCache.cs index d1d42e51c..d31214566 100644 --- a/src/Splitio/Services/Cache/Classes/InMemoryReadinessGatesCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemoryReadinessGatesCache.cs @@ -1,4 +1,7 @@ -using Splitio.Services.Cache.Interfaces; +using Splitio.Domain; +using Splitio.Services.Cache.Interfaces; +using Splitio.Services.Common; +using System.Collections.Generic; using System.Threading; namespace Splitio.Services.Client.Classes @@ -7,6 +10,12 @@ public class InMemoryReadinessGatesCache : IStatusManager { private readonly CountdownEvent _sdkReady = new CountdownEvent(1); private readonly CountdownEvent _sdkDestroyed = new CountdownEvent(1); + private readonly EventsManager _eventsManager; + + public InMemoryReadinessGatesCache(EventsManager eventsManager) + { + _eventsManager = eventsManager; + } public bool IsReady() { @@ -21,6 +30,10 @@ public bool WaitUntilReady(int milliseconds) public void SetReady() { _sdkReady.Signal(); + _eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, + new EventMetadata(new Dictionary()), + Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkReady, + _eventsManager)); } public void SetDestroy() diff --git a/src/Splitio/Services/Client/Classes/JSONFileClient.cs b/src/Splitio/Services/Client/Classes/JSONFileClient.cs index ebc40e1a6..830f5a0fa 100644 --- a/src/Splitio/Services/Client/Classes/JSONFileClient.cs +++ b/src/Splitio/Services/Client/Classes/JSONFileClient.cs @@ -25,6 +25,7 @@ public class JSONFileClient : SplitClient public JSONFileClient(string splitsFilePath, string segmentsFilePath, FallbackTreatmentCalculator fallbackTreatmentCalculator, + EventsManager eventsManager, ISegmentCache segmentCacheInstance = null, IFeatureFlagCache featureFlagCacheInstance = null, IImpressionsLog impressionsLog = null, @@ -33,9 +34,8 @@ public JSONFileClient(string splitsFilePath, ITrafficTypeValidator trafficTypeValidator = null, IImpressionsManager impressionsManager = null, IRuleBasedSegmentCache ruleBasedSegmentCache = null - ) : base("localhost", fallbackTreatmentCalculator) + ) : base("localhost", fallbackTreatmentCalculator, eventsManager) { - var eventsManager = new EventsManager(new EventsManagerConfig()); _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..b22c5f076 100644 --- a/src/Splitio/Services/Client/Classes/LocalhostClient.cs +++ b/src/Splitio/Services/Client/Classes/LocalhostClient.cs @@ -28,7 +28,8 @@ public class LocalhostClient : SplitClient private readonly object _lock = new object(); - public LocalhostClient(ConfigurationOptions configurationOptions, FallbackTreatmentCalculator fallbackTreatmentCalculator) : base("localhost", fallbackTreatmentCalculator) + public LocalhostClient(ConfigurationOptions configurationOptions, FallbackTreatmentCalculator fallbackTreatmentCalculator, + EventsManager eventsManager) : base("localhost", fallbackTreatmentCalculator, eventsManager) { var configs = (LocalhostClientConfigurations)_configService.ReadConfig(configurationOptions, ConfigTypes.Localhost, _statusManager); @@ -47,7 +48,6 @@ public LocalhostClient(ConfigurationOptions configurationOptions, FallbackTreatm BuildFlagSetsFilter(new HashSet()); - var eventsManager = new EventsManager(new EventsManagerConfig()); 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..ce314289a 100644 --- a/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs +++ b/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs @@ -55,13 +55,14 @@ public class SelfRefreshingClient : SplitClient private EventsManager _eventsManager; public SelfRefreshingClient(string apiKey, ConfigurationOptions config, - FallbackTreatmentCalculator fallbackTreatmentCalculator) : base(apiKey, fallbackTreatmentCalculator) + FallbackTreatmentCalculator fallbackTreatmentCalculator, + EventsManager eventsManager) : base(apiKey, fallbackTreatmentCalculator, eventsManager) { _config = (SelfRefreshingConfig)_configService.ReadConfig(config, ConfigTypes.InMemory); _fallbackTreatmentCalculator = fallbackTreatmentCalculator; + _eventsManager = eventsManager; BuildFlagSetsFilter(_config.FlagSetsFilter); - BuildEventsManager(); BuildSplitCache(); BuildSegmentCache(); BuildRuleBasedSegmentCache(); @@ -90,10 +91,6 @@ public SelfRefreshingClient(string apiKey, ConfigurationOptions config, } #region Private Methods - private void BuildEventsManager() - { - _eventsManager = new EventsManager(new EventsManagerConfig()); - } private void BuildSplitCache() { _featureFlagCache = new InMemorySplitCache(new ConcurrentDictionary(_config.ConcurrencyLevel, InitialCapacity), _flagSetsFilter, _eventsManager); @@ -218,7 +215,7 @@ private void BuildManager() private void BuildBlockUntilReadyService() { - _blockUntilReadyService = new SelfRefreshingBlockUntilReadyService(_statusManager, _telemetryInitProducer); + _blockUntilReadyService = new SelfRefreshingBlockUntilReadyService(_statusManager, _telemetryInitProducer, _eventsManager); } private void BuildTelemetrySyncTask() diff --git a/src/Splitio/Services/Client/Classes/SplitClient.cs b/src/Splitio/Services/Client/Classes/SplitClient.cs index 54297fdf8..7f9c0fb0e 100644 --- a/src/Splitio/Services/Client/Classes/SplitClient.cs +++ b/src/Splitio/Services/Client/Classes/SplitClient.cs @@ -64,9 +64,11 @@ public abstract class SplitClient : ISplitClient protected IClientExtensionService _clientExtensionService; protected IFlagSetsFilter _flagSetsFilter; - protected SplitClient(string apikey, FallbackTreatmentCalculator fallbackTreatmentCalculator) + protected SplitClient(string apikey, FallbackTreatmentCalculator fallbackTreatmentCalculator, + EventsManager eventsManager) { ApiKey = apikey; + Splitio.Util.Helper.BuildInternalSdkEventStatus(eventsManager); _fallbackTreatmentCalculator = fallbackTreatmentCalculator; _wrapperAdapter = WrapperAdapter.Instance(); @@ -77,7 +79,7 @@ protected SplitClient(string apikey, FallbackTreatmentCalculator fallbackTreatme _factoryInstantiationsService = FactoryInstantiationsService.Instance(); _flagSetsValidator = new FlagSetsValidator(); _configService = new ConfigService(_wrapperAdapter, _flagSetsValidator, new SdkMetadataValidator()); - _statusManager = new InMemoryReadinessGatesCache(); + _statusManager = new InMemoryReadinessGatesCache(eventsManager); _tasksManager = new TasksManager(_statusManager); } diff --git a/src/Splitio/Services/Client/Classes/SplitFactory.cs b/src/Splitio/Services/Client/Classes/SplitFactory.cs index 92f8b46ec..d22b66479 100644 --- a/src/Splitio/Services/Client/Classes/SplitFactory.cs +++ b/src/Splitio/Services/Client/Classes/SplitFactory.cs @@ -1,5 +1,6 @@ using Splitio.Domain; using Splitio.Services.Client.Interfaces; +using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; using Splitio.Services.InputValidation.Classes; using Splitio.Services.InputValidation.Interfaces; @@ -59,6 +60,8 @@ public ISplitManager Manager() private void BuildSplitClient() { FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(_options.FallbackTreatments); + EventsManager eventsManager = new EventsManager(new EventsManagerConfig()); + switch (_options.Mode) { case Mode.Standalone: @@ -66,11 +69,11 @@ private void BuildSplitClient() if (_apiKey == "localhost") { - _client = new LocalhostClient(_options, fallbackTreatmentCalculator); + _client = new LocalhostClient(_options, fallbackTreatmentCalculator, eventsManager); } else { - _client = new SelfRefreshingClient(_apiKey, _options, fallbackTreatmentCalculator); + _client = new SelfRefreshingClient(_apiKey, _options, fallbackTreatmentCalculator, eventsManager); } break; case Mode.Consumer: @@ -81,7 +84,7 @@ private void BuildSplitClient() var redisAssembly = Assembly.Load(new AssemblyName("Splitio.Redis")); var redisType = redisAssembly.GetType("Splitio.Redis.Services.Client.Classes.RedisClient"); - _client = (ISplitClient)Activator.CreateInstance(redisType, new object[] { _options, _apiKey, fallbackTreatmentCalculator }); + _client = (ISplitClient)Activator.CreateInstance(redisType, new object[] { _options, _apiKey, fallbackTreatmentCalculator, eventsManager }); } catch (ArgumentException ex) { diff --git a/src/Splitio/Services/Shared/Classes/SelfRefreshingBlockUntilReadyService.cs b/src/Splitio/Services/Shared/Classes/SelfRefreshingBlockUntilReadyService.cs index fcc27eecb..6bf5c2b91 100644 --- a/src/Splitio/Services/Shared/Classes/SelfRefreshingBlockUntilReadyService.cs +++ b/src/Splitio/Services/Shared/Classes/SelfRefreshingBlockUntilReadyService.cs @@ -1,8 +1,11 @@ -using Splitio.Services.Cache.Interfaces; +using Splitio.Domain; +using Splitio.Services.Cache.Interfaces; +using Splitio.Services.Common; using Splitio.Services.Logger; using Splitio.Services.Shared.Interfaces; using Splitio.Telemetry.Storages; using System; +using System.Collections.Generic; namespace Splitio.Services.Shared.Classes { @@ -12,11 +15,14 @@ public class SelfRefreshingBlockUntilReadyService : IBlockUntilReadyService private readonly IStatusManager _statusManager; private readonly ITelemetryInitProducer _telemetryInitProducer; + private readonly EventsManager _eventsManager; - public SelfRefreshingBlockUntilReadyService(IStatusManager statusManager, ITelemetryInitProducer telemetryInitProducer) + public SelfRefreshingBlockUntilReadyService(IStatusManager statusManager, ITelemetryInitProducer telemetryInitProducer, + EventsManager eventsManager) { _statusManager = statusManager; _telemetryInitProducer = telemetryInitProducer; + _eventsManager = eventsManager; } public void BlockUntilReady(int blockMilisecondsUntilReady) @@ -30,6 +36,10 @@ public void BlockUntilReady(int blockMilisecondsUntilReady) if (!_statusManager.WaitUntilReady(blockMilisecondsUntilReady)) { + _eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkTimedOut, + new EventMetadata(new Dictionary()), + Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkTimedOut, + _eventsManager)); _telemetryInitProducer.RecordBURTimeout(); throw new TimeoutException($"SDK was not ready in {blockMilisecondsUntilReady} milliseconds"); } diff --git a/tests/Splitio-tests/Integration Tests/BaseLocalhostClientTests.cs b/tests/Splitio-tests/Integration Tests/BaseLocalhostClientTests.cs index 4f035f950..fe9b32270 100644 --- a/tests/Splitio-tests/Integration Tests/BaseLocalhostClientTests.cs +++ b/tests/Splitio-tests/Integration Tests/BaseLocalhostClientTests.cs @@ -2,6 +2,7 @@ using Splitio.Domain; using Splitio.Redis.Services.Client.Classes; using Splitio.Services.Client.Classes; +using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; using Splitio.Telemetry.Domain; using System; @@ -24,6 +25,7 @@ public abstract class BaseLocalhostClientTests private readonly string rootFilePath; private readonly string _mode; private readonly FallbackTreatmentCalculator _fallbackTreatmentCalculator; + private readonly EventsManager _eventsManager; public BaseLocalhostClientTests(string mode) { @@ -31,6 +33,7 @@ public BaseLocalhostClientTests(string mode) rootFilePath = string.Empty; _mode = mode; _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()); + _eventsManager = new EventsManager(new EventsManagerConfig()); #if NET_LATEST rootFilePath = @"Resources\"; @@ -42,7 +45,7 @@ public async Task GetTreatmentAsync() { // Arrange. var config = GetConfiguration($"{rootFilePath}test.splits"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -81,7 +84,7 @@ public void GetTreatmentSuccessfully() { //Arrange var config = GetConfiguration($"{rootFilePath}test.splits"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -105,7 +108,7 @@ public void GetTreatmentSuccessfullyWhenUpdatingSplitsFile() // Arrange var filePath = $"{rootFilePath}test2-{_mode}.splits"; var config = GetConfiguration(filePath); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -148,7 +151,7 @@ public void GetTreatmentSuccessfullyWhenUpdatingSplitsFileSameFile() Thread.Sleep(1000); var config = GetConfiguration(filePath); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -171,7 +174,7 @@ public void ClientDestroySuccessfully() { //Arrange var config = GetConfiguration($"{rootFilePath}test.splits"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -193,7 +196,7 @@ public void GetTreatment_WhenIsYamlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -225,7 +228,7 @@ public void GetTreatmentWithConfig_WhenIsYamlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -264,7 +267,7 @@ public void GetTreatment_WhenIsYmlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -296,7 +299,7 @@ public void GetTreatmentWithConfig_WhenIsYmlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -335,7 +338,7 @@ public void GetTreatments_WhenIsYamlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -372,7 +375,7 @@ public void GetTreatmentsWithConfig_WhenIsYamlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -423,7 +426,7 @@ public void GetTreatments_WhenIsYmlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -460,7 +463,7 @@ public void GetTreatmentsWithConfig_WhenIsYmlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -514,7 +517,7 @@ public void FallbackTreatments_WhenFeatureDoesNotExist() FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(fallbackTreatmentsConfiguration); var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, fallbackTreatmentCalculator); + var client = new LocalhostClient(config, fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); diff --git a/tests/Splitio-tests/Integration Tests/InMemoryClientTests.cs b/tests/Splitio-tests/Integration Tests/InMemoryClientTests.cs index 5732ce6c3..2279838cb 100644 --- a/tests/Splitio-tests/Integration Tests/InMemoryClientTests.cs +++ b/tests/Splitio-tests/Integration Tests/InMemoryClientTests.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json.Serialization; using Splitio.Domain; using Splitio.Services.Client.Classes; +using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; namespace Splitio_Tests.Integration_Tests @@ -12,12 +13,14 @@ public class InMemoryClientTests { private readonly string rootFilePath; private readonly FallbackTreatmentCalculator _fallbackTreatmentCalculator; + private readonly EventsManager _eventsManager; public InMemoryClientTests() { // This line is to clean the warnings. rootFilePath = string.Empty; _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()); + _eventsManager = new EventsManager(new EventsManagerConfig()); #if NET_LATEST rootFilePath = @"Resources\"; @@ -36,7 +39,7 @@ public void OverridingJsonConvertSettingSnakeCaseNamingStrategy() NamingStrategy = new SnakeCaseNamingStrategy() } }; - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); //Act diff --git a/tests/Splitio-tests/Integration Tests/JSONFileClientTests.cs b/tests/Splitio-tests/Integration Tests/JSONFileClientTests.cs index efc6e8b71..6bdc8e556 100644 --- a/tests/Splitio-tests/Integration Tests/JSONFileClientTests.cs +++ b/tests/Splitio-tests/Integration Tests/JSONFileClientTests.cs @@ -3,6 +3,7 @@ using Splitio.Domain; using Splitio.Services.Cache.Interfaces; using Splitio.Services.Client.Classes; +using Splitio.Services.Common; using Splitio.Services.Events.Interfaces; using Splitio.Services.Impressions.Classes; using Splitio.Services.Impressions.Interfaces; @@ -19,12 +20,14 @@ public class JSONFileClientTests { private readonly string rootFilePath; private readonly FallbackTreatmentCalculator _fallbackTreatmentCalculator; + private readonly EventsManager _eventsManager; public JSONFileClientTests() { // This line is to clean the warnings. rootFilePath = string.Empty; _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()); + _eventsManager = new EventsManager(new EventsManagerConfig()); #if NET_LATEST rootFilePath = @"Resources\"; @@ -37,7 +40,7 @@ public JSONFileClientTests() public void ExecuteGetTreatmentOnFailedParsingSplitShouldReturnControl() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); //Act var result = client.GetTreatment("test", "fail", null); @@ -52,7 +55,7 @@ public void ExecuteGetTreatmentOnFailedParsingSplitShouldReturnControl() public void ExecuteGetTreatmentOnFailedParsingSplitShouldNotAffectOtherSplits() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -69,7 +72,7 @@ public void ExecuteGetTreatmentOnFailedParsingSplitShouldNotAffectOtherSplits() public void ExecuteGetTreatmentOnDeletedSplitShouldReturnControl() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -97,7 +100,7 @@ public void ExecuteGetTreatmentOnExceptionShouldReturnControl() .Setup(x => x.GetSplit(It.IsAny())) .Throws(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, null, splitCacheMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, null, splitCacheMock.Object); //Act var result = client.GetTreatment("test", "asd", null); @@ -113,7 +116,7 @@ public void ExecuteGetTreatmentOnExceptionShouldReturnControl() public void ExecuteGetTreatmentOnRemovedUserFromSegmentShouldReturnOff() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", $"{rootFilePath}segment_payed.json", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", $"{rootFilePath}segment_payed.json", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -135,7 +138,7 @@ public void ExecuteGetTreatmentOnRemovedUserFromSegmentShouldReturnOff() public void ExecuteGetTreatmentOnSplitWithOnOffOnPartition() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -159,7 +162,7 @@ public void ExecuteGetTreatmentOnSplitWithOnOffOnPartition() public void ExecuteGetTreatmentOnSplitWithTrafficAllocation() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -183,7 +186,7 @@ public void ExecuteGetTreatmentOnSplitWithTrafficAllocation() public void ExecuteGetTreatmentOnSplitWithTrafficAllocationWhenAllocationIsDifferentThan100() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -207,7 +210,7 @@ public void ExecuteGetTreatmentOnSplitWithTrafficAllocationWhenAllocationIsDiffe public void ExecuteGetTreatmentOnSplitWithTrafficAllocationWhenAllocationIs1ReturnsRolloutTreatment() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_7.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_7.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -223,7 +226,7 @@ public void ExecuteGetTreatmentOnSplitWithTrafficAllocationWhenAllocationIs1Retu public void ExecuteGetTreatmentOnSplitWithTrafficAllocationWhenAllocationIs1ReturnsDefaultTreatment() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_7.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_7.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -239,7 +242,7 @@ public void ExecuteGetTreatmentOnSplitWithTrafficAllocationWhenAllocationIs1Retu public void ExecuteGetTreatmentOnSplitWithSegmentNotInitialized() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -259,7 +262,7 @@ public void ExecuteGetTreatmentAndLogLabelKilled() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -283,7 +286,7 @@ public void ExecuteGetTreatmentAndLogLabelNoConditionMatched() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -307,7 +310,7 @@ public void ExecuteGetTreatmentAndLogLabelSplitNotFound() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); //Act client.RemoveSplitFromCache("asd"); @@ -336,7 +339,7 @@ public void ExecuteGetTreatmentAndLogLabelException() .Setup(x => x.GetSplit(It.IsAny())) .Throws(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, featureFlagCacheInstance: splitCacheMock.Object, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, featureFlagCacheInstance: splitCacheMock.Object, impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -360,7 +363,7 @@ public void ExecuteGetTreatmentAndLogLabelTrafficAllocationFailed() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -383,7 +386,7 @@ public void ExecuteGetTreatmentAndLogLabelForTreatment() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -406,7 +409,7 @@ public void ExecuteGetTreatmentAndLogLabelForTreatment() public void ExecuteGetTreatmentWhenUnknownMatcherIsIncluded() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); //Act var result = client.GetTreatment("xs", "Unknown_Matcher", null); @@ -421,7 +424,7 @@ public void ExecuteGetTreatmentAndNotLogLabelForTreatmentIfLabelsNotEnabled() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object, isLabelsEnabled: false); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object, isLabelsEnabled: false); client.BlockUntilReady(1000); @@ -444,7 +447,7 @@ public void ExecuteGetTreatmentAndLogLabelAndBucketingKeyForTreatment() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -468,7 +471,7 @@ public void ExecuteGetTreatmentAndLogLabelAndBucketingKeyForTreatment() public void ExecuteGetTreatmentWithBooleanAttribute() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator, _eventsManager); var attributes = new Dictionary { @@ -490,7 +493,7 @@ public void ExecuteGetTreatmentWithBooleanAttribute() public void ExecuteGetTreatmentWithSetMatcherReturnsOff() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator, _eventsManager); var attributes = new Dictionary { @@ -512,7 +515,7 @@ public void ExecuteGetTreatmentWithSetMatcherReturnsOff() public void ExecuteGetTreatmentWithSetMatcherReturnsOn() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator, _eventsManager); var attributes = new Dictionary { @@ -534,7 +537,7 @@ public void ExecuteGetTreatmentWithSetMatcherReturnsOn() public void ExecuteGetTreatmentWithStringMatcherReturnsOff() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator, _eventsManager); var attributes = new Dictionary { @@ -556,7 +559,7 @@ public void ExecuteGetTreatmentWithStringMatcherReturnsOff() public void ExecuteGetTreatmentWithStringMatcherReturnsOn() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator, _eventsManager); var attributes = new Dictionary { @@ -578,7 +581,7 @@ public void ExecuteGetTreatmentWithStringMatcherReturnsOn() public void ExecuteGetTreatmentWithDependencyMatcherReturnsOn() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -595,7 +598,7 @@ public void ExecuteGetTreatmentWithDependencyMatcherReturnsOn() public void ExecuteGetTreatmentWithDependencyMatcherReturnsOff() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -613,7 +616,7 @@ public void ExecuteGetTreatmentWithDependencyMatcherImpressionOnChild() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator, _eventsManager,impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -631,7 +634,7 @@ public void GetTreatment_WhenNameDoesntExist_DontLogImpression() { // Arrange. var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); var splitName = "not_exist"; client.BlockUntilReady(1000); @@ -649,7 +652,7 @@ public void GetTreatment_WhenNameDoesntExist_DontLogImpression() public void GetTreatment_WithoutBlockUntiltReady_ReturnsOff() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatment("key", "anding"); @@ -665,7 +668,7 @@ public void GetTreatment_WithoutBlockUntiltReady_ReturnsOff() public void ExecuteGetTreatments() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); List features = new List { "fail", @@ -696,7 +699,7 @@ public void ExecuteGetTreatments() public void ExecuteGetTreatmentsWithBucketing() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); List features = new List { "fail", @@ -728,7 +731,7 @@ public void ExecuteGetTreatmentsWithBucketing() public void ExecuteGetTreatmentsWithDependencyMatcherReturnsOn() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -751,7 +754,7 @@ public void ExecuteGetTreatmentsWithDependencyMatcherReturnsOn() public void ExecuteGetTreatmentsWithDependencyMatcherWithAttributesReturnsOn() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -779,7 +782,7 @@ public void GetTreatments_WhenNameDoesntExist_DontLogImpression() { // Arrange. var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); var splitNames = new List { "not_exist", "not_exist_1" }; client.BlockUntilReady(1000); @@ -801,7 +804,7 @@ public void GetTreatments_WhenNameDoesntExist_DontLogImpression() public void GetTreatments_WithoutBlockUntiltReady_ReturnsEmptyList() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatments("key", new List()); @@ -815,7 +818,7 @@ public void GetTreatments_WithoutBlockUntiltReady_ReturnsEmptyList() public void GetTreatments_WithoutBlockUntiltReady_ReturnsTreatments() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatments("key", new List { "anding", "in_ten_keys" }); @@ -833,7 +836,7 @@ public void GetTreatments_WithoutBlockUntiltReady_ReturnsTreatments() public void GetTreatments_WhenClientIsReadyAndFeaturesIsEmpty_ReturnsEmptyList() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(100); // Act. @@ -850,7 +853,7 @@ public void GetTreatments_WhenClientIsReadyAndFeaturesIsEmpty_ReturnsEmptyList() public void DestroySucessfully() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator, _eventsManager); var attributes = new Dictionary { @@ -886,7 +889,7 @@ public void Track_WhenClientIsNotReady_ReturnsTrue() // Arrange. var trafficTypeValidator = new Mock(); var eventLog = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, trafficTypeValidator: trafficTypeValidator.Object, eventsLog: eventLog.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, trafficTypeValidator: trafficTypeValidator.Object, eventsLog: eventLog.Object); trafficTypeValidator .Setup(mock => mock.IsValid(It.IsAny(), It.IsAny())) @@ -907,7 +910,7 @@ public void GetTreatmentWithConfig_WhenNameDoesntExist_DontLogImpression() { // Arrange. var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); var splitName = "not_exist"; client.BlockUntilReady(1000); @@ -926,7 +929,7 @@ public void GetTreatmentWithConfig_WhenNameDoesntExist_DontLogImpression() public void GetTreatmentWithConfig_WithoutBlockUntiltReady_ReturnsOff() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatmentWithConfig("key", "anding"); @@ -944,7 +947,7 @@ public void GetTreatmentsWithConfig_WhenNameDoesntExist_DontLogImpression() { // Arrange. var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); var splitNames = new List { "not_exist", "not_exist_1" }; client.BlockUntilReady(1000); @@ -967,7 +970,7 @@ public void GetTreatmentsWithConfig_WhenNameDoesntExist_DontLogImpression() public void GetTreatmentsWithConfig_WithoutBlockUntiltReady_ReturnsEmptyList() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatmentsWithConfig("anding", new List()); @@ -981,7 +984,7 @@ public void GetTreatmentsWithConfig_WithoutBlockUntiltReady_ReturnsEmptyList() public void GetTreatmentsWithConfig_WithoutBlockUntiltReady_ReturnsTreatments() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatmentsWithConfig("key", new List { "anding", "whitelisting_elements" }); @@ -1001,7 +1004,7 @@ public void GetTreatmentsWithConfig_WithoutBlockUntiltReady_ReturnsTreatments() public void GetTreatmentsWithConfig_WhenClientIsReadyAndFeaturesIsEmpty_ReturnsEmptyList() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(100); // Act. @@ -1018,7 +1021,7 @@ public void GetTreatmentsWithConfig_WhenClientIsReadyAndFeaturesIsEmpty_ReturnsE public void Split_Manager_WhenNameDoesntExist_ReturnsNull() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); var manager = client.GetSplitManager(); var splitName = "not_exist"; diff --git a/tests/Splitio-tests/Integration Tests/RedisClientTests.cs b/tests/Splitio-tests/Integration Tests/RedisClientTests.cs index 84ebcbd79..8ad5f8bef 100644 --- a/tests/Splitio-tests/Integration Tests/RedisClientTests.cs +++ b/tests/Splitio-tests/Integration Tests/RedisClientTests.cs @@ -4,6 +4,7 @@ using Splitio.Redis.Services.Client.Classes; using Splitio.Redis.Services.Domain; using Splitio.Services.Client.Classes; +using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; using Splitio.Tests.Common.Resources; using Splitio_Tests.Resources; @@ -25,6 +26,7 @@ public class RedisClientTests private ConfigurationOptions config; private RedisAdapterForTests _redisAdapter; private FallbackTreatmentCalculator _fallbackTreatmentCalculator; + private EventsManager _eventsManager; [TestInitialize] public void Initialization() @@ -38,6 +40,7 @@ public void Initialization() UserPrefix = _prefix }; _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()); + _eventsManager = new EventsManager(new EventsManagerConfig()); config = new ConfigurationOptions { CacheAdapterConfig = cacheAdapterConfig, @@ -64,7 +67,7 @@ public void Initialization() public void GetTreatment_WhenFeatureExists_ReturnsOn() { //Arrange - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(5000); @@ -75,7 +78,7 @@ public void GetTreatment_WhenFeatureExists_ReturnsOn() Assert.IsNotNull(result); Assert.AreEqual("on", result); - var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator); + var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); @@ -91,7 +94,7 @@ public void GetTreatment_WhenFeatureExists_ReturnsOn() public void GetTreatment_WhenFeatureExists_ReturnsOff() { //Arrange - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(5000); @@ -102,7 +105,7 @@ public void GetTreatment_WhenFeatureExists_ReturnsOff() Assert.IsNotNull(result); Assert.AreEqual("off", result); - var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator); + var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); result = client2.GetTreatment("test", "always_off", null); @@ -116,7 +119,7 @@ public void GetTreatment_WhenFeatureExists_ReturnsOff() public void GetTreatment_WhenFeatureDoenstExist_ReturnsControl() { //Arrange - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(5000); //Act @@ -126,7 +129,7 @@ public void GetTreatment_WhenFeatureDoenstExist_ReturnsControl() Assert.IsNotNull(result); Assert.AreEqual("control", result); - var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator); + var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); result = client2.GetTreatment("test", "always_control", null); @@ -145,7 +148,7 @@ public void GetTreatments_WhenFeaturesExists_ReturnsOnOff() var features = new List { alwaysOn, alwaysOff }; - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(5000); @@ -159,7 +162,7 @@ public void GetTreatments_WhenFeaturesExists_ReturnsOnOff() var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), - API_KEY, _fallbackTreatmentCalculator); + API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); result = client2.GetTreatments("test", features, null); @@ -180,7 +183,7 @@ public void GetTreatments_WhenOneFeatureDoenstExist_ReturnsOnOffControl() var features = new List { alwaysOn, alwaysOff, alwaysControl }; - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(5000); @@ -194,7 +197,7 @@ public void GetTreatments_WhenOneFeatureDoenstExist_ReturnsOnOffControl() Assert.AreEqual("control", result[alwaysControl]); var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), - API_KEY, _fallbackTreatmentCalculator); + API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); result = client2.GetTreatments("test", features, null); @@ -210,7 +213,7 @@ public void GetTreatments_WhenOneFeatureDoenstExist_ReturnsOnOffControl() public void GetTreatmentsWithConfig_WhenClientIsNotReady_ReturnsControl() { // Arrange. - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatmentsWithConfig("key", new List()); @@ -223,7 +226,7 @@ public void GetTreatmentsWithConfig_WhenClientIsNotReady_ReturnsControl() } var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), -API_KEY, _fallbackTreatmentCalculator); +API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); result = client2.GetTreatmentsWithConfig("key", new List()); @@ -240,7 +243,7 @@ public void GetTreatmentsWithConfig_WhenClientIsNotReady_ReturnsControl() public void GetTreatmentWithConfig_WhenClientIsNotReady_ReturnsControl() { // Arrange. - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatmentWithConfig("key", string.Empty); @@ -250,7 +253,7 @@ public void GetTreatmentWithConfig_WhenClientIsNotReady_ReturnsControl() Assert.IsNull(result.Config); var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), -API_KEY, _fallbackTreatmentCalculator); +API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); result = client2.GetTreatmentWithConfig("key", string.Empty); @@ -264,7 +267,7 @@ public void GetTreatmentWithConfig_WhenClientIsNotReady_ReturnsControl() public void GetTreatment_WhenClientIsNotReady_ReturnsControl() { // Arrange. - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatment("key", string.Empty); @@ -273,7 +276,7 @@ public void GetTreatment_WhenClientIsNotReady_ReturnsControl() Assert.AreEqual("control", result); var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), -API_KEY, _fallbackTreatmentCalculator); +API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); result = client2.GetTreatment("key", string.Empty); @@ -287,7 +290,7 @@ public void GetTreatments_WhenClientIsNotReady_ReturnsControl() { // Arrange. config.CacheAdapterConfig.Host = "fake-host"; - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatments("key", new List()); @@ -298,7 +301,7 @@ public void GetTreatments_WhenClientIsNotReady_ReturnsControl() Assert.AreEqual("control", res.Value); } - var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator); + var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); result = client2.GetTreatments("key", new List()); @@ -314,7 +317,7 @@ public void GetTreatments_WhenClientIsNotReady_ReturnsControl() public void Track_WhenClientIsNotReady_ReturnsTrue() { // Arrange. - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.Track("key", "traffic_type", "event_type"); @@ -323,7 +326,7 @@ public void Track_WhenClientIsNotReady_ReturnsTrue() Assert.IsTrue(result); var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), -API_KEY, _fallbackTreatmentCalculator); +API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); // Act. @@ -342,7 +345,7 @@ public void FallbackTreatments_WhenFeatureDoesNotExist() FallbackTreatmentsConfiguration fallbackTreatmentsConfiguration = new FallbackTreatmentsConfiguration(new FallbackTreatment("on-global", "\"prop\":\"global\""), new Dictionary() { { "feature", new FallbackTreatment("off-local", "\"prop\":\"local\"") } }); FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(fallbackTreatmentsConfiguration); - var client = new RedisClient(config, API_KEY, fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(5000); @@ -380,7 +383,7 @@ public void FallbackTreatments_WhenClientNotReady() FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(fallbackTreatmentsConfiguration); config.CacheAdapterConfig.Host = "fake-host"; - var client = new RedisClient(config, API_KEY, fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, fallbackTreatmentCalculator, _eventsManager); //Act var result = client.GetTreatmentsWithConfig("test", features, null); @@ -402,7 +405,7 @@ public void FallbackTreatments_WhenExceptionOccurrs() FallbackTreatmentsConfiguration fallbackTreatmentsConfiguration = new FallbackTreatmentsConfiguration(new FallbackTreatment("on-global", "\"prop\":\"global\""), new Dictionary() { { "feature", new FallbackTreatment("off-local", "\"prop\":\"local\"") } }); FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(fallbackTreatmentsConfiguration); - var client = new RedisClient(config, API_KEY, fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(5000); @@ -431,7 +434,7 @@ public void FallbackTreatments_WhenExceptionOccurrs() public void Destroy() { //Arrange - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(5000); //Act diff --git a/tests/Splitio-tests/Integration Tests/TargetingRulesFetcherTests.cs b/tests/Splitio-tests/Integration Tests/TargetingRulesFetcherTests.cs index f2b7dfe7c..e60492996 100644 --- a/tests/Splitio-tests/Integration Tests/TargetingRulesFetcherTests.cs +++ b/tests/Splitio-tests/Integration Tests/TargetingRulesFetcherTests.cs @@ -46,7 +46,7 @@ public async Task ExecuteGetSuccessfulWithResultsFromJSONFile() var splitChangeFetcher = new JSONFileSplitChangeFetcher($"{rootFilePath}splits_staging.json"); var flagSetsFilter = new FlagSetsFilter(new HashSet()); var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), flagSetsFilter, eventsManager); - var gates = new InMemoryReadinessGatesCache(); + var gates = new InMemoryReadinessGatesCache(eventsManager); var taskManager = new TasksManager(gates); var task = taskManager.NewPeriodicTask(Splitio.Enums.Task.FeatureFlagsFetcher, 250); var featureFlagSyncService = new FeatureFlagUpdater(splitParser, splitCache, flagSetsFilter, rbsCache); @@ -92,7 +92,7 @@ public async Task ExecuteGetSuccessfulWithResultsFromJSONFileIncludingTrafficAll var splitChangeFetcher = new JSONFileSplitChangeFetcher($"{rootFilePath}splits_staging_4.json"); var flagSetsFilter = new FlagSetsFilter(new HashSet()); var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), flagSetsFilter, eventsManager); - var gates = new InMemoryReadinessGatesCache(); + var gates = new InMemoryReadinessGatesCache(eventsManager); var taskManager = new TasksManager(gates); var task = taskManager.NewPeriodicTask(Splitio.Enums.Task.FeatureFlagsFetcher, 250); var featureFlagSyncService = new FeatureFlagUpdater(splitParser, splitCache, flagSetsFilter, rbsCache); @@ -141,8 +141,8 @@ public async Task ExecuteGetWithoutResults() var apiSplitChangeFetcher = new ApiSplitChangeFetcher(sdkApiClient); var sdkSegmentApiClient = new SegmentSdkApiClient(httpClient, telemetryStorage, baseUrl); var apiSegmentChangeFetcher = new ApiSegmentChangeFetcher(sdkSegmentApiClient); - var gates = new InMemoryReadinessGatesCache(); var eventsManager = new EventsManager(new EventsManagerConfig()); + var gates = new InMemoryReadinessGatesCache(eventsManager); var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var segmentsQueue = new SplitQueue(); var taskManager = new TasksManager(gates); diff --git a/tests/Splitio-tests/Unit Tests/Client/LocalhostClientForTesting.cs b/tests/Splitio-tests/Unit Tests/Client/LocalhostClientForTesting.cs index 09c6b39ea..b97cff0ef 100644 --- a/tests/Splitio-tests/Unit Tests/Client/LocalhostClientForTesting.cs +++ b/tests/Splitio-tests/Unit Tests/Client/LocalhostClientForTesting.cs @@ -1,11 +1,13 @@ -using Splitio.Services.Client.Classes; +using Splitio.Domain; +using Splitio.Services.Client.Classes; +using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; namespace Splitio_Tests.Unit_Tests.Client { public class LocalhostClientForTesting : LocalhostClient { - public LocalhostClientForTesting(string filePath, FallbackTreatmentCalculator fallbackTreatmentCalculator) : base(new ConfigurationOptions { LocalhostFilePath = filePath }, fallbackTreatmentCalculator) + public LocalhostClientForTesting(string filePath, FallbackTreatmentCalculator fallbackTreatmentCalculator) : base(new ConfigurationOptions { LocalhostFilePath = filePath }, fallbackTreatmentCalculator, new EventsManager(new EventsManagerConfig())) { } } } diff --git a/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs b/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs index aaf4a6a2c..95ecd3bad 100644 --- a/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs @@ -1,6 +1,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Splitio.Domain; using Splitio.Services.Client.Classes; +using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; using Splitio.Services.Shared.Classes; @@ -11,12 +12,14 @@ public class LocalhostClientUnitTests { private readonly string rootFilePath; private readonly FallbackTreatmentCalculator _fallbackTreatmentCalculator; + private readonly EventsManager _eventsManager; public LocalhostClientUnitTests() { // This line is to clean the warnings. rootFilePath = string.Empty; _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()); + _eventsManager = new EventsManager(new EventsManagerConfig()); #if NET_LATEST rootFilePath = @"Resources\"; @@ -28,7 +31,7 @@ public LocalhostClientUnitTests() public void GetTreatmentShouldReturnControlIfSplitNotFound() { //Arrange - var splitClient = new LocalhostClient(new ConfigurationOptions { LocalhostFilePath = $"{rootFilePath}test.splits" }, _fallbackTreatmentCalculator); + var splitClient = new LocalhostClient(new ConfigurationOptions { LocalhostFilePath = $"{rootFilePath}test.splits" }, _fallbackTreatmentCalculator, _eventsManager); //Act var result = splitClient.GetTreatment("test", "test"); @@ -41,7 +44,7 @@ public void GetTreatmentShouldReturnControlIfSplitNotFound() [DeploymentItem(@"Resources\test.splits")] public void GetTreatmentShouldRunAsSingleKeyUsingNullBucketingKey() { - var splitClient = new LocalhostClient(new ConfigurationOptions { LocalhostFilePath = $"{rootFilePath}test.splits" }, _fallbackTreatmentCalculator); + var splitClient = new LocalhostClient(new ConfigurationOptions { LocalhostFilePath = $"{rootFilePath}test.splits" }, _fallbackTreatmentCalculator, _eventsManager); splitClient.BlockUntilReady(1000); //Act diff --git a/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs b/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs index bf1e7b1ba..83ca9c24f 100644 --- a/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs @@ -1,16 +1,23 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; +using Splitio.Domain; using Splitio.Services.Client.Classes; +using Splitio.Services.Common; +using System; namespace Splitio_Tests.Unit_Tests.Client { [TestClass] public class InMemoryReadinessGatesCacheUnitTests { + private bool SdkReady = false; + private EventMetadata eMetadata = null; + public event EventHandler PublicSdkUpdateHandler; + [TestMethod] public void IsSDKReadyShouldReturnFalseIfSplitsAreNotReady() { //Arrange - var gates = new InMemoryReadinessGatesCache(); + var gates = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); //Act var result = gates.IsReady(); @@ -18,5 +25,29 @@ public void IsSDKReadyShouldReturnFalseIfSplitsAreNotReady() //Assert Assert.IsFalse(result); } + + [TestMethod] + public void TestFireReadyEvent() + { + //Arrange + EventsManager eventsManager = new EventsManager(new EventsManagerConfig()); + Splitio.Util.Helper.BuildInternalSdkEventStatus(eventsManager); + var gates = new InMemoryReadinessGatesCache(eventsManager); + PublicSdkUpdateHandler += sdkReady_callback; + eventsManager.Register(SdkEvent.SdkReady, sdkReady_callback); + + //Act + gates.SetReady(); + + // Assert. + Assert.IsTrue(SdkReady); + Assert.AreEqual(0, eMetadata.GetData().Count); + } + + private void sdkReady_callback(object sender, EventMetadata metadata) + { + SdkReady = true; + eMetadata = metadata; + } } } diff --git a/tests/Splitio-tests/Unit Tests/Client/SplitClientForTesting.cs b/tests/Splitio-tests/Unit Tests/Client/SplitClientForTesting.cs index 80587cd2c..12277bcba 100644 --- a/tests/Splitio-tests/Unit Tests/Client/SplitClientForTesting.cs +++ b/tests/Splitio-tests/Unit Tests/Client/SplitClientForTesting.cs @@ -1,4 +1,5 @@ -using Splitio.Services.Cache.Interfaces; +using Splitio.Domain; +using Splitio.Services.Cache.Interfaces; using Splitio.Services.Client.Classes; using Splitio.Services.Common; using Splitio.Services.Evaluator; @@ -22,7 +23,7 @@ public SplitClientForTesting(IFeatureFlagCacheConsumer featureFlagCacheConsumer, ISyncManager syncManager, FallbackTreatmentCalculator fallbackTreatmentCalculator, ITelemetryEvaluationProducer telemetryEvaluationProducer) - : base("SplitClientForTesting", fallbackTreatmentCalculator) + : base("SplitClientForTesting", fallbackTreatmentCalculator, new EventsManager(new EventsManagerConfig())) { _eventsLog = eventsLog; _impressionsLog = impressionsLog; diff --git a/tests/Splitio-tests/Unit Tests/Impressions/ImpressionsCounterTests.cs b/tests/Splitio-tests/Unit Tests/Impressions/ImpressionsCounterTests.cs index 77ce67e35..42df730c5 100644 --- a/tests/Splitio-tests/Unit Tests/Impressions/ImpressionsCounterTests.cs +++ b/tests/Splitio-tests/Unit Tests/Impressions/ImpressionsCounterTests.cs @@ -1,6 +1,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; +using Splitio.Domain; using Splitio.Services.Client.Classes; +using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; using Splitio.Services.Impressions.Interfaces; using Splitio.Services.Tasks; @@ -27,7 +29,7 @@ public void Start_ShouldSendImpressionsCount() { // Arrange. var config = new ComponentConfig(5, 5); - var statusManager = new InMemoryReadinessGatesCache(); + var statusManager = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); var taskManager = new TasksManager(statusManager); var task = taskManager.NewPeriodicTask(Splitio.Enums.Task.ImpressionsCountSender, 1); var sendBulkDataTask = taskManager.NewOnTimeTask(Splitio.Enums.Task.ImpressionCounterSendBulkData); @@ -51,7 +53,7 @@ public void Start_ShouldNotSendImpressionsCount() { // Arrange. var config = new ComponentConfig(5, 5); - var statusManager = new InMemoryReadinessGatesCache(); + var statusManager = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); var taskManager = new TasksManager(statusManager); var task = taskManager.NewPeriodicTask(Splitio.Enums.Task.ImpressionsCountSender, 1); var sendBulkDataTask = taskManager.NewOnTimeTask(Splitio.Enums.Task.ImpressionCounterSendBulkData); @@ -70,7 +72,7 @@ public async Task Stop_ShouldSendImpressionsCount() { // Arrange. var config = new ComponentConfig(5, 5); - var statusManager = new InMemoryReadinessGatesCache(); + var statusManager = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); var taskManager = new TasksManager(statusManager); var task = taskManager.NewPeriodicTask(Splitio.Enums.Task.ImpressionsCountSender, 100); var sendBulkDataTask = taskManager.NewOnTimeTask(Splitio.Enums.Task.ImpressionCounterSendBulkData); @@ -94,7 +96,7 @@ public async Task Stop_ShouldSendImpressionsCount() public async Task ShouldSend2BulksOfImpressions() { var config = new ComponentConfig(6, 3); - var statusManager = new InMemoryReadinessGatesCache(); + var statusManager = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); var taskManager = new TasksManager(statusManager); var task = taskManager.NewPeriodicTask(Splitio.Enums.Task.ImpressionsCountSender, 100); var sendBulkDataTask = taskManager.NewOnTimeTask(Splitio.Enums.Task.ImpressionCounterSendBulkData); diff --git a/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs b/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs index 9e242cc83..97a689597 100644 --- a/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs @@ -27,7 +27,7 @@ public class SelfRefreshingSegmentFetcherUnitTests public void InitializeSegmentNotExistent() { // Arrange - var gates = new InMemoryReadinessGatesCache(); + var gates = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); gates.SetReady(); var apiClient = new Mock(); var apiFetcher = new ApiSegmentChangeFetcher(apiClient.Object); diff --git a/tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs b/tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs new file mode 100644 index 000000000..d5204d8ee --- /dev/null +++ b/tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs @@ -0,0 +1,52 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Splitio.Domain; +using Splitio.Services.Cache.Interfaces; +using Splitio.Services.Common; +using Splitio.Services.Shared.Classes; +using Splitio.Telemetry.Storages; +using System; + +namespace Splitio_Tests.Unit_Tests.Shared +{ + [TestClass] + public class SelfRefreshingBlockUntilReadyServiceTests + { + private bool SdkTimedOut = false; + private EventMetadata eMetadata = null; + public event EventHandler PublicSdkUpdateHandler; + + [TestMethod] + public void TestFireTimedOutEvent() + { + //Arrange + Mock statusManager = new Mock(); + Mock telemetryProducer = new Mock(); + EventsManager eventsManager = new EventsManager(new EventsManagerConfig()); + Splitio.Util.Helper.BuildInternalSdkEventStatus(eventsManager); + var bur = new SelfRefreshingBlockUntilReadyService(statusManager.Object, telemetryProducer.Object, eventsManager); + PublicSdkUpdateHandler += SdkTimedOut_callback; + eventsManager.Register(SdkEvent.SdkReadyTimeout, SdkTimedOut_callback); + statusManager + .Setup(mock => mock.WaitUntilReady(1)) + .Returns(false); + + //Act + try + { + bur.BlockUntilReady(1); + } + catch { } + + // Assert. + Assert.IsTrue(SdkTimedOut); + Assert.AreEqual(0, eMetadata.GetData().Count); + } + + private void SdkTimedOut_callback(object sender, EventMetadata metadata) + { + SdkTimedOut = true; + eMetadata = metadata; + } + } +} diff --git a/tests/Splitio.Integration-tests/EventSourceClientTests.cs b/tests/Splitio.Integration-tests/EventSourceClientTests.cs index ba7766438..0eb26bddb 100644 --- a/tests/Splitio.Integration-tests/EventSourceClientTests.cs +++ b/tests/Splitio.Integration-tests/EventSourceClientTests.cs @@ -370,7 +370,7 @@ private static (IEventSourceClient, BlockingCollection, var sseHttpClient = new SplitioHttpClient("api-key", config, new Dictionary()); var telemetryRuntimeProducer = new InMemoryTelemetryStorage(); var notificationManagerKeeper = new NotificationManagerKeeper(telemetryRuntimeProducer, streamingStatusQueue); - var statusManager = new InMemoryReadinessGatesCache(); + var statusManager = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); var tasksManager = new TasksManager(statusManager); var task = tasksManager.NewOnTimeTask(Enums.Task.SSEConnect); diff --git a/tests/Splitio.TestSupport/SplitClientForTest.cs b/tests/Splitio.TestSupport/SplitClientForTest.cs index ddffe2eb0..f79f66748 100644 --- a/tests/Splitio.TestSupport/SplitClientForTest.cs +++ b/tests/Splitio.TestSupport/SplitClientForTest.cs @@ -1,4 +1,5 @@ using Splitio.Domain; +using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; using System.Collections.Generic; using System.Threading.Tasks; @@ -9,7 +10,8 @@ public class SplitClientForTest : SplitClient { private readonly Dictionary _tests; - public SplitClientForTest() : base("SplitClientForTest", new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration())) + public SplitClientForTest() : base("SplitClientForTest", new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()), + new EventsManager(new EventsManagerConfig())) { _tests = new Dictionary(); } From 435f395dbbe8a5324ab74a19c2d3ebeb1d1016c8 Mon Sep 17 00:00:00 2001 From: Bill Al Date: Thu, 18 Dec 2025 12:49:22 -0800 Subject: [PATCH 2/8] polish --- src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs b/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs index ce314289a..4cd7c08a4 100644 --- a/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs +++ b/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs @@ -52,7 +52,7 @@ public class SelfRefreshingClient : SplitClient private IRuleBasedSegmentCache _ruleBasedSegmentCache; private IUpdater _ruleBasedSegmentUpdater; private readonly new FallbackTreatmentCalculator _fallbackTreatmentCalculator; - private EventsManager _eventsManager; + private readonly EventsManager _eventsManager; public SelfRefreshingClient(string apiKey, ConfigurationOptions config, FallbackTreatmentCalculator fallbackTreatmentCalculator, From 9621a2650e22f962051a561297214b4c6cb41905 Mon Sep 17 00:00:00 2001 From: Bill Al Date: Mon, 22 Dec 2025 15:17:58 -0800 Subject: [PATCH 3/8] applied event manager changes --- .../Classes/InMemoryReadinessGatesCache.cs | 4 +- .../Classes/InMemoryRuleBasedSegmentCache.cs | 5 +- .../Cache/Classes/InMemorySegmentCache.cs | 8 +- .../Cache/Classes/InMemorySplitCache.cs | 8 +- .../Services/Client/Classes/SplitClient.cs | 6 +- src/Splitio/Services/Common/EventDelivery.cs | 2 +- src/Splitio/Services/Common/EventsManager.cs | 142 ++++++++++++++++- src/Splitio/Services/Common/IEventsManager.cs | 2 +- .../SelfRefreshingBlockUntilReadyService.cs | 4 +- src/Splitio/Util/Helper.cs | 146 ------------------ .../InMemory/RuleBasedSegmentCacheTests.cs | 8 +- .../Cache/InMemory/SegmentCacheAsyncTests.cs | 5 +- .../Cache/InMemory/SegmentCacheTests.cs | 4 +- .../Cache/InMemory/SplitCacheAsyncTests.cs | 4 +- .../Cache/InMemory/SplitCacheTests.cs | 4 +- .../Client/LocalhostClientUnitTests.cs | 6 +- .../Client/SdkReadinessGatesUnitTests.cs | 3 +- .../Unit Tests/Common/EventsManagerTests.cs | 75 ++++----- ...lfRefreshingBlockUntilReadyServiceTests.cs | 3 +- 19 files changed, 193 insertions(+), 246 deletions(-) diff --git a/src/Splitio/Services/Cache/Classes/InMemoryReadinessGatesCache.cs b/src/Splitio/Services/Cache/Classes/InMemoryReadinessGatesCache.cs index d31214566..d0a7d4411 100644 --- a/src/Splitio/Services/Cache/Classes/InMemoryReadinessGatesCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemoryReadinessGatesCache.cs @@ -31,9 +31,7 @@ public void SetReady() { _sdkReady.Signal(); _eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, - new EventMetadata(new Dictionary()), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkReady, - _eventsManager)); + new EventMetadata(new Dictionary())); } public void SetDestroy() diff --git a/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs b/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs index 2517fc699..30c1fbc90 100644 --- a/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs @@ -60,13 +60,12 @@ public void Update(List toAdd, List toRemove, long til foreach (var name in toRemove) { _cache.TryRemove(name, out var _); + toNotify.Add(name); } 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 7f9c0fb0e..e9c60ef68 100644 --- a/src/Splitio/Services/Client/Classes/SplitClient.cs +++ b/src/Splitio/Services/Client/Classes/SplitClient.cs @@ -63,12 +63,16 @@ public abstract class SplitClient : ISplitClient protected IImpressionsObserver _impressionsObserver; protected IClientExtensionService _clientExtensionService; protected IFlagSetsFilter _flagSetsFilter; + protected EventsManager _eventsManager; + public event EventHandler PublicSdkReadyHandler; + public event EventHandler PublicSdkUpdateHandler; + public event EventHandler PublicSdkTimedOutHandler; protected SplitClient(string apikey, FallbackTreatmentCalculator fallbackTreatmentCalculator, EventsManager eventsManager) { ApiKey = apikey; - Splitio.Util.Helper.BuildInternalSdkEventStatus(eventsManager); + _eventsManager = eventsManager; _fallbackTreatmentCalculator = fallbackTreatmentCalculator; _wrapperAdapter = WrapperAdapter.Instance(); 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/Services/Shared/Classes/SelfRefreshingBlockUntilReadyService.cs b/src/Splitio/Services/Shared/Classes/SelfRefreshingBlockUntilReadyService.cs index 6bf5c2b91..f70de053d 100644 --- a/src/Splitio/Services/Shared/Classes/SelfRefreshingBlockUntilReadyService.cs +++ b/src/Splitio/Services/Shared/Classes/SelfRefreshingBlockUntilReadyService.cs @@ -37,9 +37,7 @@ public void BlockUntilReady(int blockMilisecondsUntilReady) if (!_statusManager.WaitUntilReady(blockMilisecondsUntilReady)) { _eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkTimedOut, - new EventMetadata(new Dictionary()), - Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkTimedOut, - _eventsManager)); + new EventMetadata(new Dictionary())); _telemetryInitProducer.RecordBURTimeout(); throw new TimeoutException($"SDK was not ready in {blockMilisecondsUntilReady} milliseconds"); } 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 e3ba2df2a..d4f207c58 100644 --- a/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs +++ b/tests/Splitio-tests/Unit Tests/Cache/InMemory/RuleBasedSegmentCacheTests.cs @@ -154,17 +154,15 @@ 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" }; 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); - _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; @@ -174,7 +172,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")); } 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/Client/LocalhostClientUnitTests.cs b/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs index 95ecd3bad..05f826bee 100644 --- a/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs @@ -4,15 +4,17 @@ using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; using Splitio.Services.Shared.Classes; +using WireMock.Pact.Models.V2; namespace Splitio_Tests.Unit_Tests.Client { [TestClass] public class LocalhostClientUnitTests - { + { private readonly string rootFilePath; private readonly FallbackTreatmentCalculator _fallbackTreatmentCalculator; private readonly EventsManager _eventsManager; + private bool SdkReady = false; public LocalhostClientUnitTests() { @@ -62,7 +64,7 @@ public void TrackShouldNotStoreEvents() //Arrange var splitClient = new LocalhostClientForTesting($"{rootFilePath}test.splits", _fallbackTreatmentCalculator); splitClient.BlockUntilReady(1000); - + //Act var result = splitClient.Track("test", "test", "test"); diff --git a/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs b/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs index 83ca9c24f..8bd2f7b9f 100644 --- a/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs @@ -31,10 +31,9 @@ public void TestFireReadyEvent() { //Arrange EventsManager eventsManager = new EventsManager(new EventsManagerConfig()); - Splitio.Util.Helper.BuildInternalSdkEventStatus(eventsManager); var gates = new InMemoryReadinessGatesCache(eventsManager); PublicSdkUpdateHandler += sdkReady_callback; - eventsManager.Register(SdkEvent.SdkReady, sdkReady_callback); + eventsManager.Register(SdkEvent.SdkReady, PublicSdkUpdateHandler); //Act gates.SetReady(); 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; diff --git a/tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs b/tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs index d5204d8ee..120072f3d 100644 --- a/tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs +++ b/tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs @@ -23,10 +23,9 @@ public void TestFireTimedOutEvent() Mock statusManager = new Mock(); Mock telemetryProducer = new Mock(); EventsManager eventsManager = new EventsManager(new EventsManagerConfig()); - Splitio.Util.Helper.BuildInternalSdkEventStatus(eventsManager); var bur = new SelfRefreshingBlockUntilReadyService(statusManager.Object, telemetryProducer.Object, eventsManager); PublicSdkUpdateHandler += SdkTimedOut_callback; - eventsManager.Register(SdkEvent.SdkReadyTimeout, SdkTimedOut_callback); + eventsManager.Register(SdkEvent.SdkReadyTimeout, PublicSdkUpdateHandler); statusManager .Setup(mock => mock.WaitUntilReady(1)) .Returns(false); From c5ea092ed1ee5d9a75cf3ded68a1a9abeae1fea0 Mon Sep 17 00:00:00 2001 From: Bill Al Date: Mon, 22 Dec 2025 18:45:59 -0800 Subject: [PATCH 4/8] polish --- .../Services/Cache/Classes/InMemoryReadinessGatesCache.cs | 4 ++-- .../Services/Cache/Classes/InMemoryRuleBasedSegmentCache.cs | 4 ++-- src/Splitio/Services/Cache/Classes/InMemorySegmentCache.cs | 4 ++-- src/Splitio/Services/Cache/Classes/InMemorySplitCache.cs | 4 ++-- src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs | 4 +--- src/Splitio/Services/Client/Classes/SplitClient.cs | 4 ++-- .../Shared/Classes/SelfRefreshingBlockUntilReadyService.cs | 4 ++-- 7 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/Splitio/Services/Cache/Classes/InMemoryReadinessGatesCache.cs b/src/Splitio/Services/Cache/Classes/InMemoryReadinessGatesCache.cs index d0a7d4411..f784fbbed 100644 --- a/src/Splitio/Services/Cache/Classes/InMemoryReadinessGatesCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemoryReadinessGatesCache.cs @@ -10,9 +10,9 @@ public class InMemoryReadinessGatesCache : IStatusManager { private readonly CountdownEvent _sdkReady = new CountdownEvent(1); private readonly CountdownEvent _sdkDestroyed = new CountdownEvent(1); - private readonly EventsManager _eventsManager; + private readonly IEventsManager _eventsManager; - public InMemoryReadinessGatesCache(EventsManager eventsManager) + public InMemoryReadinessGatesCache(IEventsManager eventsManager) { _eventsManager = eventsManager; } 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; diff --git a/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs b/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs index 4cd7c08a4..7d513bc5b 100644 --- a/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs +++ b/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs @@ -52,15 +52,13 @@ public class SelfRefreshingClient : SplitClient private IRuleBasedSegmentCache _ruleBasedSegmentCache; private IUpdater _ruleBasedSegmentUpdater; private readonly new FallbackTreatmentCalculator _fallbackTreatmentCalculator; - private readonly EventsManager _eventsManager; public SelfRefreshingClient(string apiKey, ConfigurationOptions config, FallbackTreatmentCalculator fallbackTreatmentCalculator, - EventsManager eventsManager) : base(apiKey, fallbackTreatmentCalculator, eventsManager) + IEventsManager eventsManager) : base(apiKey, fallbackTreatmentCalculator, eventsManager) { _config = (SelfRefreshingConfig)_configService.ReadConfig(config, ConfigTypes.InMemory); _fallbackTreatmentCalculator = fallbackTreatmentCalculator; - _eventsManager = eventsManager; BuildFlagSetsFilter(_config.FlagSetsFilter); BuildSplitCache(); diff --git a/src/Splitio/Services/Client/Classes/SplitClient.cs b/src/Splitio/Services/Client/Classes/SplitClient.cs index e9c60ef68..d37ed283d 100644 --- a/src/Splitio/Services/Client/Classes/SplitClient.cs +++ b/src/Splitio/Services/Client/Classes/SplitClient.cs @@ -63,13 +63,13 @@ public abstract class SplitClient : ISplitClient protected IImpressionsObserver _impressionsObserver; protected IClientExtensionService _clientExtensionService; protected IFlagSetsFilter _flagSetsFilter; - protected EventsManager _eventsManager; + protected IEventsManager _eventsManager; public event EventHandler PublicSdkReadyHandler; public event EventHandler PublicSdkUpdateHandler; public event EventHandler PublicSdkTimedOutHandler; protected SplitClient(string apikey, FallbackTreatmentCalculator fallbackTreatmentCalculator, - EventsManager eventsManager) + IEventsManager eventsManager) { ApiKey = apikey; _eventsManager = eventsManager; diff --git a/src/Splitio/Services/Shared/Classes/SelfRefreshingBlockUntilReadyService.cs b/src/Splitio/Services/Shared/Classes/SelfRefreshingBlockUntilReadyService.cs index f70de053d..5edb873c5 100644 --- a/src/Splitio/Services/Shared/Classes/SelfRefreshingBlockUntilReadyService.cs +++ b/src/Splitio/Services/Shared/Classes/SelfRefreshingBlockUntilReadyService.cs @@ -15,10 +15,10 @@ public class SelfRefreshingBlockUntilReadyService : IBlockUntilReadyService private readonly IStatusManager _statusManager; private readonly ITelemetryInitProducer _telemetryInitProducer; - private readonly EventsManager _eventsManager; + private readonly IEventsManager _eventsManager; public SelfRefreshingBlockUntilReadyService(IStatusManager statusManager, ITelemetryInitProducer telemetryInitProducer, - EventsManager eventsManager) + IEventsManager eventsManager) { _statusManager = statusManager; _telemetryInitProducer = telemetryInitProducer; From e7af0f783970929da0849b8e7c7364ff1dd7c0dd Mon Sep 17 00:00:00 2001 From: Bill Al Date: Mon, 22 Dec 2025 20:36:24 -0800 Subject: [PATCH 5/8] 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 4520c7cb2bb613be91ac0fb37a8ebb5d1bcd65f8 Mon Sep 17 00:00:00 2001 From: Bill Al Date: Tue, 23 Dec 2025 12:15:05 -0800 Subject: [PATCH 6/8] refactor delivery and event manager to use action callback --- .../Cache/Classes/InMemorySplitCache.cs | 1 + .../Services/Client/Classes/SplitClient.cs | 11 +- .../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 ++-- .../Client/SdkReadinessGatesUnitTests.cs | 17 ++- .../Unit Tests/Common/EventDeliveryTests.cs | 8 +- .../Unit Tests/Common/EventsManagerTests.cs | 142 ++++++++++-------- ...lfRefreshingBlockUntilReadyServiceTests.cs | 19 ++- 16 files changed, 238 insertions(+), 173 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 d37ed283d..6e9465c0b 100644 --- a/src/Splitio/Services/Client/Classes/SplitClient.cs +++ b/src/Splitio/Services/Client/Classes/SplitClient.cs @@ -64,16 +64,15 @@ public abstract class SplitClient : ISplitClient protected IClientExtensionService _clientExtensionService; protected IFlagSetsFilter _flagSetsFilter; protected IEventsManager _eventsManager; - public event EventHandler PublicSdkReadyHandler; - public event EventHandler PublicSdkUpdateHandler; - public event EventHandler PublicSdkTimedOutHandler; - protected SplitClient(string apikey, FallbackTreatmentCalculator fallbackTreatmentCalculator, - IEventsManager eventsManager) + public event EventHandler SdkReady; + public event EventHandler SdkUpdate; + public event EventHandler SdkTimedOut; + + protected SplitClient(string apikey, FallbackTreatmentCalculator fallbackTreatmentCalculator, IEventsManager eventsManager) { ApiKey = apikey; _eventsManager = eventsManager; - _fallbackTreatmentCalculator = fallbackTreatmentCalculator; _wrapperAdapter = WrapperAdapter.Instance(); _keyValidator = new KeyValidator(); 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/Client/SdkReadinessGatesUnitTests.cs b/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs index 8bd2f7b9f..c53d52527 100644 --- a/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs @@ -9,9 +9,9 @@ namespace Splitio_Tests.Unit_Tests.Client [TestClass] public class InMemoryReadinessGatesCacheUnitTests { - private bool SdkReady = false; + private bool SdkReadyFlag = false; private EventMetadata eMetadata = null; - public event EventHandler PublicSdkUpdateHandler; + public event EventHandler SdkReady; [TestMethod] public void IsSDKReadyShouldReturnFalseIfSplitsAreNotReady() @@ -32,21 +32,26 @@ public void TestFireReadyEvent() //Arrange EventsManager eventsManager = new EventsManager(new EventsManagerConfig()); var gates = new InMemoryReadinessGatesCache(eventsManager); - PublicSdkUpdateHandler += sdkReady_callback; - eventsManager.Register(SdkEvent.SdkReady, PublicSdkUpdateHandler); + SdkReady += sdkReady_callback; + eventsManager.Register(SdkEvent.SdkReady, TriggerSdkReady); //Act gates.SetReady(); // Assert. - Assert.IsTrue(SdkReady); + Assert.IsTrue(SdkReadyFlag); Assert.AreEqual(0, eMetadata.GetData().Count); } private void sdkReady_callback(object sender, EventMetadata metadata) { - SdkReady = true; + SdkReadyFlag = true; eMetadata = metadata; } + + private void TriggerSdkReady(EventMetadata metaData) + { + SdkReady?.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); + } + } } diff --git a/tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs b/tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs index 120072f3d..65f1757d7 100644 --- a/tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs +++ b/tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs @@ -12,9 +12,9 @@ namespace Splitio_Tests.Unit_Tests.Shared [TestClass] public class SelfRefreshingBlockUntilReadyServiceTests { - private bool SdkTimedOut = false; + private bool SdkTimedOutFlag = false; private EventMetadata eMetadata = null; - public event EventHandler PublicSdkUpdateHandler; + public event EventHandler SdkTimedOut; [TestMethod] public void TestFireTimedOutEvent() @@ -24,8 +24,8 @@ public void TestFireTimedOutEvent() Mock telemetryProducer = new Mock(); EventsManager eventsManager = new EventsManager(new EventsManagerConfig()); var bur = new SelfRefreshingBlockUntilReadyService(statusManager.Object, telemetryProducer.Object, eventsManager); - PublicSdkUpdateHandler += SdkTimedOut_callback; - eventsManager.Register(SdkEvent.SdkReadyTimeout, PublicSdkUpdateHandler); + SdkTimedOut += sdkTimeout_callback; + eventsManager.Register(SdkEvent.SdkReadyTimeout, TriggerSdkTimedOut); statusManager .Setup(mock => mock.WaitUntilReady(1)) .Returns(false); @@ -38,14 +38,19 @@ public void TestFireTimedOutEvent() catch { } // Assert. - Assert.IsTrue(SdkTimedOut); + Assert.IsTrue(SdkTimedOutFlag); Assert.AreEqual(0, eMetadata.GetData().Count); } - private void SdkTimedOut_callback(object sender, EventMetadata metadata) + private void sdkTimeout_callback(object sender, EventMetadata metadata) { - SdkTimedOut = true; + SdkTimedOutFlag = true; eMetadata = metadata; } + + private void TriggerSdkTimedOut(EventMetadata metaData) + { + SdkTimedOut?.Invoke(this, metaData); + } } } From c0d0b87d95860b74da2c2b360a524851561619a9 Mon Sep 17 00:00:00 2001 From: Bill Al Date: Tue, 23 Dec 2025 16:09:57 -0800 Subject: [PATCH 7/8] add EventDelivery as a paramater to EventsManager --- .../Services/Client/Classes/SplitClient.cs | 19 +++++++++ .../Services/Client/Classes/SplitFactory.cs | 2 +- src/Splitio/Services/Common/EventsManager.cs | 20 +++++----- .../BaseLocalhostClientTests.cs | 2 +- .../Integration Tests/InMemoryClientTests.cs | 2 +- .../Integration Tests/JSONFileClientTests.cs | 2 +- .../Integration Tests/RedisClientTests.cs | 2 +- .../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 +++++++++--------- .../Client/LocalhostClientForTesting.cs | 2 +- .../Client/LocalhostClientUnitTests.cs | 2 +- .../Client/SdkReadinessGatesUnitTests.cs | 4 +- .../Client/SplitClientForTesting.cs | 2 +- .../Unit Tests/Common/EventsManagerTests.cs | 2 +- .../Impressions/ImpressionsCounterTests.cs | 2 +- .../UserDefinedSegmentMatcherAsyncTests.cs | 33 ++++++++-------- .../UserDefinedSegmentMatcherTests.cs | 39 ++++++++++--------- .../SelfRefreshingSegmentFetcherUnitTests.cs | 7 ++-- .../SelfRefreshingSegmentUnitTests.cs | 8 ++-- ...lfRefreshingBlockUntilReadyServiceTests.cs | 2 +- .../EventSourceClientTests.cs | 2 +- .../StreamingClientTests.cs | 22 +++++++++-- .../Splitio.TestSupport/SplitClientForTest.cs | 2 +- 28 files changed, 146 insertions(+), 109 deletions(-) diff --git a/src/Splitio/Services/Client/Classes/SplitClient.cs b/src/Splitio/Services/Client/Classes/SplitClient.cs index 6e9465c0b..801e416b3 100644 --- a/src/Splitio/Services/Client/Classes/SplitClient.cs +++ b/src/Splitio/Services/Client/Classes/SplitClient.cs @@ -73,6 +73,10 @@ protected SplitClient(string apikey, FallbackTreatmentCalculator fallbackTreatme { ApiKey = apikey; _eventsManager = eventsManager; + _eventsManager.Register(SdkEvent.SdkReady, TriggerSdkReadyEvent); + _eventsManager.Register(SdkEvent.SdkUpdate, TriggerSdkUpdateEvent); + _eventsManager.Register(SdkEvent.SdkReadyTimeout, TriggerSdkTimeoutEvent); + _fallbackTreatmentCalculator = fallbackTreatmentCalculator; _wrapperAdapter = WrapperAdapter.Instance(); _keyValidator = new KeyValidator(); @@ -574,6 +578,21 @@ private static SplitResult TreatmentWithConfig(List results) return new SplitResult(result.Treatment, result.Config); } + + private void TriggerSdkReadyEvent(EventMetadata metadata) + { + SdkReady?.Invoke(this, metadata); + } + + private void TriggerSdkUpdateEvent(EventMetadata metadata) + { + SdkUpdate?.Invoke(this, metadata); + } + + private void TriggerSdkTimeoutEvent(EventMetadata metadata) + { + SdkTimedOut?.Invoke(this, metadata); + } #endregion } } \ No newline at end of file diff --git a/src/Splitio/Services/Client/Classes/SplitFactory.cs b/src/Splitio/Services/Client/Classes/SplitFactory.cs index d22b66479..27742c362 100644 --- a/src/Splitio/Services/Client/Classes/SplitFactory.cs +++ b/src/Splitio/Services/Client/Classes/SplitFactory.cs @@ -60,7 +60,7 @@ public ISplitManager Manager() private void BuildSplitClient() { FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(_options.FallbackTreatments); - EventsManager eventsManager = new EventsManager(new EventsManagerConfig()); + EventsManager eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); switch (_options.Mode) { diff --git a/src/Splitio/Services/Common/EventsManager.cs b/src/Splitio/Services/Common/EventsManager.cs index d891e883e..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"); - public 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; } @@ -186,7 +186,7 @@ private List CheckRequireAll() private bool CheckPrerequisites(E sdkEvent) { - foreach (var item in _managerConfig.Prerequisites.Where(kvp => kvp.Key.Equals(sdkEvent) && + if (_managerConfig.Prerequisites.Any(kvp => kvp.Key.Equals(sdkEvent) && kvp.Value.Any(x => !EventAlreadyTriggered(x)))) { return false; @@ -197,7 +197,7 @@ private bool CheckPrerequisites(E sdkEvent) private bool CheckSuppressedBy(E sdkEvent) { - foreach (var item in _managerConfig.SuppressedBy.Where(kvp => kvp.Key.Equals(sdkEvent) && + 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; } @@ -222,10 +223,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.Any()) { validSdkEvent.Valid = true; - validSdkEvent.SdkEvent = item.Key; + validSdkEvent.SdkEvent = sdkEvent.First().Key; return validSdkEvent; } diff --git a/tests/Splitio-tests/Integration Tests/BaseLocalhostClientTests.cs b/tests/Splitio-tests/Integration Tests/BaseLocalhostClientTests.cs index fe9b32270..9bb56c7f8 100644 --- a/tests/Splitio-tests/Integration Tests/BaseLocalhostClientTests.cs +++ b/tests/Splitio-tests/Integration Tests/BaseLocalhostClientTests.cs @@ -33,7 +33,7 @@ public BaseLocalhostClientTests(string mode) rootFilePath = string.Empty; _mode = mode; _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()); - _eventsManager = new EventsManager(new EventsManagerConfig()); + _eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); #if NET_LATEST rootFilePath = @"Resources\"; diff --git a/tests/Splitio-tests/Integration Tests/InMemoryClientTests.cs b/tests/Splitio-tests/Integration Tests/InMemoryClientTests.cs index 2279838cb..e16d7f0f8 100644 --- a/tests/Splitio-tests/Integration Tests/InMemoryClientTests.cs +++ b/tests/Splitio-tests/Integration Tests/InMemoryClientTests.cs @@ -20,7 +20,7 @@ public InMemoryClientTests() // This line is to clean the warnings. rootFilePath = string.Empty; _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()); - _eventsManager = new EventsManager(new EventsManagerConfig()); + _eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); #if NET_LATEST rootFilePath = @"Resources\"; diff --git a/tests/Splitio-tests/Integration Tests/JSONFileClientTests.cs b/tests/Splitio-tests/Integration Tests/JSONFileClientTests.cs index 6bdc8e556..c4868dea4 100644 --- a/tests/Splitio-tests/Integration Tests/JSONFileClientTests.cs +++ b/tests/Splitio-tests/Integration Tests/JSONFileClientTests.cs @@ -27,7 +27,7 @@ public JSONFileClientTests() // This line is to clean the warnings. rootFilePath = string.Empty; _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()); - _eventsManager = new EventsManager(new EventsManagerConfig()); + _eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); #if NET_LATEST rootFilePath = @"Resources\"; diff --git a/tests/Splitio-tests/Integration Tests/RedisClientTests.cs b/tests/Splitio-tests/Integration Tests/RedisClientTests.cs index 8ad5f8bef..f600179a0 100644 --- a/tests/Splitio-tests/Integration Tests/RedisClientTests.cs +++ b/tests/Splitio-tests/Integration Tests/RedisClientTests.cs @@ -40,7 +40,7 @@ public void Initialization() UserPrefix = _prefix }; _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()); - _eventsManager = new EventsManager(new EventsManagerConfig()); + _eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); config = new ConfigurationOptions { CacheAdapterConfig = cacheAdapterConfig, 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 e60492996..7d4e8f532 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); @@ -141,7 +141,7 @@ public async Task ExecuteGetWithoutResults() var apiSplitChangeFetcher = new ApiSplitChangeFetcher(sdkApiClient); var sdkSegmentApiClient = new SegmentSdkApiClient(httpClient, telemetryStorage, baseUrl); var apiSegmentChangeFetcher = new ApiSegmentChangeFetcher(sdkSegmentApiClient); - var eventsManager = new EventsManager(new EventsManagerConfig()); + var eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); var gates = new InMemoryReadinessGatesCache(eventsManager); var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var segmentsQueue = new SplitQueue(); 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/Client/LocalhostClientForTesting.cs b/tests/Splitio-tests/Unit Tests/Client/LocalhostClientForTesting.cs index b97cff0ef..deb27c042 100644 --- a/tests/Splitio-tests/Unit Tests/Client/LocalhostClientForTesting.cs +++ b/tests/Splitio-tests/Unit Tests/Client/LocalhostClientForTesting.cs @@ -7,7 +7,7 @@ namespace Splitio_Tests.Unit_Tests.Client { public class LocalhostClientForTesting : LocalhostClient { - public LocalhostClientForTesting(string filePath, FallbackTreatmentCalculator fallbackTreatmentCalculator) : base(new ConfigurationOptions { LocalhostFilePath = filePath }, fallbackTreatmentCalculator, new EventsManager(new EventsManagerConfig())) + public LocalhostClientForTesting(string filePath, FallbackTreatmentCalculator fallbackTreatmentCalculator) : base(new ConfigurationOptions { LocalhostFilePath = filePath }, fallbackTreatmentCalculator, new EventsManager(new EventsManagerConfig(), new EventDelivery())) { } } } diff --git a/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs b/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs index 05f826bee..7bdfe24ac 100644 --- a/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs @@ -21,7 +21,7 @@ public LocalhostClientUnitTests() // This line is to clean the warnings. rootFilePath = string.Empty; _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()); - _eventsManager = new EventsManager(new EventsManagerConfig()); + _eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); #if NET_LATEST rootFilePath = @"Resources\"; diff --git a/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs b/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs index c53d52527..d17713b5c 100644 --- a/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs @@ -17,7 +17,7 @@ public class InMemoryReadinessGatesCacheUnitTests public void IsSDKReadyShouldReturnFalseIfSplitsAreNotReady() { //Arrange - var gates = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); + var gates = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig(), new EventDelivery())); //Act var result = gates.IsReady(); @@ -30,7 +30,7 @@ public void IsSDKReadyShouldReturnFalseIfSplitsAreNotReady() public void TestFireReadyEvent() { //Arrange - EventsManager eventsManager = new EventsManager(new EventsManagerConfig()); + EventsManager eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); var gates = new InMemoryReadinessGatesCache(eventsManager); SdkReady += sdkReady_callback; eventsManager.Register(SdkEvent.SdkReady, TriggerSdkReady); diff --git a/tests/Splitio-tests/Unit Tests/Client/SplitClientForTesting.cs b/tests/Splitio-tests/Unit Tests/Client/SplitClientForTesting.cs index 12277bcba..a44f94ebd 100644 --- a/tests/Splitio-tests/Unit Tests/Client/SplitClientForTesting.cs +++ b/tests/Splitio-tests/Unit Tests/Client/SplitClientForTesting.cs @@ -23,7 +23,7 @@ public SplitClientForTesting(IFeatureFlagCacheConsumer featureFlagCacheConsumer, ISyncManager syncManager, FallbackTreatmentCalculator fallbackTreatmentCalculator, ITelemetryEvaluationProducer telemetryEvaluationProducer) - : base("SplitClientForTesting", fallbackTreatmentCalculator, new EventsManager(new EventsManagerConfig())) + : base("SplitClientForTesting", fallbackTreatmentCalculator, new EventsManager(new EventsManagerConfig(), new EventDelivery())) { _eventsLog = eventsLog; _impressionsLog = impressionsLog; 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/Impressions/ImpressionsCounterTests.cs b/tests/Splitio-tests/Unit Tests/Impressions/ImpressionsCounterTests.cs index 42df730c5..049312b8f 100644 --- a/tests/Splitio-tests/Unit Tests/Impressions/ImpressionsCounterTests.cs +++ b/tests/Splitio-tests/Unit Tests/Impressions/ImpressionsCounterTests.cs @@ -29,7 +29,7 @@ public void Start_ShouldSendImpressionsCount() { // Arrange. var config = new ComponentConfig(5, 5); - var statusManager = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); + var statusManager = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig(), new EventDelivery())); var taskManager = new TasksManager(statusManager); var task = taskManager.NewPeriodicTask(Splitio.Enums.Task.ImpressionsCountSender, 1); var sendBulkDataTask = taskManager.NewOnTimeTask(Splitio.Enums.Task.ImpressionCounterSendBulkData); 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 97a689597..8e7110ca5 100644 --- a/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs @@ -8,7 +8,6 @@ using Splitio.Services.SegmentFetcher.Classes; using Splitio.Services.SegmentFetcher.Interfaces; using Splitio.Services.Shared.Classes; -using Splitio.Services.Shared.Interfaces; using Splitio.Services.SplitFetcher.Interfaces; using Splitio.Services.Tasks; using System.Collections.Concurrent; @@ -27,13 +26,13 @@ public class SelfRefreshingSegmentFetcherUnitTests public void InitializeSegmentNotExistent() { // Arrange - var gates = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); + var gates = new InMemoryReadinessGatesCache(new Mock>().Object); gates.SetReady(); 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 diff --git a/tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs b/tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs index 65f1757d7..6f63501d7 100644 --- a/tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs +++ b/tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs @@ -22,7 +22,7 @@ public void TestFireTimedOutEvent() //Arrange Mock statusManager = new Mock(); Mock telemetryProducer = new Mock(); - EventsManager eventsManager = new EventsManager(new EventsManagerConfig()); + EventsManager eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); var bur = new SelfRefreshingBlockUntilReadyService(statusManager.Object, telemetryProducer.Object, eventsManager); SdkTimedOut += sdkTimeout_callback; eventsManager.Register(SdkEvent.SdkReadyTimeout, TriggerSdkTimedOut); diff --git a/tests/Splitio.Integration-tests/EventSourceClientTests.cs b/tests/Splitio.Integration-tests/EventSourceClientTests.cs index 0eb26bddb..b7850c78f 100644 --- a/tests/Splitio.Integration-tests/EventSourceClientTests.cs +++ b/tests/Splitio.Integration-tests/EventSourceClientTests.cs @@ -370,7 +370,7 @@ private static (IEventSourceClient, BlockingCollection, var sseHttpClient = new SplitioHttpClient("api-key", config, new Dictionary()); var telemetryRuntimeProducer = new InMemoryTelemetryStorage(); var notificationManagerKeeper = new NotificationManagerKeeper(telemetryRuntimeProducer, streamingStatusQueue); - var statusManager = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); + var statusManager = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig(), new EventDelivery())); var tasksManager = new TasksManager(statusManager); var task = tasksManager.NewOnTimeTask(Enums.Task.SSEConnect); diff --git a/tests/Splitio.Integration-tests/StreamingClientTests.cs b/tests/Splitio.Integration-tests/StreamingClientTests.cs index 7623dadd1..6dab8142b 100644 --- a/tests/Splitio.Integration-tests/StreamingClientTests.cs +++ b/tests/Splitio.Integration-tests/StreamingClientTests.cs @@ -22,6 +22,10 @@ namespace Splitio.Integration_tests public class StreamingClientTests { public static string EventSourcePath => "/eventsource"; + private bool SdkReadyFlag = false; + private bool SdkReadyFlag2 = false; + private bool SdkUpdateFlag = false; + private EventMetadata eMetadata; [TestMethod] public void GetTreatment_SplitUpdate_ShouldFetch() @@ -60,14 +64,17 @@ public void GetTreatment_SplitUpdate_ShouldFetch() }; var apikey = "apikey1"; - var splitFactory = new SplitFactory(apikey, config); - var client = splitFactory.Client(); + var client = (SplitClient)splitFactory.Client(); + client.SdkReady += sdkReady_callback; + client.SdkReady += sdkReady_callback2; client.BlockUntilReady(10000); var result = EvaluateWithDelay("admin", "push_test", "after_fetch", client); Assert.AreEqual("after_fetch", result); + Assert.IsTrue(SdkReadyFlag); + Assert.IsTrue(SdkReadyFlag2); client.Destroy(); } @@ -169,7 +176,6 @@ public void GetTreatment_SplitKill_ShouldFetch() Thread.Sleep(5000); var result = client.GetTreatment("admin", "push_test"); - Assert.AreEqual("after_fetch", result); client.Destroy(); @@ -765,5 +771,15 @@ public static string EvaluateWithDelay(string key, string splitName, string expe return result; } + + private void sdkReady_callback(object sender, EventMetadata metadata) + { + SdkReadyFlag = true; + } + + private void sdkReady_callback2(object sender, EventMetadata metadata) + { + SdkReadyFlag2 = true; + } } } diff --git a/tests/Splitio.TestSupport/SplitClientForTest.cs b/tests/Splitio.TestSupport/SplitClientForTest.cs index f79f66748..363380c2d 100644 --- a/tests/Splitio.TestSupport/SplitClientForTest.cs +++ b/tests/Splitio.TestSupport/SplitClientForTest.cs @@ -11,7 +11,7 @@ public class SplitClientForTest : SplitClient private readonly Dictionary _tests; public SplitClientForTest() : base("SplitClientForTest", new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()), - new EventsManager(new EventsManagerConfig())) + new EventsManager(new EventsManagerConfig(), new EventDelivery())) { _tests = new Dictionary(); } From 4516fab4b73661ea83fbc96b5242d074d8583dae Mon Sep 17 00:00:00 2001 From: Bill Al Date: Fri, 26 Dec 2025 13:13:27 -0800 Subject: [PATCH 8/8] moved creating eventsManager and FallbackTreatment instances to client --- .../Services/Client/Classes/RedisClient.cs | 6 +- .../Services/Client/Classes/JSONFileClient.cs | 13 ++- .../Client/Classes/LocalhostClient.cs | 8 +- .../Client/Classes/SelfRefreshingClient.cs | 6 +- .../Services/Client/Classes/SplitClient.cs | 9 +- .../Services/Client/Classes/SplitFactory.cs | 11 +-- .../BaseLocalhostClientTests.cs | 37 +++---- .../Integration Tests/InMemoryClientTests.cs | 6 +- .../Integration Tests/JSONFileClientTests.cs | 98 +++++++++---------- .../Integration Tests/RedisClientTests.cs | 59 +++++------ .../Client/LocalhostClientForTesting.cs | 7 +- .../Client/LocalhostClientUnitTests.cs | 9 +- .../Client/SplitClientAsyncTests.cs | 10 +- .../Client/SplitClientForTesting.cs | 10 +- .../Unit Tests/Client/SplitClientUnitTests.cs | 9 +- .../Impressions/ImpressionsCounterTests.cs | 6 +- .../SelfRefreshingSegmentFetcherUnitTests.cs | 2 +- .../Splitio.TestSupport/Samples/SampleTest.cs | 6 +- .../Splitio.TestSupport/SplitClientForTest.cs | 3 +- 19 files changed, 137 insertions(+), 178 deletions(-) diff --git a/Splitio.Redis/Services/Client/Classes/RedisClient.cs b/Splitio.Redis/Services/Client/Classes/RedisClient.cs index 345a546d7..f80273207 100644 --- a/Splitio.Redis/Services/Client/Classes/RedisClient.cs +++ b/Splitio.Redis/Services/Client/Classes/RedisClient.cs @@ -9,7 +9,6 @@ using Splitio.Redis.Telemetry.Storages; using Splitio.Services.Cache.Interfaces; using Splitio.Services.Client.Classes; -using Splitio.Services.Common; using Splitio.Services.EngineEvaluator; using Splitio.Services.Evaluator; using Splitio.Services.Impressions.Classes; @@ -29,13 +28,10 @@ public class RedisClient : SplitClient private IImpressionsCache _impressionsCache; private ConnectionPoolManager _connectionPoolManager; private IFeatureFlagCacheConsumer _featureFlagCacheConsumer; - private readonly new FallbackTreatmentCalculator _fallbackTreatmentCalculator; - public RedisClient(ConfigurationOptions config, string apiKey, FallbackTreatmentCalculator fallbackTreatmentCalculator, - EventsManager eventsManager) : base(apiKey, fallbackTreatmentCalculator, eventsManager) + public RedisClient(ConfigurationOptions config, string apiKey) : base(apiKey, config) { _config = new RedisConfig(); - _fallbackTreatmentCalculator = fallbackTreatmentCalculator; ReadConfig(config); diff --git a/src/Splitio/Services/Client/Classes/JSONFileClient.cs b/src/Splitio/Services/Client/Classes/JSONFileClient.cs index cae07f344..5c2faeba1 100644 --- a/src/Splitio/Services/Client/Classes/JSONFileClient.cs +++ b/src/Splitio/Services/Client/Classes/JSONFileClient.cs @@ -24,8 +24,7 @@ public class JSONFileClient : SplitClient public JSONFileClient(string splitsFilePath, string segmentsFilePath, - FallbackTreatmentCalculator fallbackTreatmentCalculator, - EventsManager eventsManager, + ConfigurationOptions config, ISegmentCache segmentCacheInstance = null, IFeatureFlagCache featureFlagCacheInstance = null, IImpressionsLog impressionsLog = null, @@ -34,10 +33,10 @@ public JSONFileClient(string splitsFilePath, ITrafficTypeValidator trafficTypeValidator = null, IImpressionsManager impressionsManager = null, IRuleBasedSegmentCache ruleBasedSegmentCache = null - ) : base("localhost", fallbackTreatmentCalculator, eventsManager) + ) : base("localhost", config) { - _segmentCache = segmentCacheInstance ?? new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); - var rbsCache = ruleBasedSegmentCache ?? new InMemoryRuleBasedSegmentCache(new ConcurrentDictionary(), eventsManager); + _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); @@ -55,13 +54,13 @@ public JSONFileClient(string splitsFilePath, } BuildFlagSetsFilter(new HashSet()); - _featureFlagCache = featureFlagCacheInstance ?? new InMemorySplitCache(new ConcurrentDictionary(parsedSplits), _flagSetsFilter, eventsManager); + _featureFlagCache = featureFlagCacheInstance ?? new InMemorySplitCache(new ConcurrentDictionary(parsedSplits), _flagSetsFilter, _eventsManager); _impressionsLog = impressionsLog; _eventsLog = eventsLog; _trafficTypeValidator = trafficTypeValidator; _blockUntilReadyService = new NoopBlockUntilReadyService(); _manager = new SplitManager(_featureFlagCache, _blockUntilReadyService); - _evaluator = new Evaluator.Evaluator(_featureFlagCache, new Splitter(), null, fallbackTreatmentCalculator); + _evaluator = new Evaluator.Evaluator(_featureFlagCache, new Splitter(), null, _fallbackTreatmentCalculator); _uniqueKeysTracker = new NoopUniqueKeysTracker(); _impressionsCounter = new NoopImpressionsCounter(); _impressionsObserver = new NoopImpressionsObserver(); diff --git a/src/Splitio/Services/Client/Classes/LocalhostClient.cs b/src/Splitio/Services/Client/Classes/LocalhostClient.cs index b22c5f076..96495a1a7 100644 --- a/src/Splitio/Services/Client/Classes/LocalhostClient.cs +++ b/src/Splitio/Services/Client/Classes/LocalhostClient.cs @@ -1,7 +1,6 @@ using Splitio.Domain; using Splitio.Services.Cache.Classes; using Splitio.Services.Cache.Interfaces; -using Splitio.Services.Common; using Splitio.Services.EngineEvaluator; using Splitio.Services.Impressions.Classes; using Splitio.Services.InputValidation.Classes; @@ -28,8 +27,7 @@ public class LocalhostClient : SplitClient private readonly object _lock = new object(); - public LocalhostClient(ConfigurationOptions configurationOptions, FallbackTreatmentCalculator fallbackTreatmentCalculator, - EventsManager eventsManager) : base("localhost", fallbackTreatmentCalculator, eventsManager) + public LocalhostClient(ConfigurationOptions configurationOptions) : base("localhost", configurationOptions) { var configs = (LocalhostClientConfigurations)_configService.ReadConfig(configurationOptions, ConfigTypes.Localhost, _statusManager); @@ -49,7 +47,7 @@ public LocalhostClient(ConfigurationOptions configurationOptions, FallbackTreatm BuildFlagSetsFilter(new HashSet()); var splits = _localhostFileService.ParseSplitFile(_fullPath); - _featureFlagCache = new InMemorySplitCache(splits, _flagSetsFilter, eventsManager); + _featureFlagCache = new InMemorySplitCache(splits, _flagSetsFilter, _eventsManager); if (configs.FileSync != null) @@ -64,7 +62,7 @@ public LocalhostClient(ConfigurationOptions configurationOptions, FallbackTreatm _blockUntilReadyService = new NoopBlockUntilReadyService(); _manager = new SplitManager(_featureFlagCache, _blockUntilReadyService); _trafficTypeValidator = new TrafficTypeValidator(_featureFlagCache, _blockUntilReadyService); - _evaluator = new Evaluator.Evaluator(_featureFlagCache, new Splitter(), null, fallbackTreatmentCalculator); + _evaluator = new Evaluator.Evaluator(_featureFlagCache, new Splitter(), null, _fallbackTreatmentCalculator); _uniqueKeysTracker = new NoopUniqueKeysTracker(); _impressionsCounter = new NoopImpressionsCounter(); _impressionsObserver = new NoopImpressionsObserver(); diff --git a/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs b/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs index 7d513bc5b..14fae995b 100644 --- a/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs +++ b/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs @@ -51,14 +51,10 @@ public class SelfRefreshingClient : SplitClient private IUpdater _featureFlagUpdater; private IRuleBasedSegmentCache _ruleBasedSegmentCache; private IUpdater _ruleBasedSegmentUpdater; - private readonly new FallbackTreatmentCalculator _fallbackTreatmentCalculator; - public SelfRefreshingClient(string apiKey, ConfigurationOptions config, - FallbackTreatmentCalculator fallbackTreatmentCalculator, - IEventsManager eventsManager) : base(apiKey, fallbackTreatmentCalculator, eventsManager) + public SelfRefreshingClient(string apiKey, ConfigurationOptions config) : base(apiKey, config) { _config = (SelfRefreshingConfig)_configService.ReadConfig(config, ConfigTypes.InMemory); - _fallbackTreatmentCalculator = fallbackTreatmentCalculator; BuildFlagSetsFilter(_config.FlagSetsFilter); BuildSplitCache(); diff --git a/src/Splitio/Services/Client/Classes/SplitClient.cs b/src/Splitio/Services/Client/Classes/SplitClient.cs index 801e416b3..82c99b1e1 100644 --- a/src/Splitio/Services/Client/Classes/SplitClient.cs +++ b/src/Splitio/Services/Client/Classes/SplitClient.cs @@ -69,15 +69,16 @@ public abstract class SplitClient : ISplitClient public event EventHandler SdkUpdate; public event EventHandler SdkTimedOut; - protected SplitClient(string apikey, FallbackTreatmentCalculator fallbackTreatmentCalculator, IEventsManager eventsManager) + protected SplitClient(string apikey, ConfigurationOptions options) { ApiKey = apikey; - _eventsManager = eventsManager; + _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(options.FallbackTreatments); + _eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); + _eventsManager.Register(SdkEvent.SdkReady, TriggerSdkReadyEvent); _eventsManager.Register(SdkEvent.SdkUpdate, TriggerSdkUpdateEvent); _eventsManager.Register(SdkEvent.SdkReadyTimeout, TriggerSdkTimeoutEvent); - _fallbackTreatmentCalculator = fallbackTreatmentCalculator; _wrapperAdapter = WrapperAdapter.Instance(); _keyValidator = new KeyValidator(); _splitNameValidator = new SplitNameValidator(); @@ -86,7 +87,7 @@ protected SplitClient(string apikey, FallbackTreatmentCalculator fallbackTreatme _factoryInstantiationsService = FactoryInstantiationsService.Instance(); _flagSetsValidator = new FlagSetsValidator(); _configService = new ConfigService(_wrapperAdapter, _flagSetsValidator, new SdkMetadataValidator()); - _statusManager = new InMemoryReadinessGatesCache(eventsManager); + _statusManager = new InMemoryReadinessGatesCache(_eventsManager); _tasksManager = new TasksManager(_statusManager); } diff --git a/src/Splitio/Services/Client/Classes/SplitFactory.cs b/src/Splitio/Services/Client/Classes/SplitFactory.cs index 27742c362..1cb95e988 100644 --- a/src/Splitio/Services/Client/Classes/SplitFactory.cs +++ b/src/Splitio/Services/Client/Classes/SplitFactory.cs @@ -1,7 +1,5 @@ using Splitio.Domain; using Splitio.Services.Client.Interfaces; -using Splitio.Services.Common; -using Splitio.Services.Impressions.Classes; using Splitio.Services.InputValidation.Classes; using Splitio.Services.InputValidation.Interfaces; using Splitio.Services.Shared.Classes; @@ -59,9 +57,6 @@ public ISplitManager Manager() private void BuildSplitClient() { - FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(_options.FallbackTreatments); - EventsManager eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); - switch (_options.Mode) { case Mode.Standalone: @@ -69,11 +64,11 @@ private void BuildSplitClient() if (_apiKey == "localhost") { - _client = new LocalhostClient(_options, fallbackTreatmentCalculator, eventsManager); + _client = new LocalhostClient(_options); } else { - _client = new SelfRefreshingClient(_apiKey, _options, fallbackTreatmentCalculator, eventsManager); + _client = new SelfRefreshingClient(_apiKey, _options); } break; case Mode.Consumer: @@ -84,7 +79,7 @@ private void BuildSplitClient() var redisAssembly = Assembly.Load(new AssemblyName("Splitio.Redis")); var redisType = redisAssembly.GetType("Splitio.Redis.Services.Client.Classes.RedisClient"); - _client = (ISplitClient)Activator.CreateInstance(redisType, new object[] { _options, _apiKey, fallbackTreatmentCalculator, eventsManager }); + _client = (ISplitClient)Activator.CreateInstance(redisType, new object[] { _options, _apiKey }); } catch (ArgumentException ex) { diff --git a/tests/Splitio-tests/Integration Tests/BaseLocalhostClientTests.cs b/tests/Splitio-tests/Integration Tests/BaseLocalhostClientTests.cs index 9bb56c7f8..263133942 100644 --- a/tests/Splitio-tests/Integration Tests/BaseLocalhostClientTests.cs +++ b/tests/Splitio-tests/Integration Tests/BaseLocalhostClientTests.cs @@ -1,10 +1,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Splitio.Domain; -using Splitio.Redis.Services.Client.Classes; using Splitio.Services.Client.Classes; -using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; -using Splitio.Telemetry.Domain; using System; using System.Collections.Generic; using System.IO; @@ -24,16 +21,12 @@ public abstract class BaseLocalhostClientTests { private readonly string rootFilePath; private readonly string _mode; - private readonly FallbackTreatmentCalculator _fallbackTreatmentCalculator; - private readonly EventsManager _eventsManager; public BaseLocalhostClientTests(string mode) { // This line is to clean the warnings. rootFilePath = string.Empty; _mode = mode; - _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()); - _eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); #if NET_LATEST rootFilePath = @"Resources\"; @@ -45,7 +38,7 @@ public async Task GetTreatmentAsync() { // Arrange. var config = GetConfiguration($"{rootFilePath}test.splits"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); + var client = new LocalhostClient(config); client.BlockUntilReady(1000); @@ -84,7 +77,7 @@ public void GetTreatmentSuccessfully() { //Arrange var config = GetConfiguration($"{rootFilePath}test.splits"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); + var client = new LocalhostClient(config); client.BlockUntilReady(1000); @@ -108,7 +101,7 @@ public void GetTreatmentSuccessfullyWhenUpdatingSplitsFile() // Arrange var filePath = $"{rootFilePath}test2-{_mode}.splits"; var config = GetConfiguration(filePath); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); + var client = new LocalhostClient(config); client.BlockUntilReady(1000); @@ -151,7 +144,7 @@ public void GetTreatmentSuccessfullyWhenUpdatingSplitsFileSameFile() Thread.Sleep(1000); var config = GetConfiguration(filePath); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); + var client = new LocalhostClient(config); client.BlockUntilReady(1000); @@ -174,7 +167,7 @@ public void ClientDestroySuccessfully() { //Arrange var config = GetConfiguration($"{rootFilePath}test.splits"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); + var client = new LocalhostClient(config); client.BlockUntilReady(1000); @@ -196,7 +189,7 @@ public void GetTreatment_WhenIsYamlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); + var client = new LocalhostClient(config); client.BlockUntilReady(1000); @@ -228,7 +221,7 @@ public void GetTreatmentWithConfig_WhenIsYamlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); + var client = new LocalhostClient(config); client.BlockUntilReady(1000); @@ -267,7 +260,7 @@ public void GetTreatment_WhenIsYmlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); + var client = new LocalhostClient(config); client.BlockUntilReady(1000); @@ -299,7 +292,7 @@ public void GetTreatmentWithConfig_WhenIsYmlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); + var client = new LocalhostClient(config); client.BlockUntilReady(1000); @@ -338,7 +331,7 @@ public void GetTreatments_WhenIsYamlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); + var client = new LocalhostClient(config); client.BlockUntilReady(1000); @@ -375,7 +368,7 @@ public void GetTreatmentsWithConfig_WhenIsYamlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); + var client = new LocalhostClient(config); client.BlockUntilReady(1000); @@ -426,7 +419,7 @@ public void GetTreatments_WhenIsYmlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); + var client = new LocalhostClient(config); client.BlockUntilReady(1000); @@ -463,7 +456,7 @@ public void GetTreatmentsWithConfig_WhenIsYmlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); + var client = new LocalhostClient(config); client.BlockUntilReady(1000); @@ -514,10 +507,10 @@ public void FallbackTreatments_WhenFeatureDoesNotExist() { var features = new List { "testing_split_on", "feature", "feature2" }; FallbackTreatmentsConfiguration fallbackTreatmentsConfiguration = new FallbackTreatmentsConfiguration(new FallbackTreatment("on-global", "\"prop\":\"global\""), new Dictionary() { { "feature", new FallbackTreatment("off-local", "\"prop\":\"local\"") } }); - FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(fallbackTreatmentsConfiguration); var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, fallbackTreatmentCalculator, _eventsManager); + config.FallbackTreatments = fallbackTreatmentsConfiguration; + var client = new LocalhostClient(config); client.BlockUntilReady(1000); diff --git a/tests/Splitio-tests/Integration Tests/InMemoryClientTests.cs b/tests/Splitio-tests/Integration Tests/InMemoryClientTests.cs index e16d7f0f8..cf591e65e 100644 --- a/tests/Splitio-tests/Integration Tests/InMemoryClientTests.cs +++ b/tests/Splitio-tests/Integration Tests/InMemoryClientTests.cs @@ -12,15 +12,11 @@ namespace Splitio_Tests.Integration_Tests public class InMemoryClientTests { private readonly string rootFilePath; - private readonly FallbackTreatmentCalculator _fallbackTreatmentCalculator; - private readonly EventsManager _eventsManager; public InMemoryClientTests() { // This line is to clean the warnings. rootFilePath = string.Empty; - _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()); - _eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); #if NET_LATEST rootFilePath = @"Resources\"; @@ -39,7 +35,7 @@ public void OverridingJsonConvertSettingSnakeCaseNamingStrategy() NamingStrategy = new SnakeCaseNamingStrategy() } }; - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); client.BlockUntilReady(1000); //Act diff --git a/tests/Splitio-tests/Integration Tests/JSONFileClientTests.cs b/tests/Splitio-tests/Integration Tests/JSONFileClientTests.cs index c4868dea4..5ad0ea235 100644 --- a/tests/Splitio-tests/Integration Tests/JSONFileClientTests.cs +++ b/tests/Splitio-tests/Integration Tests/JSONFileClientTests.cs @@ -19,15 +19,11 @@ namespace Splitio_Tests.Integration_Tests public class JSONFileClientTests { private readonly string rootFilePath; - private readonly FallbackTreatmentCalculator _fallbackTreatmentCalculator; - private readonly EventsManager _eventsManager; public JSONFileClientTests() { // This line is to clean the warnings. rootFilePath = string.Empty; - _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()); - _eventsManager = new EventsManager(new EventsManagerConfig(), new EventDelivery()); #if NET_LATEST rootFilePath = @"Resources\"; @@ -40,7 +36,7 @@ public JSONFileClientTests() public void ExecuteGetTreatmentOnFailedParsingSplitShouldReturnControl() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); //Act var result = client.GetTreatment("test", "fail", null); @@ -55,7 +51,7 @@ public void ExecuteGetTreatmentOnFailedParsingSplitShouldReturnControl() public void ExecuteGetTreatmentOnFailedParsingSplitShouldNotAffectOtherSplits() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); client.BlockUntilReady(1000); @@ -72,7 +68,7 @@ public void ExecuteGetTreatmentOnFailedParsingSplitShouldNotAffectOtherSplits() public void ExecuteGetTreatmentOnDeletedSplitShouldReturnControl() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); client.BlockUntilReady(1000); @@ -100,7 +96,7 @@ public void ExecuteGetTreatmentOnExceptionShouldReturnControl() .Setup(x => x.GetSplit(It.IsAny())) .Throws(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, null, splitCacheMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions(), featureFlagCacheInstance: splitCacheMock.Object, impressionsLog: impressionsLogMock.Object); //Act var result = client.GetTreatment("test", "asd", null); @@ -116,7 +112,7 @@ public void ExecuteGetTreatmentOnExceptionShouldReturnControl() public void ExecuteGetTreatmentOnRemovedUserFromSegmentShouldReturnOff() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", $"{rootFilePath}segment_payed.json", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", $"{rootFilePath}segment_payed.json", new ConfigurationOptions()); client.BlockUntilReady(1000); @@ -138,7 +134,7 @@ public void ExecuteGetTreatmentOnRemovedUserFromSegmentShouldReturnOff() public void ExecuteGetTreatmentOnSplitWithOnOffOnPartition() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", new ConfigurationOptions()); client.BlockUntilReady(1000); @@ -162,7 +158,7 @@ public void ExecuteGetTreatmentOnSplitWithOnOffOnPartition() public void ExecuteGetTreatmentOnSplitWithTrafficAllocation() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", new ConfigurationOptions()); client.BlockUntilReady(1000); @@ -186,7 +182,7 @@ public void ExecuteGetTreatmentOnSplitWithTrafficAllocation() public void ExecuteGetTreatmentOnSplitWithTrafficAllocationWhenAllocationIsDifferentThan100() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", new ConfigurationOptions()); client.BlockUntilReady(1000); @@ -210,7 +206,7 @@ public void ExecuteGetTreatmentOnSplitWithTrafficAllocationWhenAllocationIsDiffe public void ExecuteGetTreatmentOnSplitWithTrafficAllocationWhenAllocationIs1ReturnsRolloutTreatment() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_7.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_7.json", "", new ConfigurationOptions()); client.BlockUntilReady(1000); @@ -226,7 +222,7 @@ public void ExecuteGetTreatmentOnSplitWithTrafficAllocationWhenAllocationIs1Retu public void ExecuteGetTreatmentOnSplitWithTrafficAllocationWhenAllocationIs1ReturnsDefaultTreatment() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_7.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_7.json", "", new ConfigurationOptions()); client.BlockUntilReady(1000); @@ -242,7 +238,7 @@ public void ExecuteGetTreatmentOnSplitWithTrafficAllocationWhenAllocationIs1Retu public void ExecuteGetTreatmentOnSplitWithSegmentNotInitialized() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); client.BlockUntilReady(1000); @@ -262,7 +258,7 @@ public void ExecuteGetTreatmentAndLogLabelKilled() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions(), impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -286,7 +282,7 @@ public void ExecuteGetTreatmentAndLogLabelNoConditionMatched() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions(), impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -310,7 +306,7 @@ public void ExecuteGetTreatmentAndLogLabelSplitNotFound() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); //Act client.RemoveSplitFromCache("asd"); @@ -339,7 +335,7 @@ public void ExecuteGetTreatmentAndLogLabelException() .Setup(x => x.GetSplit(It.IsAny())) .Throws(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, featureFlagCacheInstance: splitCacheMock.Object, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions { ImpressionsMode = ImpressionsMode.Debug }, impressionsLog: impressionsLogMock.Object, featureFlagCacheInstance: splitCacheMock.Object); client.BlockUntilReady(1000); @@ -363,7 +359,7 @@ public void ExecuteGetTreatmentAndLogLabelTrafficAllocationFailed() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", new ConfigurationOptions(), impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -386,7 +382,7 @@ public void ExecuteGetTreatmentAndLogLabelForTreatment() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions(), impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -409,7 +405,7 @@ public void ExecuteGetTreatmentAndLogLabelForTreatment() public void ExecuteGetTreatmentWhenUnknownMatcherIsIncluded() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); //Act var result = client.GetTreatment("xs", "Unknown_Matcher", null); @@ -424,7 +420,7 @@ public void ExecuteGetTreatmentAndNotLogLabelForTreatmentIfLabelsNotEnabled() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object, isLabelsEnabled: false); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions(), impressionsLog: impressionsLogMock.Object, isLabelsEnabled: false); client.BlockUntilReady(1000); @@ -447,7 +443,7 @@ public void ExecuteGetTreatmentAndLogLabelAndBucketingKeyForTreatment() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions { ImpressionsMode = ImpressionsMode.Debug }, impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -471,7 +467,7 @@ public void ExecuteGetTreatmentAndLogLabelAndBucketingKeyForTreatment() public void ExecuteGetTreatmentWithBooleanAttribute() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", new ConfigurationOptions()); var attributes = new Dictionary { @@ -493,7 +489,7 @@ public void ExecuteGetTreatmentWithBooleanAttribute() public void ExecuteGetTreatmentWithSetMatcherReturnsOff() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", new ConfigurationOptions()); var attributes = new Dictionary { @@ -515,7 +511,7 @@ public void ExecuteGetTreatmentWithSetMatcherReturnsOff() public void ExecuteGetTreatmentWithSetMatcherReturnsOn() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", new ConfigurationOptions()); var attributes = new Dictionary { @@ -537,7 +533,7 @@ public void ExecuteGetTreatmentWithSetMatcherReturnsOn() public void ExecuteGetTreatmentWithStringMatcherReturnsOff() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", new ConfigurationOptions()); var attributes = new Dictionary { @@ -559,7 +555,7 @@ public void ExecuteGetTreatmentWithStringMatcherReturnsOff() public void ExecuteGetTreatmentWithStringMatcherReturnsOn() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", new ConfigurationOptions()); var attributes = new Dictionary { @@ -581,7 +577,7 @@ public void ExecuteGetTreatmentWithStringMatcherReturnsOn() public void ExecuteGetTreatmentWithDependencyMatcherReturnsOn() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", new ConfigurationOptions()); client.BlockUntilReady(1000); @@ -598,7 +594,7 @@ public void ExecuteGetTreatmentWithDependencyMatcherReturnsOn() public void ExecuteGetTreatmentWithDependencyMatcherReturnsOff() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", new ConfigurationOptions()); client.BlockUntilReady(1000); @@ -616,7 +612,7 @@ public void ExecuteGetTreatmentWithDependencyMatcherImpressionOnChild() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator, _eventsManager,impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", new ConfigurationOptions(),impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -634,7 +630,7 @@ public void GetTreatment_WhenNameDoesntExist_DontLogImpression() { // Arrange. var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); var splitName = "not_exist"; client.BlockUntilReady(1000); @@ -652,7 +648,7 @@ public void GetTreatment_WhenNameDoesntExist_DontLogImpression() public void GetTreatment_WithoutBlockUntiltReady_ReturnsOff() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); // Act. var result = client.GetTreatment("key", "anding"); @@ -668,7 +664,7 @@ public void GetTreatment_WithoutBlockUntiltReady_ReturnsOff() public void ExecuteGetTreatments() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); List features = new List { "fail", @@ -699,7 +695,7 @@ public void ExecuteGetTreatments() public void ExecuteGetTreatmentsWithBucketing() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); List features = new List { "fail", @@ -731,7 +727,7 @@ public void ExecuteGetTreatmentsWithBucketing() public void ExecuteGetTreatmentsWithDependencyMatcherReturnsOn() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", new ConfigurationOptions()); client.BlockUntilReady(1000); @@ -754,7 +750,7 @@ public void ExecuteGetTreatmentsWithDependencyMatcherReturnsOn() public void ExecuteGetTreatmentsWithDependencyMatcherWithAttributesReturnsOn() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", new ConfigurationOptions()); client.BlockUntilReady(1000); @@ -782,7 +778,7 @@ public void GetTreatments_WhenNameDoesntExist_DontLogImpression() { // Arrange. var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); var splitNames = new List { "not_exist", "not_exist_1" }; client.BlockUntilReady(1000); @@ -804,7 +800,7 @@ public void GetTreatments_WhenNameDoesntExist_DontLogImpression() public void GetTreatments_WithoutBlockUntiltReady_ReturnsEmptyList() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); // Act. var result = client.GetTreatments("key", new List()); @@ -818,7 +814,7 @@ public void GetTreatments_WithoutBlockUntiltReady_ReturnsEmptyList() public void GetTreatments_WithoutBlockUntiltReady_ReturnsTreatments() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); // Act. var result = client.GetTreatments("key", new List { "anding", "in_ten_keys" }); @@ -836,7 +832,7 @@ public void GetTreatments_WithoutBlockUntiltReady_ReturnsTreatments() public void GetTreatments_WhenClientIsReadyAndFeaturesIsEmpty_ReturnsEmptyList() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); client.BlockUntilReady(100); // Act. @@ -853,7 +849,7 @@ public void GetTreatments_WhenClientIsReadyAndFeaturesIsEmpty_ReturnsEmptyList() public void DestroySucessfully() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", new ConfigurationOptions()); var attributes = new Dictionary { @@ -889,7 +885,7 @@ public void Track_WhenClientIsNotReady_ReturnsTrue() // Arrange. var trafficTypeValidator = new Mock(); var eventLog = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, trafficTypeValidator: trafficTypeValidator.Object, eventsLog: eventLog.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions(), trafficTypeValidator: trafficTypeValidator.Object, eventsLog: eventLog.Object); trafficTypeValidator .Setup(mock => mock.IsValid(It.IsAny(), It.IsAny())) @@ -910,7 +906,7 @@ public void GetTreatmentWithConfig_WhenNameDoesntExist_DontLogImpression() { // Arrange. var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); var splitName = "not_exist"; client.BlockUntilReady(1000); @@ -929,7 +925,7 @@ public void GetTreatmentWithConfig_WhenNameDoesntExist_DontLogImpression() public void GetTreatmentWithConfig_WithoutBlockUntiltReady_ReturnsOff() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); // Act. var result = client.GetTreatmentWithConfig("key", "anding"); @@ -947,7 +943,7 @@ public void GetTreatmentsWithConfig_WhenNameDoesntExist_DontLogImpression() { // Arrange. var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); var splitNames = new List { "not_exist", "not_exist_1" }; client.BlockUntilReady(1000); @@ -970,7 +966,7 @@ public void GetTreatmentsWithConfig_WhenNameDoesntExist_DontLogImpression() public void GetTreatmentsWithConfig_WithoutBlockUntiltReady_ReturnsEmptyList() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); // Act. var result = client.GetTreatmentsWithConfig("anding", new List()); @@ -984,7 +980,7 @@ public void GetTreatmentsWithConfig_WithoutBlockUntiltReady_ReturnsEmptyList() public void GetTreatmentsWithConfig_WithoutBlockUntiltReady_ReturnsTreatments() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); // Act. var result = client.GetTreatmentsWithConfig("key", new List { "anding", "whitelisting_elements" }); @@ -1004,7 +1000,7 @@ public void GetTreatmentsWithConfig_WithoutBlockUntiltReady_ReturnsTreatments() public void GetTreatmentsWithConfig_WhenClientIsReadyAndFeaturesIsEmpty_ReturnsEmptyList() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); client.BlockUntilReady(100); // Act. @@ -1021,7 +1017,7 @@ public void GetTreatmentsWithConfig_WhenClientIsReadyAndFeaturesIsEmpty_ReturnsE public void Split_Manager_WhenNameDoesntExist_ReturnsNull() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", new ConfigurationOptions()); var manager = client.GetSplitManager(); var splitName = "not_exist"; diff --git a/tests/Splitio-tests/Integration Tests/RedisClientTests.cs b/tests/Splitio-tests/Integration Tests/RedisClientTests.cs index f600179a0..5b7ea4c79 100644 --- a/tests/Splitio-tests/Integration Tests/RedisClientTests.cs +++ b/tests/Splitio-tests/Integration Tests/RedisClientTests.cs @@ -67,7 +67,7 @@ public void Initialization() public void GetTreatment_WhenFeatureExists_ReturnsOn() { //Arrange - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client = new RedisClient(config, API_KEY); client.BlockUntilReady(5000); @@ -78,7 +78,7 @@ public void GetTreatment_WhenFeatureExists_ReturnsOn() Assert.IsNotNull(result); Assert.AreEqual("on", result); - var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY); client2.BlockUntilReady(5000); @@ -94,7 +94,7 @@ public void GetTreatment_WhenFeatureExists_ReturnsOn() public void GetTreatment_WhenFeatureExists_ReturnsOff() { //Arrange - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client = new RedisClient(config, API_KEY); client.BlockUntilReady(5000); @@ -105,7 +105,7 @@ public void GetTreatment_WhenFeatureExists_ReturnsOff() Assert.IsNotNull(result); Assert.AreEqual("off", result); - var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY); client2.BlockUntilReady(5000); result = client2.GetTreatment("test", "always_off", null); @@ -119,7 +119,7 @@ public void GetTreatment_WhenFeatureExists_ReturnsOff() public void GetTreatment_WhenFeatureDoenstExist_ReturnsControl() { //Arrange - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client = new RedisClient(config, API_KEY); client.BlockUntilReady(5000); //Act @@ -129,7 +129,7 @@ public void GetTreatment_WhenFeatureDoenstExist_ReturnsControl() Assert.IsNotNull(result); Assert.AreEqual("control", result); - var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY); client2.BlockUntilReady(5000); result = client2.GetTreatment("test", "always_control", null); @@ -148,7 +148,7 @@ public void GetTreatments_WhenFeaturesExists_ReturnsOnOff() var features = new List { alwaysOn, alwaysOff }; - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client = new RedisClient(config, API_KEY); client.BlockUntilReady(5000); @@ -162,7 +162,7 @@ public void GetTreatments_WhenFeaturesExists_ReturnsOnOff() var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), - API_KEY, _fallbackTreatmentCalculator, _eventsManager); + API_KEY); client2.BlockUntilReady(5000); result = client2.GetTreatments("test", features, null); @@ -183,7 +183,7 @@ public void GetTreatments_WhenOneFeatureDoenstExist_ReturnsOnOffControl() var features = new List { alwaysOn, alwaysOff, alwaysControl }; - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client = new RedisClient(config, API_KEY); client.BlockUntilReady(5000); @@ -196,8 +196,7 @@ public void GetTreatments_WhenOneFeatureDoenstExist_ReturnsOnOffControl() Assert.AreEqual("on", result[alwaysOn]); Assert.AreEqual("control", result[alwaysControl]); - var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), - API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY); client2.BlockUntilReady(5000); result = client2.GetTreatments("test", features, null); @@ -213,7 +212,7 @@ public void GetTreatments_WhenOneFeatureDoenstExist_ReturnsOnOffControl() public void GetTreatmentsWithConfig_WhenClientIsNotReady_ReturnsControl() { // Arrange. - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client = new RedisClient(config, API_KEY); // Act. var result = client.GetTreatmentsWithConfig("key", new List()); @@ -225,8 +224,7 @@ public void GetTreatmentsWithConfig_WhenClientIsNotReady_ReturnsControl() Assert.IsNull(res.Value.Config); } - var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), -API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY); client2.BlockUntilReady(5000); result = client2.GetTreatmentsWithConfig("key", new List()); @@ -243,7 +241,7 @@ public void GetTreatmentsWithConfig_WhenClientIsNotReady_ReturnsControl() public void GetTreatmentWithConfig_WhenClientIsNotReady_ReturnsControl() { // Arrange. - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client = new RedisClient(config, API_KEY); // Act. var result = client.GetTreatmentWithConfig("key", string.Empty); @@ -252,8 +250,7 @@ public void GetTreatmentWithConfig_WhenClientIsNotReady_ReturnsControl() Assert.AreEqual("control", result.Treatment); Assert.IsNull(result.Config); - var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), -API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY); client2.BlockUntilReady(5000); result = client2.GetTreatmentWithConfig("key", string.Empty); @@ -267,7 +264,7 @@ public void GetTreatmentWithConfig_WhenClientIsNotReady_ReturnsControl() public void GetTreatment_WhenClientIsNotReady_ReturnsControl() { // Arrange. - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client = new RedisClient(config, API_KEY); // Act. var result = client.GetTreatment("key", string.Empty); @@ -275,8 +272,7 @@ public void GetTreatment_WhenClientIsNotReady_ReturnsControl() // Assert. Assert.AreEqual("control", result); - var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), -API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY); client2.BlockUntilReady(5000); result = client2.GetTreatment("key", string.Empty); @@ -290,7 +286,7 @@ public void GetTreatments_WhenClientIsNotReady_ReturnsControl() { // Arrange. config.CacheAdapterConfig.Host = "fake-host"; - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client = new RedisClient(config, API_KEY); // Act. var result = client.GetTreatments("key", new List()); @@ -301,7 +297,7 @@ public void GetTreatments_WhenClientIsNotReady_ReturnsControl() Assert.AreEqual("control", res.Value); } - var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY); client2.BlockUntilReady(5000); result = client2.GetTreatments("key", new List()); @@ -317,7 +313,7 @@ public void GetTreatments_WhenClientIsNotReady_ReturnsControl() public void Track_WhenClientIsNotReady_ReturnsTrue() { // Arrange. - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client = new RedisClient(config, API_KEY); // Act. var result = client.Track("key", "traffic_type", "event_type"); @@ -325,8 +321,7 @@ public void Track_WhenClientIsNotReady_ReturnsTrue() // Assert. Assert.IsTrue(result); - var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), -API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY); client2.BlockUntilReady(5000); // Act. @@ -343,9 +338,9 @@ public void FallbackTreatments_WhenFeatureDoesNotExist() var features = new List { alwaysOn, "feature", alwaysControl }; FallbackTreatmentsConfiguration fallbackTreatmentsConfiguration = new FallbackTreatmentsConfiguration(new FallbackTreatment("on-global", "\"prop\":\"global\""), new Dictionary() { { "feature", new FallbackTreatment("off-local", "\"prop\":\"local\"") } }); - FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(fallbackTreatmentsConfiguration); + config.FallbackTreatments = fallbackTreatmentsConfiguration; - var client = new RedisClient(config, API_KEY, fallbackTreatmentCalculator, _eventsManager); + var client = new RedisClient(config, API_KEY); client.BlockUntilReady(5000); @@ -380,10 +375,10 @@ public void FallbackTreatments_WhenClientNotReady() var features = new List { "feature" }; FallbackTreatmentsConfiguration fallbackTreatmentsConfiguration = new FallbackTreatmentsConfiguration(new FallbackTreatment("on-global", "\"prop\":\"global\""), new Dictionary() { { "feature", new FallbackTreatment("off-local", "\"prop\":\"local\"") } }); - FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(fallbackTreatmentsConfiguration); config.CacheAdapterConfig.Host = "fake-host"; - var client = new RedisClient(config, API_KEY, fallbackTreatmentCalculator, _eventsManager); + config.FallbackTreatments = fallbackTreatmentsConfiguration; + var client = new RedisClient(config, API_KEY); //Act var result = client.GetTreatmentsWithConfig("test", features, null); @@ -403,9 +398,9 @@ public void FallbackTreatments_WhenExceptionOccurrs() var features = new List { "always_off" }; FallbackTreatmentsConfiguration fallbackTreatmentsConfiguration = new FallbackTreatmentsConfiguration(new FallbackTreatment("on-global", "\"prop\":\"global\""), new Dictionary() { { "feature", new FallbackTreatment("off-local", "\"prop\":\"local\"") } }); - FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(fallbackTreatmentsConfiguration); + config.FallbackTreatments = fallbackTreatmentsConfiguration; - var client = new RedisClient(config, API_KEY, fallbackTreatmentCalculator, _eventsManager); + var client = new RedisClient(config, API_KEY); client.BlockUntilReady(5000); @@ -434,7 +429,7 @@ public void FallbackTreatments_WhenExceptionOccurrs() public void Destroy() { //Arrange - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); + var client = new RedisClient(config, API_KEY); client.BlockUntilReady(5000); //Act diff --git a/tests/Splitio-tests/Unit Tests/Client/LocalhostClientForTesting.cs b/tests/Splitio-tests/Unit Tests/Client/LocalhostClientForTesting.cs index deb27c042..49a16aeea 100644 --- a/tests/Splitio-tests/Unit Tests/Client/LocalhostClientForTesting.cs +++ b/tests/Splitio-tests/Unit Tests/Client/LocalhostClientForTesting.cs @@ -1,13 +1,10 @@ -using Splitio.Domain; -using Splitio.Services.Client.Classes; -using Splitio.Services.Common; -using Splitio.Services.Impressions.Classes; +using Splitio.Services.Client.Classes; namespace Splitio_Tests.Unit_Tests.Client { public class LocalhostClientForTesting : LocalhostClient { - public LocalhostClientForTesting(string filePath, FallbackTreatmentCalculator fallbackTreatmentCalculator) : base(new ConfigurationOptions { LocalhostFilePath = filePath }, fallbackTreatmentCalculator, new EventsManager(new EventsManagerConfig(), new EventDelivery())) + public LocalhostClientForTesting(string filePath) : base(new ConfigurationOptions { LocalhostFilePath = filePath }) { } } } diff --git a/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs b/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs index 7bdfe24ac..4609cd16e 100644 --- a/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs @@ -4,7 +4,6 @@ using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; using Splitio.Services.Shared.Classes; -using WireMock.Pact.Models.V2; namespace Splitio_Tests.Unit_Tests.Client { @@ -33,7 +32,7 @@ public LocalhostClientUnitTests() public void GetTreatmentShouldReturnControlIfSplitNotFound() { //Arrange - var splitClient = new LocalhostClient(new ConfigurationOptions { LocalhostFilePath = $"{rootFilePath}test.splits" }, _fallbackTreatmentCalculator, _eventsManager); + var splitClient = new LocalhostClient(new ConfigurationOptions { LocalhostFilePath = $"{rootFilePath}test.splits" }); //Act var result = splitClient.GetTreatment("test", "test"); @@ -46,7 +45,7 @@ public void GetTreatmentShouldReturnControlIfSplitNotFound() [DeploymentItem(@"Resources\test.splits")] public void GetTreatmentShouldRunAsSingleKeyUsingNullBucketingKey() { - var splitClient = new LocalhostClient(new ConfigurationOptions { LocalhostFilePath = $"{rootFilePath}test.splits" }, _fallbackTreatmentCalculator, _eventsManager); + var splitClient = new LocalhostClient(new ConfigurationOptions { LocalhostFilePath = $"{rootFilePath}test.splits" }); splitClient.BlockUntilReady(1000); //Act @@ -62,7 +61,7 @@ public void GetTreatmentShouldRunAsSingleKeyUsingNullBucketingKey() public void TrackShouldNotStoreEvents() { //Arrange - var splitClient = new LocalhostClientForTesting($"{rootFilePath}test.splits", _fallbackTreatmentCalculator); + var splitClient = new LocalhostClientForTesting($"{rootFilePath}test.splits"); splitClient.BlockUntilReady(1000); //Act @@ -78,7 +77,7 @@ public void Destroy() { //Arrange var _factoryInstantiationsService = FactoryInstantiationsService.Instance(); - var splitClient = new LocalhostClientForTesting($"{rootFilePath}test.splits", _fallbackTreatmentCalculator); + var splitClient = new LocalhostClientForTesting($"{rootFilePath}test.splits"); //Act splitClient.BlockUntilReady(10000); diff --git a/tests/Splitio-tests/Unit Tests/Client/SplitClientAsyncTests.cs b/tests/Splitio-tests/Unit Tests/Client/SplitClientAsyncTests.cs index ebacf3498..9b377b342 100644 --- a/tests/Splitio-tests/Unit Tests/Client/SplitClientAsyncTests.cs +++ b/tests/Splitio-tests/Unit Tests/Client/SplitClientAsyncTests.cs @@ -2,6 +2,7 @@ using Moq; using Splitio.Domain; using Splitio.Services.Cache.Interfaces; +using Splitio.Services.Client.Classes; using Splitio.Services.Client.Interfaces; using Splitio.Services.Common; using Splitio.Services.EngineEvaluator; @@ -40,7 +41,7 @@ public SplitClientAsyncTests() _syncManager = new Mock(); _telemetryEvaluationProducer = new Mock(); - _splitClient = new SplitClientForTesting(_splitCache.Object, _eventsLog.Object, _impressionsLog.Object, _blockUntilReadyService.Object, _evaluator.Object, _impressionsManager.Object, _syncManager.Object, new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()), _telemetryEvaluationProducer.Object); + _splitClient = new SplitClientForTesting(_splitCache.Object, _eventsLog.Object, _impressionsLog.Object, _blockUntilReadyService.Object, _evaluator.Object, _impressionsManager.Object, _syncManager.Object, _telemetryEvaluationProducer.Object, new ConfigurationOptions()); } #region GetTreatmentAsync @@ -1005,7 +1006,8 @@ public async Task FallbackTreatments_WhenFlagDoesNotExist() FallbackTreatmentsConfiguration fallbackTreatmentsConfiguration = new FallbackTreatmentsConfiguration(new FallbackTreatment("on-global", "\"prop\":\"global\""), new Dictionary() { { splitName, new FallbackTreatment("off-local", "\"prop\":\"local\"") } }); FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(fallbackTreatmentsConfiguration); IEvaluator _evaluator = new Splitio.Services.Evaluator.Evaluator(_splitCache.Object, _splitter.Object, _telemetryEvaluationProducer.Object, fallbackTreatmentCalculator); - _splitClient = new SplitClientForTesting(_splitCache.Object, _eventsLog.Object, new Mock().Object, _blockUntilReadyService.Object, _evaluator, _impressionsManager.Object, _syncManager.Object, fallbackTreatmentCalculator, _telemetryEvaluationProducer.Object); + _splitClient = new SplitClientForTesting(_splitCache.Object, _eventsLog.Object, new Mock().Object, _blockUntilReadyService.Object, _evaluator, _impressionsManager.Object, _syncManager.Object, _telemetryEvaluationProducer.Object, + new ConfigurationOptions { FallbackTreatments = fallbackTreatmentsConfiguration }); _splitClient.BlockUntilReady(1000); string treatment = await _splitClient.GetTreatmentAsync("key", splitName); @@ -1077,13 +1079,13 @@ public async Task FallbackTreatments_WhenExceptionInClient() .Returns(true); FallbackTreatmentsConfiguration fallbackTreatmentsConfiguration = new FallbackTreatmentsConfiguration(new FallbackTreatment("on-global", "\"prop\":\"global\""), new Dictionary() { { splitName, new FallbackTreatment("off-local", "\"prop\":\"local\"") } }); - FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(fallbackTreatmentsConfiguration); _evaluator = new Mock(); _evaluator .Setup(mock => mock.EvaluateFeaturesAsync(It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), true)) .Throws(); - _splitClient = new SplitClientForTesting(_splitCache.Object, _eventsLog.Object, new Mock().Object, _blockUntilReadyService.Object, _evaluator.Object, _impressionsManager.Object, _syncManager.Object, fallbackTreatmentCalculator, _telemetryEvaluationProducer.Object); + _splitClient = new SplitClientForTesting(_splitCache.Object, _eventsLog.Object, new Mock().Object, _blockUntilReadyService.Object, _evaluator.Object, _impressionsManager.Object, _syncManager.Object, _telemetryEvaluationProducer.Object, + new ConfigurationOptions { FallbackTreatments = fallbackTreatmentsConfiguration }); _splitClient.BlockUntilReady(1000); string treatment = await _splitClient.GetTreatmentAsync("key", splitName); diff --git a/tests/Splitio-tests/Unit Tests/Client/SplitClientForTesting.cs b/tests/Splitio-tests/Unit Tests/Client/SplitClientForTesting.cs index a44f94ebd..2cc6936ba 100644 --- a/tests/Splitio-tests/Unit Tests/Client/SplitClientForTesting.cs +++ b/tests/Splitio-tests/Unit Tests/Client/SplitClientForTesting.cs @@ -1,10 +1,8 @@ -using Splitio.Domain; -using Splitio.Services.Cache.Interfaces; +using Splitio.Services.Cache.Interfaces; using Splitio.Services.Client.Classes; using Splitio.Services.Common; using Splitio.Services.Evaluator; using Splitio.Services.Events.Interfaces; -using Splitio.Services.Impressions.Classes; using Splitio.Services.Impressions.Interfaces; using Splitio.Services.InputValidation.Classes; using Splitio.Services.Shared.Interfaces; @@ -21,9 +19,9 @@ public SplitClientForTesting(IFeatureFlagCacheConsumer featureFlagCacheConsumer, IEvaluator evaluator, IImpressionsManager impressionsManager, ISyncManager syncManager, - FallbackTreatmentCalculator fallbackTreatmentCalculator, - ITelemetryEvaluationProducer telemetryEvaluationProducer) - : base("SplitClientForTesting", fallbackTreatmentCalculator, new EventsManager(new EventsManagerConfig(), new EventDelivery())) + ITelemetryEvaluationProducer telemetryEvaluationProducer, + ConfigurationOptions config) + : base("SplitClientForTesting", config) { _eventsLog = eventsLog; _impressionsLog = impressionsLog; diff --git a/tests/Splitio-tests/Unit Tests/Client/SplitClientUnitTests.cs b/tests/Splitio-tests/Unit Tests/Client/SplitClientUnitTests.cs index 842b81a7d..1b9c56360 100644 --- a/tests/Splitio-tests/Unit Tests/Client/SplitClientUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/Client/SplitClientUnitTests.cs @@ -45,7 +45,7 @@ public void TestInitialize() _syncManager = new Mock(); _telemetryEvaluationProducer = new Mock(); - _splitClientForTesting = new SplitClientForTesting(_splitCacheMock.Object, _eventsLogMock.Object, new Mock().Object, _blockUntilReadyService.Object, _evaluatorMock.Object, _impressionsManager.Object, _syncManager.Object, new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()), _telemetryEvaluationProducer.Object); + _splitClientForTesting = new SplitClientForTesting(_splitCacheMock.Object, _eventsLogMock.Object, new Mock().Object, _blockUntilReadyService.Object, _evaluatorMock.Object, _impressionsManager.Object, _syncManager.Object, _telemetryEvaluationProducer.Object, new ConfigurationOptions()); _splitClientForTesting.BlockUntilReady(1000); } @@ -779,7 +779,8 @@ public void FallbackTreatments_WhenFlagDoesNotExist() FallbackTreatmentsConfiguration fallbackTreatmentsConfiguration = new FallbackTreatmentsConfiguration(new FallbackTreatment("on-global", "\"prop\":\"global\""), new Dictionary() { { splitName, new FallbackTreatment("off-local", "\"prop\":\"local\"") } }); FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(fallbackTreatmentsConfiguration); IEvaluator _evaluator = new Splitio.Services.Evaluator.Evaluator(_splitCache.Object, _splitter.Object, _telemetryEvaluationProducer.Object, fallbackTreatmentCalculator); - _splitClientForTesting = new SplitClientForTesting(_splitCache.Object, _eventsLogMock.Object, new Mock().Object, _blockUntilReadyService.Object, _evaluator, _impressionsManager.Object, _syncManager.Object, fallbackTreatmentCalculator, _telemetryEvaluationProducer.Object); + _splitClientForTesting = new SplitClientForTesting(_splitCache.Object, _eventsLogMock.Object, new Mock().Object, _blockUntilReadyService.Object, _evaluator, _impressionsManager.Object, _syncManager.Object, _telemetryEvaluationProducer.Object, + new ConfigurationOptions { FallbackTreatments = fallbackTreatmentsConfiguration }); _splitClientForTesting.BlockUntilReady(1000); string treatment = _splitClientForTesting.GetTreatment("key", splitName); @@ -851,13 +852,13 @@ public void FallbackTreatments_WhenExceptionInClient() .Returns(true); FallbackTreatmentsConfiguration fallbackTreatmentsConfiguration = new FallbackTreatmentsConfiguration(new FallbackTreatment("on-global", "\"prop\":\"global\""), new Dictionary() { { splitName, new FallbackTreatment("off-local", "\"prop\":\"local\"") } }); - FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(fallbackTreatmentsConfiguration); _evaluatorMock = new Mock(); _evaluatorMock .Setup(mock => mock.EvaluateFeatures(It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), true)) .Throws(); - _splitClientForTesting = new SplitClientForTesting(_splitCache.Object, _eventsLogMock.Object, new Mock().Object, _blockUntilReadyService.Object, _evaluatorMock.Object, _impressionsManager.Object, _syncManager.Object, fallbackTreatmentCalculator, _telemetryEvaluationProducer.Object); + _splitClientForTesting = new SplitClientForTesting(_splitCache.Object, _eventsLogMock.Object, new Mock().Object, _blockUntilReadyService.Object, _evaluatorMock.Object, _impressionsManager.Object, _syncManager.Object, _telemetryEvaluationProducer.Object, + new ConfigurationOptions { FallbackTreatments = fallbackTreatmentsConfiguration }); _splitClientForTesting.BlockUntilReady(1000); string treatment = _splitClientForTesting.GetTreatment("key", splitName); diff --git a/tests/Splitio-tests/Unit Tests/Impressions/ImpressionsCounterTests.cs b/tests/Splitio-tests/Unit Tests/Impressions/ImpressionsCounterTests.cs index 049312b8f..46424da13 100644 --- a/tests/Splitio-tests/Unit Tests/Impressions/ImpressionsCounterTests.cs +++ b/tests/Splitio-tests/Unit Tests/Impressions/ImpressionsCounterTests.cs @@ -53,7 +53,7 @@ public void Start_ShouldNotSendImpressionsCount() { // Arrange. var config = new ComponentConfig(5, 5); - var statusManager = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); + var statusManager = new InMemoryReadinessGatesCache(new Mock>().Object); var taskManager = new TasksManager(statusManager); var task = taskManager.NewPeriodicTask(Splitio.Enums.Task.ImpressionsCountSender, 1); var sendBulkDataTask = taskManager.NewOnTimeTask(Splitio.Enums.Task.ImpressionCounterSendBulkData); @@ -72,7 +72,7 @@ public async Task Stop_ShouldSendImpressionsCount() { // Arrange. var config = new ComponentConfig(5, 5); - var statusManager = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); + var statusManager = new InMemoryReadinessGatesCache(new Mock>().Object); var taskManager = new TasksManager(statusManager); var task = taskManager.NewPeriodicTask(Splitio.Enums.Task.ImpressionsCountSender, 100); var sendBulkDataTask = taskManager.NewOnTimeTask(Splitio.Enums.Task.ImpressionCounterSendBulkData); @@ -96,7 +96,7 @@ public async Task Stop_ShouldSendImpressionsCount() public async Task ShouldSend2BulksOfImpressions() { var config = new ComponentConfig(6, 3); - var statusManager = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); + var statusManager = new InMemoryReadinessGatesCache(new Mock>().Object); var taskManager = new TasksManager(statusManager); var task = taskManager.NewPeriodicTask(Splitio.Enums.Task.ImpressionsCountSender, 100); var sendBulkDataTask = taskManager.NewOnTimeTask(Splitio.Enums.Task.ImpressionCounterSendBulkData); diff --git a/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs b/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs index 8e7110ca5..2b8456988 100644 --- a/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs @@ -26,7 +26,7 @@ public class SelfRefreshingSegmentFetcherUnitTests public void InitializeSegmentNotExistent() { // Arrange - var gates = new InMemoryReadinessGatesCache(new Mock>().Object); + var gates = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig(), new EventDelivery())); gates.SetReady(); var apiClient = new Mock(); var apiFetcher = new ApiSegmentChangeFetcher(apiClient.Object); diff --git a/tests/Splitio.TestSupport/Samples/SampleTest.cs b/tests/Splitio.TestSupport/Samples/SampleTest.cs index ecaee10a3..9633110a7 100644 --- a/tests/Splitio.TestSupport/Samples/SampleTest.cs +++ b/tests/Splitio.TestSupport/Samples/SampleTest.cs @@ -1,6 +1,4 @@ -using Moq; -using Splitio.Services.Client.Classes; -using Splitio.Services.Logger; +using Splitio.Services.Client.Classes; using Xunit; namespace Splitio.TestSupport.Samples @@ -11,7 +9,7 @@ public class SampleTest public SampleTest() { - splitClient = new SplitClientForTest(); + splitClient = new SplitClientForTest(new ConfigurationOptions()); } [Theory] diff --git a/tests/Splitio.TestSupport/SplitClientForTest.cs b/tests/Splitio.TestSupport/SplitClientForTest.cs index 363380c2d..101d52107 100644 --- a/tests/Splitio.TestSupport/SplitClientForTest.cs +++ b/tests/Splitio.TestSupport/SplitClientForTest.cs @@ -10,8 +10,7 @@ public class SplitClientForTest : SplitClient { private readonly Dictionary _tests; - public SplitClientForTest() : base("SplitClientForTest", new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()), - new EventsManager(new EventsManagerConfig(), new EventDelivery())) + public SplitClientForTest(ConfigurationOptions config) : base("SplitClientForTest", config) { _tests = new Dictionary(); }