Example #1
0
        public void ShouldFragmentMessageOverTwoFrames()
        {
            int          msgLength        = MaxPayloadLength + 1;
            int          headerLength     = _defaultHeader.Capacity;
            int          frameLength      = headerLength + 1;
            int          requiredCapacity = BitUtil.Align(headerLength + 1, FrameDescriptor.FRAME_ALIGNMENT) + MaxFrameLength;
            UnsafeBuffer buffer           = new UnsafeBuffer(new byte[msgLength]);
            int          tail             = 0;

            A.CallTo(() => _metaDataBuffer.GetAndAddLong(LogBufferDescriptor.TERM_TAIL_COUNTER_OFFSET, requiredCapacity)).Returns(TermAppender.Pack(TermID, tail));

            Assert.That(_termAppender.AppendFragmentedMessage(_headerWriter, buffer, 0, msgLength, MaxPayloadLength, RVS), Is.EqualTo((long)requiredCapacity));

            A.CallTo(() => _metaDataBuffer.GetAndAddLong(LogBufferDescriptor.TERM_TAIL_COUNTER_OFFSET, requiredCapacity)).MustHaveHappened()
            .Then(A.CallTo(() => _headerWriter.Write(_termBuffer, tail, MaxFrameLength, TermID)).MustHaveHappened())
            .Then(A.CallTo(() => _termBuffer.PutBytes(tail + headerLength, buffer, 0, MaxPayloadLength)).MustHaveHappened())
            .Then(A.CallTo(() => _termBuffer.PutByte(FrameDescriptor.FlagsOffset(tail), FrameDescriptor.BEGIN_FRAG_FLAG)).MustHaveHappened())
            .Then(A.CallTo(() => _termBuffer.PutLong(tail + DataHeaderFlyweight.RESERVED_VALUE_OFFSET, RV)).MustHaveHappened())
            .Then(A.CallTo(() => _termBuffer.PutIntOrdered(tail, MaxFrameLength)).MustHaveHappened())

            .Then(A.CallTo(() => _headerWriter.Write(_termBuffer, MaxFrameLength, frameLength, TermID)).MustHaveHappened())
            .Then(A.CallTo(() => _termBuffer.PutBytes(MaxFrameLength + headerLength, buffer, MaxPayloadLength, 1)).MustHaveHappened())
            .Then(A.CallTo(() => _termBuffer.PutByte(FrameDescriptor.FlagsOffset(MaxFrameLength), FrameDescriptor.END_FRAG_FLAG)).MustHaveHappened())
            .Then(A.CallTo(() => _termBuffer.PutLong(MaxFrameLength + DataHeaderFlyweight.RESERVED_VALUE_OFFSET, RV)).MustHaveHappened())
            .Then(A.CallTo(() => _termBuffer.PutIntOrdered(MaxFrameLength, frameLength)).MustHaveHappened());
        }
Example #2
0
        public void ShouldGetByteArrayFromBuffer(IAtomicBuffer buffer)
        {
            byte[] testArray = { (byte)'H', (byte)'e', (byte)'l', (byte)'l', (byte)'o' };

            var i = Index;

            foreach (var v in testArray)
            {
                buffer.PutByte(i, v);
                i += BitUtil.SIZE_OF_BYTE;
            }

            var result = new byte[testArray.Length];

            buffer.GetBytes(Index, result);

            Assert.That(result, Is.EqualTo(testArray));
        }
Example #3
0
 public static void FrameFlags(IAtomicBuffer buffer, int termOffset, byte flags)
 {
     buffer.PutByte(FlagsOffset(termOffset), flags);
 }
Example #4
0
        public void ShouldPutByteToBuffer(IAtomicBuffer buffer)
        {
            buffer.PutByte(Index, ByteValue);

            Assert.That(Marshal.ReadByte(buffer.BufferPointer, Index), Is.EqualTo(ByteValue));
        }
Example #5
0
 /// <summary>
 /// Write the flags field for a frame.
 /// </summary>
 /// <param name="buffer">     containing the frame. </param>
 /// <param name="termOffset"> at which a frame begins. </param>
 /// <param name="flags">      value for the frame. </param>
 public static void FrameFlags(IAtomicBuffer buffer, int termOffset, byte flags)
 {
     buffer.PutByte(FlagsOffset(termOffset), flags);
 }