Example #1
0
        public void ShouldGetAndAddLongToNativeBuffer(IAtomicBuffer buffer)
        {
            Marshal.WriteInt64(buffer.BufferPointer, Index, LongValue);

            const long delta       = 1;
            var        beforeValue = buffer.GetAndAddLong(Index, delta);

            Assert.That(beforeValue, Is.EqualTo(LongValue));
            Assert.That(Marshal.ReadInt64(buffer.BufferPointer, Index), Is.EqualTo(LongValue + delta));
        }
Example #2
0
 /// <summary>
 /// Get the next value that can be used for a correlation id on an message when a response needs to be correlated.
 ///
 /// This method should be thread safe.
 /// </summary>
 /// <returns> the next value in the correlation sequence. </returns>
 public long NextCorrelationId()
 {
     return(_buffer.GetAndAddLong(_correlationIdCounterIndex, 1));
 }
Example #3
0
 /// <summary>
 /// Perform an atomic increment that will not lose updates across threads.
 /// </summary>
 /// <returns> the previous value of the counter </returns>
 public long Increment()
 {
     return(_buffer.GetAndAddLong(_offset, 1));
 }
Example #4
0
        public void ShouldAppendFrameToEmptyLog()
        {
            int          headerLength       = _defaultHeader.Capacity;
            UnsafeBuffer buffer             = new UnsafeBuffer(new byte[128]);
            const int    msgLength          = 20;
            int          frameLength        = msgLength + headerLength;
            int          alignedFrameLength = BitUtil.Align(frameLength, FrameDescriptor.FRAME_ALIGNMENT);
            const int    tail = 0;

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

            Assert.That(_termAppender.AppendUnfragmentedMessage(_headerWriter, buffer, 0, msgLength), Is.EqualTo((long)alignedFrameLength));

            A.CallTo(() => _metaDataBuffer.GetAndAddLong(LogBufferDescriptor.TERM_TAIL_COUNTER_OFFSET, alignedFrameLength)).MustHaveHappened()
            .Then(A.CallTo(() => _headerWriter.Write(_termBuffer, tail, frameLength, TermID)).MustHaveHappened())
            .Then(A.CallTo(() => _termBuffer.PutBytes(headerLength, buffer, 0, msgLength)).MustHaveHappened())
            .Then(A.CallTo(() => _termBuffer.PutIntOrdered(tail, frameLength)).MustHaveHappened());
        }
Example #5
0
 private long GetAndAddRawTail(int alignedLength)
 {
     return(_metaDataBuffer.GetAndAddLong(LogBufferDescriptor.TERM_TAIL_COUNTER_OFFSET, alignedLength));
 }