-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add ConfigurationResolver * refactor test * remove tests * update README * add system-lambda for testing * refactoring * refactor ConnectionManager
- Loading branch information
Showing
7 changed files
with
134 additions
and
28 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
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
31 changes: 31 additions & 0 deletions
31
src/main/java/rocks/inspectit/gepard/agent/config/ConfigurationResolver.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,31 @@ | ||
package rocks.inspectit.gepard.agent.config; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* This resolver provides the configured configuration server url. Currently, it is possible to | ||
* configure the url via system properties or environmental properties. System properties are higher | ||
* prioritized than environmental properties. | ||
*/ | ||
public class ConfigurationResolver { | ||
|
||
private static final String SERVER_URL_SYSTEM_PROPERTY = "inspectit.config.http.url"; | ||
|
||
private static final String SERVER_URL_ENV_PROPERTY = "INSPECTIT_CONFIG_HTTP_URL"; | ||
|
||
private ConfigurationResolver() {} | ||
|
||
/** | ||
* Get the configured configuration server url. If no url was configured, an empty string will be | ||
* returned. | ||
* | ||
* @return the configured configuration server url | ||
*/ | ||
public static String getServerUrl() { | ||
String serverUrlSystemProperty = System.getProperty(SERVER_URL_SYSTEM_PROPERTY); | ||
if (Objects.nonNull(serverUrlSystemProperty)) return serverUrlSystemProperty; | ||
|
||
String serverUrlEnvProperty = System.getenv(SERVER_URL_ENV_PROPERTY); | ||
return Objects.nonNull(serverUrlEnvProperty) ? serverUrlEnvProperty : ""; | ||
} | ||
} |
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
10 changes: 4 additions & 6 deletions
10
...java/rocks/inspectit/gepard/agent/notify/http/exception/ClientConfigurationException.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 |
---|---|---|
@@ -1,11 +1,9 @@ | ||
package rocks.inspectit.gepard.agent.notify.http.exception; | ||
|
||
/** | ||
* Exception, for errors in the configuration of the HTTP client | ||
*/ | ||
/** Exception, for errors in the configuration of the HTTP client */ | ||
public class ClientConfigurationException extends RuntimeException { | ||
|
||
public ClientConfigurationException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
public ClientConfigurationException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/test/java/rocks/inspectit/gepard/agent/config/ConfigurationResolverTest.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,60 @@ | ||
package rocks.inspectit.gepard.agent.config; | ||
|
||
import static com.github.stefanbirkner.systemlambda.SystemLambda.restoreSystemProperties; | ||
import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class ConfigurationResolverTest { | ||
|
||
private static final String SERVER_URL_SYSTEM_PROPERTY = "inspectit.config.http.url"; | ||
|
||
private static final String SERVER_URL_ENV_PROPERTY = "INSPECTIT_CONFIG_HTTP_URL"; | ||
|
||
private static final String TEST_URL = "https://inspectit.rocks/"; | ||
|
||
@Test | ||
void resolverReturnsUrlIfSystemPropertyExists() throws Exception { | ||
restoreSystemProperties( | ||
() -> { | ||
System.setProperty(SERVER_URL_SYSTEM_PROPERTY, TEST_URL); | ||
|
||
String url = ConfigurationResolver.getServerUrl(); | ||
|
||
assertEquals(TEST_URL, url); | ||
}); | ||
} | ||
|
||
@Test | ||
void resolverReturnsUrlIfEnvironmentPropertyExists() throws Exception { | ||
String url = | ||
withEnvironmentVariable(SERVER_URL_ENV_PROPERTY, TEST_URL) | ||
.execute(ConfigurationResolver::getServerUrl); | ||
|
||
assertEquals(TEST_URL, url); | ||
} | ||
|
||
@Test | ||
void resolverReturnsSystemPropertyIfSystemAndEnvPropertyExist() throws Exception { | ||
String envTestUrl = TEST_URL + "1"; | ||
restoreSystemProperties( | ||
() -> { | ||
System.setProperty(SERVER_URL_SYSTEM_PROPERTY, TEST_URL); | ||
|
||
String url = | ||
withEnvironmentVariable(SERVER_URL_ENV_PROPERTY, envTestUrl) | ||
.execute(ConfigurationResolver::getServerUrl); | ||
|
||
assertEquals(TEST_URL, url); | ||
}); | ||
} | ||
|
||
@Test | ||
void resolverReturnsEmptyStringIfNoPropertyExists() { | ||
String url = ConfigurationResolver.getServerUrl(); | ||
|
||
assertTrue(url.isEmpty()); | ||
} | ||
} |