package Ġmy . ch aster . messaging Ċ Ċ import Ġmy . ch aster . Abstract IntegrationTest Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġjava . util . function . Consumer Ċ Ċ internal Ġclass ĠMessaging Executor IntegrationTest Ġ: ĠAbstract IntegrationTest () Ġ{ ĊĊ ĉ @ Autowired Ċ ĉ private Ġlateinit Ġvar Ġtest ee : ĠMessaging Executor ĊĊ ĉ @ Autowired Ċ ĉ private Ġlateinit Ġvar Ġapplication Message TestData : ĠApplication Message TestData ĊĊ ĉ @ Autowired Ċ ĉ private Ġlateinit Ġvar Ġtest Messaging Consumer : ĠTest Messaging Consumer ĊĊ ĉ @ Autowired Ċ ĉ private Ġlateinit Ġvar Ġapplication Message Repository : ĠApplication Message Repository ĊĊĊ ĉ @ Test Ċ ĉ fun Ġ` fetch And Execute Messages Ġshould Ġexecute Ġall Ġtasks Ġwhen Ġmore Ġthan Ġpage Ġsize `() Ġ{ Ċĉ ĉ // given Ċĉ ĉ val Ġtest Messages Ġ= ĠInt Range ( 1 , ĠMessaging Executor . PAGE _ SIZE Ġ+ Ġ 1 ) Ċĉĉ ĉ . map Ġ{ ĠTest Message . random () Ġ} Ċĉ ĉ val Ġapplication Messages Ġ= Ġtest Messages . map Ġ{ Ġapplication Message TestData . create (" test Messaging Consumer ", Ġit ) Ġ} ĊĊĊĉ ĉ // when Ċĉ ĉ END _ TRANSACTION () Ċĉ ĉ test ee . fetch And Execute Messages () Ċĉ ĉ START _ TRANSACTION () ĊĊĉ ĉ // then Ċĉ ĉ test Messaging Consumer . await Message ( test Messages . last ()) Ċĉ ĉ assertThat ( test Messaging Consumer . received Messages ) Ċĉĉ ĉ . contains Sub sequence ( test Messages ) Ċĉĉ ĉ . contains Only Once (* test Messages . to Typed Array ()) ĊĊĉ ĉ assertThat ( application Messages ). isNotEmpty Ċĉĉ ĉ . all Satisf y ( Consumer { ĠassertThat ( application Message Repository . findById ( it . id )). isNot Present Ġ}) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġ` fetch And Execute Messages Ġshould Ġpersist Ġexception Ġand Ġnot Ġstop Ġother Ġmessages `() Ġ{ Ċĉ ĉ // given Ċĉ ĉ val Ġtest Messages Ġ= ĠlistOf ( Ċĉĉ ĉ Test Message . random ( consumer Should Throw Exception Ġ= Ġtrue ), Ċĉĉ ĉ Test Message . random ( consumer Should Throw Exception Ġ= Ġfalse ), Ċĉ ĉ ) Ċĉ ĉ val Ġapplication Messages Ġ= Ġtest Messages . map Ġ{ Ġapplication Message TestData . create (" test Messaging Consumer ", Ġit ) Ġ} ĊĊĉ ĉ // when Ċĉ ĉ END _ TRANSACTION () Ċĉ ĉ test ee . fetch And Execute Messages () Ċĉ ĉ START _ TRANSACTION () ĊĊĉ ĉ // then Ċĉ ĉ test Messaging Consumer . await Message ( test Messages . last ()) Ċĉ ĉ assertThat ( test Messaging Consumer . received Messages ) Ċĉĉ ĉ . contains Sub sequence ( test Messages ) Ċĉĉ ĉ . contains Only Once (* test Messages . to Typed Array ()) ĊĊĉ ĉ assertThat ( application Message Repository . findById ( application Messages [ 0 ]. id )) Ċĉĉ ĉ . isPresent Ċĉĉ ĉ . satisf ies ( Consumer Ġ{ Ġfailed Message Ġ-> Ċĉĉĉ ĉ assertThat ( failed Message . get (). failure ). isEqualTo ("[ java . lang . IllegalStateException ] ĠI Ġshould Ġbe Ġthrown ...") Ċĉĉ ĉ }) Ċĉ ĉ assertThat ( application Message Repository . findById ( application Messages [ 1 ]. id )). isNot Present Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġ` fetch And Execute Messages Ġshould Ġnot Ġexecute Ġfailed Ġmessages `() Ġ{ Ċĉ ĉ // given Ċĉ ĉ val Ġtest Messages Ġ= ĠlistOf ( Ċĉĉ ĉ Test Message . random (), Ċĉĉ ĉ Test Message . random (), Ċĉ ĉ ) Ċĉ ĉ val Ġapplication Messages Ġ= ĠlistOf ( Ċĉĉ ĉ application Message TestData . create (" test Messaging Consumer ", Ġtest Messages [ 0 ], Ġ" some Ġfailure Ġreason "), Ċĉĉ ĉ application Message TestData . create (" test Messaging Consumer ", Ġtest Messages [ 1 ]), Ċĉ ĉ ) ĊĊĉ ĉ // when Ċĉ ĉ END _ TRANSACTION () Ċĉ ĉ test ee . fetch And Execute Messages () Ċĉ ĉ START _ TRANSACTION () ĊĊĉ ĉ // then Ċĉ ĉ test Messaging Consumer . await Message ( test Messages . last ()) Ċĉ ĉ assertThat ( test Messaging Consumer . received Messages ) Ċĉĉ ĉ . contains ( test Messages [ 1 ]) Ċĉĉ ĉ . does Not Contain ( test Messages [ 0 ]) Ġ// failed Ġone ĊĊĉ ĉ assertThat ( application Message Repository . findById ( application Messages [ 0 ]. id )). isPresent Ċĉ ĉ assertThat ( application Message Repository . findById ( application Messages [ 1 ]. id )). isNot Present Ċ ĉ } Ċ }