Skip to content

Commit

Permalink
Added a ReadBufferSize property
Browse files Browse the repository at this point in the history
  • Loading branch information
mgnsm committed Mar 6, 2024
1 parent 94f6522 commit 14a22c8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
14 changes: 13 additions & 1 deletion Source/Millistream.Streaming/MarketDataFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,26 @@ public bool HandleDelay
/// <remarks>The corresponding native function is mdf_get_mclass.</remarks>
public ulong MessageClass => _nativeImplementation.mdf_get_mclass != default ? _nativeImplementation.mdf_get_mclass(_feedHandle) : default;

/// <summary>
/// Gets the number of bytes waiting to be processed in the internal read buffer after a call to <see cref="Consume(int)"/>.
/// </summary>
/// <exception cref="InvalidOperationException">The native value of the <see cref="MDF_OPTION.MDF_OPT_RBUF_SIZE"/> option cannot be fetched or modified.</exception>
public uint ReadBufferSize => (uint)GetUInt64Property(MDF_OPTION.MDF_OPT_RBUF_SIZE);

/// <summary>
/// Gets or sets the current size of the internal read buffer.
/// </summary>
/// <exception cref="ArgumentOutOfRangeException">The value is less than <see cref="ReadBufferSize"/>.</exception>
/// <exception cref="InvalidOperationException">The native value of the <see cref="MDF_OPTION.MDF_OPT_RBUF_MAXSIZE"/> option cannot be fetched or modified.</exception>
public uint ReadBufferMaxSize
{
get => (uint)GetUInt64Property(MDF_OPTION.MDF_OPT_RBUF_MAXSIZE);
set => SetProperty(MDF_OPTION.MDF_OPT_RBUF_MAXSIZE, value);
set
{
if (value < ReadBufferSize)
throw new ArgumentOutOfRangeException(nameof(value));
SetProperty(MDF_OPTION.MDF_OPT_RBUF_MAXSIZE, value);
}
}
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public void GetAndSetPropertiesTest()

Assert.AreEqual(0UL, mdf.ReceivedBytes);
Assert.AreEqual(0UL, mdf.SentBytes);
Assert.AreEqual(2048UL, mdf.ReadBufferMaxSize);
Assert.AreEqual(0U, mdf.ReadBufferSize);
Assert.AreEqual(2048U, mdf.ReadBufferMaxSize);

//HandleDelay
Assert.IsFalse(mdf.HandleDelay);
Expand Down
26 changes: 26 additions & 0 deletions Tests/Millistream.Streaming.UnitTests/MarketDataFeedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ public void GetMessageClassTest()
Assert.AreEqual(MessageClass, mdf.MessageClass);
}

[TestMethod]
public void GetReadBufferSizeTest() => GetUInt64Property(MDF_OPTION.MDF_OPT_RBUF_SIZE, mdf => mdf.ReadBufferSize);

[TestMethod]
public void GetReadBufferMaxSizeTest() => GetUInt64Property(MDF_OPTION.MDF_OPT_RBUF_MAXSIZE, mdf => mdf.ReadBufferMaxSize);

Expand All @@ -456,6 +459,10 @@ public void SetReadBufferMaxSizeTest()
{
const uint ReadBufferMaxSize = 5000;
Mock<INativeImplementation> nativeImplementation = new();
nativeImplementation
.Setup(x => x.mdf_get_property(It.IsAny<IntPtr>(), (int)MDF_OPTION.MDF_OPT_RBUF_SIZE, ref It.Ref<ulong>.IsAny))
.Returns(1)
.Callback(new GetUInt64PropertyCallback((IntPtr handler, int option_, ref ulong value) => value = 0));
Setup(nativeImplementation, MDF_OPTION.MDF_OPT_RBUF_MAXSIZE, ReadBufferMaxSize);

using MarketDataFeed mdf = new()
Expand All @@ -465,6 +472,25 @@ public void SetReadBufferMaxSizeTest()
nativeImplementation.Verify();
}

[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void ToLargeReadBufferMaxSizeTest()
{
const uint ReadBufferSize = 100;
Mock<INativeImplementation> nativeImplementation = new();
nativeImplementation
.Setup(x => x.mdf_get_property(It.IsAny<IntPtr>(), (int)MDF_OPTION.MDF_OPT_RBUF_SIZE, ref It.Ref<ulong>.IsAny))
.Returns(1)
.Callback(new GetUInt64PropertyCallback((IntPtr handler, int option_, ref ulong value) => value = ReadBufferSize))
.Verifiable();
NativeImplementation.Implementation = nativeImplementation.Object;
using MarketDataFeed mdf = new()
{
ReadBufferMaxSize = ReadBufferSize - 1
};
nativeImplementation.Verify();
}

[TestMethod]
public void GetAndSetDataCallbackTest()
{
Expand Down

0 comments on commit 14a22c8

Please sign in to comment.