-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* testing no remote sovlers * written failing test which found the bug * test was wrong, feature is working * extracting to specific class * refactoring * created tests
- Loading branch information
Showing
10 changed files
with
272 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/com/mageddo/dnsproxyserver/config/dataprovider/mapper/ConfigJsonV2Mapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.mageddo.dnsproxyserver.config.dataprovider.mapper; | ||
|
||
import com.mageddo.dnsproxyserver.config.CircuitBreaker; | ||
import com.mageddo.dnsproxyserver.config.Config; | ||
import com.mageddo.dnsproxyserver.config.SolverRemote; | ||
import com.mageddo.dnsproxyserver.config.dataprovider.vo.ConfigJson; | ||
import com.mageddo.dnsproxyserver.utils.Booleans; | ||
|
||
import java.nio.file.Path; | ||
|
||
public class ConfigJsonV2Mapper { | ||
|
||
public static Config toConfig(ConfigJson json, Path configFileAbsolutePath) { | ||
return Config.builder() | ||
.webServerPort(json.getWebServerPort()) | ||
.dnsServerPort(json.getDnsServerPort()) | ||
.defaultDns(json.getDefaultDns()) | ||
.logLevel(ConfigFieldsValuesMapper.mapLogLevelFrom(json.getLogLevel())) | ||
.logFile(ConfigFieldsValuesMapper.mapLogFileFrom(json.getLogFile())) | ||
.registerContainerNames(json.getRegisterContainerNames()) | ||
.hostMachineHostname(json.getHostMachineHostname()) | ||
.domain(json.getDomain()) | ||
.mustConfigureDpsNetwork(json.getDpsNetwork()) | ||
.dpsNetworkAutoConnect(json.getDpsNetworkAutoConnect()) | ||
.remoteDnsServers(json.getRemoteDnsServers()) | ||
.serverProtocol(json.getServerProtocol()) | ||
.dockerHost(json.getDockerHost()) | ||
.resolvConfOverrideNameServers(json.getResolvConfOverrideNameServers()) | ||
.noEntriesResponseCode(json.getNoEntriesResponseCode()) | ||
.dockerSolverHostMachineFallbackActive(json.getDockerSolverHostMachineFallbackActive()) | ||
.configPath(configFileAbsolutePath) | ||
.solverRemote(toSolverRemote(json)) | ||
.build(); | ||
} | ||
|
||
static SolverRemote toSolverRemote(ConfigJson json) { | ||
final var solverRemote = json.getSolverRemote(); | ||
if (solverRemote == null) { | ||
return null; | ||
} | ||
final var circuitBreaker = solverRemote.getCircuitBreaker(); | ||
if (circuitBreaker == null) { | ||
return null; | ||
} | ||
return SolverRemote | ||
.builder() | ||
.active(Booleans.reverseWhenNotNull(json.getNoRemoteServers())) | ||
.circuitBreaker(CircuitBreaker | ||
.builder() | ||
.failureThreshold(circuitBreaker.getFailureThreshold()) | ||
.failureThresholdCapacity(circuitBreaker.getFailureThresholdCapacity()) | ||
.successThreshold(circuitBreaker.getSuccessThreshold()) | ||
.testDelay(circuitBreaker.getTestDelay()) | ||
.build() | ||
) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...st/java/com/mageddo/dnsproxyserver/config/dataprovider/mapper/ConfigJsonV2MapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.mageddo.dnsproxyserver.config.dataprovider.mapper; | ||
|
||
import com.mageddo.dnsproxyserver.config.Config; | ||
import com.mageddo.dnsproxyserver.config.dataprovider.vo.ConfigJson; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
import testing.templates.ConfigJsonTemplates; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
class ConfigJsonV2MapperTest { | ||
|
||
static final Path RANDOM_CONFIG_PATH = Paths.get("/tmp/conf.json"); | ||
|
||
@Test | ||
void mustMapSolverRemoteAsInactiveWhenNoRemoteServersFlagIsSet(){ | ||
// arrange | ||
final var configJson = ConfigJsonTemplates.withNoRemoteServersAndCircuitBreakerDefined(); | ||
|
||
// act | ||
final var config = toConfig(configJson); | ||
|
||
// assert | ||
assertFalse(config.isSolverRemoteActive()); | ||
} | ||
|
||
@Test | ||
@Disabled("by the bug reported at #513") | ||
void mustMapSolverRemoteAsInactiveEvenWhenCircuitBreakerIsNOTSet(){ | ||
// arrange | ||
final var configJson = ConfigJsonTemplates.withoutCircuitBreakerDefinedWithNoRemoteServers(); | ||
|
||
// act | ||
final var config = toConfig(configJson); | ||
|
||
// assert | ||
assertFalse(config.isSolverRemoteActive()); | ||
} | ||
|
||
static Config toConfig(ConfigJson configJson) { | ||
return ConfigJsonV2Mapper.toConfig(configJson, RANDOM_CONFIG_PATH); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package testing.templates; | ||
|
||
import com.mageddo.dnsproxyserver.config.dataprovider.JsonConfigs; | ||
import com.mageddo.dnsproxyserver.config.dataprovider.vo.ConfigJson; | ||
import com.mageddo.utils.TestUtils; | ||
|
||
public class ConfigJsonTemplates { | ||
|
||
public static ConfigJson withNoRemoteServersAndCircuitBreakerDefined() { | ||
final var path = "/configs-test/005.json"; | ||
return JsonConfigs.loadConfig(TestUtils.readString(path)); | ||
} | ||
|
||
public static ConfigJson withoutCircuitBreakerDefinedWithNoRemoteServers() { | ||
final var path = "/configs-test/007.json"; | ||
return JsonConfigs.loadConfig(TestUtils.readString(path)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"version" : 2, | ||
"activeEnv" : "MARROI", | ||
"remoteDnsServers" : [ ], | ||
"envs" : [ { | ||
"name" : "MARROI", | ||
"hostnames" : null | ||
} ], | ||
"webServerPort" : 9393, | ||
"dnsServerPort" : 5391, | ||
"defaultDns" : false, | ||
"logLevel" : "DEBUG", | ||
"logFile" : "true", | ||
"registerContainerNames" : true, | ||
"hostMachineHostname" : "batata.com", | ||
"domain" : "acme", | ||
"dpsNetwork" : true, | ||
"dpsNetworkAutoConnect" : true, | ||
"noRemoteServers": true, | ||
"solverRemote" : { | ||
"circuitBreaker" : { | ||
"failureThreshold" : 3, | ||
"failureThresholdCapacity" : 10, | ||
"successThreshold" : 5, | ||
"testDelay" : "PT1M" | ||
} | ||
} | ||
} |
Oops, something went wrong.