Skip to content

Commit

Permalink
Merge branch '2.2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
spencergibb committed May 22, 2020
2 parents 5832212 + e70cc1e commit 21b5f90
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -18,4 +18,4 @@ consul_*.zip
consul_*.zip.*
.vscode/
.flattened-pom.xml

.sdkmanrc
Expand Up @@ -23,6 +23,7 @@
import javax.validation.constraints.DecimalMin;

import org.apache.commons.logging.Log;
import org.joda.time.Period;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.convert.DurationUnit;
Expand Down Expand Up @@ -52,9 +53,10 @@ public class HeartbeatProperties {
@DecimalMax("0.9")
private double intervalRatio = 2.0 / 3.0;

// TODO: did heartbeatInterval need to be a field?

protected Duration computeHearbeatInterval() {
/**
* @return the computed heartbeat interval
*/
protected Duration computeHeartbeatInterval() {
// heartbeat rate at ratio * ttl, but no later than ttl -1s and, (under lesser
// priority), no sooner than 1s from now
double interval = this.ttl.getSeconds() * this.intervalRatio;
Expand Down
Expand Up @@ -64,7 +64,7 @@ public void add(final NewService service) {
public void add(String instanceId) {
ScheduledFuture task = this.scheduler.scheduleAtFixedRate(
new ConsulHeartbeatTask(instanceId),
this.configuration.computeHearbeatInterval().toMillis());
this.configuration.computeHeartbeatInterval().toMillis());
ScheduledFuture previousTask = this.serviceHeartbeats.put(instanceId, task);
if (previousTask != null) {
previousTask.cancel(true);
Expand Down
Expand Up @@ -31,7 +31,7 @@ public class HeartbeatPropertiesTests {
@Test
public void computeHeartbeatIntervalWorks() {
HeartbeatProperties properties = new HeartbeatProperties();
Duration period = properties.computeHearbeatInterval();
Duration period = properties.computeHeartbeatInterval();

assertThat(period).isNotNull();
assertThat(period.get(ChronoUnit.SECONDS)).isEqualTo(20);
Expand All @@ -41,7 +41,7 @@ public void computeHeartbeatIntervalWorks() {
public void computeShortHeartbeat() {
HeartbeatProperties properties = new HeartbeatProperties();
properties.setTtl(Duration.ofSeconds(2));
Duration period = properties.computeHearbeatInterval();
Duration period = properties.computeHeartbeatInterval();

assertThat(period).isNotNull();
assertThat(period.get(ChronoUnit.SECONDS)).isEqualTo(1);
Expand Down

0 comments on commit 21b5f90

Please sign in to comment.