Skip to content

Commit

Permalink
Merge pull request #1736 from DataDog/jmoskovich/rum-2245/wireframe-i…
Browse files Browse the repository at this point in the history
…d-as-int

RUM-2245 Generate wireframe ids as 32bit Int
  • Loading branch information
jonathanmos authored Nov 21, 2023
2 parents 764129c + 21b12e7 commit f48127c
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 9 deletions.
1 change: 1 addition & 0 deletions detekt_custom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ datadog:
- "java.security.MessageDigest.update(kotlin.ByteArray?)"
- "java.security.SecureRandom.constructor()"
- "java.security.SecureRandom.nextFloat()"
- "java.security.SecureRandom.nextInt()"
- "java.security.SecureRandom.nextLong()"
- "java.util.HashSet.find(kotlin.Function1)"
- "java.util.Properties.constructor()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class ShapeWireframeForgeryFactory :
ForgeryFactory<MobileSegment.Wireframe.ShapeWireframe> {
override fun getForgery(forge: Forge): MobileSegment.Wireframe.ShapeWireframe {
return MobileSegment.Wireframe.ShapeWireframe(
id = forge.aPositiveLong(),
id = forge.aPositiveInt().toLong(),
x = forge.aPositiveLong(),
y = forge.aPositiveLong(),
width = forge.aPositiveLong(strict = true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class TextWireframeForgeryFactory :
ForgeryFactory<MobileSegment.Wireframe.TextWireframe> {
override fun getForgery(forge: Forge): MobileSegment.Wireframe.TextWireframe {
return MobileSegment.Wireframe.TextWireframe(
id = forge.aPositiveLong(),
id = forge.aPositiveInt().toLong(),
x = forge.aPositiveLong(),
y = forge.aPositiveLong(),
width = forge.aPositiveLong(strict = true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object UniqueIdentifierGenerator {
// was a long and use that as an identifier.
uniqueIdentifier as? Long
} else {
val newUniqueIdentifier = secureRandom.nextLong()
val newUniqueIdentifier = secureRandom.nextInt().toLong()
parent.setTag(key, newUniqueIdentifier)
newUniqueIdentifier
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class ImageWireframeForgeryFactory :
ForgeryFactory<MobileSegment.Wireframe.ImageWireframe> {
override fun getForgery(forge: Forge): MobileSegment.Wireframe.ImageWireframe {
return MobileSegment.Wireframe.ImageWireframe(
id = forge.aPositiveLong(),
id = forge.aPositiveInt().toLong(),
x = forge.aPositiveLong(),
y = forge.aPositiveLong(),
width = forge.aPositiveLong(strict = true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class PlaceholderWireframeForgeryFactory :
ForgeryFactory<MobileSegment.Wireframe.PlaceholderWireframe> {
override fun getForgery(forge: Forge): MobileSegment.Wireframe.PlaceholderWireframe {
return MobileSegment.Wireframe.PlaceholderWireframe(
id = forge.aPositiveLong(),
id = forge.aPositiveInt().toLong(),
x = forge.aPositiveLong(),
y = forge.aPositiveLong(),
width = forge.aPositiveLong(strict = true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class ShapeWireframeForgeryFactory :
ForgeryFactory<MobileSegment.Wireframe.ShapeWireframe> {
override fun getForgery(forge: Forge): MobileSegment.Wireframe.ShapeWireframe {
return MobileSegment.Wireframe.ShapeWireframe(
id = forge.aPositiveLong(),
id = forge.aPositiveInt().toLong(),
x = forge.aPositiveLong(),
y = forge.aPositiveLong(),
width = forge.aPositiveLong(strict = true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class ShapeWireframeMutationForgeryFactory :
override fun getForgery(forge: Forge):
MobileSegment.WireframeUpdateMutation.ShapeWireframeUpdate {
return MobileSegment.WireframeUpdateMutation.ShapeWireframeUpdate(
id = forge.aPositiveLong(),
id = forge.aPositiveInt().toLong(),
x = forge.aNullable { aPositiveLong() },
y = forge.aNullable { aPositiveLong() },
width = forge.aNullable { aPositiveLong(strict = true) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class TextWireframeForgeryFactory :
ForgeryFactory<MobileSegment.Wireframe.TextWireframe> {
override fun getForgery(forge: Forge): MobileSegment.Wireframe.TextWireframe {
return MobileSegment.Wireframe.TextWireframe(
id = forge.aPositiveLong(),
id = forge.aPositiveInt().toLong(),
x = forge.aPositiveLong(),
y = forge.aPositiveLong(),
width = forge.aPositiveLong(strict = true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class TextWireframeMutationForgeryFactory :
override fun getForgery(forge: Forge):
MobileSegment.WireframeUpdateMutation.TextWireframeUpdate {
return MobileSegment.WireframeUpdateMutation.TextWireframeUpdate(
id = forge.aPositiveLong(),
id = forge.aPositiveInt().toLong(),
x = forge.aNullable { aPositiveLong() },
y = forge.aNullable { aPositiveLong() },
width = forge.aNullable { aPositiveLong(strict = true) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,23 @@ internal class UniqueIdentifierGeneratorTest {

assertThat(generatedUniqueNumbers).isEmpty()
}

@Test
fun `M always generate a 32bit Int compatible identifier W resolveChildUniqueIdentifier`(forge: Forge) {
// Given
val numberOfCalls = 1000

// When
val results = forge.aList<View>(numberOfCalls) { mock() }
.map {
UniqueIdentifierGenerator.resolveChildUniqueIdentifier(mock(), forge.aString())
}

// Then
results.forEach {
if (it != null) {
assertThat(it).isBetween(Int.MIN_VALUE.toLong(), Int.MAX_VALUE.toLong())
}
}
}
}

0 comments on commit f48127c

Please sign in to comment.