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 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 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 AddAndRemove(int COUNT, int durationSec, double delMargin) { using (var cache = PileCacheTestCore.MakeDurableCache()) { var tA = cache.GetOrCreateTable <Guid>("A"); var dict = new Dictionary <Guid, string>(); var sw = System.Diagnostics.Stopwatch.StartNew(); var ls = 0L; while (sw.Elapsed.TotalSeconds < durationSec) { while (dict.Count < COUNT) { var key = Guid.NewGuid(); var value = "value is " + key; dict.Add(key, value); var pr = tA.Put(key, value); Aver.AreObjectsEqual(PutResult.Inserted, pr); } var todelete = Ambient.Random.NextScaledRandomInteger(0, (int)(COUNT * delMargin)); for (var i = 0; i < todelete; i++) { var key = dict.Keys.Skip(Ambient.Random.NextScaledRandomInteger(0, dict.Count - 2)).First(); Aver.IsTrue(dict.Remove(key)); Aver.IsTrue(tA.Remove(key)); Aver.AreEqual(dict.Count, tA.Count); } if (sw.ElapsedMilliseconds - ls > 1000) { Console.WriteLine("Elapsed: {0:n0} of {1:n0}; Removed {2:n0}, count is {3:n0}", sw.Elapsed.TotalSeconds, durationSec, todelete, tA.Count); ls = sw.ElapsedMilliseconds; } Aver.AreEqual(dict.Count, tA.Count); foreach (var kvp in dict) { Aver.AreEqual(kvp.Value, tA.Get(kvp.Key) as string); } } //delete everything foreach (var kvp in dict) { Aver.IsTrue(tA.ContainsKey(kvp.Key)); Aver.IsTrue(tA.Remove(kvp.Key)); Aver.IsFalse(tA.ContainsKey(kvp.Key)); } Aver.AreEqual(0, cache.Pile.ObjectCount);//Pile is empty } }
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 SweepOldRejuvenateSome(int COUNT) { using (var cache = PileCacheTestCore.MakeDurableCache()) { var tA = cache.GetOrCreateTable <long>("A"); for (var i = 0; i < COUNT; i++) { var key = i * 7; var value = "value of " + i.ToString(); var pr = tA.Put(key, value, maxAgeSec: 20); Aver.AreObjectEqualTest(PutResult.Inserted, pr); } Aver.AreEqual(COUNT, tA.Count); const int WAIT = 45; for (var j = 0; j < WAIT; j++) { Console.WriteLine("Wait loop iteration #{0} of {1}", j, WAIT); for (var i = 0; i < COUNT; i++) { var odd = (i & 1) != 0; if (odd) { continue;//do not rejuvenate ODD } var key = i * 7; Aver.IsTrue(tA.Rejuvenate(key)); } Thread.Sleep(1000); } for (var i = 0; i < COUNT; i++) { var key = i * 7; var value = "value of " + i.ToString(); var odd = (i & 1) != 0; var got = tA.Get(key) as string; if (odd) { Aver.IsNull(got); } else { Aver.AreEqual(value, got); } } Aver.AreEqual(COUNT / 2, cache.Pile.ObjectCount);//Half of objects died } }
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 BasicDurable(int COUNT) { using (var cache = PileCacheTestCore.MakeDurableCache()) { var tA = cache.GetOrCreateTable <Guid>("A"); Aver.AreObjectsEqual(CollisionMode.Durable, 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); Aver.IsTrue(PutResult.Inserted == tA.PutPointer(key, ptr)); } Aver.AreEqual(COUNT, tA.Count); foreach (var kvp in dict) { var gotPointer = tA.GetPointer(kvp.Key); Aver.IsTrue(gotPointer.Valid); Aver.AreEqual(gotPointer, kvp.Value); var gotObject = tA.Get(kvp.Key) as string; Aver.IsNotNull(gotObject); Aver.AreEqual(kvp.Key.ToString(), gotObject); } //because there is durable chaining, object count in pile is greater than in table Aver.IsTrue(COUNT <= cache.Pile.ObjectCount); foreach (var kvp in dict) { Aver.IsTrue(tA.Remove(kvp.Key)); } Aver.AreEqual(0, tA.Count); Aver.AreEqual(0, cache.Pile.ObjectCount); } }
public void AddAndRetainAll(int COUNT) { using (var cache = PileCacheTestCore.MakeDurableCache()) { var tA = cache.GetOrCreateTable <Guid>("A"); var tB = cache.GetOrCreateTable <string>("B"); Aver.AreObjectsEqual(CollisionMode.Durable, tA.CollisionMode); Aver.AreObjectsEqual(CollisionMode.Durable, tB.CollisionMode); var dict = new Dictionary <Guid, string>(); for (var i = 0; i < COUNT; i++) { var key = Guid.NewGuid(); var value = "this is a value of " + key; dict.Add(key, value); var pr = tA.Put(key, value); Aver.IsTrue(PutResult.Inserted == pr); pr = tB.Put(key.ToString(), value); Aver.IsTrue(PutResult.Inserted == pr); } Aver.AreEqual(COUNT, dict.Count); Aver.AreEqual(COUNT, tA.Count); Aver.AreEqual(COUNT, tB.Count); foreach (var kvp in dict) { Aver.IsTrue(tA.ContainsKey(kvp.Key)); Aver.AreEqual(kvp.Value, tA.Get(kvp.Key) as string); Aver.AreEqual(kvp.Value, tB.Get(kvp.Key.ToString()) as string); } } }
public void SweepOld(int COUNT) { using (var cache = PileCacheTestCore.MakeDurableCache()) { var tA = cache.GetOrCreateTable <long>("A"); for (var i = 0; i < COUNT; i++) { var key = i * 7; var value = "value of " + i.ToString(); var odd = (i & 1) != 0; var pr = tA.Put(key, value, maxAgeSec: odd ? 1 : 0); Aver.AreObjectEqualTest(PutResult.Inserted, pr); } Aver.AreEqual(COUNT, tA.Count); Thread.Sleep(15000); for (var i = 0; i < COUNT; i++) { var key = i * 7; var value = "value of " + i.ToString(); var odd = (i & 1) != 0; var got = tA.Get(key) as string; if (odd) { Aver.IsNull(got); } else { Aver.AreEqual(value, got); } } Aver.AreEqual(COUNT / 2, cache.Pile.ObjectCount);//Half of objects died } }
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 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 AddThenEnumerateAll(int COUNT) { using (var cache = PileCacheTestCore.MakeDurableCache()) { var tA = cache.GetOrCreateTable <Guid>("A"); var dict = new Dictionary <Guid, string>(); for (var i = 0; i < COUNT; i++) { var key = Guid.NewGuid(); var value = "this is a value of " + key; dict.Add(key, value); var pr = tA.Put(key, value); Aver.IsTrue(PutResult.Inserted == pr); } Aver.AreEqual(COUNT, dict.Count); Aver.AreEqual(COUNT, tA.Count); foreach (var kvp in dict) { Aver.IsTrue(tA.ContainsKey(kvp.Key)); Aver.AreEqual(kvp.Value, tA.Get(kvp.Key) as string); } var hs = new HashSet <Guid>(); var cnt = 0; foreach (var entry in tA.AsEnumerable(false))//no materialization { var value = dict[entry.Key]; Aver.IsTrue(hs.Add(entry.Key));//ensure no duplication in enumerator Aver.IsNull(entry.Value); Aver.AreEqual(value, tA.Get(entry.Key) as string); cnt++; } Aver.AreEqual(dict.Count, cnt);//ensure the same# of elements hs = new HashSet <Guid>(); cnt = 0; foreach (var entry in tA.AsEnumerable(true))//with materialization { var value = dict[entry.Key]; Aver.IsTrue(hs.Add(entry.Key));//ensure no duplication in enumerator Aver.AreEqual(value, entry.Value as string); cnt++; } Aver.AreEqual(dict.Count, cnt);//ensure the same# of elements //------- Manual enumerator ------- var enumerator = tA.AsEnumerable(false).GetEnumerator(); cnt = 0; hs = new HashSet <Guid>(); while (enumerator.MoveNext()) { var value = dict[enumerator.Current.Key]; Aver.IsTrue(hs.Add(enumerator.Current.Key));//ensure no duplication in enumerator Aver.IsNull(enumerator.Current.Value); Aver.AreEqual(value, tA.Get(enumerator.Current.Key) as string); cnt++; } Aver.AreEqual(dict.Count, cnt);//ensure the same# of elements //Reset enumerator enumerator.Reset();//<----------------------------- cnt = 0; hs = new HashSet <Guid>(); while (enumerator.MoveNext()) { var value = dict[enumerator.Current.Key]; Aver.IsTrue(hs.Add(enumerator.Current.Key));//ensure no duplication in enumerator Aver.IsNull(enumerator.Current.Value); Aver.AreEqual(value, tA.Get(enumerator.Current.Key) as string); cnt++; } Aver.AreEqual(dict.Count, cnt);//ensure the same# of elements } }
public void T9000000_ParalellGetPutRemove(int workers, int tables, int putCount, int durationSec) { PileCacheTestCore.ParalellGetPutRemove(workers, tables, putCount, durationSec); }
public void VarSizes_Checkboard(bool isParallel, int cnt, int minSz, int maxSz, bool speed) { PileCacheTestCore.VarSizes_Checkboard(isParallel, cnt, minSz, maxSz, speed); }
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); } }
public void T160_ResizeTable(int cnt, int rec, int payload) { PileCacheTestCore.ResizeTable(cnt, rec, payload); }
public void T150_KeyString_ManyPutGet(int cnt) { PileCacheTestCore.KeyString_ManyPutGet(cnt); }
public void T140_KeyGDID_ManyPutGet(int cnt) { PileCacheTestCore.KeyGDID_ManyPutGet(cnt); }
public void T130_KeyInt_ManyPutGet(int cnt) { PileCacheTestCore.KeyInt_ManyPutGet(cnt); }
public void VarSizes_Increasing_Random(bool isParallel, int cnt, int minSz, int maxSz, bool speed, bool rnd) { PileCacheTestCore.VarSizes_Increasing_Random(isParallel, cnt, minSz, maxSz, speed, rnd); }
public void T190_FID_PutGetCorrectness(int cnt, int tbls) { PileCacheTestCore.FID_PutGetCorrectness(cnt, tbls); }