Пример #1
0
        /// <summary>
        /// Abort a claim of the message space to the log buffer so that the log can progress by ignoring this claim.
        /// </summary>
        public void Abort()
        {
            var frameLength = _buffer.Capacity;

            _buffer.PutShort(HeaderFlyweight.TYPE_FIELD_OFFSET, (short)HeaderFlyweight.HDR_TYPE_PAD);
            _buffer.PutIntOrdered(HeaderFlyweight.FRAME_LENGTH_FIELD_OFFSET, frameLength);
        }
Пример #2
0
        /// <summary>
        /// Return an initialised default Data Frame Header.
        /// </summary>
        /// <param name="sessionId"> for the header </param>
        /// <param name="streamId">  for the header </param>
        /// <param name="termId">    for the header </param>
        /// <returns> byte array containing the header </returns>
        public static UnsafeBuffer CreateDefaultHeader(int sessionId, int streamId, int termId)
        {
            var buffer = new UnsafeBuffer(new byte[HEADER_LENGTH]);

            buffer.PutByte(VERSION_FIELD_OFFSET, CURRENT_VERSION);
            buffer.PutByte(FLAGS_FIELD_OFFSET, (byte)BEGIN_AND_END_FLAGS);
            buffer.PutShort(TYPE_FIELD_OFFSET, HDR_TYPE_DATA);
            buffer.PutInt(SESSION_ID_FIELD_OFFSET, sessionId);
            buffer.PutInt(STREAM_ID_FIELD_OFFSET, streamId);
            buffer.PutInt(TERM_ID_FIELD_OFFSET, termId);
            buffer.PutLong(RESERVED_VALUE_OFFSET, DEFAULT_RESERVE_VALUE);

            return(buffer);
        }
Пример #3
0
        /// <summary>
        /// Return an initialised default Data Frame Header.
        /// </summary>
        /// <param name="sessionId"> for the header </param>
        /// <param name="streamId">  for the header </param>
        /// <param name="termId">    for the header </param>
        /// <returns> byte array containing the header </returns>
        public static UnsafeBuffer CreateDefaultHeader(int sessionId, int streamId, int termId)
        {
            var buffer = new UnsafeBuffer(BufferUtil.AllocateDirectAligned(HEADER_LENGTH, FrameDescriptor.FRAME_ALIGNMENT));

            buffer.PutByte(VERSION_FIELD_OFFSET, CURRENT_VERSION);
            buffer.PutByte(FLAGS_FIELD_OFFSET, (byte)BEGIN_AND_END_FLAGS);
            buffer.PutShort(TYPE_FIELD_OFFSET, HDR_TYPE_DATA);
            buffer.PutInt(SESSION_ID_FIELD_OFFSET, sessionId);
            buffer.PutInt(STREAM_ID_FIELD_OFFSET, streamId);
            buffer.PutInt(TERM_ID_FIELD_OFFSET, termId);
            buffer.PutLong(RESERVED_VALUE_OFFSET, DEFAULT_RESERVE_VALUE);

            return(buffer);
        }
Пример #4
0
        public void ShouldInsertLastFrameIntoBuffer()
        {
            int          frameLength = BitUtil.Align(256, FrameDescriptor.FRAME_ALIGNMENT);
            const int    srcOffset   = 0;
            int          tail        = TERM_BUFFER_CAPACITY - frameLength;
            int          termOffset  = tail;
            UnsafeBuffer packet      = new UnsafeBuffer(new byte[frameLength]);

            packet.PutShort(FrameDescriptor.TypeOffset(srcOffset), (short)FrameDescriptor.PADDING_FRAME_TYPE);
            packet.PutInt(srcOffset, frameLength);

            TermRebuilder.Insert(_termBuffer, termOffset, packet, frameLength);

            A.CallTo(() => _termBuffer.PutBytes(tail + DataHeaderFlyweight.HEADER_LENGTH, packet, srcOffset + DataHeaderFlyweight.HEADER_LENGTH, frameLength - DataHeaderFlyweight.HEADER_LENGTH)).MustHaveHappened();
        }
Пример #5
0
        public void ShouldPadLogWhenAppendingWithInsufficientRemainingCapacity()
        {
            const int    msgLength         = 120;
            int          headerLength      = _defaultHeader.Capacity;
            int          requiredFrameSize = BitUtil.Align(headerLength + msgLength, FrameDescriptor.FRAME_ALIGNMENT);
            int          tailValue         = TermBufferLength - BitUtil.Align(msgLength, FrameDescriptor.FRAME_ALIGNMENT);
            UnsafeBuffer buffer            = new UnsafeBuffer(new byte[128]);
            int          frameLength       = TermBufferLength - tailValue;

            _logMetaDataBuffer.PutLong(TermTailCounterOffset, LogBufferDescriptor.PackTail(TermID, tailValue));

            Assert.That(_termAppender.AppendUnfragmentedMessage(_headerWriter, buffer, 0, msgLength, RVS, TermID), Is.EqualTo(TermAppender.FAILED));

            Assert.AreEqual(LogBufferDescriptor.RawTailVolatile(_logMetaDataBuffer, PartionIndex), LogBufferDescriptor.PackTail(TermID, tailValue + requiredFrameSize));

            A.CallTo(() => _headerWriter.Write(_termBuffer, tailValue, frameLength, TermID)).MustHaveHappened()
            .Then(A.CallTo(() => _termBuffer.PutShort(FrameDescriptor.TypeOffset(tailValue), FrameDescriptor.PADDING_FRAME_TYPE)).MustHaveHappened())
            .Then(A.CallTo(() => _termBuffer.PutIntOrdered(tailValue, frameLength)).MustHaveHappened());
        }
Пример #6
0
 /// <summary>
 /// Set the value of the header type field. The lower 16 bits are valid.
 /// </summary>
 /// <param name="type"> value to be set in the header. </param>
 /// <returns> this for a fluent API. </returns>
 /// <seealso cref="DataHeaderFlyweight"></seealso>
 public BufferClaim HeaderType(int type)
 {
     _buffer.PutShort(HeaderFlyweight.TYPE_FIELD_OFFSET, (short)type, ByteOrder.LittleEndian);
     return(this);
 }
Пример #7
0
        /// <summary>
        /// Set the value of the header type field. The lower 16 bits are valid.
        /// </summary>
        /// <param name="type"> value to be set in the header. </param>
        /// <returns> this for a fluent API. </returns>
        /// <seealso cref="DataHeaderFlyweight"/>
        public ExclusiveBufferClaim HeaderType(int type)
        {
            _buffer.PutShort(HeaderFlyweight.TYPE_FIELD_OFFSET, (short)type);

            return(this);
        }