Beispiel #1
0
        public void ShouldReadFirstMessage()
        {
            const int msgLength   = 1;
            int       frameLength = HEADER_LENGTH + msgLength;
            const int termOffset  = 0;

            A.CallTo(() => termBuffer.GetIntVolatile(0))
            .Returns(frameLength);
            A.CallTo(() => termBuffer.GetShort(FrameDescriptor.TypeOffset(0)))
            .Returns((short)HeaderFlyweight.HDR_TYPE_DATA);

            long readOutcome = TermReader.Read(termBuffer, termOffset, handler, int.MaxValue, header, errorHandler);

            Assert.That(TermReader.FragmentsRead(readOutcome), Is.EqualTo(1));

            A.CallTo(() => termBuffer.GetIntVolatile(0)).MustHaveHappened();
            A.CallTo(() => handler(termBuffer, HEADER_LENGTH, msgLength, A <Header> ._)).MustHaveHappened();
        }
Beispiel #2
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);

            A.CallTo(() => _termBuffer.GetInt(tail)).Returns(frameLength);
            A.CallTo(() => _termBuffer.GetShort(FrameDescriptor.TypeOffset(tail))).Returns((short)FrameDescriptor.PADDING_FRAME_TYPE);

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

            A.CallTo(() => (_termBuffer).PutBytes(tail, packet, srcOffset, frameLength)).MustHaveHappened();
        }
Beispiel #3
0
 public static bool IsPaddingFrame(IAtomicBuffer buffer, int termOffset)
 {
     return(buffer.GetShort(TypeOffset(termOffset)) == PADDING_FRAME_TYPE);
 }
Beispiel #4
0
 public static int FrameType(IAtomicBuffer buffer, int termOffset)
 {
     //return buffer.GetShort(TypeOffset(termOffset), LITTLE_ENDIAN) & 0xFFFF;
     return(buffer.GetShort(TypeOffset(termOffset)) & 0xFFFF);
 }
Beispiel #5
0
        public void ShouldGetShortFromNativeBuffer(IAtomicBuffer buffer)
        {
            Marshal.WriteInt16(buffer.BufferPointer, Index, ShortValue);

            Assert.That(buffer.GetShort(Index), Is.EqualTo(ShortValue));
        }
Beispiel #6
0
        public void ShouldReadFirstMessage()
        {
            const int offset               = 0;
            int       limit                = _termBuffer.Capacity;
            const int messageLength        = 50;
            int       alignedMessageLength = BitUtil.Align(messageLength, FrameDescriptor.FRAME_ALIGNMENT);

            A.CallTo(() => _termBuffer.GetIntVolatile(FrameDescriptor.LengthOffset(offset)))
            .Returns(messageLength);
            A.CallTo(() => _termBuffer.GetShort(FrameDescriptor.TypeOffset(offset)))
            .Returns((short)HeaderFlyweight.HDR_TYPE_DATA);

            int newOffset = TermBlockScanner.Scan(_termBuffer, offset, limit);

            Assert.That(newOffset, Is.EqualTo(alignedMessageLength));
        }
Beispiel #7
0
 /// <summary>
 /// Is the frame starting at the termOffset a padding frame at the end of a buffer?
 /// </summary>
 /// <param name="buffer">     containing the frame. </param>
 /// <param name="termOffset"> at which a frame begins. </param>
 /// <returns> true if the frame is a padding frame otherwise false. </returns>
 public static bool IsPaddingFrame(IAtomicBuffer buffer, int termOffset)
 {
     return buffer.GetShort(TypeOffset(termOffset)) == PADDING_FRAME_TYPE;
 }
Beispiel #8
0
 /// <summary>
 /// Read the type of of the frame from header.
 /// </summary>
 /// <param name="buffer">     containing the frame. </param>
 /// <param name="termOffset"> at which a frame begins. </param>
 /// <returns> the value of the frame type header. </returns>
 public static int FrameType(IAtomicBuffer buffer, int termOffset)
 {
     //return buffer.GetShort(TypeOffset(termOffset), LITTLE_ENDIAN) & 0xFFFF;
     return buffer.GetShort(TypeOffset(termOffset)) & 0xFFFF;
 }