Beispiel #1
0
        public void ShouldWriteToEmptyBuffer()
        {
            const int length              = 8;
            var       recordLength        = length + RingBufferDescriptor.HeaderLength;
            var       alignedRecordLength = recordLength.AlignToMultipleOf(RingBufferDescriptor.RecordAlignment);

            const int headValue = 0;

            _atomicLong.VolatileRead(Arg.Is(Head)).Returns(headValue);
            const int tailValue = 0;

            _atomicLong.Read(Arg.Is(Tail)).Returns(tailValue);

            var block = stackalloc byte[100];

            var chunk = new ByteChunk(block, length);

            Assert.IsTrue(_ringBuffer.Write(MessageTypeId, chunk));

            Received.InOrder(() =>
            {
                _buffer.Write(RingBufferDescriptor.EncodedMsgOffset(tailValue), chunk);
                _buffer.GetAtomicLong(tailValue);
                _atomicLong.VolatileWrite(CurrentSlot, RingBufferDescriptor.MakeHeader(recordLength, MessageTypeId));
                _atomicLong.VolatileWrite(Tail, tailValue + alignedRecordLength);
            });
        }
Beispiel #2
0
        public void ShouldReadNothingFromEmptyBuffer()
        {
            const long head = 0L;

            _atomicLong.Read(Head).Returns(head);

            var handler = default(MessageHandler);
            var read    = _ringBuffer.Read(handler, 100);

            Assert.AreEqual(0, read);
        }