Deprecates joda time usage

Fixes gh-612
This commit is contained in:
spencergibb
2020-05-22 15:09:30 -04:00
parent 7944de7c68
commit e70cc1e82f
3 changed files with 13 additions and 5 deletions

View File

@@ -54,8 +54,11 @@ public class HeartbeatProperties {
@DecimalMax("0.9")
private double intervalRatio = 2.0 / 3.0;
// TODO: did heartbeatInterval need to be a field?
/**
* @deprecated the joda time {@link Period} will be replaced with java8 duration.
* @return the computed heartbeat interval
*/
@Deprecated
protected Period computeHearbeatInterval() {
// heartbeat rate at ratio * ttl, but no later than ttl -1s and, (under lesser
// priority), no sooner than 1s from now
@@ -68,6 +71,11 @@ public class HeartbeatProperties {
return heartbeatInterval;
}
@Deprecated
protected Period computeHeartbeatInterval() {
return computeHearbeatInterval();
}
public String getTtl() {
return this.ttlValue + this.ttlUnit;
}

View File

@@ -64,7 +64,7 @@ public class TtlScheduler {
public void add(String instanceId) {
ScheduledFuture task = this.scheduler.scheduleAtFixedRate(
new ConsulHeartbeatTask(instanceId), this.configuration
.computeHearbeatInterval().toStandardDuration().getMillis());
.computeHeartbeatInterval().toStandardDuration().getMillis());
ScheduledFuture previousTask = this.serviceHeartbeats.put(instanceId, task);
if (previousTask != null) {
previousTask.cancel(true);

View File

@@ -29,7 +29,7 @@ public class HeartbeatPropertiesTests {
@Test
public void computeHeartbeatIntervalWorks() {
HeartbeatProperties properties = new HeartbeatProperties();
Period period = properties.computeHearbeatInterval();
Period period = properties.computeHeartbeatInterval();
assertThat(period).isNotNull();
assertThat(period.getSeconds()).isEqualTo(20);
@@ -39,7 +39,7 @@ public class HeartbeatPropertiesTests {
public void computeShortHeartbeat() {
HeartbeatProperties properties = new HeartbeatProperties();
properties.setTtlValue(2);
Period period = properties.computeHearbeatInterval();
Period period = properties.computeHeartbeatInterval();
assertThat(period).isNotNull();
assertThat(period.getSeconds()).isEqualTo(1);