public void T110_PriorityCollideWithMaxCap() { using (var cache = PileCacheTestCore.MakeCache()) { var tA = cache.GetOrCreateTable <int>("A"); tA.Options.MaximumCapacity = 7; const int CNT = 4000; var lst = new List <PutResult>(); for (var i = 0; i < CNT; i++) { var pr = tA.Put(i, "value" + i.ToString(), priority: 10); //PRIORITY +10! // Console.WriteLine("{0} -> {1}", i, pr); Aver.IsTrue(pr == PutResult.Inserted || pr == PutResult.Overwritten); //the table is capped, so some values will be overwritten lst.Add(pr); } Aver.IsTrue(lst.Count(r => r == PutResult.Inserted) > 0); Aver.IsTrue(lst.Count(r => r == PutResult.Overwritten) > 0); lst.Clear(); for (var i = CNT; i < 2 * CNT; i++) { var pr = tA.Put(i, "value" + i.ToString(), priority: -10);//only collision, because priority is lowe r than what already exists // Console.WriteLine("{0} -> {1}", i, pr); Aver.IsTrue(pr == PutResult.Collision); lst.Add(pr); } } }
public void T090_PutGetWithMaxCap() { using (var cache = PileCacheTestCore.MakeCache()) { var tA = cache.GetOrCreateTable <int>("A"); tA.Options.MaximumCapacity = 7; const int CNT = 4000; var lst = new List <PutResult>(); for (var i = 0; i < CNT; i++) { var pr = tA.Put(i, "value" + i.ToString(), priority: 10); // Console.WriteLine("{0} -> {1}", i, pr); Aver.IsTrue(pr == PutResult.Inserted || pr == PutResult.Overwritten);//the table is capped, so some values will be overwritten lst.Add(pr); } Aver.IsTrue(lst.Count(r => r == PutResult.Inserted) > 0); Aver.IsTrue(lst.Count(r => r == PutResult.Overwritten) > 0); for (var i = 0; i < CNT; i++) { var v = tA.Get(i); // Console.WriteLine("{0} -> {1}", i, v); Aver.IsTrue(v == null || v.Equals("value" + i.ToString())); } } }
public void T030_Comparers() { using (var cache = PileCacheTestCore.MakeCache()) { var tA = cache.GetOrCreateTable <string>("A", StringComparer.Ordinal); var tB = cache.GetOrCreateTable <string>("A", StringComparer.OrdinalIgnoreCase); } }
public void T010_MainOperations() { using (var cache = PileCacheTestCore.MakeCache()) { var tA = cache.GetOrCreateTable <string>("A"); var tB = cache.GetOrCreateTable <string>("B"); Aver.IsNotNull(tA); Aver.IsNotNull(tB); Aver.AreEqual(2, cache.Tables.Count); Aver.AreEqual(0, tA.Count); Aver.AreEqual(0, tB.Count); Aver.IsTrue(PutResult.Inserted == tA.Put("key1", "avalue1")); Aver.IsTrue(PutResult.Inserted == tA.Put("key2", "avalue2")); Aver.IsTrue(PutResult.Inserted == tB.Put("key1", "bvalue1")); Aver.AreEqual(3, cache.Count); Aver.AreEqual(2, tA.Count); Aver.AreEqual(1, tB.Count); Aver.IsTrue(tA.ContainsKey("key1")); Aver.IsTrue(tA.ContainsKey("key2")); Aver.IsFalse(tA.ContainsKey("key3 that was never put")); Aver.IsTrue(tB.ContainsKey("key1")); Aver.IsFalse(tB.ContainsKey("key2")); Aver.AreObjectsEqual("avalue1", tA.Get("key1")); Aver.AreObjectsEqual("avalue2", tA.Get("key2")); Aver.IsNull(tA.Get("key3")); Aver.AreObjectsEqual("bvalue1", tB.Get("key1")); Aver.AreObjectsEqual("avalue1", cache.GetTable <string>("A").Get("key1")); Aver.AreObjectsEqual("bvalue1", cache.GetTable <string>("B").Get("key1")); Aver.IsTrue(tA.Remove("key1")); Aver.IsFalse(tA.Remove("key2342341")); Aver.AreEqual(2, cache.Count); Aver.AreEqual(1, tA.Count); Aver.AreEqual(1, tB.Count); cache.PurgeAll(); Aver.AreEqual(0, cache.Count); Aver.AreEqual(0, tA.Count); Aver.AreEqual(0, tB.Count); Aver.AreEqual(0, cache.Pile.UtilizedBytes); Aver.AreEqual(0, cache.Pile.ObjectCount); } }
public void T180_GetOrPut() { using (var cache = PileCacheTestCore.MakeCache()) { var tA = cache.GetOrCreateTable <int>("A"); tA.Put(1, "value 1"); tA.Put(122, "value 122"); PutResult?pResult; var v = tA.GetOrPut(2, (t, k, _) => "value " + k.ToString(), null, out pResult); Aver.AreObjectsEqual("value 2", v); Aver.IsTrue(pResult.HasValue); Aver.IsTrue(PutResult.Inserted == pResult.Value); Aver.AreEqual(3, tA.Count); tA.Put(1, "value 1"); tA.Put(2, "value 2"); tA.Put(122, "value 122"); v = tA.GetOrPut(1, (t, k, _) => "value " + k.ToString(), null, out pResult); Aver.AreObjectsEqual("value 1", v); Aver.IsFalse(pResult.HasValue); Aver.AreEqual(3, tA.Count); tA.Put(1, "value 1"); tA.Put(2, "value 2"); tA.Put(122, "value 122"); v = tA.GetOrPut(777, (t, k, _) => "value " + k.ToString(), null, out pResult); Aver.AreObjectsEqual("value 777", v); Aver.IsTrue(pResult.HasValue); Aver.IsTrue(PutResult.Inserted == pResult.Value); Aver.AreEqual(4, tA.Count); tA.Put(1, "value 1"); tA.Put(2, "value 2"); tA.Put(122, "value 122"); tA.Put(777, "value 777"); pResult = tA.Put(2, "mod value 2"); Aver.IsTrue(PutResult.Replaced == pResult.Value); Aver.AreEqual(4, tA.Count); tA.Put(1, "value 1"); tA.Put(2, "mod value 2"); tA.Put(122, "value 122"); tA.Put(777, "value 777"); } }
public void BasicSpeculative(int COUNT) { using (var cache = PileCacheTestCore.MakeCache()) { var tA = cache.GetOrCreateTable <Guid>("A"); Aver.AreObjectsEqual(CollisionMode.Speculative, tA.CollisionMode); var dict = new Dictionary <Guid, PilePointer>(); for (var i = 0; i < COUNT; i++) { var key = Guid.NewGuid(); var ptr = cache.Pile.Put(key.ToString(), preallocateBlockSize: 1024); dict.Add(key, ptr); var pr = tA.PutPointer(key, ptr); Aver.IsTrue(PutResult.Inserted == pr || PutResult.Overwritten == pr); } var ratio = tA.Count / (double)COUNT; Console.WriteLine(ratio); Aver.IsTrue(ratio > 0.85d); foreach (var kvp in dict) { var gotPointer = tA.GetPointer(kvp.Key); if (!gotPointer.Valid) { continue; } Aver.AreEqual(gotPointer, kvp.Value); var gotObject = tA.Get(kvp.Key) as string; Aver.IsNotNull(gotObject); Aver.AreEqual(kvp.Key.ToString(), gotObject); } foreach (var kvp in dict) { tA.Remove(kvp.Key); } Aver.AreEqual(0, tA.Count); Aver.AreEqual(0, cache.Pile.ObjectCount); } }
public void T020_Comparers() { using (var cache = PileCacheTestCore.MakeCache()) { var tA = cache.GetOrCreateTable <string>("A", StringComparer.Ordinal); var tB = cache.GetOrCreateTable <string>("B", StringComparer.OrdinalIgnoreCase); Aver.IsTrue(PutResult.Inserted == tA.Put("key1", "avalue1")); Aver.IsTrue(PutResult.Inserted == tA.Put("Key1", "avalue2")); Aver.IsTrue(PutResult.Inserted == tB.Put("key1", "bvalue1")); Aver.IsTrue(PutResult.Replaced == tB.Put("Key1", "bvalue2")); Aver.AreEqual(2, tA.Count); Aver.AreEqual(1, tB.Count); Aver.AreObjectsEqual("avalue1", tA.Get("key1")); Aver.AreObjectsEqual("avalue2", tA.Get("Key1")); Aver.IsNull(tA.Get("key3")); Aver.AreObjectsEqual("bvalue2", tB.Get("key1")); Aver.AreObjectsEqual("bvalue2", tB.Get("Key1")); } }
public void T080_PutGetWithoutMaxCap() { using (var cache = PileCacheTestCore.MakeCache()) { var tA = cache.GetOrCreateTable <int>("A"); //// tA.Options.MaximumCapacity = 7; const int CNT = 4000; for (var i = 0; i < CNT; i++) { var pr = tA.Put(i, "value" + i.ToString(), priority: 10); // Console.WriteLine("{0} -> {1}", i, pr); Aver.IsTrue(pr == PutResult.Inserted);//no overwrite because table keeps growing } for (var i = 0; i < CNT; i++) { var v = tA.Get(i); // Console.WriteLine("{0} -> {1}", i, v); Aver.IsTrue(v.Equals("value" + i.ToString())); } } }
public void T170_Config() { var conf1 = @" store { default-table-options { initial-capacity=1000000 detailed-instrumentation=true } table { name='A' minimum-capacity=800000 maximum-capacity=987654321 initial-capacity=780000 growth-factor=2.3 shrink-factor=0.55 load-factor-lwm=0.1 load-factor-hwm=0.9 default-max-age-sec=145 detailed-instrumentation=true } table { name='B' maximum-capacity=256000 detailed-instrumentation=false } } "; var c1 = conf1.AsLaconicConfig(handling: ConvertErrorHandling.Throw); using (var cache = PileCacheTestCore.MakeCache(c1)) { var tA = cache.GetOrCreateTable <int>("A"); var topt = cache.DefaultTableOptions; Aver.AreEqual(1000000, topt.InitialCapacity); Aver.AreEqual(true, topt.DetailedInstrumentation); topt = cache.TableOptions["a"]; Aver.AreEqual(800000, topt.MinimumCapacity); Aver.AreEqual(987654321, topt.MaximumCapacity); Aver.AreEqual(780000, topt.InitialCapacity); Aver.AreEqual(2.3d, topt.GrowthFactor); Aver.AreEqual(0.55d, topt.ShrinkFactor); Aver.AreEqual(0.1d, topt.LoadFactorLWM); Aver.AreEqual(0.9d, topt.LoadFactorHWM); Aver.AreEqual(145, topt.DefaultMaxAgeSec); Aver.AreEqual(true, topt.DetailedInstrumentation); topt = cache.GetOrCreateTable <int>("A").Options; Aver.AreEqual(800000, topt.MinimumCapacity); Aver.AreEqual(987654321, topt.MaximumCapacity); Aver.AreEqual(780000, topt.InitialCapacity); Aver.AreEqual(2.3d, topt.GrowthFactor); Aver.AreEqual(0.55d, topt.ShrinkFactor); Aver.AreEqual(0.1d, topt.LoadFactorLWM); Aver.AreEqual(0.9d, topt.LoadFactorHWM); Aver.AreEqual(145, topt.DefaultMaxAgeSec); Aver.AreEqual(true, topt.DetailedInstrumentation); cache.GetOrCreateTable <int>("A").Options.DefaultMaxAgeSec = 197; Aver.AreEqual(197, cache.GetOrCreateTable <int>("A").Options.DefaultMaxAgeSec); Aver.AreEqual(145, cache.TableOptions["a"].DefaultMaxAgeSec); topt = cache.GetOrCreateTable <int>("b").Options; Aver.AreEqual(256000, topt.MaximumCapacity); Aver.AreEqual(false, topt.DetailedInstrumentation); } }