23
23
import org .junit .Ignore ;
24
24
import org .junit .Test ;
25
25
26
+ import java .util .concurrent .CompletableFuture ;
26
27
import java .util .concurrent .CountDownLatch ;
27
28
import java .util .concurrent .TimeUnit ;
28
29
import java .util .concurrent .atomic .AtomicBoolean ;
@@ -195,6 +196,20 @@ public void testUpdateConfigNotificationGetsTriggered() throws InterruptedExcept
195
196
assertTrue (countDownLatch .await (500 , TimeUnit .MILLISECONDS ));
196
197
}
197
198
199
+ @ Test
200
+ public void testUpdateConfigNotificationDoesNotResultInDeadlock () throws Exception {
201
+ NotificationCenter notificationCenter = new NotificationCenter ();
202
+
203
+ TestProjectConfigManager testProjectConfigManager = new TestProjectConfigManager (projectConfig , TimeUnit .SECONDS .toMillis (10 ), notificationCenter );
204
+ notificationCenter .getNotificationManager (UpdateConfigNotification .class )
205
+ .addHandler (message -> {
206
+ assertNotNull (testProjectConfigManager .getConfig ());
207
+ });
208
+
209
+ testProjectConfigManager .start ();
210
+ CompletableFuture .runAsync (testProjectConfigManager ::getConfig ).get (5 , TimeUnit .SECONDS );
211
+ }
212
+
198
213
private static class TestProjectConfigManager extends PollingProjectConfigManager {
199
214
private final AtomicInteger counter = new AtomicInteger ();
200
215
@@ -206,7 +221,11 @@ private TestProjectConfigManager() {
206
221
}
207
222
208
223
private TestProjectConfigManager (ProjectConfig projectConfig ) {
209
- super (POLLING_PERIOD , POLLING_UNIT , POLLING_PERIOD / 2 , POLLING_UNIT , new NotificationCenter ());
224
+ this (projectConfig , POLLING_PERIOD / 2 , new NotificationCenter ());
225
+ }
226
+
227
+ private TestProjectConfigManager (ProjectConfig projectConfig , long blockPeriod , NotificationCenter notificationCenter ) {
228
+ super (POLLING_PERIOD , POLLING_UNIT , blockPeriod , POLLING_UNIT , notificationCenter );
210
229
this .projectConfig = projectConfig ;
211
230
}
212
231
0 commit comments