Skip to content

Commit

Permalink
Merge pull request #121 from cfg4j/atomic-consul-reload
Browse files Browse the repository at this point in the history
Atomic consul reload
  • Loading branch information
norbertpotocki committed Oct 1, 2015
2 parents 06db657 + d64531c commit 121a4fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Expand Up @@ -101,7 +101,7 @@ public void init() {

@Override
public void reload() {
consulValues = new HashMap<>();
Map<String, String> newConsulValues = new HashMap<>();
List<Value> valueList;

try {
Expand All @@ -120,9 +120,10 @@ public void reload() {

LOG.trace("Consul provided configuration key: " + value.getKey() + " with value: " + val);

consulValues.put(value.getKey(), val);
newConsulValues.put(value.getKey(), val);
}

consulValues = newConsulValues;
}

@Override
Expand Down
Expand Up @@ -34,6 +34,8 @@
import org.mockito.runners.MockitoJUnitRunner;

import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;


Expand Down Expand Up @@ -145,6 +147,19 @@ public void reloadShouldThrowOnConnectionFailure() throws Exception {
source.reload();
}

@Test
public void shouldReturnOldValuesDuringReload() throws Exception {
new Timer().schedule(new TimerTask() {
@Override
public void run() {
source.reload();
}
}, 0);

Environment environment = new ImmutableEnvironment("us-west-1");
assertThat(source.getConfiguration(environment)).contains(MapEntry.entry("featureA.toggle", "disabled"));
}

private void runMockServer() throws IOException {
server = new MockWebServer();
server.setDispatcher(dispatcher);
Expand Down

0 comments on commit 121a4fb

Please sign in to comment.