Skip to content

Commit

Permalink
Fix random generated numbers for parsed message (#281)
Browse files Browse the repository at this point in the history
* Fix random generated numbers for parsed message

* Use long min value as a marker for unset sequence

* Correct range for sequence in test
  • Loading branch information
OptimumCode authored Oct 13, 2023
1 parent 0bb4984 commit 333206d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ data class MessageId(
}


private const val SEQUENCE_NOT_SET = -1L
private const val SEQUENCE_NOT_SET = Long.MIN_VALUE

private class MessageIdBuilderImpl : MessageId.Builder {
private var _sessionAlias: String? = null
Expand Down Expand Up @@ -128,7 +128,7 @@ private class MessageIdBuilderImpl : MessageId.Builder {
override fun isDirectionSet(): Boolean = _direction != null

override fun setSequence(sequence: Long): MessageId.Builder = apply {
require(sequence > SEQUENCE_NOT_SET) { "Property \"sequence\" should not be negative" }
require(sequence != SEQUENCE_NOT_SET) { "Value $sequence for property \"sequence\" is reserved" }
this._sequence = sequence
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ class ParsedMessageTest {
private const val TEST_PROTOCOL = "test-protocol"
private const val TEST_SESSION_ALIAS = "test-session-alias"
private const val TEST_MESSAGE_TYPE = "test-message-type"
private val TEST_SEQUENCE = Random.nextLong()
private val TEST_SUB_SEQUENCE = listOf(Random.nextInt(), Random.nextInt())
private val TEST_SEQUENCE = Random.nextLong(from = Long.MIN_VALUE + 1, until = Long.MAX_VALUE)
private val TEST_SUB_SEQUENCE = listOf(
Random.nextInt(from = 0, until = Int.MAX_VALUE),
Random.nextInt(from = 0, until = Int.MAX_VALUE),
)
}
}

0 comments on commit 333206d

Please sign in to comment.