Skip to content

Commit 6db82f5

Browse files
authored
Fixing SolverRemote NPE #533 (#556)
* Fixing SolverRemote NPE #533 * creating test
1 parent 1b8cf1c commit 6db82f5

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

RELEASE-NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 3.25.14
2+
* Fixing SolverRemote NPE #533
3+
14
## 3.25.13
25
* Unifying circuit breaker abstractions #553
36

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=3.25.13-snapshot
1+
version=3.25.14-snapshot

src/main/java/com/mageddo/dnsproxyserver/solver/remote/application/failsafe/CircuitBreakerFactory.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,23 @@ public List<Stats> stats() {
9999
}
100100

101101
public CircuitStatus findStatus(InetSocketAddress remoteAddress) {
102-
return this.circuitBreakerMap.get(remoteAddress)
103-
.findStatus();
102+
final var circuitBreaker = this.findCircuitBreakerFromCache(remoteAddress);
103+
if (circuitBreaker == null) {
104+
return null;
105+
}
106+
return circuitBreaker.findStatus();
104107
}
105108

106109
private Stats toStats(InetSocketAddress remoteAddr) {
107-
final var circuitBreaker = this.circuitBreakerMap.get(remoteAddr);
110+
final var circuitBreaker = this.findCircuitBreakerFromCache(remoteAddr);
108111
final var state = circuitBreaker.findStatus().name();
109112
return Stats.of(remoteAddr.toString(), state);
110113
}
111114

115+
private CircuitBreakerDelegate findCircuitBreakerFromCache(InetSocketAddress remoteAddress) {
116+
return this.circuitBreakerMap.get(remoteAddress);
117+
}
118+
112119
@Value
113120
public static class Stats {
114121

src/test/java/com/mageddo/dnsproxyserver/solver/remote/application/failsafe/CircuitBreakerFactoryTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import static org.junit.jupiter.api.Assertions.assertEquals;
1616
import static org.junit.jupiter.api.Assertions.assertNotEquals;
17+
import static org.junit.jupiter.api.Assertions.assertNull;
1718
import static org.mockito.ArgumentMatchers.any;
1819
import static org.mockito.Mockito.doReturn;
1920
import static org.mockito.Mockito.mock;
@@ -130,4 +131,14 @@ void mustBuildNonResilientCircuitBreaker(){
130131

131132
}
132133

134+
@Test
135+
void mustReturnNullWhenNoStatusIsFound(){
136+
137+
final var addr = InetSocketAddressTemplates._8_8_8_8();
138+
139+
final var status = this.factory.findStatus(addr);
140+
141+
assertNull(status);
142+
}
143+
133144
}

0 commit comments

Comments
 (0)