From 5ab04ac8e45b8ca45bccc8331f00a3643d1f0002 Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 11 Feb 2025 19:56:58 +0300 Subject: [PATCH] Allow SequenceResets through run-one --- .../java/com/exactpro/th2/FixHandler.java | 10 +- .../th2/conn/dirty/fix/MessageCorrupter.kt | 92 +++++++++++++++++++ 2 files changed, 98 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/exactpro/th2/FixHandler.java b/src/main/java/com/exactpro/th2/FixHandler.java index b2d3e9b..a9511f2 100644 --- a/src/main/java/com/exactpro/th2/FixHandler.java +++ b/src/main/java/com/exactpro/th2/FixHandler.java @@ -1055,7 +1055,7 @@ public void onOutgoingUpdateTag(@NotNull ByteBuf message, @NotNull Map negativeStructureOtgoingProcessor(ByteBuf message, M LOGGER.info("Strategy '{}' is disabled for {} message type", strategy.getType(), msgTypeField.getValue()); return null; } - String msgType = msgTypeField.getValue(); - if(ADMIN_MESSAGES.contains(msgType) && !Objects.equals(msgType, MSG_TYPE_HEARTBEAT)) { - return null; + if(msgTypeField != null) { + String msgType = msgTypeField.getValue(); + if(ADMIN_MESSAGES.contains(msgType) && !Objects.equals(msgType, MSG_TYPE_HEARTBEAT)) { + return null; + } } Function1> nextCorruption = strategy.getNextCorruption(); diff --git a/src/main/kotlin/com/exactpro/th2/conn/dirty/fix/MessageCorrupter.kt b/src/main/kotlin/com/exactpro/th2/conn/dirty/fix/MessageCorrupter.kt index 923c469..c8950ea 100644 --- a/src/main/kotlin/com/exactpro/th2/conn/dirty/fix/MessageCorrupter.kt +++ b/src/main/kotlin/com/exactpro/th2/conn/dirty/fix/MessageCorrupter.kt @@ -434,6 +434,76 @@ enum class CorruptionAction { buf.updateChecksum() } + return mapOf( + "corruptionType" to "TAG_THAT_NOT_BELONGS_TO_HEADER_TRAILER", + "tag" to "$tag" + ) + } + }, + INVALID_LENGTH_UP { + override fun transform( + buf: ByteBuf, + tag: Tag, + updateChecksum: Boolean, + updateLength: Boolean, + tagInfo: TagInfo, + corruptionConfiguration: CorruptionConfiguration + ): MetadataUpdate? { + + val field = buf.findField(BODY_LENGTH_TAG) ?: return null + + val actions = listOf( + Action( + replace = FieldSelector(BODY_LENGTH_TAG), + with = FieldDefinition(BODY_LENGTH_TAG, ((field.value?.toIntOrNull() ?: buf.writerIndex()) + 1).toString()) + ) + ) + + MessageTransformer.transformWithoutResults(buf, actions, DEFAULT_CONTEXT) + + if (updateLength) { + buf.updateLength() + } + + if (updateChecksum) { + buf.updateChecksum() + } + + return mapOf( + "corruptionType" to "TAG_THAT_NOT_BELONGS_TO_HEADER_TRAILER", + "tag" to "$tag" + ) + } + }, + INVALID_LENGTH_DOWN { + override fun transform( + buf: ByteBuf, + tag: Tag, + updateChecksum: Boolean, + updateLength: Boolean, + tagInfo: TagInfo, + corruptionConfiguration: CorruptionConfiguration + ): MetadataUpdate? { + + val field = buf.findField(BODY_LENGTH_TAG) ?: return null + + val actions = listOf( + Action( + replace = FieldSelector(BODY_LENGTH_TAG), + with = FieldDefinition(BODY_LENGTH_TAG, ((field.value?.toIntOrNull() ?: buf.writerIndex()) - 1).toString()) + ) + ) + + MessageTransformer.transformWithoutResults(buf, actions, DEFAULT_CONTEXT) + + if (updateLength) { + buf.updateLength() + } + + if (updateChecksum) { + buf.updateChecksum() + } + return mapOf( "corruptionType" to "TAG_THAT_NOT_BELONGS_TO_HEADER_TRAILER", "tag" to "$tag" @@ -523,9 +593,31 @@ object CorruptionGenerator { CorruptionAction.MOVE_TAG_OUT_OF_ORDER -> {} CorruptionAction.TAG_THAT_IS_NOT_EXIST -> {} CorruptionAction.TAG_THAT_NOT_BELONGS_TO_HEADER_TRAILER -> {} + CorruptionAction.INVALID_LENGTH_UP -> { updateLength = false } + CorruptionAction.INVALID_LENGTH_DOWN -> {updateLength = false} } } + if(tagInfos[tag]!!.dataType == DataType.STRING && corruption == CorruptionAction.NEGATIVE_NUMBER) { + continue + } + + if(tagInfos[tag]!!.dataType == DataType.BOOLEAN && corruption == CorruptionAction.NEGATIVE_NUMBER) { + continue + } + + if(tagInfos[tag]!!.dataType == DataType.BOOLEAN && corruption == CorruptionAction.OUT_OF_RANGE) { + continue + } + + if(tag != BODY_LENGTH_TAG && corruption == CorruptionAction.INVALID_LENGTH_UP) { + continue + } + + if(tag != BODY_LENGTH_TAG && corruption == CorruptionAction.INVALID_LENGTH_DOWN) { + continue + } + val corruptionFunction = { buf: ByteBuf -> createCorruptionCarry(corruption, buf, tag, updateChecksum, updateLength, tagInfos)