Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaozhang committed Feb 23, 2023
1 parent a0e2bf3 commit 5b2d191
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 36 deletions.
36 changes: 0 additions & 36 deletions src/Microsoft.IdentityModel.Tokens/BaseConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ public abstract class BaseConfigurationManager
private DateTime? _lastKnownGoodConfigFirstUse = null;

internal EventBasedLRUCache<BaseConfiguration, DateTime> _lastKnownGoodConfigurationCache;
//private EventBasedLRUCache<BaseConfiguration, DateTime> _lastKnownGoodConfigurationCache = new EventBasedLRUCache<BaseConfiguration, DateTime>(10, TaskCreationOptions.None, new BaseConfigurationComparer(), true, maintainLRU: true);

private int _lastKnownGoodConfigurationSizeLimit = DefaultLastKnownGoodConfigurationSizeLimit;
private IEqualityComparer<BaseConfiguration> _baseConfigurationComparer = new BaseConfigurationComparer();

/// <summary>
/// Gets or sets the <see cref="TimeSpan"/> that controls how often an automatic metadata refresh should occur.
Expand All @@ -43,18 +39,6 @@ public TimeSpan AutomaticRefreshInterval
}
}

/// <summary>
/// Gets or sets the BaseConfgiurationComparer that to compare <see cref="BaseConfiguration"/>.
/// </summary>
public IEqualityComparer<BaseConfiguration> BaseConfigurationComparer
{
get { return _baseConfigurationComparer; }
set
{
_baseConfigurationComparer = value ?? throw LogHelper.LogExceptionMessage(new ArgumentNullException(nameof(value)));
}
}

/// <summary>
/// 12 hours is the default time interval that afterwards will obtain new configuration.
/// </summary>
Expand All @@ -65,11 +49,6 @@ public IEqualityComparer<BaseConfiguration> BaseConfigurationComparer
/// </summary>
public static readonly TimeSpan DefaultLastKnownGoodConfigurationLifetime = new TimeSpan(0, 1, 0, 0);

/// <summary>
/// 10 is the default size limit of the cache (in number of items) for last known good configuration.
/// </summary>
public static readonly int DefaultLastKnownGoodConfigurationSizeLimit = 10;

/// <summary>
/// 5 minutes is the default time interval that must pass for <see cref="RequestRefresh"/> to obtain a new configuration.
/// </summary>
Expand Down Expand Up @@ -114,26 +93,11 @@ public BaseConfiguration LastKnownGoodConfiguration
_lastKnownGoodConfiguration = value ?? throw LogHelper.LogArgumentNullException(nameof(value));
_lastKnownGoodConfigFirstUse = DateTime.UtcNow;

if (_lastKnownGoodConfigurationCache == null)
_lastKnownGoodConfigurationCache = new EventBasedLRUCache<BaseConfiguration, DateTime>(LastKnownGoodConfigurationSizeLimit, TaskCreationOptions.None, BaseConfigurationComparer, true, maintainLRU: true);

// LRU cache will remove the expired configuration
_lastKnownGoodConfigurationCache.SetValue(_lastKnownGoodConfiguration, DateTime.UtcNow + LastKnownGoodLifetime, DateTime.UtcNow + LastKnownGoodLifetime);
}
}

/// <summary>
/// The size limit of the cache (in number of items) for last known good configuration.
/// </summary>
public int LastKnownGoodConfigurationSizeLimit
{
get { return _lastKnownGoodConfigurationSizeLimit; }
set
{
_lastKnownGoodConfigurationSizeLimit = (value > 0) ? value : throw LogHelper.LogExceptionMessage(new ArgumentOutOfRangeException(nameof(value)));
}
}

/// <summary>
/// The length of time that a last known good configuration is valid for.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using Microsoft.IdentityModel.Logging;
using Microsoft.IdentityModel.Protocols;
using Microsoft.IdentityModel.Protocols.Configuration;
using Microsoft.IdentityModel.Tokens;

namespace Microsoft.IdentityModel.TestUtils
Expand All @@ -32,6 +33,11 @@ public MockConfigurationManager(T configuration)
throw LogHelper.LogExceptionMessage(new ArgumentNullException(nameof(configuration)));

_configuration = configuration;
_lastKnownGoodConfigurationCache = new EventBasedLRUCache<BaseConfiguration, DateTime>(
LastKnownGoodConfigurationCacheOptions.DefaultLastKnownGoodConfigurationSizeLimit,
TaskCreationOptions.None,
new BaseConfigurationComparer(),
true);
}

/// <summary>
Expand Down

0 comments on commit 5b2d191

Please sign in to comment.