Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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;
}

Expand Down