Skip to content

Commit

Permalink
Allow SequenceResets through run-one
Browse files Browse the repository at this point in the history
  • Loading branch information
purplegen committed Feb 11, 2025
1 parent 4764cba commit 5ab04ac
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/com/exactpro/th2/FixHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ public void onOutgoingUpdateTag(@NotNull ByteBuf message, @NotNull Map<String, S
FixField msgType = findField(message, MSG_TYPE_TAG, US_ASCII);

if(msgType != null && ADMIN_MESSAGES.contains(msgType.getValue())) {
if(!Objects.equals(msgType.getValue(), MSG_TYPE_RESEND_REQUEST)) {
if(!Objects.equals(msgType.getValue(), MSG_TYPE_RESEND_REQUEST) && !Objects.equals(msgType.getValue(), MSG_TYPE_SEQUENCE_RESET)) {
return;
}
}
Expand Down Expand Up @@ -1765,9 +1765,11 @@ private Map<String, String> 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<ByteBuf, Map<String, String>> nextCorruption = strategy.getNextCorruption();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5ab04ac

Please sign in to comment.