From c64cf3757cd32d2ba9ad574dc96c66359e70bffb Mon Sep 17 00:00:00 2001 From: Jaya Gupta Date: Tue, 2 May 2023 16:05:27 +0530 Subject: [PATCH 1/9] load config from System Properties if present --- .../metrics/jinsight/ConfigService.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java b/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java index 64a9d89..cfdf79a 100644 --- a/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java +++ b/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java @@ -184,9 +184,36 @@ private static Properties loadProperties(File configFilePath) throws IOException try (InputStream inputStream = new BufferedInputStream(new FileInputStream(configFilePath))) { config.load(inputStream); } + // override with system properties, if present + config.putAll(loadSystemProperties()); return config; } + private static Map loadSystemProperties() { + Map systemProperties = new HashMap<>(); + String reporter = System.getProperty(REPORTER_PROPERTY_NAME); + if(reporter != null && !reporter.equals("")){ + systemProperties.put(REPORTER_PROPERTY_NAME, reporter); + } + + String accessToken = System.getProperty(ACCESS_TOKEN_PROPERTY_NAME); + if(accessToken != null && !accessToken.equals("")){ + systemProperties.put(ACCESS_TOKEN_PROPERTY_NAME, accessToken); + } + + String apiEndpoint = System.getProperty(API_ENDPOINT_PROPERTY_NAME); + if(apiEndpoint != null && !apiEndpoint.equals("")){ + systemProperties.put(API_ENDPOINT_PROPERTY_NAME, apiEndpoint); + } + + String globalTags = System.getProperty(GLOBAL_TAGS_PROPERTY_NAME); + if(globalTags != null && !globalTags.equals("")){ + systemProperties.put(GLOBAL_TAGS_PROPERTY_NAME, globalTags); + } + + return systemProperties; + } + private Sanitizer readSanitizer(Properties config) { String configSanitizer = config.getProperty("apptuit.sanitizer"); if (configSanitizer != null && !configSanitizer.equals("")) { From b18cf494201054b488d0ebbc545630d76de56e4c Mon Sep 17 00:00:00 2001 From: Jaya Gupta Date: Tue, 2 May 2023 16:30:37 +0530 Subject: [PATCH 2/9] read from system environment and then system property --- .../apptuit/metrics/jinsight/ConfigService.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java b/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java index cfdf79a..f47e93f 100644 --- a/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java +++ b/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java @@ -191,22 +191,22 @@ private static Properties loadProperties(File configFilePath) throws IOException private static Map loadSystemProperties() { Map systemProperties = new HashMap<>(); - String reporter = System.getProperty(REPORTER_PROPERTY_NAME); + String reporter = getProperty(REPORTER_PROPERTY_NAME); if(reporter != null && !reporter.equals("")){ systemProperties.put(REPORTER_PROPERTY_NAME, reporter); } - String accessToken = System.getProperty(ACCESS_TOKEN_PROPERTY_NAME); + String accessToken = getProperty(ACCESS_TOKEN_PROPERTY_NAME); if(accessToken != null && !accessToken.equals("")){ systemProperties.put(ACCESS_TOKEN_PROPERTY_NAME, accessToken); } - String apiEndpoint = System.getProperty(API_ENDPOINT_PROPERTY_NAME); + String apiEndpoint = getProperty(API_ENDPOINT_PROPERTY_NAME); if(apiEndpoint != null && !apiEndpoint.equals("")){ systemProperties.put(API_ENDPOINT_PROPERTY_NAME, apiEndpoint); } - String globalTags = System.getProperty(GLOBAL_TAGS_PROPERTY_NAME); + String globalTags = getProperty(GLOBAL_TAGS_PROPERTY_NAME); if(globalTags != null && !globalTags.equals("")){ systemProperties.put(GLOBAL_TAGS_PROPERTY_NAME, globalTags); } @@ -214,6 +214,14 @@ private static Map loadSystemProperties() { return systemProperties; } + private static String getProperty(String propertyName) { + String propertyValue = System.getenv(propertyName); + if(propertyValue == null || propertyValue.equals("")){ + propertyValue = System.getProperty(propertyName); + } + return propertyValue; + } + private Sanitizer readSanitizer(Properties config) { String configSanitizer = config.getProperty("apptuit.sanitizer"); if (configSanitizer != null && !configSanitizer.equals("")) { From 63de39bba5c049bb986aab6f67ffb3b8c6eeb8b6 Mon Sep 17 00:00:00 2001 From: Jaya Gupta Date: Tue, 2 May 2023 16:40:50 +0530 Subject: [PATCH 3/9] added unit test --- .../ai/apptuit/metrics/jinsight/ConfigServiceTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java b/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java index 6b1f1dc..0ccc743 100644 --- a/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java +++ b/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java @@ -315,6 +315,13 @@ public void testAgentVersion() throws Exception { assertEquals(System.getProperty("project.version"), cs.getAgentVersion()); } + @Test + public void testGetReporterFromSystemProperty() throws Exception { + System.setProperty("reporter", "APPTUIT"); + ReporterType reporterType = ConfigService.getInstance().getReporterType(); + assertEquals(ReporterType.APPTUIT, reporterType); + } + private Properties getDefaultConfigProperties() { return new Properties(); } From a8c5c484ce4d88a3ebb3e20867a9239044a96b5f Mon Sep 17 00:00:00 2001 From: Jaya Gupta Date: Wed, 3 May 2023 13:32:50 +0530 Subject: [PATCH 4/9] code and test refactoring --- .../metrics/jinsight/ConfigService.java | 22 +++++++++++-------- .../metrics/jinsight/ConfigServiceTest.java | 8 +++---- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java b/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java index f47e93f..9c0eaf1 100644 --- a/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java +++ b/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java @@ -50,14 +50,18 @@ public class ConfigService { public static final String REPORTING_FREQ_PROPERTY_NAME = "reporting_frequency"; private static final String GLOBAL_TAGS_PROPERTY_NAME = "global_tags"; + private static final String GLOBAL_TAGS_SYSTEM_PROPERTY_NAME = "jinsight.global_tags"; public static final String REPORTER_PROPERTY_NAME = "reporter"; + public static final String REPORTER_SYSTEM_PROPERTY_NAME = "jinsight.reporter"; public static final String PROMETHEUS_EXPORTER_PORT = "prometheus.exporter_port"; public static final String PROMETHEUS_METRICS_PATH = "prometheus.exporter_endpoint"; public static final String REPORTING_MODE_PROPERTY_NAME = "apptuit.reporting_mode"; private static final String ACCESS_TOKEN_PROPERTY_NAME = "apptuit.access_token"; + private static final String ACCESS_TOKEN_SYSTEM_PROPERTY_NAME = "jinsight.apptuit.access_token"; private static final String API_ENDPOINT_PROPERTY_NAME = "apptuit.api_url"; + private static final String API_ENDPOINT_SYSTEM_PROPERTY_NAME = "jinsight.apptuit.api_url"; private static final String HOST_TAG_NAME = "host"; private static final String UUID_TEMPLATE_VARIABLE = "${UUID}"; @@ -191,23 +195,23 @@ private static Properties loadProperties(File configFilePath) throws IOException private static Map loadSystemProperties() { Map systemProperties = new HashMap<>(); - String reporter = getProperty(REPORTER_PROPERTY_NAME); - if(reporter != null && !reporter.equals("")){ + String reporter = getProperty(REPORTER_SYSTEM_PROPERTY_NAME); + if(reporter != null){ systemProperties.put(REPORTER_PROPERTY_NAME, reporter); } - String accessToken = getProperty(ACCESS_TOKEN_PROPERTY_NAME); - if(accessToken != null && !accessToken.equals("")){ + String accessToken = getProperty(ACCESS_TOKEN_SYSTEM_PROPERTY_NAME); + if(accessToken != null){ systemProperties.put(ACCESS_TOKEN_PROPERTY_NAME, accessToken); } - String apiEndpoint = getProperty(API_ENDPOINT_PROPERTY_NAME); - if(apiEndpoint != null && !apiEndpoint.equals("")){ + String apiEndpoint = getProperty(API_ENDPOINT_SYSTEM_PROPERTY_NAME); + if(apiEndpoint != null){ systemProperties.put(API_ENDPOINT_PROPERTY_NAME, apiEndpoint); } - String globalTags = getProperty(GLOBAL_TAGS_PROPERTY_NAME); - if(globalTags != null && !globalTags.equals("")){ + String globalTags = getProperty(GLOBAL_TAGS_SYSTEM_PROPERTY_NAME); + if(globalTags != null){ systemProperties.put(GLOBAL_TAGS_PROPERTY_NAME, globalTags); } @@ -219,7 +223,7 @@ private static String getProperty(String propertyName) { if(propertyValue == null || propertyValue.equals("")){ propertyValue = System.getProperty(propertyName); } - return propertyValue; + return propertyValue != null && !propertyValue.equals("") ? propertyValue : null; } private Sanitizer readSanitizer(Properties config) { diff --git a/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java b/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java index 0ccc743..934c2d3 100644 --- a/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java +++ b/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java @@ -316,10 +316,10 @@ public void testAgentVersion() throws Exception { } @Test - public void testGetReporterFromSystemProperty() throws Exception { - System.setProperty("reporter", "APPTUIT"); - ReporterType reporterType = ConfigService.getInstance().getReporterType(); - assertEquals(ReporterType.APPTUIT, reporterType); + public void testGetGlobalTagsFromSystemProperty() throws Exception { + System.setProperty("jinsight.global_tags", "env:dev"); + Map globalTags = ConfigService.getInstance().getGlobalTags(); + assertEquals("dev", globalTags.get("env")); } private Properties getDefaultConfigProperties() { From 00b7902cc9af47cdad9a41783670a839595dfe79 Mon Sep 17 00:00:00 2001 From: Jaya Gupta Date: Wed, 3 May 2023 15:26:15 +0530 Subject: [PATCH 5/9] updated test --- .../metrics/jinsight/ConfigServiceTest.java | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java b/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java index 934c2d3..4428937 100644 --- a/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java +++ b/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java @@ -16,21 +16,26 @@ package ai.apptuit.metrics.jinsight; -import static ai.apptuit.metrics.jinsight.ConfigService.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - import ai.apptuit.metrics.client.Sanitizer; import ai.apptuit.metrics.dropwizard.ApptuitReporter.ReportingMode; import ai.apptuit.metrics.jinsight.ConfigService.ReporterType; +import org.junit.Test; + +import java.lang.reflect.Field; import java.net.URL; import java.util.Collections; import java.util.Map; import java.util.Properties; import java.util.UUID; -import org.junit.Test; + +import static ai.apptuit.metrics.jinsight.ConfigService.REPORTER_PROPERTY_NAME; +import static ai.apptuit.metrics.jinsight.ConfigService.REPORTING_FREQ_PROPERTY_NAME; +import static ai.apptuit.metrics.jinsight.ConfigService.REPORTING_MODE_PROPERTY_NAME; +import static ai.apptuit.metrics.jinsight.ConfigService.getThisJVMProcessID; +import static ai.apptuit.metrics.jinsight.ConfigService.initialize; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; /** * @author Rajiv Shivane @@ -316,10 +321,25 @@ public void testAgentVersion() throws Exception { } @Test - public void testGetGlobalTagsFromSystemProperty() throws Exception { + public void testGetGlobalTags_SystemProperty() throws Exception { + // setup here since ConfigService.getInstance() has been initialized in several tests System.setProperty("jinsight.global_tags", "env:dev"); - Map globalTags = ConfigService.getInstance().getGlobalTags(); + + Field singletonField = ConfigService.class.getDeclaredField("singleton"); + singletonField.setAccessible(true); + singletonField.set(null, null); + + initialize(); + + ConfigService cs = ConfigService.getInstance(); + Map globalTags = cs.getGlobalTags(); assertEquals("dev", globalTags.get("env")); + + // clean the setup + System.setProperty("jinsight.global_tags", ""); + singletonField = ConfigService.class.getDeclaredField("singleton"); + singletonField.setAccessible(true); + singletonField.set(null, null); } private Properties getDefaultConfigProperties() { From 9bbd773e93da5fb96ee35da3fb0a5c1e3790dfce Mon Sep 17 00:00:00 2001 From: Jaya Gupta Date: Wed, 3 May 2023 15:39:24 +0530 Subject: [PATCH 6/9] updated test --- .../apptuit/metrics/jinsight/ConfigServiceTest.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java b/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java index 4428937..69d7234 100644 --- a/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java +++ b/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java @@ -321,8 +321,11 @@ public void testAgentVersion() throws Exception { } @Test - public void testGetGlobalTags_SystemProperty() throws Exception { + public void testLoadSystemProperties() throws Exception { // setup here since ConfigService.getInstance() has been initialized in several tests + System.setProperty("jinsight.reporter", "APPTUIT"); + System.setProperty("jinsight.apptuit.access_token", "TEST_TOKEN"); + System.setProperty("jinsight.apptuit.api_url", "http://api.test.bicycle.io"); System.setProperty("jinsight.global_tags", "env:dev"); Field singletonField = ConfigService.class.getDeclaredField("singleton"); @@ -332,10 +335,17 @@ public void testGetGlobalTags_SystemProperty() throws Exception { initialize(); ConfigService cs = ConfigService.getInstance(); + + assertEquals("APPTUIT", cs.getReporterType().name()); + assertEquals("TEST_TOKEN", cs.getApiToken()); + assertEquals("http://api.test.bicycle.io", cs.getApiUrl().toString()); Map globalTags = cs.getGlobalTags(); assertEquals("dev", globalTags.get("env")); // clean the setup + System.setProperty("jinsight.reporter", ""); + System.setProperty("jinsight.apptuit.access_token", ""); + System.setProperty("jinsight.apptuit.api_url", ""); System.setProperty("jinsight.global_tags", ""); singletonField = ConfigService.class.getDeclaredField("singleton"); singletonField.setAccessible(true); From 774e2237e2831ac065d6bd439d11ae3ac7bd8867 Mon Sep 17 00:00:00 2001 From: Jaya Gupta Date: Wed, 3 May 2023 16:14:32 +0530 Subject: [PATCH 7/9] incorporated review comments and updated test --- .../metrics/jinsight/ConfigService.java | 15 +++++----- .../metrics/jinsight/ConfigServiceTest.java | 28 +++++++++++++------ 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java b/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java index 9c0eaf1..3346d90 100644 --- a/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java +++ b/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java @@ -50,18 +50,14 @@ public class ConfigService { public static final String REPORTING_FREQ_PROPERTY_NAME = "reporting_frequency"; private static final String GLOBAL_TAGS_PROPERTY_NAME = "global_tags"; - private static final String GLOBAL_TAGS_SYSTEM_PROPERTY_NAME = "jinsight.global_tags"; public static final String REPORTER_PROPERTY_NAME = "reporter"; - public static final String REPORTER_SYSTEM_PROPERTY_NAME = "jinsight.reporter"; public static final String PROMETHEUS_EXPORTER_PORT = "prometheus.exporter_port"; public static final String PROMETHEUS_METRICS_PATH = "prometheus.exporter_endpoint"; public static final String REPORTING_MODE_PROPERTY_NAME = "apptuit.reporting_mode"; private static final String ACCESS_TOKEN_PROPERTY_NAME = "apptuit.access_token"; - private static final String ACCESS_TOKEN_SYSTEM_PROPERTY_NAME = "jinsight.apptuit.access_token"; private static final String API_ENDPOINT_PROPERTY_NAME = "apptuit.api_url"; - private static final String API_ENDPOINT_SYSTEM_PROPERTY_NAME = "jinsight.apptuit.api_url"; private static final String HOST_TAG_NAME = "host"; private static final String UUID_TEMPLATE_VARIABLE = "${UUID}"; @@ -195,22 +191,22 @@ private static Properties loadProperties(File configFilePath) throws IOException private static Map loadSystemProperties() { Map systemProperties = new HashMap<>(); - String reporter = getProperty(REPORTER_SYSTEM_PROPERTY_NAME); + String reporter = getProperty(REPORTER_PROPERTY_NAME); if(reporter != null){ systemProperties.put(REPORTER_PROPERTY_NAME, reporter); } - String accessToken = getProperty(ACCESS_TOKEN_SYSTEM_PROPERTY_NAME); + String accessToken = getProperty(ACCESS_TOKEN_PROPERTY_NAME); if(accessToken != null){ systemProperties.put(ACCESS_TOKEN_PROPERTY_NAME, accessToken); } - String apiEndpoint = getProperty(API_ENDPOINT_SYSTEM_PROPERTY_NAME); + String apiEndpoint = getProperty(API_ENDPOINT_PROPERTY_NAME); if(apiEndpoint != null){ systemProperties.put(API_ENDPOINT_PROPERTY_NAME, apiEndpoint); } - String globalTags = getProperty(GLOBAL_TAGS_SYSTEM_PROPERTY_NAME); + String globalTags = getProperty(GLOBAL_TAGS_PROPERTY_NAME); if(globalTags != null){ systemProperties.put(GLOBAL_TAGS_PROPERTY_NAME, globalTags); } @@ -219,6 +215,9 @@ private static Map loadSystemProperties() { } private static String getProperty(String propertyName) { + if(!propertyName.contains(".")) { + propertyName = "jinsight." + propertyName; + } String propertyValue = System.getenv(propertyName); if(propertyValue == null || propertyValue.equals("")){ propertyValue = System.getProperty(propertyName); diff --git a/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java b/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java index 69d7234..5776048 100644 --- a/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java +++ b/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java @@ -23,6 +23,8 @@ import java.lang.reflect.Field; import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.Collections; import java.util.Map; import java.util.Properties; @@ -324,13 +326,11 @@ public void testAgentVersion() throws Exception { public void testLoadSystemProperties() throws Exception { // setup here since ConfigService.getInstance() has been initialized in several tests System.setProperty("jinsight.reporter", "APPTUIT"); - System.setProperty("jinsight.apptuit.access_token", "TEST_TOKEN"); - System.setProperty("jinsight.apptuit.api_url", "http://api.test.bicycle.io"); + System.setProperty("apptuit.access_token", "TEST_TOKEN"); + System.setProperty("apptuit.api_url", "http://api.test.bicycle.io"); System.setProperty("jinsight.global_tags", "env:dev"); - Field singletonField = ConfigService.class.getDeclaredField("singleton"); - singletonField.setAccessible(true); - singletonField.set(null, null); + doPrivilegedAction(); initialize(); @@ -347,9 +347,21 @@ public void testLoadSystemProperties() throws Exception { System.setProperty("jinsight.apptuit.access_token", ""); System.setProperty("jinsight.apptuit.api_url", ""); System.setProperty("jinsight.global_tags", ""); - singletonField = ConfigService.class.getDeclaredField("singleton"); - singletonField.setAccessible(true); - singletonField.set(null, null); + doPrivilegedAction(); + } + + private void doPrivilegedAction() { + AccessController.doPrivileged((PrivilegedAction) () -> { + try { + Field singletonField = ConfigService.class.getDeclaredField("singleton"); + singletonField.setAccessible(true); + singletonField.set(null, null); + return ""; + } catch (ReflectiveOperationException | SecurityException e) { + throw new RuntimeException(e); + } + }); + } private Properties getDefaultConfigProperties() { From a9a93c849145b7d615ebde6c291e4fdf332198ec Mon Sep 17 00:00:00 2001 From: Jaya Gupta Date: Wed, 3 May 2023 16:37:24 +0530 Subject: [PATCH 8/9] incorporated review comments and updated test --- .../apptuit/metrics/jinsight/ConfigService.java | 7 ++++--- .../metrics/jinsight/ConfigServiceTest.java | 17 +++++------------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java b/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java index 3346d90..7732a1a 100644 --- a/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java +++ b/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java @@ -215,12 +215,13 @@ private static Map loadSystemProperties() { } private static String getProperty(String propertyName) { + String updatedPropertyName = propertyName; if(!propertyName.contains(".")) { - propertyName = "jinsight." + propertyName; + updatedPropertyName = "jinsight." + propertyName; } - String propertyValue = System.getenv(propertyName); + String propertyValue = System.getenv(updatedPropertyName); if(propertyValue == null || propertyValue.equals("")){ - propertyValue = System.getProperty(propertyName); + propertyValue = System.getProperty(updatedPropertyName); } return propertyValue != null && !propertyValue.equals("") ? propertyValue : null; } diff --git a/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java b/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java index 5776048..d765e4a 100644 --- a/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java +++ b/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java @@ -322,6 +322,7 @@ public void testAgentVersion() throws Exception { assertEquals(System.getProperty("project.version"), cs.getAgentVersion()); } + @SuppressWarnings("all") @Test public void testLoadSystemProperties() throws Exception { // setup here since ConfigService.getInstance() has been initialized in several tests @@ -335,7 +336,6 @@ public void testLoadSystemProperties() throws Exception { initialize(); ConfigService cs = ConfigService.getInstance(); - assertEquals("APPTUIT", cs.getReporterType().name()); assertEquals("TEST_TOKEN", cs.getApiToken()); assertEquals("http://api.test.bicycle.io", cs.getApiUrl().toString()); @@ -350,17 +350,10 @@ public void testLoadSystemProperties() throws Exception { doPrivilegedAction(); } - private void doPrivilegedAction() { - AccessController.doPrivileged((PrivilegedAction) () -> { - try { - Field singletonField = ConfigService.class.getDeclaredField("singleton"); - singletonField.setAccessible(true); - singletonField.set(null, null); - return ""; - } catch (ReflectiveOperationException | SecurityException e) { - throw new RuntimeException(e); - } - }); + private void doPrivilegedAction() throws Exception { + Field singletonField = ConfigService.class.getDeclaredField("singleton"); + singletonField.setAccessible(true); + singletonField.set(null, null); } From 736144567ecb8bc210854ac3a4f983ca84d8fce7 Mon Sep 17 00:00:00 2001 From: Jaya Gupta Date: Wed, 3 May 2023 16:48:53 +0530 Subject: [PATCH 9/9] removed unused imports --- .../java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java b/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java index d765e4a..2533e36 100644 --- a/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java +++ b/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java @@ -23,8 +23,6 @@ import java.lang.reflect.Field; import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Collections; import java.util.Map; import java.util.Properties;