Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions QuickFIXn/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1646,9 +1646,12 @@ protected void Persist(Message message, string messageString)
if (PersistMessages)
{
SeqNumType msgSeqNum = message.Header.GetULong(Fields.Tags.MsgSeqNum);
_state.Set(msgSeqNum, messageString);
_state.SetAndIncrNextSenderMsgSeqNum(msgSeqNum, messageString);
}
else
{
_state.IncrNextSenderMsgSeqNum();
}
_state.IncrNextSenderMsgSeqNum();
}

protected bool IsGoodTime(Message msg)
Expand Down
5 changes: 5 additions & 0 deletions QuickFIXn/SessionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ public void IncrNextTargetMsgSeqNum()
lock (_sync) { MessageStore.IncrNextTargetMsgSeqNum(); }
}

public bool SetAndIncrNextSenderMsgSeqNum(SeqNumType msgSeqNum, string msg)
{
lock (_sync) { return MessageStore.SetAndIncrNextSenderMsgSeqNum(msgSeqNum, msg); }
}

public DateTime? CreationTime
{
get
Expand Down
21 changes: 20 additions & 1 deletion QuickFIXn/Store/IMessageStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface IMessageStore : IDisposable
void Get(SeqNumType startSeqNum, SeqNumType endSeqNum, List<string> messages);

/// <summary>
/// Adds a raw fix message to the store with the give sequence number
/// Adds a raw fix message to the store with the given sequence number
/// </summary>
/// <param name="msgSeqNum">the sequence number</param>
/// <param name="msg">the raw FIX message string</param>
Expand All @@ -31,6 +31,24 @@ public interface IMessageStore : IDisposable
void IncrNextSenderMsgSeqNum();
void IncrNextTargetMsgSeqNum();

/// <summary>
/// The purpose of this method is to combine <see cref="Set(SeqNumType, string)"/>
/// and <see cref="IncrNextSenderMsgSeqNum()"/> into one call, for use in situations
/// when these operations should be performed together.
/// The default implementation simply calls those two functions.
/// Certain custom IMessageStore implementations (e.g. DB-backed stores)
/// may need to override the default implementation to ensure that these two behaviors
/// are combined into a single atomic operation.
/// <param name="msgSeqNum">the sequence number</param>
/// <param name="msg">the raw FIX message string</param>
/// <returns>true if successful, false otherwise</returns>
/// </summary>
bool SetAndIncrNextSenderMsgSeqNum(SeqNumType msgSeqNum, string msg)
{
bool result = Set(msgSeqNum, msg);
IncrNextSenderMsgSeqNum();
return result;
}

DateTime? CreationTime { get; }

Expand All @@ -49,3 +67,4 @@ public interface IMessageStore : IDisposable
/// </summary>
void Refresh();
}

1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ What's New
* #949 - new settings RedactFieldsInLogs & RedactionLogText (gbirchmeier)
* #983 - new MessageFactoryNotFound exception provides better feedback (gbirchmeier)
* #1014 - deprecate DateTimeConverter.ParseToTimeOnly (gbirchmeier)
* #987 - new interface method IMessageStore.SetAndIncrNextSenderMsgSeqNum (asmeisne)


### v1.14.0
Expand Down
26 changes: 26 additions & 0 deletions UnitTests/FileStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,30 @@ public void GetTest()

Assert.That(msgs, Is.EqualTo(expected));
}

[Test]
public void SetAndIncrNextSenderMsgSeqNumTest()
{
IMessageStore messageStore = _store ?? throw new InvalidProgramException();

messageStore.SetAndIncrNextSenderMsgSeqNum(1, "dude");
messageStore.SetAndIncrNextSenderMsgSeqNum(2, "pude");
messageStore.SetAndIncrNextSenderMsgSeqNum(3, "ok");
messageStore.SetAndIncrNextSenderMsgSeqNum(4, "ohai");

var msgs = new List<string>();
_store.Get(2, 3, msgs);
var expected = new List<string>() { "pude", "ok" };

Assert.That(msgs, Is.EqualTo(expected));
Assert.That(_store.NextSenderMsgSeqNum, Is.EqualTo(5));

RebuildStore();

msgs = new List<string>();
_store.Get(2, 3, msgs);

Assert.That(msgs, Is.EqualTo(expected));
Assert.That(_store.NextSenderMsgSeqNum, Is.EqualTo(5));
}
}
19 changes: 19 additions & 0 deletions UnitTests/MemoryStoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,23 @@ public void GetTest()
store.Get(5, 6, msgs);
Assert.That(msgs, Is.Empty);
}

[Test]
public void SetAndIncrNextSenderMsgSeqNumTest()
{
IMessageStore store = new MemoryStore();
store.SetAndIncrNextSenderMsgSeqNum(1, "dude");
store.SetAndIncrNextSenderMsgSeqNum(2, "pude");
store.SetAndIncrNextSenderMsgSeqNum(3, "ok");
store.SetAndIncrNextSenderMsgSeqNum(4, "ohai");
var msgs = new List<string>();
store.Get(2, 3, msgs);
var expected = new List<string>() { "pude", "ok" };
Assert.That(msgs, Is.EqualTo(expected));

msgs = new List<string>();
store.Get(5, 6, msgs);
Assert.That(msgs, Is.Empty);
Assert.That(store.NextSenderMsgSeqNum, Is.EqualTo(5));
}
}
Loading