Merge branch '2.2.x'
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -18,4 +18,4 @@ consul_*.zip
|
||||
consul_*.zip.*
|
||||
.vscode/
|
||||
.flattened-pom.xml
|
||||
|
||||
.sdkmanrc
|
||||
|
||||
@@ -23,6 +23,7 @@ import javax.validation.constraints.DecimalMax;
|
||||
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;
|
||||
@@ -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;
|
||||
|
||||
@@ -64,7 +64,7 @@ public class TtlScheduler {
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
@@ -41,7 +41,7 @@ public class HeartbeatPropertiesTests {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user