File tree Expand file tree Collapse file tree 6 files changed +51
-3
lines changed
main/java/io/sentry/spring7/cache
test/kotlin/io/sentry/spring7/cache
sentry-spring-jakarta/src
main/java/io/sentry/spring/jakarta/cache
test/kotlin/io/sentry/spring/jakarta/cache
main/java/io/sentry/spring/cache
test/kotlin/io/sentry/spring/cache Expand file tree Collapse file tree 6 files changed +51
-3
lines changed Original file line number Diff line number Diff line change @@ -287,7 +287,7 @@ public boolean invalidate() {
287287 }
288288 try {
289289 final boolean result = delegate .invalidate ();
290- span .setData (SpanDataConvention .CACHE_WRITE , true );
290+ span .setData (SpanDataConvention .CACHE_WRITE , result );
291291 span .setStatus (SpanStatus .OK );
292292 return result ;
293293 } catch (Throwable e ) {
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import kotlin.test.BeforeTest
1313import kotlin.test.Test
1414import kotlin.test.assertEquals
1515import kotlin.test.assertFailsWith
16+ import kotlin.test.assertFalse
1617import kotlin.test.assertNull
1718import kotlin.test.assertTrue
1819import org.mockito.kotlin.any
@@ -450,6 +451,21 @@ class SentryCacheWrapperTest {
450451 assertEquals(" invalidate" , tx.spans.first().getData(SpanDataConvention .CACHE_OPERATION ))
451452 }
452453
454+ @Test
455+ fun `invalidate sets cache write false when cache had no mappings` () {
456+ val tx = createTransaction()
457+ val wrapper = SentryCacheWrapper (delegate, scopes)
458+ whenever(delegate.invalidate()).thenReturn(false )
459+
460+ val result = wrapper.invalidate()
461+
462+ assertFalse(result)
463+ assertEquals(1 , tx.spans.size)
464+ assertEquals(" cache.invalidate" , tx.spans.first().operation)
465+ assertEquals(false , tx.spans.first().getData(SpanDataConvention .CACHE_WRITE ))
466+ assertEquals(" invalidate" , tx.spans.first().getData(SpanDataConvention .CACHE_OPERATION ))
467+ }
468+
453469 // -- no span when no active transaction --
454470
455471 @Test
Original file line number Diff line number Diff line change @@ -287,7 +287,7 @@ public boolean invalidate() {
287287 }
288288 try {
289289 final boolean result = delegate .invalidate ();
290- span .setData (SpanDataConvention .CACHE_WRITE , true );
290+ span .setData (SpanDataConvention .CACHE_WRITE , result );
291291 span .setStatus (SpanStatus .OK );
292292 return result ;
293293 } catch (Throwable e ) {
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import kotlin.test.BeforeTest
1313import kotlin.test.Test
1414import kotlin.test.assertEquals
1515import kotlin.test.assertFailsWith
16+ import kotlin.test.assertFalse
1617import kotlin.test.assertNull
1718import kotlin.test.assertTrue
1819import org.mockito.kotlin.any
@@ -450,6 +451,21 @@ class SentryCacheWrapperTest {
450451 assertEquals(" invalidate" , tx.spans.first().getData(SpanDataConvention .CACHE_OPERATION ))
451452 }
452453
454+ @Test
455+ fun `invalidate sets cache write false when cache had no mappings` () {
456+ val tx = createTransaction()
457+ val wrapper = SentryCacheWrapper (delegate, scopes)
458+ whenever(delegate.invalidate()).thenReturn(false )
459+
460+ val result = wrapper.invalidate()
461+
462+ assertFalse(result)
463+ assertEquals(1 , tx.spans.size)
464+ assertEquals(" cache.invalidate" , tx.spans.first().operation)
465+ assertEquals(false , tx.spans.first().getData(SpanDataConvention .CACHE_WRITE ))
466+ assertEquals(" invalidate" , tx.spans.first().getData(SpanDataConvention .CACHE_OPERATION ))
467+ }
468+
453469 // -- no span when no active transaction --
454470
455471 @Test
Original file line number Diff line number Diff line change @@ -214,7 +214,7 @@ public boolean invalidate() {
214214 }
215215 try {
216216 final boolean result = delegate .invalidate ();
217- span .setData (SpanDataConvention .CACHE_WRITE , true );
217+ span .setData (SpanDataConvention .CACHE_WRITE , result );
218218 span .setStatus (SpanStatus .OK );
219219 return result ;
220220 } catch (Throwable e ) {
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import kotlin.test.BeforeTest
1111import kotlin.test.Test
1212import kotlin.test.assertEquals
1313import kotlin.test.assertFailsWith
14+ import kotlin.test.assertFalse
1415import kotlin.test.assertNull
1516import kotlin.test.assertTrue
1617import org.mockito.kotlin.any
@@ -274,6 +275,21 @@ class SentryCacheWrapperTest {
274275 assertEquals(" invalidate" , tx.spans.first().getData(SpanDataConvention .CACHE_OPERATION ))
275276 }
276277
278+ @Test
279+ fun `invalidate sets cache write false when cache had no mappings` () {
280+ val tx = createTransaction()
281+ val wrapper = SentryCacheWrapper (delegate, scopes)
282+ whenever(delegate.invalidate()).thenReturn(false )
283+
284+ val result = wrapper.invalidate()
285+
286+ assertFalse(result)
287+ assertEquals(1 , tx.spans.size)
288+ assertEquals(" cache.invalidate" , tx.spans.first().operation)
289+ assertEquals(false , tx.spans.first().getData(SpanDataConvention .CACHE_WRITE ))
290+ assertEquals(" invalidate" , tx.spans.first().getData(SpanDataConvention .CACHE_OPERATION ))
291+ }
292+
277293 // -- no span when no active transaction --
278294
279295 @Test
You can’t perform that action at this time.
0 commit comments