Skip to content

Commit f7c5148

Browse files
authored
Fixing noRemoteServers wasn't being respected at the JSON file #513 (#515)
* bug and test fixed * fixing one more test * release notes * [Gradle Release Plugin] - new version commit: '3.24.1-snapshot'.
1 parent 5321bd1 commit f7c5148

File tree

9 files changed

+82
-9
lines changed

9 files changed

+82
-9
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.24.1
2+
* Fixing `noRemoteServers` wasn't being respected at the JSON file #513
3+
14
## 3.24.0
25
* Downgraded necessary libc version to run aarch binary to 2.28 #507
36

gradle.properties

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

src/main/java/com/mageddo/dnsproxyserver/config/dataprovider/mapper/ConfigJsonV2Mapper.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import com.mageddo.dnsproxyserver.config.Config;
55
import com.mageddo.dnsproxyserver.config.SolverRemote;
66
import com.mageddo.dnsproxyserver.config.dataprovider.vo.ConfigJson;
7+
import com.mageddo.dnsproxyserver.config.dataprovider.vo.ConfigJsonV2;
78
import com.mageddo.dnsproxyserver.utils.Booleans;
9+
import org.apache.commons.lang3.ObjectUtils;
810

911
import java.nio.file.Path;
1012

@@ -34,14 +36,30 @@ public static Config toConfig(ConfigJson json, Path configFileAbsolutePath) {
3436
}
3537

3638
static SolverRemote toSolverRemote(ConfigJson json) {
37-
final var solverRemote = json.getSolverRemote();
38-
if (solverRemote == null) {
39-
return null;
40-
}
41-
final var circuitBreaker = solverRemote.getCircuitBreaker();
42-
if (circuitBreaker == null) {
39+
if(nothingIsSet(json)){
4340
return null;
41+
} else if (isPossibleToBuildComplete(json)) {
42+
return buildCompleteSolverRemote(json, json.getSolverRemoteCircuitBreaker());
4443
}
44+
return buildSimpleSolverRemote(json);
45+
}
46+
47+
static boolean nothingIsSet(ConfigJson json) {
48+
return ObjectUtils.allNull(json.getNoRemoteServers(), json.getSolverRemote(), json.getSolverRemoteCircuitBreaker());
49+
}
50+
51+
static boolean isPossibleToBuildComplete(ConfigJson json) {
52+
return ObjectUtils.allNotNull(json.getSolverRemote(), json.getSolverRemoteCircuitBreaker());
53+
}
54+
55+
static SolverRemote buildSimpleSolverRemote(ConfigJson json) {
56+
return SolverRemote
57+
.builder()
58+
.active(Booleans.reverseWhenNotNull(json.getNoRemoteServers()))
59+
.build();
60+
}
61+
62+
static SolverRemote buildCompleteSolverRemote(ConfigJson json, ConfigJsonV2.CircuitBreaker circuitBreaker) {
4563
return SolverRemote
4664
.builder()
4765
.active(Booleans.reverseWhenNotNull(json.getNoRemoteServers()))

src/main/java/com/mageddo/dnsproxyserver/config/dataprovider/vo/ConfigJson.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,6 @@ public interface ConfigJson {
4949

5050
ConfigJsonV2.SolverRemote getSolverRemote();
5151

52+
ConfigJsonV2.CircuitBreaker getSolverRemoteCircuitBreaker();
53+
5254
}

src/main/java/com/mageddo/dnsproxyserver/config/dataprovider/vo/ConfigJsonV1.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ public ConfigJsonV2.SolverRemote getSolverRemote() {
113113
return null;
114114
}
115115

116+
@Override
117+
public ConfigJsonV2.CircuitBreaker getSolverRemoteCircuitBreaker() {
118+
return null;
119+
}
120+
116121
public ConfigJsonV2 toConfigV2() {
117122
return new ConfigJsonV2()
118123
.setDomain(this.getDomain())

src/main/java/com/mageddo/dnsproxyserver/config/dataprovider/vo/ConfigJsonV2.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ public Boolean getDockerSolverHostMachineFallbackActive() {
8888
return this.dockerSolverHostMachineFallbackActive;
8989
}
9090

91+
@JsonIgnore
92+
@Override
93+
public CircuitBreaker getSolverRemoteCircuitBreaker() {
94+
if (this.solverRemote != null) {
95+
return this.solverRemote.circuitBreaker;
96+
}
97+
return null;
98+
}
99+
91100
@Data
92101
@Accessors(chain = true)
93102
public static class Env {

src/test/java/com/mageddo/dnsproxyserver/config/dataprovider/mapper/ConfigJsonV2MapperTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import com.mageddo.dnsproxyserver.config.Config;
44
import com.mageddo.dnsproxyserver.config.dataprovider.vo.ConfigJson;
5-
import org.junit.jupiter.api.Disabled;
65
import org.junit.jupiter.api.Test;
76
import testing.templates.ConfigJsonTemplates;
87

98
import java.nio.file.Path;
109
import java.nio.file.Paths;
1110

1211
import static org.junit.jupiter.api.Assertions.assertFalse;
12+
import static org.junit.jupiter.api.Assertions.assertNull;
1313

1414
class ConfigJsonV2MapperTest {
1515

@@ -28,7 +28,6 @@ void mustMapSolverRemoteAsInactiveWhenNoRemoteServersFlagIsSet(){
2828
}
2929

3030
@Test
31-
@Disabled("by the bug reported at #513")
3231
void mustMapSolverRemoteAsInactiveEvenWhenCircuitBreakerIsNOTSet(){
3332
// arrange
3433
final var configJson = ConfigJsonTemplates.withoutCircuitBreakerDefinedWithNoRemoteServers();
@@ -40,6 +39,18 @@ void mustMapSolverRemoteAsInactiveEvenWhenCircuitBreakerIsNOTSet(){
4039
assertFalse(config.isSolverRemoteActive());
4140
}
4241

42+
@Test
43+
void mustReturnNullWhenNothingIsSet(){
44+
// arrange
45+
final var configJson = ConfigJsonTemplates.noRemoteServerFlagsSet();
46+
47+
// act
48+
final var config = toConfig(configJson);
49+
50+
// assert
51+
assertNull(config.getSolverRemote());
52+
}
53+
4354
static Config toConfig(ConfigJson configJson) {
4455
return ConfigJsonV2Mapper.toConfig(configJson, RANDOM_CONFIG_PATH);
4556
}

src/test/java/testing/templates/ConfigJsonTemplates.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@ public static ConfigJson withoutCircuitBreakerDefinedWithNoRemoteServers() {
1515
final var path = "/configs-test/007.json";
1616
return JsonConfigs.loadConfig(TestUtils.readString(path));
1717
}
18+
19+
public static ConfigJson noRemoteServerFlagsSet() {
20+
final var path = "/configs-test/008.json";
21+
return JsonConfigs.loadConfig(TestUtils.readString(path));
22+
}
23+
1824
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version" : 2,
3+
"activeEnv" : "MARROI",
4+
"remoteDnsServers" : [ ],
5+
"envs" : [ {
6+
"name" : "MARROI",
7+
"hostnames" : null
8+
} ],
9+
"webServerPort" : 9393,
10+
"dnsServerPort" : 5391,
11+
"defaultDns" : false,
12+
"logLevel" : "DEBUG",
13+
"logFile" : "true",
14+
"registerContainerNames" : true,
15+
"hostMachineHostname" : "batata.com",
16+
"domain" : "acme",
17+
"dpsNetwork" : true,
18+
"dpsNetworkAutoConnect" : true
19+
}

0 commit comments

Comments
 (0)