Пример #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));
        }
Пример #2
0
        /// <summary>
        /// Unsafe method for attempting to dequeue a message.
        /// </summary>
        /// <param name="envelope">The message that might be dequeued.</param>
        /// <returns><c>true</c> if a message was available to be dequeued, <c>false</c> otherwise.</returns>
        /// <remarks>
        /// Called from within a synchronization mechanism.
        /// </remarks>
        protected override bool LockedTryDequeue(out Envelope envelope)
        {
            if (_prependBuffer.Count > 0)
            {
                envelope = _prependBuffer.Pop();
                return(true);
            }

            if (_prioQueue.Count() > 0)
            {
                envelope = _prioQueue.Dequeue();
                return(true);
            }
            envelope = default(Envelope);
            return(false);
        }