Пример #1
0
        public void ShouldLateJoinTransmission()
        {
            const int length              = 8;
            var       recordLength        = length + RecordDescriptor.HeaderLength;
            var       recordLengthAligned = BitUtil.Align(recordLength, RecordDescriptor.RecordAlignment);
            var       tail         = Capacity * 3L + RecordDescriptor.HeaderLength + recordLengthAligned;
            var       latestRecord = tail - recordLengthAligned;
            var       recordOffset = (int)latestRecord & (Capacity - 1);

            A.CallTo(() => _buffer.GetLongVolatile(TailIntentCounterOffset)).Returns(tail);
            A.CallTo(() => _buffer.GetLongVolatile(TailCounterIndex)).Returns(tail);
            A.CallTo(() => _buffer.GetLong(LatestCounterIndex)).Returns(latestRecord);

            A.CallTo(() => _buffer.GetInt(RecordDescriptor.GetLengthOffset(recordOffset))).Returns(recordLength);
            A.CallTo(() => _buffer.GetInt(RecordDescriptor.GetTypeOffset(recordOffset))).Returns(MsgTypeID);

            Assert.IsTrue(_broadcastReceiver.ReceiveNext());
            Assert.AreEqual(MsgTypeID, _broadcastReceiver.TypeId());
            Assert.AreEqual(_buffer, _broadcastReceiver.Buffer());
            Assert.AreEqual(RecordDescriptor.GetMsgOffset(recordOffset), _broadcastReceiver.Offset());
            Assert.AreEqual(length, _broadcastReceiver.Length());
            Assert.True(_broadcastReceiver.Validate());

            Assert.Greater(_broadcastReceiver.LappedCount(), 0);
        }
Пример #2
0
        public void ShouldReadNothingFromEmptyBuffer()
        {
            const long head = 0L;

            A.CallTo(() => _buffer.GetLong(HeadCounterIndex)).Returns(head);

            MessageHandler handler = (msgTypeId, buffer, index, length) => Assert.Fail("should not be called");

            var messagesRead = _ringBuffer.Read(handler);

            Assert.AreEqual(messagesRead, 0);
        }
Пример #3
0
        /// <summary>
        /// Read all the errors in a log since a given timestamp.
        /// </summary>
        /// <param name="buffer">         containing the <seealso cref="DistinctErrorLog"/>. </param>
        /// <param name="consumer">       to be called for each exception encountered. </param>
        /// <param name="sinceTimestamp"> for filtering errors that have been recorded since this time. </param>
        /// <returns> the number of entries that has been read. </returns>
        public static int Read(IAtomicBuffer buffer, ErrorConsumer consumer, long sinceTimestamp)
        {
            int entries  = 0;
            int offset   = 0;
            int capacity = buffer.Capacity;

            while (offset < capacity)
            {
                int length = buffer.GetIntVolatile(offset + DistinctErrorLog.LengthOffset);
                if (0 == length)
                {
                    break;
                }

                long lastObservationTimestamp = buffer.GetLongVolatile(offset + DistinctErrorLog.LastObservationTimestampOffset);
                if (lastObservationTimestamp >= sinceTimestamp)
                {
                    ++entries;

                    consumer(
                        buffer.GetInt(offset + DistinctErrorLog.ObservationCountOffset),
                        buffer.GetLong(offset + DistinctErrorLog.FirstObservationTimestampOffset),
                        lastObservationTimestamp,
                        buffer.GetStringWithoutLengthUtf8(offset + DistinctErrorLog.EncodedErrorOffset, length - DistinctErrorLog.EncodedErrorOffset));
                }

                offset += BitUtil.Align(length, DistinctErrorLog.RecordAlignment);
            }

            return(entries);
        }
Пример #4
0
        /// <summary>
        /// Read all the errors in a log since a given timestamp.
        /// </summary>
        /// <param name="buffer">         containing the <seealso cref="DistinctErrorLog"/>. </param>
        /// <param name="consumer">       to be called for each exception encountered. </param>
        /// <param name="sinceTimestamp"> for filtering errors that have been recorded since this time. </param>
        /// <returns> the number of entries that has been read. </returns>
        public static int Read(IAtomicBuffer buffer, ErrorConsumer consumer, long sinceTimestamp)
        {
            int entries = 0;
            int offset = 0;
            int capacity = buffer.Capacity;

            while (offset < capacity)
            {
                int length = buffer.GetIntVolatile(offset + DistinctErrorLog.LengthOffset);
                if (0 == length)
                {
                    break;
                }

                long lastObservationTimestamp = buffer.GetLongVolatile(offset + DistinctErrorLog.LastObservationTimestampOffset);
                if (lastObservationTimestamp >= sinceTimestamp)
                {
                    ++entries;

                    consumer(
                        buffer.GetInt(offset + DistinctErrorLog.ObservationCountOffset), 
                        buffer.GetLong(offset + DistinctErrorLog.FirstObservationTimestampOffset), 
                        lastObservationTimestamp, 
                        buffer.GetStringUtf8(offset + DistinctErrorLog.EncodedErrorOffset, 
                        length - DistinctErrorLog.EncodedErrorOffset));
                }

                offset += BitUtil.Align(length, DistinctErrorLog.RecordAlignment);
            }

            return entries;
        }
Пример #5
0
        /// <summary>
        /// Get the value of the counter using weak ordering semantics. This is the same a standard read of a field.
        /// </summary>
        /// <returns> the  value for the counter. </returns>
        public long GetWeak()
        {
            // UnsafeAccess.UNSAFE.getLong(buffer, addressOffset);

            return(_valuesBuffer.GetLong(_addressOffset));
        }
Пример #6
0
        public void ShouldGetLongFromNativeBuffer(IAtomicBuffer buffer)
        {
            Marshal.WriteInt64(buffer.BufferPointer, Index, LongValue);

            Assert.That(buffer.GetLong(Index), Is.EqualTo(LongValue));
        }
Пример #7
0
 /// <summary>
 /// Get the value of the counter using weak ordering semantics. This is the same a standard read of a field.
 /// </summary>
 /// <returns> the  value for the counter. </returns>
 public long GetWeak()
 {
     return(_buffer.GetLong(_offset));
 }