public void SegmentAddedDeleted() { using (var pile = new DefaultPile() { SegmentSize = PileCacheTestCore.SEG_SIZE }) { pile.Start(); var ipile = pile as IPile; var pp = PilePointer.Invalid; for (ulong i = 0; i < PileCacheTestCore.SEG_SIZE && ipile.SegmentCount < 2; i++) { var ch = ChargeRow.MakeFake(new GDID(1, i)); pp = ipile.Put(ch); } Aver.AreEqual(2, ipile.SegmentCount); ipile.Delete(pp); Aver.AreEqual(1, ipile.SegmentCount); } }
public static CheckoutRow MakeFake(GDID gdid) { var ch = new CheckoutRow() { ID = gdid, FileName = "myface_" + gdid.ID.ToString(), Date = DateTime.Now, StartOffset = gdid.ID * 20, G_Block = gdid, Address1 = NFX.Parsing.NaturalTextGenerator.Generate(50), Address2 = (gdid.ID % 7) == 0 ? NFX.Parsing.NaturalTextGenerator.Generate(50) : null }; var chCnt = (int)(gdid.ID % 10); ch.Charges = new ChargeRow[chCnt]; for (int i = 0; i < chCnt; i++) { ch.Charges[i] = ChargeRow.MakeFake(gdid); } return(ch); }
public void Parallel_PutDeleteGet_Checkerboard() { const int CNT = 1002030;//1000203; var tuples = new Tuple <PilePointer, ChargeRow> [CNT]; using (var pile = new DefaultPile()) { pile.Start(); var ipile = pile as IPile; Parallel.For(0, CNT, i => { var ch = ChargeRow.MakeFake(new GDID(0, (ulong)i)); var pp = ipile.Put(ch); tuples[i] = new Tuple <PilePointer, ChargeRow>(pp, ch); }); Aver.AreEqual(CNT, ipile.ObjectCount); Parallel.For(0, CNT, i => { if (i % 3 != 0) { ipile.Delete(tuples[i].Item1); } }); Aver.AreEqual(CNT / 3, ipile.ObjectCount); var deletedHits = new ConcurrentDictionary <int, int>(); Parallel.For(0, CNT, i => { if (i % 3 != 0) { try { deletedHits.AddOrUpdate(System.Threading.Thread.CurrentThread.ManagedThreadId, 1, (threadId, val) => val + 1); ipile.Get(tuples[i].Item1); Aver.Fail("Object is deleted but its pointer doesn't throw exception!"); } catch (PileAccessViolationException) {} } else { var ch = ipile.Get(tuples[i].Item1); Aver.AreObjectsEqual(ch, tuples[i].Item2); } }); foreach (var kvp in deletedHits) { Console.WriteLine("Thread '{0}' {1:n0} times accessed deleted pointer", kvp.Key, kvp.Value); } } }
public void Parallel_PutGet() { const int CNT = 1000000; var tuples = new Tuple <PilePointer, ChargeRow> [CNT]; using (var pile = new DefaultPile()) { pile.Start(); var ipile = pile as IPile; Parallel.For(0, CNT, i => { var ch = ChargeRow.MakeFake(new GDID(0, (ulong)i)); var pp = ipile.Put(ch); tuples[i] = new Tuple <PilePointer, ChargeRow>(pp, ch); }); Aver.AreEqual(CNT, ipile.ObjectCount); Parallel.ForEach(tuples, t => { Aver.AreObjectsEqual(t.Item2, ipile.Get(t.Item1)); }); } }