Skip to content

Commit

Permalink
Added a HandleDelay property.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgnsm committed May 10, 2022
1 parent 0f0f4aa commit 3e0be47
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Source/Millistream.Streaming/MDF_OPTION.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal enum MDF_OPTION
MDF_OPT_CRYPT_CIPHERS,
MDF_OPT_CRYPT_DIGEST,
MDF_OPT_CRYPT_CIPHER,
MDF_OPT_TIMEOUT
MDF_OPT_TIMEOUT,
MDF_OPT_HANDLE_DELAY
};
}
12 changes: 12 additions & 0 deletions Source/Millistream.Streaming/MarketDataFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,18 @@ public string Ciphers
/// <exception cref="InvalidOperationException">The native value of the <see cref="MDF_OPTION.MDF_OPT_TIMEOUT"/> option cannot be fetched.</exception>
/// <exception cref="ObjectDisposedException">The <see cref="MarketDataFeed{TCallbackData,TStatusCallbackData}"/> instance has been disposed.</exception>
public int Timeout => GetInt32Property(MDF_OPTION.MDF_OPT_TIMEOUT);

/// <summary>
/// Enables or disables delay-mode in where the server adds the intended delay to each message sent. This also enables the client to set the intended delay of the messages the client sends to the server. It's disabled by default.
/// </summary>
/// <exception cref="InvalidOperationException">The native value of the <see cref="MDF_OPTION.MDF_OPT_HANDLE_DELAY"/> option cannot be fetched or modified.</exception>
/// <exception cref="ObjectDisposedException">The <see cref="MarketDataFeed{TCallbackData,TStatusCallbackData}"/> instance has been disposed.</exception>
/// <remarks>Must be set prior to calling <see cref="Connect(string)"/>.</remarks>
public bool HandleDelay
{
get => Convert.ToBoolean(GetInt32Property(MDF_OPTION.MDF_OPT_HANDLE_DELAY));
set => SetProperty(MDF_OPTION.MDF_OPT_HANDLE_DELAY, value ? 1 : 0);
}
#endregion

#region Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public void GetAndSetPropertiesTest()
Assert.AreEqual(0UL, mdf.ReceivedBytes);
Assert.AreEqual(0UL, mdf.SentBytes);

//HandleDelay
Assert.IsFalse(mdf.HandleDelay);
mdf.HandleDelay = true;
//Assert.IsTrue(mdf.HandleDelay);

//FileDescriptor
Assert.AreEqual(-1, mdf.FileDescriptor);
Assert.IsTrue(mdf.Connect(GetTestRunParameter("host")));
Expand Down Expand Up @@ -150,6 +155,9 @@ public void GetAndSetPropertiesTest()

_ = mdf.Timeout;

mdf.HandleDelay = false;
_ = mdf.HandleDelay;

Assert.AreEqual(allocatedBytes, GetTotalAllocatedBytes());
}

Expand Down
43 changes: 39 additions & 4 deletions Tests/Millistream.Streaming.UnitTests/MarketDataFeedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ public void GetAndSetNoDelayTest()
NativeImplementation.Implementation = nativeImplementation.Object;
using MarketDataFeed mdf = new();
//assert that the expected values are returned from the getter
Assert.AreEqual(true, mdf.NoDelay);
Assert.IsTrue(mdf.NoDelay);
returnValue = 0;
Assert.AreEqual(false, mdf.NoDelay);
Assert.IsFalse(mdf.NoDelay);
//set the property
mdf.NoDelay = true;
//verify that the setter was invoked
Expand All @@ -285,9 +285,9 @@ public void GetAndSetNoEncryptionTest()
NativeImplementation.Implementation = nativeImplementation.Object;
using MarketDataFeed mdf = new();
//assert that the expected values are returned from the getter
Assert.AreEqual(true, mdf.NoEncryption);
Assert.IsTrue(mdf.NoEncryption);
returnValue = 0;
Assert.AreEqual(false, mdf.NoEncryption);
Assert.IsFalse(mdf.NoEncryption);
//set the property
mdf.NoEncryption = true;
//verify that the setter was invoked
Expand Down Expand Up @@ -388,6 +388,33 @@ public void GetCipherTest() =>
public void GetTimeoutTest() =>
GetInt32Property(MDF_OPTION.MDF_OPT_TIMEOUT, mdf => mdf.Timeout);

[TestMethod]
public void GetAndSetHandleDelayTest()
{
Mock<INativeImplementation> nativeImplementation = new();
int returnValue = 1;
nativeImplementation
.Setup(x => x.mdf_get_property(It.IsAny<IntPtr>(), (int)MDF_OPTION.MDF_OPT_HANDLE_DELAY, ref It.Ref<int>.IsAny))
.Returns(1)
.Callback(new GetInt32PropertyCallback((IntPtr handler, int option_, ref int value) => value = returnValue));

nativeImplementation
.Setup(x => x.mdf_set_property(It.IsAny<IntPtr>(), (int)MDF_OPTION.MDF_OPT_HANDLE_DELAY, It.IsAny<IntPtr>()))
.Returns(1)
.Verifiable();

NativeImplementation.Implementation = nativeImplementation.Object;
using MarketDataFeed mdf = new();
//assert that the expected values are returned from the getter
Assert.IsTrue(mdf.HandleDelay);
returnValue = 0;
Assert.IsFalse(mdf.HandleDelay);
//set the property
mdf.HandleDelay = true;
//verify that the setter was invoked
nativeImplementation.Verify();
}

[TestMethod]
public void GetAndSetDataCallbackTest()
{
Expand Down Expand Up @@ -690,6 +717,14 @@ public void SendTest()
[ExpectedException(typeof(ObjectDisposedException))]
public void CannotGetTimeoutAfterDisposeTest() => _ = GetDisposedMdf().Timeout;

[TestMethod]
[ExpectedException(typeof(ObjectDisposedException))]
public void CannotGetHandleDelayAfterDisposeTest() => _ = GetDisposedMdf().HandleDelay;

[TestMethod]
[ExpectedException(typeof(ObjectDisposedException))]
public void CannotSetHandleDelayAfterDisposeTest() => GetDisposedMdf().HandleDelay = true;

[TestMethod]
[ExpectedException(typeof(ObjectDisposedException))]
public void CannotGetDataCallbackfterDisposeTest() => _ = GetDisposedMdf().DataCallback;
Expand Down

0 comments on commit 3e0be47

Please sign in to comment.