public void TestRemove() { var comPlusCache = new ComPlusCache("TestCache"); comPlusCache.Add("Entry 1", "Hello"); Assert.IsTrue(comPlusCache.Contains("Entry 1")); comPlusCache.Remove("Entry 1"); Assert.IsFalse(comPlusCache.Contains("Entry 1")); }
public void TestStressConcurrent() { const int threadCount = 4; const int loops = 1000; var totalLoops = 0; var threads = new Thread[threadCount]; for (var i = 0; i < threadCount; i++) { (threads[i] = new Thread(context => { var externalCache = new ComPlusCache(); for (var j = 0; j < loops; j++) { var item = new Dynamo(); var item2 = new Dynamo(); item["P1"] = "Property " + j; externalCache.AddOrUpdate($"Item {(int) context}-{j}", () => item, () => item2); Assert.IsTrue(externalCache.Contains($"Item {(int) context}-{j}")); var returnedItem = (Dynamo)externalCache.Get($"Item {(int) context}-{j}"); Assert.AreEqual("Property " + j, returnedItem["P1"]); externalCache.Remove($"Item {(int) context}-{j}"); Assert.IsFalse(externalCache.Contains($"Item {(int) context}-{j}")); externalCache.AddOrUpdate($"Item {j}", () => item, () => item2); Assert.IsTrue(externalCache.Contains($"Item {j}")); var item3 = externalCache.GetOrAdd($"Item {j}", () => item2); Assert.IsNotNull(item3); Interlocked.Increment(ref totalLoops); } })).Start(i); } foreach (var thread in threads) { thread.Join(); } Assert.AreEqual(threadCount * loops, totalLoops); }