Skip to content

Commit

Permalink
test data copied to benchmark classes
Browse files Browse the repository at this point in the history
  • Loading branch information
lumber1000 committed Aug 15, 2024
1 parent c5320bb commit b761c17
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 63 deletions.
72 changes: 67 additions & 5 deletions src/jmh/kotlin/com/exactpro/th2/codec/fixng/FixNgCodecBenchmark.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import com.exactpro.sf.common.messages.structures.IDictionaryStructure
import com.exactpro.sf.common.messages.structures.loaders.XmlDictionaryStructureLoader
import com.exactpro.th2.codec.api.IPipelineCodec
import com.exactpro.th2.codec.api.IReportingContext
import com.exactpro.th2.codec.fixng.FixNgCodecFactory.Companion.PROTOCOL
import com.exactpro.th2.common.schema.message.impl.rabbitmq.transport.Direction
import com.exactpro.th2.common.schema.message.impl.rabbitmq.transport.EventId
import com.exactpro.th2.common.schema.message.impl.rabbitmq.transport.MessageGroup
import com.exactpro.th2.common.schema.message.impl.rabbitmq.transport.MessageId
import com.exactpro.th2.common.schema.message.impl.rabbitmq.transport.ParsedMessage
import com.exactpro.th2.common.schema.message.impl.rabbitmq.transport.RawMessage
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
Expand All @@ -31,6 +36,7 @@ import org.openjdk.jmh.annotations.Mode
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.Setup
import org.openjdk.jmh.annotations.State
import java.time.Instant

@State(Scope.Benchmark)
open class BenchmarkState {
Expand All @@ -45,10 +51,8 @@ open class BenchmarkState {
.getResourceAsStream("dictionary.xml")
.use(XmlDictionaryStructureLoader()::load)

val parsedMessage = FixNgCodecTest.createParsedMessage()

codec = FixNgCodec(dictionary, FixNgCodecSettings(dictionary = "", decodeValuesToStrings = false))
rawBody = Unpooled.wrappedBuffer(FixNgCodecTest.MSG_CORRECT.toByteArray(Charsets.US_ASCII))
codec = FixNgCodec(dictionary, FixNgCodecSettings(dictionary = "", decodeValuesToStrings = true))
rawBody = Unpooled.wrappedBuffer(MSG_CORRECT.toByteArray(Charsets.US_ASCII))
rawGroup = MessageGroup(listOf(RawMessage(id = parsedMessage.id, eventId = parsedMessage.eventId, body = rawBody)))
parsedGroup = MessageGroup(listOf(parsedMessage))
}
Expand All @@ -57,6 +61,64 @@ open class BenchmarkState {
fun resetReader() {
rawBody.resetReaderIndex()
}

companion object {
private const val MSG_CORRECT = "8=FIXT.1.1\u00019=295\u000135=8\u000149=SENDER\u000156=RECEIVER\u000134=10947\u000152=20230419-10:36:07.415088\u000117=495504662\u000111=zSuNbrBIZyVljs\u000141=zSuNbrBIZyVljs\u000137=49415882\u0001150=0\u000139=0\u0001151=500\u000114=500\u000148=NWDR\u000122=8\u0001453=2\u0001448=NGALL1FX01\u0001447=D\u0001452=76\u0001448=0\u0001447=P\u0001452=3\u00011=test\u000140=A\u000159=0\u000154=B\u000155=ABC\u000138=500\u000144=1000\u000147=500\u000160=20180205-10:38:08.000008\u000110=191\u0001"
private val parsedMessage = ParsedMessage(
MessageId("test_alias", Direction.OUTGOING, 0L, Instant.now(), emptyList()),
EventId("test_id", "test_book", "test_scope", Instant.now()),
"ExecutionReport",
mapOf("encode-mode" to "dirty"),
PROTOCOL,
mapOf(
"header" to mapOf(
"MsgSeqNum" to "10947",
"SenderCompID" to "SENDER",
"SendingTime" to "2023-04-19T10:36:07.415088",
"TargetCompID" to "RECEIVER",
"BeginString" to "FIXT.1.1",
"BodyLength" to "295",
"MsgType" to "8"
),
"ExecID" to "495504662",
"ClOrdID" to "zSuNbrBIZyVljs",
"OrigClOrdID" to "zSuNbrBIZyVljs",
"OrderID" to "49415882",
"ExecType" to '0',
"OrdStatus" to '0',
"LeavesQty" to "500",
"CumQty" to "500",
"SecurityID" to "NWDR",
"SecurityIDSource" to "8",
"TradingParty" to mapOf(
"NoPartyIDs" to listOf(
mapOf(
"PartyID" to "NGALL1FX01",
"PartyIDSource" to "D",
"PartyRole" to "76"
),
mapOf(
"PartyID" to "0",
"PartyIDSource" to "P",
"PartyRole" to "3"
)
)
),
"Account" to "test",
"OrdType" to "A",
"TimeInForce" to "0",
"Side" to "B",
"Symbol" to "ABC",
"OrderQty" to "500",
"Price" to "1000",
"Unknown" to "500",
"TransactTime" to "2018-02-05T10:38:08.000008",
"trailer" to mapOf(
"CheckSum" to "191"
)
)
)
}
}

open class FixNgCodecBenchmark {
Expand All @@ -73,7 +135,7 @@ open class FixNgCodecBenchmark {
}

companion object {
private val context = object : IReportingContext {
private val context = object : IReportingContext {
override fun warning(message: String) { }
override fun warnings(messages: Iterable<String>) { }
}
Expand Down
114 changes: 56 additions & 58 deletions src/test/kotlin/com/exactpro/th2/codec/fixng/FixNgCodecTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,60 @@ class FixNgCodecTest {
else -> value.toString()
}

private val parsedMessage = createParsedMessage()
private val parsedMessage = ParsedMessage(
MessageId("test_alias", Direction.OUTGOING, 0L, Instant.now(), emptyList()),
EventId("test_id", "test_book", "test_scope", Instant.now()),
"ExecutionReport",
mutableMapOf("encode-mode" to "dirty"),
PROTOCOL,
mutableMapOf(
"header" to mutableMapOf(
"MsgSeqNum" to 10947,
"SenderCompID" to "SENDER",
"SendingTime" to LocalDateTime.parse("2023-04-19T10:36:07.415088"),
"TargetCompID" to "RECEIVER",
"BeginString" to "FIXT.1.1",
"BodyLength" to 295,
"MsgType" to "8"
),
"ExecID" to "495504662",
"ClOrdID" to "zSuNbrBIZyVljs",
"OrigClOrdID" to "zSuNbrBIZyVljs",
"OrderID" to "49415882",
"ExecType" to '0',
"OrdStatus" to '0',
"LeavesQty" to 500,
"CumQty" to BigDecimal(500),
"SecurityID" to "NWDR",
"SecurityIDSource" to "8",
"TradingParty" to mutableMapOf(
"NoPartyIDs" to mutableListOf(
mutableMapOf(
"PartyID" to "NGALL1FX01",
"PartyIDSource" to 'D',
"PartyRole" to 76
),
mutableMapOf(
"PartyID" to "0",
"PartyIDSource" to 'P',
"PartyRole" to 3
)
)
),
"Account" to "test",
"OrdType" to 'A',
"TimeInForce" to '0',
"Side" to 'B',
"Symbol" to "ABC",
"OrderQty" to 500,
"Price" to 1000,
"Unknown" to "500",
"TransactTime" to LocalDateTime.parse("2018-02-05T10:38:08.000008"),
"trailer" to mutableMapOf(
"CheckSum" to "191"
)
)
)
private val parsedBody: MutableMap<String, Any?> = parsedMessage.body as MutableMap

private val expectedParsedMessage = ParsedMessage(
Expand Down Expand Up @@ -388,7 +441,7 @@ class FixNgCodecTest {
companion object {
private const val DIRTY_MODE_WARNING_PREFIX = "Dirty mode WARNING: "

const val MSG_CORRECT = "8=FIXT.1.1\u00019=295\u000135=8\u000149=SENDER\u000156=RECEIVER\u000134=10947\u000152=20230419-10:36:07.415088\u000117=495504662\u000111=zSuNbrBIZyVljs\u000141=zSuNbrBIZyVljs\u000137=49415882\u0001150=0\u000139=0\u0001151=500\u000114=500\u000148=NWDR\u000122=8\u0001453=2\u0001448=NGALL1FX01\u0001447=D\u0001452=76\u0001448=0\u0001447=P\u0001452=3\u00011=test\u000140=A\u000159=0\u000154=B\u000155=ABC\u000138=500\u000144=1000\u000147=500\u000160=20180205-10:38:08.000008\u000110=191\u0001"
private const val MSG_CORRECT = "8=FIXT.1.1\u00019=295\u000135=8\u000149=SENDER\u000156=RECEIVER\u000134=10947\u000152=20230419-10:36:07.415088\u000117=495504662\u000111=zSuNbrBIZyVljs\u000141=zSuNbrBIZyVljs\u000137=49415882\u0001150=0\u000139=0\u0001151=500\u000114=500\u000148=NWDR\u000122=8\u0001453=2\u0001448=NGALL1FX01\u0001447=D\u0001452=76\u0001448=0\u0001447=P\u0001452=3\u00011=test\u000140=A\u000159=0\u000154=B\u000155=ABC\u000138=500\u000144=1000\u000147=500\u000160=20180205-10:38:08.000008\u000110=191\u0001"
private const val MSG_CORRECT_WITHOUT_BODY = "8=FIX.4.2\u00019=55\u000135=0\u000134=125\u000149=MZHOT0\u000152=20240801-08:03:01.229\u000156=INET\u000110=039\u0001"
private const val MSG_ADDITIONAL_FIELD_DICT = "8=FIXT.1.1\u00019=305\u000135=8\u000149=SENDER\u000156=RECEIVER\u000134=10947\u000152=20230419-10:36:07.415088\u000117=495504662\u000111=zSuNbrBIZyVljs\u000141=zSuNbrBIZyVljs\u000137=49415882\u0001150=0\u000139=0\u0001151=500\u000114=500\u000148=NWDR\u000122=8\u0001453=2\u0001448=NGALL1FX01\u0001447=D\u0001452=76\u0001448=0\u0001447=P\u0001452=3\u00011=test\u000140=A\u000159=0\u000154=B\u000155=ABC\u000138=500\u000144=1000\u000147=500\u000160=20180205-10:38:08.000008\u0001461=12345\u000110=143\u0001"
private const val MSG_ADDITIONAL_FIELD_NO_DICT = "8=FIXT.1.1\u00019=305\u000135=8\u000149=SENDER\u000156=RECEIVER\u000134=10947\u000152=20230419-10:36:07.415088\u000117=495504662\u000111=zSuNbrBIZyVljs\u000141=zSuNbrBIZyVljs\u000137=49415882\u0001150=0\u000139=0\u0001151=500\u000114=500\u000148=NWDR\u000122=8\u0001453=2\u0001448=NGALL1FX01\u0001447=D\u0001452=76\u0001448=0\u0001447=P\u0001452=3\u00011=test\u000140=A\u000159=0\u000154=B\u000155=ABC\u000138=500\u000144=1000\u000147=500\u000160=20180205-10:38:08.000008\u00019999=54321\u000110=097\u0001"
Expand All @@ -414,60 +467,5 @@ class FixNgCodecTest {
.appendPattern("HH:mm:ss")
.appendFraction(ChronoField.MILLI_OF_SECOND, 0, 9, true)
.toFormatter()

fun createParsedMessage() = ParsedMessage(
MessageId("test_alias", Direction.OUTGOING, 0L, Instant.now(), emptyList()),
EventId("test_id", "test_book", "test_scope", Instant.now()),
"ExecutionReport",
mutableMapOf("encode-mode" to "dirty"),
PROTOCOL,
mutableMapOf(
"header" to mutableMapOf(
"MsgSeqNum" to 10947,
"SenderCompID" to "SENDER",
"SendingTime" to LocalDateTime.parse("2023-04-19T10:36:07.415088"),
"TargetCompID" to "RECEIVER",
"BeginString" to "FIXT.1.1",
"BodyLength" to 295,
"MsgType" to "8"
),
"ExecID" to "495504662",
"ClOrdID" to "zSuNbrBIZyVljs",
"OrigClOrdID" to "zSuNbrBIZyVljs",
"OrderID" to "49415882",
"ExecType" to '0',
"OrdStatus" to '0',
"LeavesQty" to 500,
"CumQty" to BigDecimal(500),
"SecurityID" to "NWDR",
"SecurityIDSource" to "8",
"TradingParty" to mutableMapOf(
"NoPartyIDs" to mutableListOf(
mutableMapOf(
"PartyID" to "NGALL1FX01",
"PartyIDSource" to 'D',
"PartyRole" to 76
),
mutableMapOf(
"PartyID" to "0",
"PartyIDSource" to 'P',
"PartyRole" to 3
)
)
),
"Account" to "test",
"OrdType" to 'A',
"TimeInForce" to '0',
"Side" to 'B',
"Symbol" to "ABC",
"OrderQty" to 500,
"Price" to 1000,
"Unknown" to "500",
"TransactTime" to LocalDateTime.parse("2018-02-05T10:38:08.000008"),
"trailer" to mutableMapOf(
"CheckSum" to "191"
)
)
)
}
}
}

0 comments on commit b761c17

Please sign in to comment.