Skip to content

Commit cb0f83a

Browse files
Fix partially configured regions not fallback-ing on defauts
* Fixes #19 * Cleanup of modified classes * Upgrade of AsyncGenerator, it was failing with up-to-date VS
1 parent 4cde979 commit cb0f83a

File tree

20 files changed

+451
-468
lines changed

20 files changed

+451
-468
lines changed

EnyimMemcached/NHibernate.Caches.EnyimMemcached.Tests/Async/MemCacheFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public async Task TestRemove144Async()
4848

4949
// add the item
5050
await (cache.PutAsync(key, value, CancellationToken.None));
51-
Thread.Sleep(1000);
51+
await (Task.Delay(1000));
5252

5353
// make sure it's there
5454
var item = await (cache.GetAsync(key, CancellationToken.None));

MemCache/NHibernate.Caches.MemCache.Tests/Async/MemCacheFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public async Task TestRemove144Async()
7474

7575
// add the item
7676
await (cache.PutAsync(key, value, CancellationToken.None));
77-
Thread.Sleep(1000);
77+
await (Task.Delay(1000));
7878

7979
// make sure it's there
8080
var item = await (cache.GetAsync(key, CancellationToken.None));

NHibernate.Caches.Common.Tests/Async/CacheFixture.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ public async Task TestObjectExpirationAsync([ValueSource(nameof(ExpirationSettin
166166
Assert.That(await (cache.GetAsync(key, CancellationToken.None)), Is.Null, "Unexpected entry for key");
167167
await (cache.PutAsync(key, obj, CancellationToken.None));
168168
// Wait up to 1 sec before expiration
169-
Thread.Sleep(TimeSpan.FromSeconds(expirySeconds - 1));
169+
await (Task.Delay(TimeSpan.FromSeconds(expirySeconds - 1)));
170170
Assert.That(await (cache.GetAsync(key, CancellationToken.None)), Is.Not.Null, "Missing entry for key");
171171

172172
// Wait expiration
173-
Thread.Sleep(TimeSpan.FromSeconds(2));
173+
await (Task.Delay(TimeSpan.FromSeconds(2)));
174174

175175
// Check it expired
176176
Assert.That(await (cache.GetAsync(key, CancellationToken.None)), Is.Null, "Unexpected entry for key after expiration");
@@ -197,7 +197,7 @@ public async Task TestObjectExpirationAfterUpdateAsync([ValueSource(nameof(Expir
197197
Assert.That(await (cache.GetAsync(key, CancellationToken.None)), Is.Not.Null, "Missing entry for key after update");
198198

199199
// Wait
200-
Thread.Sleep(TimeSpan.FromSeconds(expirySeconds + 2));
200+
await (Task.Delay(TimeSpan.FromSeconds(expirySeconds + 2)));
201201

202202
// Check it expired
203203
Assert.That(await (cache.GetAsync(key, CancellationToken.None)), Is.Null, "Unexpected entry for key after expiration");
@@ -219,15 +219,15 @@ public async Task TestSlidingExpirationAsync()
219219

220220
await (cache.PutAsync(key, obj, CancellationToken.None));
221221
// Wait up to 1 sec before expiration
222-
Thread.Sleep(TimeSpan.FromSeconds(expirySeconds - 1));
222+
await (Task.Delay(TimeSpan.FromSeconds(expirySeconds - 1)));
223223
Assert.That(await (cache.GetAsync(key, CancellationToken.None)), Is.Not.Null, "Missing entry for key");
224224

225225
// Wait up to 1 sec before expiration again
226-
Thread.Sleep(TimeSpan.FromSeconds(expirySeconds - 1));
226+
await (Task.Delay(TimeSpan.FromSeconds(expirySeconds - 1)));
227227
Assert.That(await (cache.GetAsync(key, CancellationToken.None)), Is.Not.Null, "Missing entry for key after get and wait less than expiration");
228228

229229
// Wait expiration
230-
Thread.Sleep(TimeSpan.FromSeconds(expirySeconds + 1));
230+
await (Task.Delay(TimeSpan.FromSeconds(expirySeconds + 1)));
231231

232232
// Check it expired
233233
Assert.That(await (cache.GetAsync(key, CancellationToken.None)), Is.Null, "Unexpected entry for key after expiration");

NHibernate.Caches.Common.Tests/CacheProviderFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void TestBuildCacheNoRegionNoProperties()
1616
public void TestBuildCacheNoRegionWithProperties()
1717
{
1818
// Using same "region" than another test, need to get another provider for avoiding it
19-
// to yield a previously built cache.
19+
// to yield a previously built cache if the underlying provider does some instance caching.
2020
var cache = GetNewProvider().BuildCache(null, GetDefaultProperties());
2121
Assert.That(cache, Is.Not.Null, "no cache returned");
2222
}

RtMemoryCache/NHibernate.Caches.RtMemoryCache.Tests/App.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<rtmemorycache>
1111
<cache region="foo" expiration="500" sliding="true" />
12+
<cache region="noExplicitExpiration" sliding="true" />
1213
</rtmemorycache>
1314
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
1415
<session-factory>

RtMemoryCache/NHibernate.Caches.RtMemoryCache.Tests/RtMemoryCacheProviderFixture.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,28 @@ public void TestBuildCacheFromConfig()
4949
ICache cache = DefaultProvider.BuildCache("foo", null);
5050
Assert.That(cache, Is.Not.Null, "pre-configured cache not found");
5151
}
52+
53+
[Test]
54+
public void TestExpiration()
55+
{
56+
var cache = DefaultProvider.BuildCache("foo", null) as RtMemoryCache;
57+
Assert.That(cache, Is.Not.Null, "pre-configured foo cache not found");
58+
Assert.That(cache.Expiration, Is.EqualTo(TimeSpan.FromSeconds(500)), "Unexpected expiration value for foo region");
59+
60+
cache = DefaultProvider.BuildCache("noExplicitExpiration", null) as RtMemoryCache;
61+
Assert.That(cache.Expiration, Is.EqualTo(TimeSpan.FromSeconds(300)),
62+
"Unexpected expiration value for noExplicitExpiration region");
63+
Assert.That(cache.UseSlidingExpiration, Is.True, "Unexpected sliding value for noExplicitExpiration region");
64+
65+
cache = DefaultProvider
66+
.BuildCache("noExplicitExpiration", new Dictionary<string, string> { { "expiration", "100" } }) as RtMemoryCache;
67+
Assert.That(cache.Expiration, Is.EqualTo(TimeSpan.FromSeconds(100)),
68+
"Unexpected expiration value for noExplicitExpiration region with default expiration");
69+
70+
cache = DefaultProvider
71+
.BuildCache("noExplicitExpiration", new Dictionary<string, string> { { Cfg.Environment.CacheDefaultExpiration, "50" } }) as RtMemoryCache;
72+
Assert.That(cache.Expiration, Is.EqualTo(TimeSpan.FromSeconds(50)),
73+
"Unexpected expiration value for noExplicitExpiration region with cache.default_expiration");
74+
}
5275
}
5376
}

RtMemoryCache/NHibernate.Caches.RtMemoryCache.Tests/RtMemoryCacheSectionHandlerFixture.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
#endregion
2424

25-
using System.Collections.Generic;
26-
using System.Runtime.Caching;
2725
using System.Xml;
2826
using NUnit.Framework;
2927

@@ -39,16 +37,6 @@ public XmlNode GetConfigurationSection(string xml)
3937
return doc.DocumentElement;
4038
}
4139

42-
public RtMemoryCache[] CreateCache(CacheConfig[] configuration)
43-
{
44-
var result = new List<RtMemoryCache>(configuration.Length);
45-
foreach (var config in configuration)
46-
{
47-
result.Add(new RtMemoryCache(config.Region, config.Properties));
48-
}
49-
return result.ToArray();
50-
}
51-
5240
[Test]
5341
public void TestGetConfigNullSection()
5442
{

0 commit comments

Comments
 (0)