public void QCahce_test_expiry() { QCache target = new QCache(); var key1 = target.Add("1", 1000); var key2 = target.Add("2", 3000); var key3 = target.Add("3", 6000); Assert.AreEqual("1", target.GetObj(key1)); Assert.AreEqual("2", target.GetObj(key2)); Assert.AreEqual("3", target.GetObj(key3)); Thread.Sleep(1200); Assert.IsNull(target.GetObj(key1)); Assert.AreEqual("2", target.GetObj(key2)); Assert.AreEqual("3", target.GetObj(key3)); Thread.Sleep(2000); Assert.IsNull(target.GetObj(key1)); Assert.IsNull(target.GetObj(key2)); Assert.IsNotNull(target.GetObj(key3)); Thread.Sleep(3000); Assert.IsNull(target.GetObj(key1)); Assert.IsNull(target.GetObj(key2)); Assert.IsNull(target.GetObj(key3)); Thread.Sleep(10000); //wait for disposing all obj. target.Dispose(); }
public void QCacheConstructorTest() { for (int i = 0; i < 3; i++) { QCache target = new QCache(); var key = target.Add("15", 1000); Assert.AreEqual("15", target.GetObj(key), "index:" + i); } }