From d47fb2ee6f6d7ecb21091fceb619ec500c8b6d9b Mon Sep 17 00:00:00 2001 From: Colin DuPlantis Date: Wed, 26 Apr 2023 10:41:34 -0700 Subject: [PATCH] MATP-1176 Review GitHub Dependabot updates --- .../main/java/org/marketcetera/core/Util.java | 2 +- .../marketcetera/quickfix/FIXMessageUtil.java | 30 +++++++++++++++ .../ors/brokers/SessionCustomizationTest.java | 37 +++++++++++++++++-- pom.xml | 2 +- 4 files changed, 65 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/marketcetera/core/Util.java b/core/src/main/java/org/marketcetera/core/Util.java index 3a964a58b5..3208826bec 100644 --- a/core/src/main/java/org/marketcetera/core/Util.java +++ b/core/src/main/java/org/marketcetera/core/Util.java @@ -420,7 +420,7 @@ public long skip(long inSkip) if(inSkip < 0) { return 0; } - pos += inSkip; + pos += (int)inSkip; return inSkip; } /* (non-Javadoc) diff --git a/core/src/main/java/org/marketcetera/quickfix/FIXMessageUtil.java b/core/src/main/java/org/marketcetera/quickfix/FIXMessageUtil.java index 1a4c10ca82..2ff5d7e81e 100644 --- a/core/src/main/java/org/marketcetera/quickfix/FIXMessageUtil.java +++ b/core/src/main/java/org/marketcetera/quickfix/FIXMessageUtil.java @@ -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; @@ -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 quickfix.Message value + * @return a boolean 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 quickfix.Message value + * @return a boolean 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); } @@ -1337,4 +1362,9 @@ private static HashMap fieldsToMap(FieldMap inMap, } return fields; } + /** + * holds the session message types + */ + public static final Set 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); } diff --git a/dare/src/test/java/org/marketcetera/ors/brokers/SessionCustomizationTest.java b/dare/src/test/java/org/marketcetera/ors/brokers/SessionCustomizationTest.java index bf2518f8c9..056fc59c99 100644 --- a/dare/src/test/java/org/marketcetera/ors/brokers/SessionCustomizationTest.java +++ b/dare/src/test/java/org/marketcetera/ors/brokers/SessionCustomizationTest.java @@ -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(), @@ -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)); @@ -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 quickfix.Message 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). * @@ -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 int value + * @param inAppMessageOnly a boolean value * @return a quickfix.Message 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(); @@ -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", diff --git a/pom.xml b/pom.xml index 0484cebf29..3aef7819ac 100644 --- a/pom.xml +++ b/pom.xml @@ -782,7 +782,7 @@ org.apache.mina mina-core - 2.1.4 + 2.1.5 runtime