public void PileSmallObjects(int payloadSize, params int[] freeChunkSizes) { using (var pile = new DefaultPile() { SegmentSize = PileCacheTestCore.SEG_SIZE, AllocMode = AllocationMode.ReuseSpace }) { pile.FreeChunkSizes = freeChunkSizes; pile.Start(); var pps = new List <PilePointer>(); while (pile.SegmentCount < 2) { pps.Add(pile.Put(generatePayload(payloadSize))); } pile.Delete(pps.Last()); pps.RemoveAt(pps.Count - 1); Console.WriteLine("Just removed the last added payload and segment should be 1 now, real segment count is {0}", pile.SegmentCount); Aver.AreEqual(1, pile.SegmentCount); var objectsInFirstSegment = pps.Count; Console.WriteLine("put {0:N0} objects in first segment, pile.ObjectCount {1:N0}", objectsInFirstSegment, pile.ObjectCount); var deletedObjectCount = 0; for (int i = 0; i < pps.Count; i += 2, deletedObjectCount++) { Assert.IsTrue(pile.Delete(pps[i])); } var objectsInFirstSegmentAfterDelete = pile.ObjectCount; Console.WriteLine("Deleted {0:N0} objects from 1st segment, pile.ObjectCount {1:N0}", deletedObjectCount, pile.ObjectCount); Aver.AreEqual(objectsInFirstSegment / 2, objectsInFirstSegmentAfterDelete); Console.WriteLine("---------------------------------------------------------"); var crawlStatus = pile.Crawl(false); Console.WriteLine("crawl: {0}", crawlStatus); var pps1 = new List <PilePointer>(); var c = 0; while (pile.SegmentCount < 3) { pps1.Add(pile.Put(generatePayload(payloadSize))); if (c % 20000 == 0) { pile.Crawl(true); //we do crawl because otherwise the 25000 free index xlots get exhausted AND } c++; //this unit tests does not run long enough to cause Crawl within allocator (5+ seconds) } //so we induce Crawl by hand to rebiild indexes pile.Delete(pps1.Last()); pps1.RemoveAt(pps1.Count - 1); Console.WriteLine("Again just removed the last added payload and segment should be 2 now, real segment count is {0}", pile.SegmentCount); Aver.AreEqual(2, pile.SegmentCount); var objectsInSecondRound = pps1.Count; Console.WriteLine("Put {0:N0} objects in second round, pile.ObjectCount {1:N0}", objectsInSecondRound, pile.ObjectCount); Aver.AreWithin(objectsInFirstSegment + objectsInFirstSegmentAfterDelete, objectsInSecondRound, 2d, "#1"); Aver.AreEqual(objectsInFirstSegmentAfterDelete + objectsInSecondRound, pile.ObjectCount, "#2"); } }