From 2bf8645eadeeb353369d2d2d62ce6245b0951a63 Mon Sep 17 00:00:00 2001 From: Mike Davis Date: Fri, 21 Jun 2019 13:32:42 -0700 Subject: [PATCH 1/5] Fix blocking behavior when sending update notification. --- .../config/PollingProjectConfigManager.java | 2 +- .../PollingProjectConfigManagerTest.java | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/core-api/src/main/java/com/optimizely/ab/config/PollingProjectConfigManager.java b/core-api/src/main/java/com/optimizely/ab/config/PollingProjectConfigManager.java index 9037169da..14349f1cf 100644 --- a/core-api/src/main/java/com/optimizely/ab/config/PollingProjectConfigManager.java +++ b/core-api/src/main/java/com/optimizely/ab/config/PollingProjectConfigManager.java @@ -99,8 +99,8 @@ void setConfig(ProjectConfig projectConfig) { logger.info("New datafile set with revision: {}. Old revision: {}", projectConfig.getRevision(), previousRevision); currentProjectConfig.set(projectConfig); - notificationCenter.send(SIGNAL); countDownLatch.countDown(); + notificationCenter.send(SIGNAL); } public NotificationCenter getNotificationCenter() { diff --git a/core-api/src/test/java/com/optimizely/ab/config/PollingProjectConfigManagerTest.java b/core-api/src/test/java/com/optimizely/ab/config/PollingProjectConfigManagerTest.java index ea35ec1a5..9e65cf837 100644 --- a/core-api/src/test/java/com/optimizely/ab/config/PollingProjectConfigManagerTest.java +++ b/core-api/src/test/java/com/optimizely/ab/config/PollingProjectConfigManagerTest.java @@ -23,6 +23,7 @@ import org.junit.Ignore; import org.junit.Test; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -195,6 +196,20 @@ public void testUpdateConfigNotificationGetsTriggered() throws InterruptedExcept assertTrue(countDownLatch.await(500, TimeUnit.MILLISECONDS)); } + @Test + public void testUpdateConfigNotificationDoesNotResultInDeadlock() throws Exception { + NotificationCenter notificationCenter = new NotificationCenter(); + + TestProjectConfigManager testProjectConfigManager = new TestProjectConfigManager(projectConfig, TimeUnit.SECONDS.toMillis(10), notificationCenter); + notificationCenter.getNotificationManager(UpdateConfigNotification.class) + .addHandler(message -> { + assertNotNull(testProjectConfigManager.getConfig()); + }); + + testProjectConfigManager.start(); + CompletableFuture.runAsync(testProjectConfigManager::getConfig).get(5, TimeUnit.SECONDS); + } + private static class TestProjectConfigManager extends PollingProjectConfigManager { private final AtomicInteger counter = new AtomicInteger(); @@ -206,7 +221,11 @@ private TestProjectConfigManager() { } private TestProjectConfigManager(ProjectConfig projectConfig) { - super(POLLING_PERIOD, POLLING_UNIT, POLLING_PERIOD / 2, POLLING_UNIT, new NotificationCenter()); + this(projectConfig, POLLING_PERIOD / 2, new NotificationCenter()); + } + + private TestProjectConfigManager(ProjectConfig projectConfig, long blockPeriod, NotificationCenter notificationCenter) { + super(POLLING_PERIOD, POLLING_UNIT, blockPeriod, POLLING_UNIT, notificationCenter); this.projectConfig = projectConfig; } From 6fbbc610d8950ec348d8d19458fb539f63fdf0b1 Mon Sep 17 00:00:00 2001 From: Mike Davis Date: Tue, 25 Jun 2019 10:00:46 -0700 Subject: [PATCH 2/5] Retrigger build. From eb9e8d9f628d6784cd2bd2aec4192255808c6a09 Mon Sep 17 00:00:00 2001 From: Mike Davis Date: Tue, 25 Jun 2019 13:36:22 -0700 Subject: [PATCH 3/5] Retrigger build. From e42dfb944429d4204a1f935bb78c365b8819317b Mon Sep 17 00:00:00 2001 From: Mike Davis Date: Tue, 25 Jun 2019 16:10:17 -0700 Subject: [PATCH 4/5] Retrigger build. From a1243b65b6853869a150a90659d3017edfb3e288 Mon Sep 17 00:00:00 2001 From: Mike Davis Date: Wed, 26 Jun 2019 09:25:32 -0700 Subject: [PATCH 5/5] Retrigger build.