Exemplo n.º 1
0
        public void FixedSizeBuffer_must_start_as_empty(int size)
        {
            var buf = FixedSizeBuffer.Create <NotUsed>(size);

            buf.IsEmpty.Should().BeTrue();
            buf.IsFull.Should().BeFalse();
        }
Exemplo n.º 2
0
        public void FixedSizeBuffer_must_become_nonempty_after_enqueuing(int size)
        {
            var buf = FixedSizeBuffer.Create <string>(size);

            buf.Enqueue("test");
            buf.IsEmpty.Should().BeFalse();
            buf.IsFull.Should().Be(size == 1);
        }
Exemplo n.º 3
0
            public Logic(Shape shape, Merge <TIn, TOut> stage) : base(shape)
            {
                _stage            = stage;
                _runningUpstreams = _stage._inputPorts;
                _pendingQueue     = FixedSizeBuffer.Create <Inlet <TIn> >(_stage._inputPorts);

                var outlet = _stage.Out;

                foreach (var inlet in _stage.Shape.Ins)
                {
                    SetHandler(inlet, onPush: () =>
                    {
                        if (IsAvailable(outlet))
                        {
                            if (!IsPending)
                            {
                                Push(outlet, Grab(inlet));
                                TryPull(inlet);
                            }
                        }
                        else
                        {
                            _pendingQueue.Enqueue(inlet);
                        }
                    },
                               onUpstreamFinish: () =>
                    {
                        if (_stage._eagerComplete)
                        {
                            foreach (var i in _stage.Shape.Ins)
                            {
                                Cancel(i);
                            }
                            _runningUpstreams = 0;
                            if (!IsPending)
                            {
                                CompleteStage();
                            }
                        }
                        else
                        {
                            _runningUpstreams--;
                            if (AreUpstreamsClosed && !IsPending)
                            {
                                CompleteStage();
                            }
                        }
                    });
                }

                SetHandler(outlet, onPull: () =>
                {
                    if (IsPending)
                    {
                        DequeueAndDispatch();
                    }
                });
            }
Exemplo n.º 4
0
        public void FixedSizeBuffer_must_become_empty_after_enqueuing_and_head_drop(int size)
        {
            var buf = FixedSizeBuffer.Create <string>(size);

            buf.Enqueue("test");
            buf.DropHead();
            buf.IsEmpty.Should().BeTrue();
            buf.IsFull.Should().BeFalse();
        }
Exemplo n.º 5
0
        public void FixedSizeBuffer_must_become_full_after_size_elements_are_enqueued(int size)
        {
            var buf = FixedSizeBuffer.Create <string>(size);

            for (var i = 0; i < size; i++)
            {
                buf.Enqueue("test");
            }
            buf.IsEmpty.Should().BeFalse();
            buf.IsFull.Should().BeTrue();
        }
Exemplo n.º 6
0
        public void FixedSizeBuffer_must_become_non_full_after_head_dropped_from_full_buffer(int size)
        {
            var buf = FixedSizeBuffer.Create <string>(size);

            for (var elem = 1; elem <= size; elem++)
            {
                buf.Enqueue("test");
            }

            buf.DropHead();

            buf.IsEmpty.Should().Be(size == 1);
            buf.IsFull.Should().BeFalse();
        }
Exemplo n.º 7
0
        public void FixedSizeBuffer_must_drop_head_properly(int size)
        {
            var buf = FixedSizeBuffer.Create <int>(size);

            for (var elem = 1; elem <= size; elem++)
            {
                buf.Enqueue(elem);
            }

            buf.DropHead();
            for (var elem = 2; elem <= size; elem++)
            {
                buf.Dequeue().Should().Be(elem);
            }
        }
Exemplo n.º 8
0
        public void FixedSizeBuffer_must_work_properly_with_full_range_filling_draining_cycles(int size)
        {
            var buf = FixedSizeBuffer.Create <int>(size);

            for (var i = 0; i < 10; i++)
            {
                buf.IsEmpty.Should().BeTrue();
                buf.IsFull.Should().BeFalse();
                for (var elem = 1; elem <= size; elem++)
                {
                    buf.Enqueue(elem);
                }
                buf.IsEmpty.Should().BeFalse();
                buf.IsFull.Should().BeTrue();
                for (var elem = 1; elem <= size; elem++)
                {
                    buf.Dequeue().Should().Be(elem);
                }
            }
        }