How to decode RefreshMsg for unittesting purposes
I am writing unittests for our application, How do I decode the "payload()" part of RefreshMsg? TA similar question was asked some years ago here: https://community.developers.refinitiv.com/questions/6594/what-is-the-preferred-way-to-unit-test-decoding-of.html
However none of the links and suggestions here work anymore.
Best Answer
-
No, its not supported in the EMA layer, and app will get this message:
Decoding of just encoded object in the same application is not supported
as implemented here - https://github.com/Refinitiv/Real-Time-SDK/blob/465c6d6e85549a53ecd07cb1d9743a7dc5be8942/Java/Ema/Core/src/main/java/com/refinitiv/ema/access/RefreshMsgImpl.java#L477
It is however possible to create a refresh message and decode it in the same app, but requires the use of ETA layer. See a complete working sample of this in this Unit Test example as mentioned previously by @jirapongse.phuriphanvichai.
0
Answers
-
Hi @martin.eriksen,
Refresh message payload could be anything depending on the instrument, asset class and the venue that you subscribe to. Even if you unit test one type, say L1 US equities the actual application might fail if it receives L2 data, because payload will not contain a very different object.
Best way to test the application is with Dev/QA credentials or use infrastructure tools to playback some simulated market activity. You may also try to use a EMA provider to connect your EMA consumer to test the application locally. See provider examples in https://github.com/Refinitiv/Real-Time-SDK/tree/master/Cpp-C/Ema/Examples/Training and follow these tutorials.
0 -
Unit test examples are available in the packages.
- Java: \Java\Ema\Core\src\test\java\com\refinitiv\ema\unittest
- C++: Cpp-C\Ema\Examples\Test\UnitTest
0 -
Thanks for your input. I don't quite the see question answered. Do you know if there is a way to decode the payload without sending it over the network or isn't there one?
0 -
@martin.eriksen, You could manually create a Refresh message and call your onRefreshMsg method with this object, if thats what you are interested in.
See example of creating a refresh message here - https://github.com/Refinitiv/Real-Time-SDK/blob/master/Java/Ema/Examples/src/main/java/com/refinitiv/ema/examples/training/iprovider/series100/ex100_MP_Streaming/IProvider.javaFieldList fieldList = EmaFactory.createFieldList();
fieldList.add( EmaFactory.createFieldEntry().real(22, 3990, OmmReal.MagnitudeType.EXPONENT_NEG_2));
fieldList.add( EmaFactory.createFieldEntry().real(25, 3994, OmmReal.MagnitudeType.EXPONENT_NEG_2));
fieldList.add( EmaFactory.createFieldEntry().real(30, 9, OmmReal.MagnitudeType.EXPONENT_0));
fieldList.add( EmaFactory.createFieldEntry().real(31, 19, OmmReal.MagnitudeType.EXPONENT_0));
RefreshMsg rmsg = EmaFactory.createRefreshMsg().name(reqMsg.name())
.serviceId(reqMsg.serviceId())
.solicited(true)
.state(OmmState.StreamState.OPEN, OmmState.DataState.OK, OmmState.StatusCode.NONE, "Refresh Completed")
.payload(fieldList)
.complete(true);
__yourapplication_decoder__.onRefreshMsg(rmsg, null);
This approach suffers from the shortcomings that I mentioned previously.0 -
Thanks! Can you provide a line of code that decodes the payload to get its contents? Instead of the
__yourapplication_decoder__.onRefreshMsg(rmsg, null);?
0 -
Please see the consumer sample series100/ex120_MP_FieldListWalk/Consumer.java which ships with SDK.
0 -
Thanks for your input. However, the example you provided decodes after connecting to a server. I want to decode IN THE SAME PROCESS. For unittesting purposes. Is this possible? we have gone over examples etc but not been able to find a way to do it. So I am looking for a line or a few lines of code that can be put instead of "
- __yourapplication_decoder__.onRefreshMsg(rmsg, null);"
Which will decode the payload. So I am looking for a function DecodePayload so that this works:
FieldList decodedFields=DecodePayload(rmsg)
Can you write this function, DecodePayload, for me? Or can such a function not be made without elaborate network / interthread communication that would be overkill for unittesting purposes?
0 -
@martin.eriksen, Seems like you are trying to program without understanding the system and it is liable to run into issues. You can extract the decode() method from previous linked example and use it unit test.
If you are just interested in extracting the FieldList from refresh message, then do the following:
if(rmsg.payload().dataType() == DataType.DataTypes.FIELD_LIST)
FieldList fl = rmsg.payload().fieldList();0 -
Hi Gurpreet, Thanks for your answer, it seems now we are homing in on the core of the issue we experience so that is very nice :-) I just tried to run the code from our case, like this:
FieldList fieldList = EmaFactory.createFieldList();
fieldList.add( EmaFactory.createFieldEntry().real(22, 3990, OmmReal.MagnitudeType.EXPONENT_NEG_2));
fieldList.add( EmaFactory.createFieldEntry().real(25, 3994, OmmReal.MagnitudeType.EXPONENT_NEG_2));
fieldList.add( EmaFactory.createFieldEntry().real(30, 9, OmmReal.MagnitudeType.EXPONENT_0));
fieldList.add( EmaFactory.createFieldEntry().real(31, 19, OmmReal.MagnitudeType.EXPONENT_0));
RefreshMsg rmsg = EmaFactory.createRefreshMsg().name("somename")
.serviceId(42)
.solicited(true)
.state(OmmState.StreamState.OPEN, OmmState.DataState.OK, OmmState.StatusCode.NONE, "Refresh Completed")
.payload(fieldList)
.complete(true);
try{
FieldList fl = rmsg.payload().fieldList();
} catch (Exception e){
System.out.println("Exeption decoding: " + e.getMessage());
e.printStackTrace();
System.exit(-1);
}It throws this exception:
Exeption decoding: Attempt to fieldList() while actual data type is NoData
Exception Type='OmmInvalidUsageException', Text='Attempt to fieldList() while actual data type is NoData', Error Code='-4048'
at com.thomsonreuters.ema.access.PayloadAttribSummaryImpl.ommIUExcept(PayloadAttribSummaryImpl.java:276)
......
Do you get the same result? Our understanding is that there is a fundamental "feature" of the trep api that makes it impossible to decode a payload in the same process in which is was created. Have you heard about that? Any way to get around it so we can unit test the code?
0 -
Thanks!
It is a 1300 lines file. You link to the method: "testRefreshMsg_Decode() ". I assume that means you think the answer is in that method? I am not quite able to find a place in that method where for example fieldlist is accessed. As it seems you know the answer is in that file, are you able to give more pointers/ code snippets that work in the context of the code I posted in my previous post?
0 -
Its more then 1300 lines because it depends on other classes in that namespace.
Anyways, line #108 is where field list is applied to refresh message and #194 is where payload data type is checked while decoding the said refresh message.
0 -
Thanks! I still don't see the field list contents being accessed. Take for example this line from my code example above:
- fieldList.add( EmaFactory.createFieldEntry().real(25, 3994, OmmReal.MagnitudeType.EXPONENT_NEG_2));
Is it possible to decode this from the RefreshMsg, in my try/catch block in the example I posted?
0 -
No. You cannot decode the EMA factory created Refresh message in the same application.0
Categories
- All Categories
- 6 AHS
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛