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()); }
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)); }
public static void FrameFlags(IAtomicBuffer buffer, int termOffset, byte flags) { buffer.PutByte(FlagsOffset(termOffset), flags); }
public void ShouldPutByteToBuffer(IAtomicBuffer buffer) { buffer.PutByte(Index, ByteValue); Assert.That(Marshal.ReadByte(buffer.BufferPointer, Index), Is.EqualTo(ByteValue)); }
/// <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); }