Esempio n. 1
0
        public Property StableListPriorityQueue_must_be_stable(NonEmptyString[] values)
        {
            var sortedValues = values
                               .Select(x => x.Item)
                               .GroupBy(x => x.Length)
                               .OrderBy(x => x.Key)
                               .SelectMany(x => x).ToList();
            var pq = new StableListPriorityQueue(10, Priority);

            foreach (var i in values.Select(x => x.Item))
            {
                pq.Enqueue(new Envelope(i, ActorRefs.NoSender));
            }

            var isConsistent = pq.IsConsistent().ToProperty().Label("Expected queue to be consistent, but was not.");

            var queueValues = new List <string>();

            while (pq.Count() > 0)
            {
                queueValues.Add((string)pq.Dequeue().Message);
            }

            var sequenceEqual = queueValues.SequenceEqual(sortedValues).ToProperty().Label(
                $"Expected output to be [{string.Join(",", sortedValues)}] but was [{string.Join(",", queueValues)}]");

            return(sequenceEqual.And(isConsistent));
        }
Esempio n. 2
0
 /// <summary>
 /// Unsafe method for enqueuing a new message to the queue.
 /// </summary>
 /// <param name="envelope">The message to enqueue.</param>
 /// <remarks>
 /// Called from within a synchronization mechanism.
 /// </remarks>
 protected override void LockedEnqueue(Envelope envelope)
 {
     _prioQueue.Enqueue(envelope);
 }