Imported Upstream version 4.2.0.179

Former-commit-id: 4610231f55806d2a05ed69e5ff3faa7336cc1479
This commit is contained in:
Xamarin Public Jenkins
2015-08-26 07:17:56 -04:00
committed by Jo Shields
parent aa7da660d6
commit c042cd0c52
7507 changed files with 90259 additions and 657307 deletions

View File

@@ -833,17 +833,9 @@ namespace MonoTests.System.Runtime.Caching
{
bool expired = false;
CacheEntryRemovedReason reason = CacheEntryRemovedReason.CacheSpecificEviction;
NameValueCollection config;
int sleepPeriod;
#if !DOTNET
config = new NameValueCollection ();
config.Add ("__MonoTimerPeriod", "1");
sleepPeriod = 1100;
#else
config = null;
sleepPeriod = 20100; // 20s is the .NET period - discovered by experimentation
#endif
var mc = new PokerMemoryCache ("MyCache", config);
int sleepPeriod = 1100;
var mc = new PokerMemoryCache ("MyCache");
var cip = new CacheItemPolicy ();
cip.RemovedCallback = (CacheEntryRemovedArguments args) => {
@@ -871,6 +863,7 @@ namespace MonoTests.System.Runtime.Caching
mc.Set ("key", "value", cip);
Thread.Sleep (sleepPeriod);
Assert.IsNull (mc.Get ("key"), "#A3-0");
Assert.IsTrue (expired, "#A3-1");
Assert.AreEqual (CacheEntryRemovedReason.Expired, reason, "#A3-2");
@@ -903,6 +896,10 @@ namespace MonoTests.System.Runtime.Caching
mc.Set ("key4", "value4", cip);
Thread.Sleep (sleepPeriod);
Assert.IsNull (mc.Get ("key1"), "#A4-1");
Assert.IsNull (mc.Get ("key2"), "#A4-2");
Assert.IsNull (mc.Get ("key3"), "#A4-3");
Assert.IsNotNull (mc.Get ("key4"), "#A4-4");
Assert.AreEqual (3, expiredCount, "#A4");
}
@@ -1235,11 +1232,7 @@ namespace MonoTests.System.Runtime.Caching
var config = new NameValueCollection ();
config["cacheMemoryLimitMegabytes"] = 0.ToString ();
config["physicalMemoryLimitPercentage"] = 100.ToString ();
config["__MonoEmulateOneCPU"] = true.ToString ();
// it appears that pollingInterval does nothing, so we set the Mono timer as well
config["pollingInterval"] = new TimeSpan (0, 0, 1).ToString ();
config["__MonoTimerPeriod"] = 1.ToString ();
using (var mc = new MemoryCache ("TestCacheShrink", config)) {
Assert.AreEqual (0, mc.GetCount (), "#CS1");
@@ -1263,6 +1256,9 @@ namespace MonoTests.System.Runtime.Caching
// wait for the cache thread to expire the short duration items, this will also shrink the size of the cache
global::System.Threading.Thread.Sleep (5 * 1000);
for (int i = 0; i < HEAP_RESIZE_SHORT_ENTRIES; i++) {
Assert.IsNull (mc.Get ("short-" + i), "#CS4-" + i);
}
Assert.AreEqual (HEAP_RESIZE_LONG_ENTRIES, mc.GetCount (), "#CS4");
// add some new items into the cache, this will grow the cache again
@@ -1280,11 +1276,7 @@ namespace MonoTests.System.Runtime.Caching
var config = new NameValueCollection ();
config["cacheMemoryLimitMegabytes"] = 0.ToString ();
config["physicalMemoryLimitPercentage"] = 100.ToString ();
config["__MonoEmulateOneCPU"] = true.ToString ();
// it appears that pollingInterval does nothing, so we set the Mono timer as well
config["pollingInterval"] = new TimeSpan (0, 0, 10).ToString ();
config["__MonoTimerPeriod"] = 10.ToString ();
using (var mc = new MemoryCache ("TestExpiredGetValues", config)) {
Assert.AreEqual (0, mc.GetCount (), "#EGV1");
@@ -1320,11 +1312,7 @@ namespace MonoTests.System.Runtime.Caching
var config = new NameValueCollection ();
config["cacheMemoryLimitMegabytes"] = 0.ToString ();
config["physicalMemoryLimitPercentage"] = 100.ToString ();
config["__MonoEmulateOneCPU"] = true.ToString ();
// it appears that pollingInterval does nothing, so we set the Mono timer as well
config["pollingInterval"] = new TimeSpan (0, 0, 1).ToString ();
config["__MonoTimerPeriod"] = 1.ToString ();
using (var mc = new MemoryCache ("TestCacheExpiryOrdering", config)) {
Assert.AreEqual (0, mc.GetCount (), "#CEO1");
@@ -1349,6 +1337,9 @@ namespace MonoTests.System.Runtime.Caching
global::System.Threading.Thread.Sleep (4 * 1000);
for (int i = 0; i < 100; i++) {
Assert.IsNull (mc.Get ("short-" + i), "#CEO4-" + i);
}
Assert.AreEqual (100, mc.GetCount (), "#CEO4");
}
}
@@ -1359,11 +1350,7 @@ namespace MonoTests.System.Runtime.Caching
var config = new NameValueCollection ();
config["cacheMemoryLimitMegabytes"] = 0.ToString ();
config["physicalMemoryLimitPercentage"] = 100.ToString ();
config["__MonoEmulateOneCPU"] = true.ToString ();
// it appears that pollingInterval does nothing, so we set the Mono timer as well
config["pollingInterval"] = new TimeSpan (0, 0, 1).ToString ();
config["__MonoTimerPeriod"] = 1.ToString ();
using (var mc = new MemoryCache ("TestCacheSliding", config)) {
Assert.AreEqual (0, mc.GetCount (), "#CSL1");
@@ -1390,10 +1377,16 @@ namespace MonoTests.System.Runtime.Caching
Assert.AreNotEqual (null, item, "#CSL3-" + i);
}
Assert.IsNull (mc.Get ("expire1"), "#CSL4-1");
Assert.IsNull (mc.Get ("expire2"), "#CSL4-2");
Assert.IsNull (mc.Get ("expire3"), "#CSL4-3");
Assert.IsNull (mc.Get ("expire4"), "#CSL4-4");
Assert.IsNull (mc.Get ("expire5"), "#CSL4-5");
Assert.AreEqual (1, mc.GetCount (), "#CSL4");
global::System.Threading.Thread.Sleep (4 * 1000);
Assert.IsNull (mc.Get ("slidingtest"), "#CSL5a");
Assert.AreEqual (0, mc.GetCount (), "#CSL5");
}
}