diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/HintRequestContext.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/HintRequestContext.java index ac3bec5e..0ef6b1cc 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/HintRequestContext.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/HintRequestContext.java @@ -16,6 +16,8 @@ package org.springframework.cloud.client.loadbalancer; +import java.util.Objects; + import org.springframework.core.style.ToStringCreator; /** @@ -53,4 +55,21 @@ public class HintRequestContext { return to.toString(); } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof HintRequestContext)) { + return false; + } + HintRequestContext that = (HintRequestContext) o; + return Objects.equals(hint, that.hint); + } + + @Override + public int hashCode() { + return Objects.hash(hint); + } + } diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/RetryableRequestContext.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/RetryableRequestContext.java index 20595fa2..ef8b32ec 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/RetryableRequestContext.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/RetryableRequestContext.java @@ -16,7 +16,10 @@ package org.springframework.cloud.client.loadbalancer; +import java.util.Objects; + import org.springframework.cloud.client.ServiceInstance; +import org.springframework.core.style.ToStringCreator; /** * A request context object that allows storing information on previously used service @@ -46,4 +49,31 @@ public class RetryableRequestContext extends DefaultRequestContext { return previousServiceInstance; } + @Override + public String toString() { + ToStringCreator to = new ToStringCreator(this); + to.append("previousServiceInstance", previousServiceInstance); + return to.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof RetryableRequestContext)) { + return false; + } + if (!super.equals(o)) { + return false; + } + RetryableRequestContext context = (RetryableRequestContext) o; + return Objects.equals(previousServiceInstance, context.previousServiceInstance); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), previousServiceInstance); + } + }