Skip to content

Commit

Permalink
Use AT runner '-o' option to write TestResult.xml instead of using IO…
Browse files Browse the repository at this point in the history
… redirection.

AT 11c passing (send Reject for invalid seq reset)
  • Loading branch information
mgatny committed Aug 2, 2011
1 parent 1b97e24 commit d05953a
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 24 deletions.
4 changes: 2 additions & 2 deletions AcceptanceTest/runat.bat
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ goto start

call setup.bat %2

REM release\at\atrun -t run -s "%DIR%\AcceptanceTest.exe cfg\at.cfg" -d . -c "ruby Runner.rb 127.0.0.1 %2 definitions\server\fix40\*.def definitions\server\fix41\*.def definitions\server\fix42\*.def definitions\server\fix43\*.def definitions\server\fix44\*.def definitions\server\fix50\*.def definitions\server\fix50sp1\*.def definitions\server\fix50sp2\*.def" -i .\
release\at\atrun -t run -s "%DIR%\AcceptanceTest.exe cfg\at.cfg" -d . -c "ruby Runner.rb 127.0.0.1 %2 %TESTS%" -i .\
REM release\at\atrun -t run -s "%DIR%\AcceptanceTest.exe cfg\at.cfg" -d . -c "ruby Runner.rb 127.0.0.1 %2 definitions\server\fix40\*.def definitions\server\fix41\*.def definitions\server\fix42\*.def definitions\server\fix43\*.def definitions\server\fix44\*.def definitions\server\fix50\*.def definitions\server\fix50sp1\*.def definitions\server\fix50sp2\*.def" -i .\ -o TestResult.xml
release\at\atrun -t run -s "%DIR%\AcceptanceTest.exe cfg\at.cfg" -d . -c "ruby Runner.rb 127.0.0.1 %2 %TESTS%" -i .\ -o TestResult.xml
goto quit

:usage
Expand Down
9 changes: 5 additions & 4 deletions QuickFIX.NET/Fields/Converters/IntConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ namespace QuickFix.Fields.Converters
/// </summary>
public static class IntConverter
{
/// <summary>
/// Converts string to int
/// </summary>
/// <exception cref="BadConversionException"/>
/// <summary>
/// Converts string to int
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
public static int Convert(string i)
{
try
Expand Down
51 changes: 43 additions & 8 deletions QuickFIX.NET/FixValues.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,61 @@

namespace QuickFix
{
public class FixValue<T>
{
private T value_;
private string description_;

public T Value { get { return value_; } }
public string Description { get { return description_; } }

public FixValue(T value, string description)
{
value_ = value;
description_ = description;
}

public override bool Equals(object obj)
{
if ((null == obj) || (this.GetType() != obj.GetType()))
return false;
FixValue<T> rhs = (FixValue<T>)obj;
return this.Value.Equals(rhs.Value);
}

public override int GetHashCode()
{
return value_.GetHashCode();
}

public override string ToString()
{
return description_;
}
}

/// <summary>
/// TODO generate this class
/// </summary>
namespace FixValues
{
public class MsgType
{
public const string HEARTBEAT = "0";
public const string TEST_REQUEST = "1";
public const string RESEND_REQUEST = "2";
public const string REJECT = "3";
public const string SEQUENCE_RESET = "4";
public const string LOGOUT = "5";
public const string LOGON = "A";
public const string HEARTBEAT = "0";
public const string TEST_REQUEST = "1";
public const string RESEND_REQUEST = "2";
public const string REJECT = "3";
public const string SEQUENCE_RESET = "4";
public const string LOGOUT = "5";
public const string LOGON = "A";
public const string NEW_ORDER_SINGLE = "D";
}

public class SessionRejectReason
{
public const int VALUE_IS_INCORRECT = 5;
public static FixValue<int> INVALID_TAG_NUMBER = new FixValue<int>(0, "Invalid tag number");
public static FixValue<int> VALUE_IS_INCORRECT = new FixValue<int>(5, "Value is incorrect (out of range) for this tag");
public static FixValue<int> INVALID_MSGTYPE = new FixValue<int>(11, "Invalid MsgType");
}
}
}
5 changes: 5 additions & 0 deletions QuickFIX.NET/Message/FieldMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public int[] getFieldOrder()
return _fieldOrder;
}

public bool RemoveField(int field)
{
return _fields.Remove(field);
}

/// <summary>
/// set field in the fieldmap
/// will overwrite field if it exists
Expand Down
85 changes: 85 additions & 0 deletions QuickFIX.NET/Message/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,91 @@ public static string GetMsgType(string msg)

#endregion

public void ReverseRoute(Header header)
{
// required routing tags
this.Header.RemoveField(Fields.Tags.BeginString);
this.Header.RemoveField(Fields.Tags.SenderCompID);
this.Header.RemoveField(Fields.Tags.TargetCompID);

if (header.isSetField(Fields.Tags.BeginString))
{
string beginString = header.GetField(Fields.Tags.BeginString);
if (beginString.Length > 0)
this.Header.setField(new BeginString(beginString));

this.Header.RemoveField(Fields.Tags.OnBehalfOfLocationID);
this.Header.RemoveField(Fields.Tags.DeliverToLocationID);

if (beginString.CompareTo("FIX.4.1") >= 0)
{
if (header.isSetField(Fields.Tags.OnBehalfOfLocationID))
{
string onBehalfOfLocationID = header.GetField(Fields.Tags.OnBehalfOfLocationID);
if (onBehalfOfLocationID.Length > 0)
this.Header.setField(new DeliverToLocationID(onBehalfOfLocationID));
}

if (header.isSetField(Fields.Tags.DeliverToLocationID))
{
string deliverToLocationID = header.GetField(Fields.Tags.DeliverToLocationID);
if (deliverToLocationID.Length > 0)
this.Header.setField(new OnBehalfOfLocationID(deliverToLocationID));
}
}
}

if (header.isSetField(Fields.Tags.SenderCompID))
{
SenderCompID senderCompID = new SenderCompID();
header.getField(senderCompID);
if (senderCompID.Obj.Length > 0)
this.Header.setField(new TargetCompID(senderCompID.Obj));
}

if (header.isSetField(Fields.Tags.TargetCompID))
{
TargetCompID targetCompID = new TargetCompID();
header.getField(targetCompID);
if (targetCompID.Obj.Length > 0)
this.Header.setField(new SenderCompID(targetCompID.Obj));
}

// optional routing tags
this.Header.RemoveField(Fields.Tags.OnBehalfOfCompID);
this.Header.RemoveField(Fields.Tags.OnBehalfOfSubID);
this.Header.RemoveField(Fields.Tags.DeliverToCompID);
this.Header.RemoveField(Fields.Tags.DeliverToSubID);

if(header.isSetField(Fields.Tags.OnBehalfOfCompID))
{
string onBehalfOfCompID = header.GetField(Fields.Tags.OnBehalfOfCompID);
if(onBehalfOfCompID.Length > 0)
this.Header.setField(new DeliverToCompID(onBehalfOfCompID));
}

if(header.isSetField(Fields.Tags.OnBehalfOfSubID))
{
string onBehalfOfSubID = header.GetField( Fields.Tags.OnBehalfOfSubID);
if(onBehalfOfSubID.Length > 0)
this.Header.setField(new DeliverToSubID(onBehalfOfSubID));
}

if(header.isSetField(Fields.Tags.DeliverToCompID))
{
string deliverToCompID = header.GetField(Fields.Tags.DeliverToCompID);
if(deliverToCompID.Length > 0)
this.Header.setField(new OnBehalfOfCompID(deliverToCompID));
}

if(header.isSetField(Fields.Tags.DeliverToSubID))
{
string deliverToSubID = header.GetField(Fields.Tags.DeliverToSubID);
if(deliverToSubID.Length > 0)
this.Header.setField(new OnBehalfOfSubID(deliverToSubID));
}
}

public int CheckSum()
{
return (
Expand Down
5 changes: 5 additions & 0 deletions QuickFIX.NET/ResendRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ public ResendRange(int begin, int end)
BeginSeqNo = begin;
EndSeqNo = end;
}

public override string ToString()
{
return BeginSeqNo + ":" + EndSeqNo;
}
}
}
86 changes: 80 additions & 6 deletions QuickFIX.NET/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public void Disconnect(string reason)
public void Next()
{
//System.Console.WriteLine(state_.ToString());
//this.Log.OnEvent(state_.ToString());

if (!IsEnabled)
{
Expand Down Expand Up @@ -323,6 +324,7 @@ public void Next(Message message)
protected void NextQueued()
{
System.Console.WriteLine("FIXME - Session.NextQueued not implemented!");
this.Log.OnEvent("FIXME - Session.NextQueued not implemented!");
}

protected void NextLogon(Message logon)
Expand Down Expand Up @@ -696,14 +698,86 @@ public bool GenerateHeartbeat(Message testRequest)
return SendRaw(heartbeat, 0);
}

public bool GenerateReject(Message msg, int err)
{
return GenerateReject(msg, err, 0);
public bool GenerateReject(Message message, FixValue<int> sessionRejectReason)
{
return GenerateReject(message, sessionRejectReason, 0);
}
public bool GenerateReject(Message message, FixValue<int> sessionRejectReason, int field)
{
string beginString = this.SessionID.BeginString;

Message reject = new Message();
reject.Header.setField(new Fields.MsgType(FixValues.MsgType.REJECT));
reject.ReverseRoute(message.Header);
InitializeHeader(reject);

string msgType;
if(message.Header.isSetField(Fields.Tags.MsgType))
msgType = message.Header.GetField(Fields.Tags.MsgType);
else
msgType = "";

int msgSeqNum = 0;
if(message.Header.isSetField(Fields.Tags.MsgSeqNum))
{
try
{
msgSeqNum = Fields.Converters.IntConverter.Convert(message.Header.GetField(Fields.Tags.MsgSeqNum)); /// FIXME
reject.setField(new Fields.RefSeqNum(msgSeqNum));
}
catch(System.Exception)
{ }
}

if(beginString.CompareTo("FIX.4.2") >= 0)
{
if(msgType.Length > 0)
reject.setField(new Fields.RefMsgType(msgType));
if (("FIX.4.2".Equals(beginString) && sessionRejectReason.Value <= FixValues.SessionRejectReason.INVALID_MSGTYPE.Value) || ("FIX.4.2".CompareTo(beginString) > 0))
{
reject.setField(new Fields.SessionRejectReason(sessionRejectReason.Value));
}
}
if ( !FixValues.MsgType.LOGON.Equals(msgType)
&& !FixValues.MsgType.SEQUENCE_RESET.Equals(msgType)
&& (msgSeqNum == state_.GetNextTargetMsgSeqNum()) )
{
state_.IncrNextTargetMsgSeqNum();
}

if((0 != field) || FixValues.SessionRejectReason.INVALID_TAG_NUMBER.Equals(sessionRejectReason))
{
PopulateRejectReason(reject, msgType, field, sessionRejectReason.Description);
this.Log.OnEvent("Message " + msgSeqNum + " Rejected: " + sessionRejectReason.Value + ":" + field);
}
else
{
PopulateRejectReason(reject, sessionRejectReason.Description);
this.Log.OnEvent("Message " + msgSeqNum + " Rejected: " + sessionRejectReason.Value);
}

if (!state_.ReceivedLogon)
throw new QuickFIXException("Tried to send a reject while not logged on");

return SendRaw(reject, 0);
}

protected void PopulateRejectReason(Message reject, string msgType, int field, string text)
{
if (FixValues.MsgType.REJECT.Equals(msgType) && "FIX.4.2".CompareTo(this.SessionID.BeginString) >= 0)
{
reject.setField(new Fields.RefTagID(field));
reject.setField(new Fields.Text(text));
}
else
{
reject.setField(new Fields.Text(text + " (" + field + ")"));
}
}
public bool GenerateReject(Message msg, int err, int field)

protected void PopulateRejectReason(Message reject, string text)
{
System.Console.WriteLine("FIXME - GenerateReject not implemented!");
return false;
reject.setField(new Fields.Text(text));
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions QuickFIX.NET/SessionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ public bool ResendRequested()
public void Queue(int msgSeqNum, Message msg)
{
System.Console.WriteLine("FIXME - SessionState.Queue(int,Message) not implemented!");
this.Log.OnEvent("FIXME - SessionState.Queue(int,Message) not implemented!");
}

public void ClearQueue()
Expand All @@ -278,6 +279,7 @@ public override string ToString()
.Append(", WithinHeartbeat=").Append(WithinHeartbeat())
.Append(", NeedHeartbeat=").Append(NeedHeartbeat())
.Append(", NeedTestRequest=").Append(NeedTestRequest())
.Append(", ResendRange=").Append(GetResendRange())
.Append(" ]").ToString();

}
Expand Down
29 changes: 28 additions & 1 deletion QuickFIX.NET/SocketReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ public void Read()
int bytesRead = tcpClient_.Client.Receive(readBuffer_);
if (0 == bytesRead)
throw new SocketException(System.Convert.ToInt32(SocketError.ConnectionReset));
OnMessageFound(System.Text.Encoding.UTF8.GetString(readBuffer_, 0, bytesRead));

string msg;
string buf = System.Text.Encoding.UTF8.GetString(readBuffer_, 0, bytesRead);
while (ReadFixMessage(out msg, out buf, buf))
OnMessageFound(msg);

//parser_.AddToStream(System.Text.Encoding.UTF8.GetString(readBuffer_, 0, bytesRead));
}
else if (null != qfSession_)
Expand All @@ -50,6 +55,28 @@ public void Read()
}
}

/// FIXME move to Parser
public bool ReadFixMessage(out string msg, out string outbuf, string inbuf)
{
msg = "";
outbuf = inbuf;
int pos = 0;

pos = inbuf.IndexOf("\x01"+"10=", pos);
if (-1 == pos)
return false;
pos += 4;

pos = inbuf.IndexOf("\x01", pos);
if (-1 == pos)
return false;
pos += 1;

msg = inbuf.Substring(0, pos);
outbuf = inbuf.Remove(0, pos);
return true;
}

public void OnMessageFound(string msg)
{
try
Expand Down
2 changes: 0 additions & 2 deletions QuickFIX.NET/Values.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ public class Values
public const string BeginString_FIX42 = "FIX.4.2";
public const string BeginString_FIX41 = "FIX.4.1";
public const string BeginString_FIX40 = "FIX.4.0";

public const string SessionRejectReason_VALUE_IS_INCORRECT_TEXT = "Value is incorrect (out of range) for this tag";
}
}
2 changes: 1 addition & 1 deletion acceptance_test.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ set RESULT=0

pushd AcceptanceTest
del TestResult.xml AcceptanceTests.html
call runat release 5001 > TestResult.xml
call runat release 5001
if ERRORLEVEL 1 set RESULT=1
xsltproc.exe -o AcceptanceTests.html at.xsl TestResult.xml
popd
Expand Down

0 comments on commit d05953a

Please sign in to comment.