8000 feat: Fix NotificationCenter Issue for ODPManager by mikechu-optimizely · Pull Request #324 · optimizely/csharp-sdk · GitHub
[go: up one dir, main page]

Skip to content

feat: Fix NotificationCenter Issue for ODPManager #324

New issue < 8000 details-dialog class="Box Box--overlay d-flex flex-column anim-fade-in fast overflow-auto" aria-label="Sign up for GitHub">

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More PR changes
(as I understand them)
  • Loading branch information
mikechu-optimizely committed Jan 6, 2023
commit ebd61f679fe8c833ba93b0f710ad2c942bd25ca2
32 changes: 16 additions & 16 deletions OptimizelySDK.Tests/OdpTests/OdpSegmentManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public void ShouldFetchSegmentsOnCacheMiss()
_mockApiManager.Setup(a => a.FetchSegments(It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<OdpUserKeyType>(), It.IsAny<string>(), It.IsAny<List<string>>())).
Returns(segmentsToCheck.ToArray());
var manager = new OdpSegmentManager(_odpConfig, _mockApiManager.Object,
Constants.DEFAULT_MAX_CACHE_SIZE, null, _mockLogger.Object, _mockCache.Object);
var manager = new OdpSegmentManager(_mockApiManager.Object, _odpConfig,
_mockCache.Object, _mockLogger.Object);

var segments = manager.FetchQualifiedSegments(FS_USER_ID);

Expand Down Expand Up @@ -98,8 +98,8 @@ public void ShouldFetchSegmentsSuccessOnCacheHit()
_mockCache.Setup(c => c.Lookup(Capture.In(keyCollector))).Returns(segmentsToCheck);
_mockApiManager.Setup(a => a.FetchSegments(It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<OdpUserKeyType>(), It.IsAny<string>(), It.IsAny<List<string>>()));
var manager = new OdpSegmentManager(_odpConfig, _mockApiManager.Object,
Constants.DEFAULT_MAX_CACHE_SIZE, null, _mockLogger.Object, _mockCache.Object);
var manager = new OdpSegmentManager(_mockApiManager.Object, _odpConfig,
_mockCache.Object, _mockLogger.Object);

var segments = manager.FetchQualifiedSegments(FS_USER_ID);

Expand All @@ -124,8 +124,8 @@ public void ShouldHandleFetchSegmentsWithError()
_mockApiManager.Setup(a => a.FetchSegments(It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<OdpUserKeyType>(), It.IsAny<string>(), It.IsAny<List<string>>())).
Returns(null as string[]);
var manager = new OdpSegmentManager(_odpConfig, _mockApiManager.Object,
Constants.DEFAULT_MAX_CACHE_SIZE, null, _mockLogger.Object, _mockCache.Object);
var manager = new OdpSegmentManager(_mockApiManager.Object, _odpConfig,
_mockCache.Object, _mockLogger.Object);

var segments = manager.FetchQualifiedSegments(FS_USER_ID);

Expand All @@ -143,8 +143,8 @@ public void ShouldHandleFetchSegmentsWithError()
public void ShouldLogAndReturnAnEmptySetWhenNoSegmentsToCheck()
{
var odpConfig = new OdpConfig(API_KEY, API_HOST, new List<string>(0));
var manager = new OdpSegmentManager(odpConfig, _mockApiManager.Object,
Constants.DEFAULT_MAX_CACHE_SIZE, null, _mockLogger.Object, _mockCache.Object);
var manager = new OdpSegmentManager(_mockApiManager.Object, odpConfig,
_mockCache.Object, _mockLogger.Object);

var segments = manager.FetchQualifiedSegments(FS_USER_ID);

Expand All @@ -160,8 +160,8 @@ public void ShouldLogAndReturnNullWhenOdpConfigNotReady()
{
var mockOdpConfig = new Mock<OdpConfig>(API_KEY, API_HOST, new List<string>(0));
mockOdpConfig.Setup(o => o.IsReady()).Returns(false);
var manager = new OdpSegmentManager(mockOdpConfig.Object, _mockApiManager.Object,
Constants.DEFAULT_MAX_CACHE_SIZE, null, _mockLogger.Object, _mockCache.Object);
var manager = new OdpSegmentManager(_mockApiManager.Object, mockOdpConfig.Object,
_mockCache.Object, _mockLogger.Object);

var segments = manager.FetchQualifiedSegments(FS_USER_ID);

Expand All @@ -174,8 +174,8 @@ public void ShouldLogAndReturnNullWhenOdpConfigNotReady()
[Test]
public void ShouldIgnoreCache()
{
var manager = new OdpSegmentManager(_odpConfig, _mockApiManager.Object,
Constants.DEFAULT_MAX_CACHE_SIZE, null, _mockLogger.Object, _mockCache.Object);
var manager = new OdpSegmentManager(_mockApiManager.Object, _odpConfig,
_mockCache.Object, _mockLogger.Object);

manager.FetchQualifiedSegments(FS_USER_ID, new List<OdpSegmentOption>
{
Expand All @@ -194,8 +194,8 @@ public void ShouldIgnoreCache()
[Test]
public void ShouldResetCache()
{
var manager = new OdpSegmentManager(_odpConfig, _mockApiManager.Object,
Constants.DEFAULT_MAX_CACHE_SIZE, null, _mockLogger.Object, _mockCache.Object);
var manager = new OdpSegmentManager(_mockApiManager.Object, _odpConfig,
_mockCache.Object, _mockLogger.Object);

manager.FetchQualifiedSegments(FS_USER_ID, new List<OdpSegmentOption>
{
Expand All @@ -216,8 +216,8 @@ public void ShouldMakeValidCacheKey()
{
var keyCollector = new List<string>();
_mockCache.Setup(c => c.Lookup(Capture.In(keyCollector)));
var manager = new OdpSegmentManager(_odpConfig, _mockApiManager.Object,
Constants.DEFAULT_MAX_CACHE_SIZE, null, _mockLogger.Object, _mockCache.Object);
var manager = new OdpSegmentManager(_mockApiManager.Object, _odpConfig,
_mockCache.Object, _mockLogger.Object);

manager.FetchQualifiedSegments(FS_USER_ID);

Expand Down
8 changes: 4 additions & 4 deletions OptimizelySDK/Odp/OdpManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ public OdpManager Build(bool asEnabled = true)
manager.EventManager = new OdpEventManager.Builder().
WithOdpConfig(_odpConfig).
WithBatchSize(Constants.DEFAULT_MAX_CACHE_SIZE).
WithTimeoutInterval(TimeSpan.FromMilliseconds(Constants.DEFAULT_CACHE_SECONDS)).
WithTimeoutInterval(
TimeSpan.FromMilliseconds(Constants.DEFAULT_CACHE_SECONDS)).
WithOdpEventApiManager(eventApiManager).
WithLogger(_logger).
WithErrorHandler(_errorHandler).
Expand All @@ -237,11 +238,10 @@ public OdpManager Build(bool asEnabled = true)

if (_segmentManager == null)
{
var cacheTimeout = TimeSpan.FromSeconds(Constants.DEFAULT_CACHE_SECONDS);
var apiManager = new OdpSegmentApiManager(_logger, _errorHandler);

manager.SegmentManager = new OdpSegmentManager(_odpConfig, apiManager,
Constants.DEFAULT_MAX_CACHE_SIZE, cacheTimeout, _logger, _cache);
manager.SegmentManager =
new OdpSegmentManager(apiManager, _odpConfig, _cache, _logger);
}
else
{
Expand Down
23 changes: 20 additions & 3 deletions OptimizelySDK/Odp/OdpSegmentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,32 @@ public class OdpSegmentManager : IOdpSegmentManager
/// </summary>
private readonly ICache<List<string>> _segmentsCache;

public OdpSegmentManager(OdpConfig odpConfig, IOdpSegmentApiManager apiManager,
int? cacheSize = null, TimeSpan? itemTimeout = null,
ILogger logger = null, ICache<List<string>> cache = null
public OdpSegmentManager(IOdpSegmentApiManager apiManager,
OdpConfig odpConfig,
ICache<List<string>> cache = null,
ILogger logger = null
)
{
_apiManager = apiManager;
_odpConfig = odpConfig;
_logger = logger ?? new DefaultLogger();

_segmentsCache =
cache ?? new LruCache<List<string>>(Constants.DEFAULT_MAX_CACHE_SIZE,
TimeSpan.FromSeconds(Constants.DEFAULT_CACHE_SECONDS), logger);
}

public OdpSegmentManager(IOdpSegmentApiManager apiManager,
int? cacheSize = null,
TimeSpan? itemTimeout = null,
ICache<List<string>> cache = null,
ILogger logger = null
)
{
_apiManager = apiManager;
_odpConfig = new OdpConfig();
_logger = logger ?? new DefaultLogger();

itemTimeout = itemTimeout ?? TimeSpan.FromSeconds(Constants.DEFAULT_CACHE_SECONDS);
if (itemTimeout < TimeSpan.Zero)
{
Expand Down
0