Skip to content

Commit 25ad73c

Browse files
authored
Feat: Added set polling interval and set blocking timeout period method in OptimizelyFactory (#264)
1 parent a436510 commit 25ad73c

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

OptimizelySDK.Tests/OptimizelyFactoryTest.cs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2020, Optimizely and contributors
3+
* Copyright 2020-2021, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -62,7 +62,6 @@ public void TestOptimizelyInstanceUsingConfigFile()
6262
optimizely.Dispose();
6363
}
6464

65-
6665
[Test]
6766
public void TestProjectConfigManagerUsingSDKKey()
6867
{
@@ -78,8 +77,8 @@ public void TestProjectConfigManagerUsingSDKKey()
7877
Url = "https://cdn.optimizely.com/datafiles/my-sdk-key.json",
7978
LastModified = "",
8079
AutoUpdate = true,
81-
BlockingTimeout = TimeSpan.FromSeconds(15),
82-
PollingInterval = TimeSpan.FromMinutes(5)
80+
BlockingTimeout = TimeSpan.FromSeconds(30),
81+
PollingInterval = TimeSpan.FromMilliseconds(2023)
8382
};
8483

8584
Assert.AreEqual(actualConfigManagerProps, expectedConfigManagerProps);
@@ -102,15 +101,40 @@ public void TestProjectConfigManagerWithDatafileAccessToken()
102101
LastModified = "",
103102
DatafileAccessToken = "access-token",
104103
AutoUpdate = true,
105-
BlockingTimeout = TimeSpan.FromSeconds(15),
106-
PollingInterval = TimeSpan.FromMinutes(5)
104+
BlockingTimeout = TimeSpan.FromSeconds(30),
105+
PollingInterval = TimeSpan.FromMilliseconds(2023)
107106
};
108107

109108
Assert.AreEqual(actualConfigManagerProps, expectedConfigManagerProps);
110109

111110
optimizely.Dispose();
112111
}
113112

113+
[Test]
114+
public void TestOptimizelyInstanceUsingConfigNotUseFactoryClassBlockingTimeoutAndPollingInterval()
115+
{
116+
OptimizelyFactory.SetBlockingTimeOutPeriod(TimeSpan.FromSeconds(30));
117+
OptimizelyFactory.SetPollingInterval(TimeSpan.FromMilliseconds(2023));
118+
var optimizely = OptimizelyFactory.NewDefaultInstance();
119+
// Check values are loaded from app.config or not.
120+
var projectConfigManager = optimizely.ProjectConfigManager as HttpProjectConfigManager;
121+
Assert.NotNull(projectConfigManager);
122+
123+
var actualConfigManagerProps = new ProjectConfigManagerProps(projectConfigManager);
124+
var expectedConfigManagerProps = new ProjectConfigManagerProps
125+
{
126+
Url = "www.testurl.com",
127+
LastModified = "",
128+
AutoUpdate = true,
129+
DatafileAccessToken = "testingtoken123",
130+
BlockingTimeout = TimeSpan.FromMilliseconds(10000),
131+
PollingInterval = TimeSpan.FromMilliseconds(2000)
132+
};
133+
134+
Assert.AreEqual(actualConfigManagerProps, expectedConfigManagerProps);
135+
optimizely.Dispose();
136+
}
137+
114138
[Test]
115139
public void TestProjectConfigManagerWithCustomProjectConfigManager()
116140
{

OptimizelySDK/OptimizelyFactory.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2020, Optimizely
2+
* Copyright 2019-2021, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use file except in compliance with the License.
@@ -35,6 +35,8 @@ public static class OptimizelyFactory
3535
{
3636
private static int MaxEventBatchSize;
3737
private static TimeSpan MaxEventFlushInterval;
38+
private static TimeSpan PollingInterval;
39+
private static TimeSpan BlockingTimeOutPeriod;
3840
private static ILogger OptimizelyLogger;
3941
private const string ConfigSectionName = "optlySDKConfigSection";
4042

@@ -49,6 +51,16 @@ public static void SetFlushInterval(TimeSpan flushInterval)
4951
MaxEventFlushInterval = flushInterval;
5052
}
5153

54+
public static void SetPollingInterval(TimeSpan pollingInterval)
55+
{
56+
PollingInterval = pollingInterval;
57+
}
58+
59+
public static void SetBlockingTimeOutPeriod(TimeSpan blockingTimeOutPeriod)
60+
{
61+
BlockingTimeOutPeriod = blockingTimeOutPeriod;
62+
}
63+
5264
public static void SetLogger(ILogger logger)
5365
{
5466
OptimizelyLogger = logger;
@@ -76,7 +88,6 @@ public static Optimizely NewDefaultInstance()
7688
var eventDispatcher = new DefaultEventDispatcher(logger);
7789
var builder = new HttpProjectConfigManager.Builder();
7890
var notificationCenter = new NotificationCenter();
79-
8091
var configManager = builder
8192
.WithSdkKey(httpProjectConfigElement.SDKKey)
8293
.WithUrl(httpProjectConfigElement.Url)
@@ -111,7 +122,7 @@ public static Optimizely NewDefaultInstance()
111122
}
112123
#endif
113124

114-
public static Optimizely NewDefaultInstance(string sdkKey)
125+
public static Optimizely NewDefaultInstance(string sdkKey)
115126
{
116127
return NewDefaultInstance(sdkKey, null);
117128
}
@@ -128,6 +139,8 @@ public static Optimizely NewDefaultInstance(string sdkKey, string fallback, stri
128139
.WithSdkKey(sdkKey)
129140
.WithDatafile(fallback)
130141
.WithLogger(logger)
142+
.WithPollingInterval(PollingInterval)
143+
.WithBlockingTimeoutPeriod(BlockingTimeOutPeriod)
131144
.WithErrorHandler(errorHandler)
132145
.WithAccessToken(datafileAuthToken)
133146
.WithNotificationCenter(notificationCenter)
@@ -160,6 +173,8 @@ public static Optimizely NewDefaultInstance(string sdkKey, string fallback)
160173
.WithSdkKey(sdkKey)
161174
.WithDatafile(fallback)
162175
.WithLogger(logger)
176+
.WithPollingInterval(PollingInterval)
177+
.WithBlockingTimeoutPeriod(BlockingTimeOutPeriod)
163178
.WithErrorHandler(errorHandler)
164179
.WithNotificationCenter(notificationCenter)
165180
.Build(true);

0 commit comments

Comments
 (0)