Esempio n. 1
0
        [Test] public void PutChokesWhenQueueIsBroken()
        {
            LinkedBlockingQueue <T> q = NewLinkedBlockingQueue();

            q.Break();
            Assert.Throws <QueueBrokenException>(() => q.Put(TestData <T> .One));
        }
Esempio n. 2
0
        [Test] public void TryPutReturnFalseWhenQueueIsBroken()
        {
            LinkedBlockingQueue <T> q = NewLinkedBlockingQueue();

            q.Break();
            Assert.IsFalse(q.TryPut(TestData <T> .One));
        }
Esempio n. 3
0
        public void ConstructorCreatesQueueWithUnlimitedCapacity()
        {
            Options.SkipWhen(CollectionContractOptions.Bounded);
            var queue = new LinkedBlockingQueue <T>();

            Assert.AreEqual(int.MaxValue, queue.RemainingCapacity);
            Assert.AreEqual(int.MaxValue, queue.Capacity);
        }
Esempio n. 4
0
        public void ConstructorCreatesQueueWithGivenCapacity()
        {
            Options.SkipWhenNot(CollectionContractOptions.Bounded);
            var queue = new LinkedBlockingQueue <T>(SampleSize);

            Assert.AreEqual(SampleSize, queue.RemainingCapacity);
            Assert.AreEqual(SampleSize, queue.Capacity);
        }
 internal LinkedBlockingQueueEnumerator(LinkedBlockingQueue <T> queue)
 {
     _queue = queue;
     lock (_queue._putLock) {
         lock (_queue._takeLock) {
             _currentNode = _queue._head;
         }
     }
 }
Esempio n. 6
0
 internal LinkedBlockingQueueEnumerator(LinkedBlockingQueue <T> enclosingInstance)
 {
     _enclosingInstance = enclosingInstance;
     lock (Enclosing_Instance.putLock) {
         lock (Enclosing_Instance.takeLock) {
             CurrentNode   = Enclosing_Instance.head;
             _countAtStart = Enclosing_Instance.Count;
         }
     }
 }
Esempio n. 7
0
        internal static LinkedBlockingQueue <T> NewLinkedBlockingQueue(bool isBounded, int size, bool isFilled)
        {
            LinkedBlockingQueue <T> sut = isBounded ?
                                          new LinkedBlockingQueue <T>(size) : new LinkedBlockingQueue <T>();

            if (isFilled)
            {
                sut.AddRange(TestData <T> .MakeTestArray(size));
            }
            return(sut);
        }
Esempio n. 8
0
        public void ConstructorCreatesQueueConstainsAllElementsInCollection()
        {
            Options.SkipWhen(CollectionContractOptions.Bounded);
            var q = new LinkedBlockingQueue <T>(Samples);

            foreach (T sample in Samples)
            {
                T value;
                Assert.IsTrue(q.Poll(out value));
                Assert.That(value, Is.EqualTo(sample));
            }
        }
Esempio n. 9
0
        public void ConstructorWelcomesNullElememtInCollectionArgument()
        {
            Options.SkipWhen(CollectionContractOptions.Bounded);
            T[] arrayWithDefaulValue = new T[SampleSize];
            var q = new LinkedBlockingQueue <T>(arrayWithDefaulValue);

            foreach (T sample in arrayWithDefaulValue)
            {
                T value;
                Assert.IsTrue(q.Poll(out value));
                Assert.That(value, Is.EqualTo(sample));
            }
        }