Skip to content

Commit

Permalink
Merge pull request #1168 from Marketcetera/MATP-1176
Browse files Browse the repository at this point in the history
MATP-1176 Review GitHub Dependabot updates
  • Loading branch information
colinduplantis committed Apr 26, 2023
2 parents 4e8511f + d47fb2e commit 0a9c225
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/marketcetera/core/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public long skip(long inSkip)
if(inSkip < 0) {
return 0;
}
pos += inSkip;
pos += (int)inSkip;
return inSkip;
}
/* (non-Javadoc)
Expand Down
30 changes: 30 additions & 0 deletions core/src/main/java/org/marketcetera/quickfix/FIXMessageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Sets;

import quickfix.DataDictionary;
import quickfix.Field;
Expand Down Expand Up @@ -702,6 +703,30 @@ public static String getMessageIdentifier(Message inMessage)
}
return output.toString();
}
/**
* Indicate if the given message is a session message.
*
* @param inMessage a <code>quickfix.Message</code> value
* @return a <code>boolean</code> value
* @throws quickfix.FieldNotFound if the message is malformed
*/
public static boolean isSessionMessage(quickfix.Message inMessage)
throws quickfix.FieldNotFound
{
return sessionMessageTypes.contains(inMessage.getHeader().getString(quickfix.field.MsgType.FIELD));
}
/**
* Indicate if the given message is an application message.
*
* @param inMessage a <code>quickfix.Message</code> value
* @return a <code>boolean</code> value
* @throws quickfix.FieldNotFound if the message is malformed
*/
public static boolean isApplicationMessage(quickfix.Message inMessage)
throws quickfix.FieldNotFound
{
return !(isSessionMessage(inMessage));
}
public static boolean isExecutionReport(Message message) {
return msgTypeHelper(message, MsgType.EXECUTION_REPORT);
}
Expand Down Expand Up @@ -1337,4 +1362,9 @@ private static HashMap<String, String> fieldsToMap(FieldMap inMap,
}
return fields;
}
/**
* holds the session message types
*/
public static final Set<String> sessionMessageTypes = Sets.newHashSet(quickfix.field.MsgType.HEARTBEAT,quickfix.field.MsgType.TEST_REQUEST,quickfix.field.MsgType.RESEND_REQUEST,quickfix.field.MsgType.REJECT,
quickfix.field.MsgType.SEQUENCE_RESET,quickfix.field.MsgType.LOGOUT,quickfix.field.MsgType.LOGON);
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void doCustomizationTest(boolean inIsIntercepted,
resetMessageInterceptedEvents();
outgoingMessageRecorder.reset();
OrderSingle outgoingOrder = sendOrder(brokerId);
quickfix.Message outgoingOrderMessage = outgoingMessageRecorder.getFirstRecordedMessage();
quickfix.Message outgoingOrderMessage = outgoingMessageRecorder.getFirstRecordedAppMessage();
assertTrue("Expected order single: " + FIXMessageUtil.toHumanDelimitedString(outgoingOrderMessage),
FIXMessageUtil.isOrderSingle(outgoingOrderMessage));
assertEquals(outgoingOrder.getOrderID().getValue(),
Expand All @@ -146,7 +146,7 @@ private void doCustomizationTest(boolean inIsIntercepted,
resetMessageInterceptedEvents();
incomingMessageRecorder.reset();
quickfix.Message report = ackOrder(targetSessionId);
quickfix.Message incomingReportMessage = incomingMessageRecorder.getFirstRecordedMessage();
quickfix.Message incomingReportMessage = incomingMessageRecorder.getFirstRecordedAppMessage();
assertTrue(FIXMessageUtil.isExecutionReport(incomingReportMessage));
assertEquals(report.getString(quickfix.field.ClOrdID.FIELD),
incomingReportMessage.getString(quickfix.field.ClOrdID.FIELD));
Expand Down Expand Up @@ -263,6 +263,18 @@ public boolean modify(ServerFixSession inServerFixSession,
}
return false;
}
/**
* Wait for and return the first recorded app (not admin) message (FIFO).
*
* @return a <code>quickfix.Message</code> value
* @throws Exception if an unexpected error occurs
*/
private quickfix.Message getFirstRecordedAppMessage()
throws Exception
{
return getFirstRecordedMessage(10,
true);
}
/**
* Wait for and return the first recorded message (FIFO).
*
Expand All @@ -272,16 +284,19 @@ public boolean modify(ServerFixSession inServerFixSession,
private quickfix.Message getFirstRecordedMessage()
throws Exception
{
return getFirstRecordedMessage(10);
return getFirstRecordedMessage(10,
false);
}
/**
* Wait for the given number of seconds for a message to be available and return it (FIFO).
*
* @param inSeconds an <code>int</code> value
* @param inAppMessageOnly a <code>boolean</code> value
* @return a <code>quickfix.Message</code> value
* @throws Exception if an unexpected error occurs
*/
private quickfix.Message getFirstRecordedMessage(int inSeconds)
private quickfix.Message getFirstRecordedMessage(int inSeconds,
boolean inAppMessageOnly)
throws Exception
{
long startTime = System.currentTimeMillis();
Expand All @@ -291,6 +306,20 @@ private quickfix.Message getFirstRecordedMessage(int inSeconds)
synchronized(recordedMessages) {
recordedMessage = recordedMessages.pollFirst();
}
if(recordedMessage != null) {
if(inAppMessageOnly) {
if(FIXMessageUtil.isApplicationMessage(recordedMessage)) {
// we want an app message and this is an app message - stop looking
break;
} else {
// we want an app message and this is not an app message - keep looking
recordedMessage = null;
}
} else {
// we don't care what message we get, either session or app, and there is a message, so just keep that one
break;
}
}
Thread.sleep(100);
}
assertNotNull("No recorded message in " + inSeconds + "s",
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
<version>2.1.4</version>
<version>2.1.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
Expand Down

0 comments on commit 0a9c225

Please sign in to comment.