-
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lazy uuid generation for SentryId and SpanId (#3770)
* lazy uuid generation for SentryId and SpanId * add changelog * add tests for lazy init, rework SentryId to cache string result * fix changelog * Update sentry/src/main/java/io/sentry/protocol/SentryId.java Co-authored-by: Stefano <stefano.siano@sentry.io> * Update sentry/src/main/java/io/sentry/protocol/SentryId.java Co-authored-by: Stefano <stefano.siano@sentry.io> * Update sentry/src/main/java/io/sentry/protocol/SentryId.java Co-authored-by: Stefano <stefano.siano@sentry.io> * Update sentry/src/main/java/io/sentry/protocol/SentryId.java Co-authored-by: Stefano <stefano.siano@sentry.io> * Update sentry/src/main/java/io/sentry/protocol/SentryId.java Co-authored-by: Stefano <stefano.siano@sentry.io> * Format code * Add object comparison to SpanFrameMetricsCollector only check for time difference of .equals if objects are not the same --------- Co-authored-by: Alexander Dinauer <adinauer@users.noreply.github.com> Co-authored-by: Stefano <stefano.siano@sentry.io> Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io>
- Loading branch information
1 parent
57b2da5
commit d2c4d5e
Showing
8 changed files
with
144 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.sentry.protocol | ||
|
||
import io.sentry.SpanId | ||
import io.sentry.util.StringUtils | ||
import org.mockito.Mockito | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.never | ||
import org.mockito.kotlin.times | ||
import java.util.* | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class SpanIdTest { | ||
|
||
@Test | ||
fun `UUID is not generated on initialization`() { | ||
val uuid = UUID.randomUUID() | ||
Mockito.mockStatic(UUID::class.java).use { utils -> | ||
utils.`when`<UUID> { UUID.randomUUID() }.thenReturn(uuid) | ||
val ignored = SpanId() | ||
utils.verify({ UUID.randomUUID() }, never()) | ||
} | ||
} | ||
|
||
@Test | ||
fun `UUID is generated only once`() { | ||
val uuid = UUID.randomUUID() | ||
Mockito.mockStatic(java.util.UUID::class.java).use { utils -> | ||
utils.`when`<UUID> { UUID.randomUUID() }.thenReturn(uuid) | ||
val spanId = SpanId() | ||
val uuid1 = spanId.toString() | ||
val uuid2 = spanId.toString() | ||
|
||
assertEquals(uuid1, uuid2) | ||
utils.verify({ UUID.randomUUID() }, times(1)) | ||
} | ||
} | ||
|
||
@Test | ||
fun `normalizeUUID is only called once`() { | ||
Mockito.mockStatic(StringUtils::class.java).use { utils -> | ||
utils.`when`<Any> { StringUtils.normalizeUUID(any()) }.thenReturn("00000000000000000000000000000000") | ||
val spanId = SpanId() | ||
val uuid1 = spanId.toString() | ||
val uuid2 = spanId.toString() | ||
|
||
assertEquals(uuid1, uuid2) | ||
utils.verify({ StringUtils.normalizeUUID(any()) }, times(1)) | ||
} | ||
} | ||
} |