diff --git a/OptimizelySDK.Tests/OptimizelyFactoryTest.cs b/OptimizelySDK.Tests/OptimizelyFactoryTest.cs index 1ae01b44..92d2a23b 100644 --- a/OptimizelySDK.Tests/OptimizelyFactoryTest.cs +++ b/OptimizelySDK.Tests/OptimizelyFactoryTest.cs @@ -1,6 +1,6 @@ /** * - * Copyright 2020, Optimizely and contributors + * Copyright 2020-2021, Optimizely and contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,7 +62,6 @@ public void TestOptimizelyInstanceUsingConfigFile() optimizely.Dispose(); } - [Test] public void TestProjectConfigManagerUsingSDKKey() { @@ -78,8 +77,8 @@ public void TestProjectConfigManagerUsingSDKKey() Url = "https://cdn.optimizely.com/datafiles/my-sdk-key.json", LastModified = "", AutoUpdate = true, - BlockingTimeout = TimeSpan.FromSeconds(15), - PollingInterval = TimeSpan.FromMinutes(5) + BlockingTimeout = TimeSpan.FromSeconds(30), + PollingInterval = TimeSpan.FromMilliseconds(2023) }; Assert.AreEqual(actualConfigManagerProps, expectedConfigManagerProps); @@ -102,8 +101,8 @@ public void TestProjectConfigManagerWithDatafileAccessToken() LastModified = "", DatafileAccessToken = "access-token", AutoUpdate = true, - BlockingTimeout = TimeSpan.FromSeconds(15), - PollingInterval = TimeSpan.FromMinutes(5) + BlockingTimeout = TimeSpan.FromSeconds(30), + PollingInterval = TimeSpan.FromMilliseconds(2023) }; Assert.AreEqual(actualConfigManagerProps, expectedConfigManagerProps); @@ -111,6 +110,31 @@ public void TestProjectConfigManagerWithDatafileAccessToken() optimizely.Dispose(); } + [Test] + public void TestOptimizelyInstanceUsingConfigNotUseFactoryClassBlockingTimeoutAndPollingInterval() + { + OptimizelyFactory.SetBlockingTimeOutPeriod(TimeSpan.FromSeconds(30)); + OptimizelyFactory.SetPollingInterval(TimeSpan.FromMilliseconds(2023)); + var optimizely = OptimizelyFactory.NewDefaultInstance(); + // Check values are loaded from app.config or not. + var projectConfigManager = optimizely.ProjectConfigManager as HttpProjectConfigManager; + Assert.NotNull(projectConfigManager); + + var actualConfigManagerProps = new ProjectConfigManagerProps(projectConfigManager); + var expectedConfigManagerProps = new ProjectConfigManagerProps + { + Url = "www.testurl.com", + LastModified = "", + AutoUpdate = true, + DatafileAccessToken = "testingtoken123", + BlockingTimeout = TimeSpan.FromMilliseconds(10000), + PollingInterval = TimeSpan.FromMilliseconds(2000) + }; + + Assert.AreEqual(actualConfigManagerProps, expectedConfigManagerProps); + optimizely.Dispose(); + } + [Test] public void TestProjectConfigManagerWithCustomProjectConfigManager() { diff --git a/OptimizelySDK/OptimizelyFactory.cs b/OptimizelySDK/OptimizelyFactory.cs index 95d74960..8e78bcf8 100644 --- a/OptimizelySDK/OptimizelyFactory.cs +++ b/OptimizelySDK/OptimizelyFactory.cs @@ -1,5 +1,5 @@ /* - * Copyright 2019-2020, Optimizely + * Copyright 2019-2021, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use file except in compliance with the License. @@ -35,6 +35,8 @@ public static class OptimizelyFactory { private static int MaxEventBatchSize; private static TimeSpan MaxEventFlushInterval; + private static TimeSpan PollingInterval; + private static TimeSpan BlockingTimeOutPeriod; private static ILogger OptimizelyLogger; private const string ConfigSectionName = "optlySDKConfigSection"; @@ -49,6 +51,16 @@ public static void SetFlushInterval(TimeSpan flushInterval) MaxEventFlushInterval = flushInterval; } + public static void SetPollingInterval(TimeSpan pollingInterval) + { + PollingInterval = pollingInterval; + } + + public static void SetBlockingTimeOutPeriod(TimeSpan blockingTimeOutPeriod) + { + BlockingTimeOutPeriod = blockingTimeOutPeriod; + } + public static void SetLogger(ILogger logger) { OptimizelyLogger = logger; @@ -76,7 +88,6 @@ public static Optimizely NewDefaultInstance() var eventDispatcher = new DefaultEventDispatcher(logger); var builder = new HttpProjectConfigManager.Builder(); var notificationCenter = new NotificationCenter(); - var configManager = builder .WithSdkKey(httpProjectConfigElement.SDKKey) .WithUrl(httpProjectConfigElement.Url) @@ -111,7 +122,7 @@ public static Optimizely NewDefaultInstance() } #endif - public static Optimizely NewDefaultInstance(string sdkKey) + public static Optimizely NewDefaultInstance(string sdkKey) { return NewDefaultInstance(sdkKey, null); } @@ -128,6 +139,8 @@ public static Optimizely NewDefaultInstance(string sdkKey, string fallback, stri .WithSdkKey(sdkKey) .WithDatafile(fallback) .WithLogger(logger) + .WithPollingInterval(PollingInterval) + .WithBlockingTimeoutPeriod(BlockingTimeOutPeriod) .WithErrorHandler(errorHandler) .WithAccessToken(datafileAuthToken) .WithNotificationCenter(notificationCenter) @@ -160,6 +173,8 @@ public static Optimizely NewDefaultInstance(string sdkKey, string fallback) .WithSdkKey(sdkKey) .WithDatafile(fallback) .WithLogger(logger) + .WithPollingInterval(PollingInterval) + .WithBlockingTimeoutPeriod(BlockingTimeOutPeriod) .WithErrorHandler(errorHandler) .WithNotificationCenter(notificationCenter) .Build(true);