@@ -47,74 +47,70 @@ class PersistentDomainEventIntegrationTest {
47
47
@ Test
48
48
void exposesEventPublicationForFailedListener () throws Exception {
49
49
50
- AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ();
51
- context .getEnvironment ().getPropertySources ().addFirst (
52
- new MapPropertySource ("test" , Map .of ("spring.modulith.republish-outstanding-events-on-restart" , "true" )));
53
- context .register (ApplicationConfiguration .class , InfrastructureConfiguration .class );
54
- context .refresh ();
50
+ try (var context = new AnnotationConfigApplicationContext ()) {
55
51
56
- EventPublicationRegistry registry = context .getBean (EventPublicationRegistry .class );
52
+ context .getEnvironment ().getPropertySources ().addFirst (
53
+ new MapPropertySource ("test" , Map .of ("spring.modulith.republish-outstanding-events-on-restart" , "true" )));
54
+ context .register (ApplicationConfiguration .class , InfrastructureConfiguration .class );
55
+ context .refresh ();
57
56
58
- try {
57
+ var registry = context . getBean ( EventPublicationRegistry . class );
59
58
60
- context . getBean ( Client . class ). method ();
59
+ try {
61
60
62
- Thread .sleep (200 );
63
-
64
- assertThat (context .getBean (NonTxEventListener .class ).getInvoked ()).isEqualTo (1 );
65
- assertThat (context .getBean (FirstTxEventListener .class ).getInvoked ()).isEqualTo (1 );
66
- assertThat (context .getBean (SecondTxEventListener .class ).getInvoked ()).isEqualTo (1 );
67
- assertThat (context .getBean (ThirdTxEventListener .class ).getInvoked ()).isEqualTo (1 );
68
- assertThat (context .getBean (FourthTxEventListener .class ).getInvoked ()).isEqualTo (1 );
69
-
70
- } catch (Throwable e ) {
61
+ context .getBean (Client .class ).method ();
71
62
72
- System . out . println ( e );
63
+ Thread . sleep ( 200 );
73
64
74
- } finally {
65
+ assertThat (context .getBean (NonTxEventListener .class ).getInvoked ()).isEqualTo (1 );
66
+ assertThat (context .getBean (FirstTxEventListener .class ).getInvoked ()).isEqualTo (1 );
67
+ assertThat (context .getBean (SecondTxEventListener .class ).getInvoked ()).isEqualTo (1 );
68
+ assertThat (context .getBean (ThirdTxEventListener .class ).getInvoked ()).isEqualTo (1 );
69
+ assertThat (context .getBean (FourthTxEventListener .class ).getInvoked ()).isEqualTo (1 );
75
70
76
- assertThat (registry .findIncompletePublications ()) //
77
- .extracting (TargetEventPublication ::getTargetIdentifier ) //
78
- .extracting (PublicationTargetIdentifier ::getValue ) //
79
- .hasSize (2 ) //
80
- .allSatisfy (id -> {
81
- assertThat (id )
82
- .matches (it -> //
83
- it .contains (SecondTxEventListener .class .getName ()) //
84
- || it .contains (FourthTxEventListener .class .getName ()));
85
- });
71
+ } finally {
86
72
87
- }
73
+ assertThat (registry .findIncompletePublications ()) //
74
+ .extracting (TargetEventPublication ::getTargetIdentifier ) //
75
+ .extracting (PublicationTargetIdentifier ::getValue ) //
76
+ .hasSize (2 ) //
77
+ .allSatisfy (id -> {
78
+ assertThat (id )
79
+ .matches (it -> //
80
+ it .contains (SecondTxEventListener .class .getName ()) //
81
+ || it .contains (FourthTxEventListener .class .getName ()));
82
+ });
88
83
89
- // Resubmit failed publications
90
- var incompletePublications = context .getBean (IncompleteEventPublications .class );
84
+ }
91
85
92
- incompletePublications .resubmitIncompletePublications (__ -> true );
86
+ // Resubmit failed publications
87
+ var incompletePublications = context .getBean (IncompleteEventPublications .class );
93
88
94
- Thread . sleep ( 200 );
89
+ incompletePublications . resubmitIncompletePublications ( __ -> true );
95
90
96
- assertThat (context .getBean (NonTxEventListener .class ).getInvoked ()).isEqualTo (1 );
97
- assertThat (context .getBean (FirstTxEventListener .class ).getInvoked ()).isEqualTo (1 );
98
- assertThat (context .getBean (SecondTxEventListener .class ).getInvoked ()).isEqualTo (2 );
99
- assertThat (context .getBean (ThirdTxEventListener .class ).getInvoked ()).isEqualTo (1 );
100
- assertThat (context .getBean (FourthTxEventListener .class ).getInvoked ()).isEqualTo (2 );
91
+ Thread .sleep (200 );
101
92
102
- // Still 2 uncompleted publications
103
- assertThat (registry .findIncompletePublications ()).hasSize (2 );
93
+ assertThat (context .getBean (NonTxEventListener .class ).getInvoked ()).isEqualTo (1 );
94
+ assertThat (context .getBean (FirstTxEventListener .class ).getInvoked ()).isEqualTo (1 );
95
+ assertThat (context .getBean (SecondTxEventListener .class ).getInvoked ()).isEqualTo (2 );
96
+ assertThat (context .getBean (ThirdTxEventListener .class ).getInvoked ()).isEqualTo (1 );
97
+ assertThat (context .getBean (FourthTxEventListener .class ).getInvoked ()).isEqualTo (2 );
104
98
105
- incompletePublications .resubmitIncompletePublications (it -> {
106
- return TargetEventPublication .class .cast (it )
107
- .getTargetIdentifier ()
108
- .getValue ().contains (SecondTxEventListener .class .getName ());
109
- });
99
+ // Still 2 uncompleted publications
100
+ assertThat (registry .findIncompletePublications ()).hasSize (2 );
110
101
111
- assertThat ( context . getBean ( NonTxEventListener . class ). getInvoked ()). isEqualTo ( 1 );
112
- assertThat ( context . getBean ( FirstTxEventListener . class ). getInvoked ()). isEqualTo ( 1 );
113
- assertThat ( context . getBean ( SecondTxEventListener . class ). getInvoked ()). isEqualTo ( 3 );
114
- assertThat ( context . getBean ( ThirdTxEventListener .class ). getInvoked ()). isEqualTo ( 1 );
115
- assertThat ( context . getBean ( FourthTxEventListener . class ). getInvoked ()). isEqualTo ( 2 );
102
+ incompletePublications . resubmitIncompletePublications ( it -> {
103
+ return TargetEventPublication . class . cast ( it )
104
+ . getTargetIdentifier ()
105
+ . getValue (). contains ( SecondTxEventListener .class . getName () );
106
+ } );
116
107
117
- context .close ();
108
+ assertThat (context .getBean (NonTxEventListener .class ).getInvoked ()).isEqualTo (1 );
109
+ assertThat (context .getBean (FirstTxEventListener .class ).getInvoked ()).isEqualTo (1 );
110
+ assertThat (context .getBean (SecondTxEventListener .class ).getInvoked ()).isEqualTo (3 );
111
+ assertThat (context .getBean (ThirdTxEventListener .class ).getInvoked ()).isEqualTo (1 );
112
+ assertThat (context .getBean (FourthTxEventListener .class ).getInvoked ()).isEqualTo (2 );
113
+ }
118
114
}
119
115
120
116
@ Configuration
0 commit comments