From f2f071e782eeae70379e91796a7d8191a598a7f6 Mon Sep 17 00:00:00 2001 From: AKosylo Date: Thu, 12 Oct 2023 15:22:15 +0200 Subject: [PATCH] add integration test for order --- DXFeedFramework/Events/EventCode.swift | 1 + .../Events/Market/Extra/OrderBase.swift | 2 +- .../Events/Market/Extra/OrderSource.swift | 50 ++++++++++++++++++- DXFeedFramework/Native/Graal/Isolate.swift | 2 + DXFeedFramework/Utils/ConcurrentDict.swift | 6 ++- DXFeedFrameworkTests/OrderTest.swift | 23 ++------- 6 files changed, 61 insertions(+), 23 deletions(-) diff --git a/DXFeedFramework/Events/EventCode.swift b/DXFeedFramework/Events/EventCode.swift index 8f7a0a02c..d901b5ee7 100644 --- a/DXFeedFramework/Events/EventCode.swift +++ b/DXFeedFramework/Events/EventCode.swift @@ -39,6 +39,7 @@ public enum EventCode: CaseIterable { case timeAndSale /// **Doesn't need to be implemented. Abstract class** case orderBase + /// See ``AnalyticOrder`` case order /// See ``AnalyticOrder`` case analyticOrder diff --git a/DXFeedFramework/Events/Market/Extra/OrderBase.swift b/DXFeedFramework/Events/Market/Extra/OrderBase.swift index 1f8e90689..64ca4194b 100644 --- a/DXFeedFramework/Events/Market/Extra/OrderBase.swift +++ b/DXFeedFramework/Events/Market/Extra/OrderBase.swift @@ -282,7 +282,7 @@ extension OrderBase { """ \(eventSymbol), \ eventTime=\(TimeUtil.toLocalDateString(millis: eventTime)), \ -source=\(eventSource), \ +source=\(eventSource.name), \ eventFlags=0x\(String(format: "%02X", eventFlags)), \ index=0x\(String(format: "%02X", index)), \ time=\(TimeUtil.toLocalDateString(millis: time)), \ diff --git a/DXFeedFramework/Events/Market/Extra/OrderSource.swift b/DXFeedFramework/Events/Market/Extra/OrderSource.swift index bcff48da5..17749ea36 100644 --- a/DXFeedFramework/Events/Market/Extra/OrderSource.swift +++ b/DXFeedFramework/Events/Market/Extra/OrderSource.swift @@ -44,7 +44,7 @@ public class OrderSource: IndexedEventSource { /// /// It is a synthetic source. /// The subscription on composite ``Quote`` event is observed when this source is subscribed to. - public static let compsoiteBid = try? OrderSource(1, "DEFAULT", pubOrder | pubAnalyticOrder | pubSpreadOrder | fullOrderBook) + public static let compsoiteBid = try? OrderSource(1, "COMPOSITE_BID", pubOrder | pubAnalyticOrder | pubSpreadOrder | fullOrderBook) /// Ask side of a composite ``Quote``. /// It is a synthetic source. /// The subscription on composite ``Quote`` event is observed when this source is subscribed to. @@ -160,6 +160,46 @@ public class OrderSource: IndexedEventSource { /// Members Exchange. Record for price level book. public static let memx = try? OrderSource("memx", pubOrder) + /// Don't use it. Just for initialization all static variable. + /// static let - is always lazy initialized + fileprivate static let allValues = [OrderSource.defaultOrderSource, + OrderSource.compsoiteBid, + OrderSource.compsoiteAsk, + OrderSource.regionalBid, + OrderSource.regionalAsk, + OrderSource.agregateBid, + OrderSource.agregateAsk, + OrderSource.NTV, + OrderSource.ntv, + OrderSource.NFX, + OrderSource.ESPD, + OrderSource.XNFI, + OrderSource.ICE, + OrderSource.ISE, + OrderSource.DEA, + OrderSource.DEX, + OrderSource.BYX, + OrderSource.BZX, + OrderSource.BATE, + OrderSource.CHIX, + OrderSource.CEUX, + OrderSource.BXTR, + OrderSource.IST, + OrderSource.BI20, + OrderSource.ABE, + OrderSource.FAIR, + OrderSource.GLBX, + OrderSource.glbx, + OrderSource.ERIS, + OrderSource.XEUR, + OrderSource.xeur, + OrderSource.CFE, + OrderSource.C2OX, + OrderSource.SMFE, + OrderSource.smfe, + OrderSource.iex, + OrderSource.MEMX, + OrderSource.memx] override init(_ identifier: Int, _ name: String) { self.pubFlags = 0 @@ -306,3 +346,11 @@ public class OrderSource: IndexedEventSource { } } + +extension OrderSource { + /// Don't use it. Just for initialization all static variable. + /// static let - is always lazy initialized + internal static func initAllValues() { + _ = OrderSource.allValues + } +} diff --git a/DXFeedFramework/Native/Graal/Isolate.swift b/DXFeedFramework/Native/Graal/Isolate.swift index c18f6890d..827eefddd 100644 --- a/DXFeedFramework/Native/Graal/Isolate.swift +++ b/DXFeedFramework/Native/Graal/Isolate.swift @@ -83,6 +83,8 @@ class Isolate { let errorMessage = "!!!Isolate init failed: Unexpected error \(error)" fatalError(errorMessage) } + + OrderSource.initAllValues() } // only for testing diff --git a/DXFeedFramework/Utils/ConcurrentDict.swift b/DXFeedFramework/Utils/ConcurrentDict.swift index a53be8259..5753773ce 100644 --- a/DXFeedFramework/Utils/ConcurrentDict.swift +++ b/DXFeedFramework/Utils/ConcurrentDict.swift @@ -60,7 +60,11 @@ class ConcurrentDict: CustomStringConvertible { public func tryInsert(key: Key, value: Value) -> Bool { return accessQueue.sync { - return set.updateValue(value, forKey: key) == nil + if set[key] == nil { + set[key] = value + return true + } + return false } } diff --git a/DXFeedFrameworkTests/OrderTest.swift b/DXFeedFrameworkTests/OrderTest.swift index fb2f62faf..d00bcbf91 100644 --- a/DXFeedFrameworkTests/OrderTest.swift +++ b/DXFeedFrameworkTests/OrderTest.swift @@ -22,14 +22,6 @@ final class OrderTest: XCTestCase { try receiveOrder(code: .order) } - func testAnalyticOrder() throws { - try receiveOrder(code: .analyticOrder) - } - - func testSpreadOrder() throws { - try receiveOrder(code: .spreadOrder) - } - private func receiveOrder(code: EventCode) throws { let endpoint = try DXEndpoint.builder().withRole(.feed).withProperty("test", "value").build() try endpoint.connect("demo.dxfeed.com:7300") @@ -38,19 +30,10 @@ final class OrderTest: XCTestCase { receivedEventExp.assertForOverFulfill = false let listener = AnonymousClass { anonymCl in anonymCl.callback = { events in - events.forEach { event in - if event.type == .order { - print(event.order.toString()) - } - - } if events.count > 0 { let event = events.first - if FeedTest.checkType(code, event) { - if event?.type == .order { - print(event?.order.toString()) - } -// receivedEventExp.fulfill() + if FeedTest.checkType(code, event) { + receivedEventExp.fulfill() } } } @@ -58,6 +41,6 @@ final class OrderTest: XCTestCase { } try subscription?.add(observer: listener) try subscription?.addSymbols(["IBM"]) - wait(for: [receivedEventExp], timeout: 10) + wait(for: [receivedEventExp], timeout: 2) } }