This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob.git


The following commit(s) were added to refs/heads/master by this push:
     new 6edec35  Remove system evn load for email configuration (#1512)
6edec35 is described below

commit 6edec35e596c2e1f3aa259409c2cdd7b03f77e01
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Sep 29 11:36:47 2020 +0800

    Remove system evn load for email configuration (#1512)
---
 .../handler/email/EmailConfigurationLoader.java    | 42 --------------
 .../error/handler/email/EmailJobErrorHandler.java  | 11 +---
 .../handler/email/EmailJobErrorHandlerTest.java    | 65 ++++------------------
 3 files changed, 14 insertions(+), 104 deletions(-)

diff --git 
a/elasticjob-error-handler/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailConfigurationLoader.java
 
b/elasticjob-error-handler/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailConfigurationLoader.java
index b4f79c0..76ca96e 100644
--- 
a/elasticjob-error-handler/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailConfigurationLoader.java
+++ 
b/elasticjob-error-handler/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailConfigurationLoader.java
@@ -19,7 +19,6 @@ package 
org.apache.shardingsphere.elasticjob.error.handler.email;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
-import org.apache.commons.lang3.StringUtils;
 import org.apache.shardingsphere.elasticjob.infra.yaml.YamlEngine;
 
 import java.io.IOException;
@@ -47,45 +46,4 @@ public final class EmailConfigurationLoader {
             throw new RuntimeException(ex);
         }
     }
-    
-    /**
-     * Unmarshal configuration from system properties.
-     *
-     * @return object from system properties
-     */
-    public static EmailConfiguration unmarshalFromSystemProperties() {
-        String isBySystemProperties = 
System.getProperty("error-handler-email.use-system-properties");
-        if (!Boolean.parseBoolean(isBySystemProperties)) {
-            return null;
-        }
-        EmailConfiguration result = new EmailConfiguration();
-        result.setHost(System.getProperty("error-handler-email.host"));
-        result.setUsername(System.getProperty("error-handler-email.username"));
-        result.setPassword(System.getProperty("error-handler-email.password"));
-        result.setFrom(System.getProperty("error-handler-email.from"));
-        result.setTo(System.getProperty("error-handler-email.to"));
-        result.setCc(System.getProperty("error-handler-email.cc"));
-        result.setBcc(System.getProperty("error-handler-email.bcc"));
-        String protocol = System.getProperty("error-handler-email.protocol");
-        if (StringUtils.isNotBlank(protocol)) {
-            
result.setProtocol(System.getProperty("error-handler-email.protocol"));
-        }
-        String useSSL = System.getProperty("error-handler-email.use-ssl");
-        if (StringUtils.isNotBlank(useSSL)) {
-            result.setUseSsl(Boolean.parseBoolean(useSSL));
-        }
-        String subject = System.getProperty("error-handler-email.subject");
-        if (StringUtils.isNotBlank(subject)) {
-            result.setSubject(subject);
-        }
-        String port = System.getProperty("error-handler-email.port");
-        if (StringUtils.isNotBlank(port)) {
-            result.setPort(Integer.valueOf(port));
-        }
-        String debug = System.getProperty("error-handler-email.debug");
-        if (StringUtils.isNotBlank(debug)) {
-            result.setDebug(Boolean.parseBoolean(debug));
-        }
-        return result;
-    }
 }
diff --git 
a/elasticjob-error-handler/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandler.java
 
b/elasticjob-error-handler/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandler.java
index 2ae34d5..d1b83d2 100644
--- 
a/elasticjob-error-handler/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandler.java
+++ 
b/elasticjob-error-handler/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandler.java
@@ -48,19 +48,12 @@ public final class EmailJobErrorHandler implements 
JobErrorHandler {
     
     public static final String CONFIG_PREFIX = "email";
     
-    private EmailConfiguration config;
+    private final EmailConfiguration config;
     
     private Session session;
     
     public EmailJobErrorHandler() {
-        loadConfiguration();
-    }
-    
-    private void loadConfiguration() {
-        config = EmailConfigurationLoader.unmarshalFromSystemProperties();
-        if (null == config) {
-            config = EmailConfigurationLoader.unmarshal(CONFIG_PREFIX);
-        }
+        config = EmailConfigurationLoader.unmarshal(CONFIG_PREFIX);
     }
     
     @Override
diff --git 
a/elasticjob-error-handler/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerTest.java
 
b/elasticjob-error-handler/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerTest.java
index b84aa18..5ff12ec 100644
--- 
a/elasticjob-error-handler/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerTest.java
+++ 
b/elasticjob-error-handler/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerTest.java
@@ -42,43 +42,22 @@ public final class EmailJobErrorHandlerTest {
     
     @Test
     public void assertHandleExceptionWithYAMLConfiguration() throws 
ReflectiveOperationException {
-        resetSystemProperties();
         EmailJobErrorHandler emailJobErrorHandler = new EmailJobErrorHandler();
         emailJobErrorHandler.handleException("test job name", new 
RuntimeException("test exception"));
         Field field = 
emailJobErrorHandler.getClass().getDeclaredField("config");
         field.setAccessible(true);
-        EmailConfiguration emailConfiguration = (EmailConfiguration) 
field.get(emailJobErrorHandler);
-        assertNotNull(emailConfiguration);
-        assertThat(emailConfiguration.getHost(), equalTo("yaml.email.com"));
-        assertThat(emailConfiguration.getPort(), equalTo(123));
-        assertThat(emailConfiguration.getUsername(), equalTo("yaml.username"));
-        assertThat(emailConfiguration.getFrom(), 
equalTo("[email protected]"));
-        assertThat(emailConfiguration.getTo(), equalTo("[email protected]"));
-        assertThat(emailConfiguration.getBcc(), equalTo("[email protected]"));
-        assertThat(emailConfiguration.getProtocol(), equalTo("yaml.smtp"));
-        assertThat(emailConfiguration.getSubject(), equalTo("yaml.subject"));
-        assertTrue(emailConfiguration.isUseSsl());
-        assertTrue(emailConfiguration.isDebug());
-    }
-    
-    @Test
-    public void assertHandleExceptionWithSystemPropertiesConfiguration() 
throws ReflectiveOperationException {
-        initSystemProperties();
-        EmailJobErrorHandler emailJobErrorHandler = new EmailJobErrorHandler();
-        emailJobErrorHandler.handleException("test job name", new 
RuntimeException("test exception"));
-        Field field = 
emailJobErrorHandler.getClass().getDeclaredField("config");
-        field.setAccessible(true);
-        EmailConfiguration emailConfiguration = (EmailConfiguration) 
field.get(emailJobErrorHandler);
-        assertNotNull(emailConfiguration);
-        assertThat(emailConfiguration.getHost(), equalTo("system.email.com"));
-        assertThat(emailConfiguration.getPort(), equalTo(345));
-        assertThat(emailConfiguration.getUsername(), 
equalTo("system.username"));
-        assertThat(emailConfiguration.getFrom(), 
equalTo("[email protected]"));
-        assertThat(emailConfiguration.getTo(), equalTo("[email protected]"));
-        assertThat(emailConfiguration.getCc(), equalTo("[email protected]"));
-        assertThat(emailConfiguration.getProtocol(), equalTo("smtp"));
-        assertTrue(emailConfiguration.isUseSsl());
-        assertTrue(emailConfiguration.isDebug());
+        EmailConfiguration config = (EmailConfiguration) 
field.get(emailJobErrorHandler);
+        assertNotNull(config);
+        assertThat(config.getHost(), equalTo("yaml.email.com"));
+        assertThat(config.getPort(), equalTo(123));
+        assertThat(config.getUsername(), equalTo("yaml.username"));
+        assertThat(config.getFrom(), equalTo("[email protected]"));
+        assertThat(config.getTo(), equalTo("[email protected]"));
+        assertThat(config.getBcc(), equalTo("[email protected]"));
+        assertThat(config.getProtocol(), equalTo("yaml.smtp"));
+        assertThat(config.getSubject(), equalTo("yaml.subject"));
+        assertTrue(config.isUseSsl());
+        assertTrue(config.isDebug());
     }
     
     @Test
@@ -108,24 +87,4 @@ public final class EmailJobErrorHandlerTest {
         EmailJobErrorHandler emailJobErrorHandler = new EmailJobErrorHandler();
         assertThat(emailJobErrorHandler.getType(), equalTo("EMAIL"));
     }
-    
-    private void initSystemProperties() {
-        System.setProperty("error-handler-email.use-system-properties", 
"true");
-        System.setProperty("error-handler-email.host", "system.email.com");
-        System.setProperty("error-handler-email.port", "345");
-        System.setProperty("error-handler-email.protocol", "smtp");
-        System.setProperty("error-handler-email.use-ssl", "true");
-        System.setProperty("error-handler-email.username", "system.username");
-        System.setProperty("error-handler-email.password", "system.password");
-        System.setProperty("error-handler-email.subject", "system.subject");
-        System.setProperty("error-handler-email.from", "[email protected]");
-        System.setProperty("error-handler-email.to", "[email protected]");
-        System.setProperty("error-handler-email.cc", "[email protected]");
-        System.setProperty("error-handler-email.bcc", "[email protected]");
-        System.setProperty("error-handler-email.debug", "true");
-    }
-    
-    private void resetSystemProperties() {
-        System.setProperty("error-handler-email.use-system-properties", 
"false");
-    }
 }

Reply via email to