Skip to content

Commit

Permalink
refactor!: remove backward compatibility for durations - message-brok…
Browse files Browse the repository at this point in the history
…er-nats
  • Loading branch information
mattnichols committed Mar 17, 2023
1 parent 287cfbe commit b77a678
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 52 deletions.
2 changes: 1 addition & 1 deletion message-broker-nats/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
coppuccino {
coverage {
minimumCoverage = 0.87
minimumCoverage = 0.86
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import java.time.Duration;

import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;

import com.mx.common.configuration.ConfigurationField;

Expand All @@ -13,7 +11,7 @@ public class NatsConfiguration {
private static final int DEFAULT_DISPATCHER_COUNT = 1;
private static final boolean DEFAULT_ENABLED = true;
private static final String DEFAULT_SERVERS = "nats://127.0.0.1:4222";
private static final int DEFAULT_TIMEOUT_IN_MILLISECONDS = 10000;
private static final Duration DEFAULT_TIMEOUT = Duration.ofMillis(10000);
private static final String DEFAULT_TLS_CA_CERT_PATH = null;
private static final String DEFAULT_TLS_CLIENT_CERT_PATH = null;
private static final String DEFAULT_TLS_CLIENT_KEY_PATH = null;
Expand All @@ -28,16 +26,8 @@ public class NatsConfiguration {
@ConfigurationField(required = true, placeholder = "nats://127.0.0.1:4222")
private String servers = DEFAULT_SERVERS;

/**
* @deprecated use timeout
*/
@Deprecated
@ConfigurationField
@Getter(AccessLevel.PRIVATE)
private Integer timeoutInMilliseconds = null;

@ConfigurationField
private Duration timeout = null;
private Duration timeout = DEFAULT_TIMEOUT;

@ConfigurationField
private String tlsCaCertPath = DEFAULT_TLS_CA_CERT_PATH;
Expand All @@ -50,20 +40,4 @@ public class NatsConfiguration {

@ConfigurationField
private boolean tlsDisabled = DEFAULT_TLS_DISABLED;

/**
* Maintain backward compatibility. Remove with timeoutInMilliseconds
* @return timeout as a Duration
*/
public final Duration getTimeout() {
if (timeout == null) {
if (timeoutInMilliseconds != null) {
timeout = Duration.ofMillis(timeoutInMilliseconds);
} else {
timeout = Duration.ofMillis(DEFAULT_TIMEOUT_IN_MILLISECONDS);
}
}

return timeout;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ class NatsConfigurationTest extends Specification {
def subject = new NatsConfiguration()

when:
subject.setTimeoutInMilliseconds(201)

then: "uses timeoutInMilliseconds"
subject.getTimeout() == Duration.ofMillis(201)

when:
subject.setTimeoutInMilliseconds(null)
subject.setTimeout(Duration.ofSeconds(2))

then: "uses timeout"
Expand Down Expand Up @@ -52,22 +45,6 @@ class NatsConfigurationTest extends Specification {

when:
configurations.tap {
put("timeoutInMilliseconds", 4000)
}

result = binder.build(NatsConfiguration, configurations)

then:
verifyAll(result) {
it.isEnabled()
it.getServers() == "nats://127.0.0.1:4223"
it.getDispatcherCount() == 9
it.getTimeout() == Duration.ofSeconds(4) // uses timeoutInMilliseconds
}

when:
configurations.tap {
remove("timeoutInMilliseconds")
put("timeout", "11s")
}

Expand Down

0 comments on commit b77a678

Please sign in to comment.