2323import de .codecentric .boot .admin .server .domain .values .InstanceId ;
2424import de .codecentric .boot .admin .server .domain .values .Registration ;
2525import de .codecentric .boot .admin .server .domain .values .StatusInfo ;
26+ import reactor .core .publisher .Mono ;
2627import reactor .test .publisher .TestPublisher ;
2728
2829import org .junit .Test ;
2930
31+ import static org .mockito .ArgumentMatchers .any ;
3032import static org .mockito .Mockito .clearInvocations ;
3133import static org .mockito .Mockito .mock ;
3234import static org .mockito .Mockito .never ;
3335import static org .mockito .Mockito .times ;
3436import static org .mockito .Mockito .verify ;
37+ import static org .mockito .Mockito .when ;
3538
3639public class NotificationTriggerTest {
3740 private final Instance instance = Instance .create (InstanceId .of ("id-1" ))
@@ -47,17 +50,44 @@ public void should_notify_on_event() throws InterruptedException {
4750 Thread .sleep (500L ); //wait for subscription
4851
4952 //when registered event is emitted
50- InstanceStatusChangedEvent event = new InstanceStatusChangedEvent (instance .getId (), instance .getVersion (),
51- StatusInfo .ofDown ());
53+ InstanceStatusChangedEvent event = new InstanceStatusChangedEvent (this .instance .getId (),
54+ this .instance .getVersion (),
55+ StatusInfo .ofDown ()
56+ );
5257 events .next (event );
5358 //then should notify
5459 verify (notifier , times (1 )).notify (event );
5560
5661 //when registered event is emitted but the trigger has been stopped
5762 trigger .stop ();
5863 clearInvocations (notifier );
59- events .next (new InstanceRegisteredEvent (instance .getId (), instance .getVersion (), instance .getRegistration ()));
64+ events .next (new InstanceRegisteredEvent (this . instance .getId (), this . instance .getVersion (), this . instance .getRegistration ()));
6065 //then should not notify
6166 verify (notifier , never ()).notify (event );
6267 }
68+
69+ @ Test
70+ public void should_resume_on_exceptopn () throws InterruptedException {
71+ //given
72+ Notifier notifier = mock (Notifier .class );
73+ TestPublisher <InstanceEvent > events = TestPublisher .create ();
74+ NotificationTrigger trigger = new NotificationTrigger (notifier , events );
75+ trigger .start ();
76+ Thread .sleep (500L ); //wait for subscription
77+
78+
79+ when (notifier .notify (any ())).thenReturn (Mono .error (new IllegalStateException ("Test" ))).thenReturn (Mono .empty ());
80+
81+ //when exception for the first event is thrown and a subsequent event is fired
82+ InstanceStatusChangedEvent event = new InstanceStatusChangedEvent (this .instance .getId (),
83+ this .instance .getVersion (),
84+ StatusInfo .ofDown ()
85+ );
86+ events .next (event );
87+ events .next (event );
88+
89+ //the notifier was after the exception
90+ verify (notifier , times (2 )).notify (event );
91+ }
92+
6393}
0 commit comments