Skip to content

Commit

Permalink
Optimize SofaRuntimeConfigurationProperties.(#185)
Browse files Browse the repository at this point in the history
Optimize SofaRuntimeConfigurationProperties.
  • Loading branch information
ScienJus authored and QilongZhang committed Aug 14, 2018
1 parent be66043 commit e79bb10
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
6 changes: 6 additions & 0 deletions runtime-sofa-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>

<!-- provided -->
<dependency>
<groupId>com.alipay.sofa</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,23 @@
*/
@ConfigurationProperties(SofaRuntimeConfigurationProperties.PREFIX)
public class SofaRuntimeConfigurationProperties {
static final String PREFIX = "com.alipay.sofa.boot";

private boolean skipJvmReferenceHealthCheck = false;
private boolean disableJvmFirst = false;
static final String PREFIX = "com.alipay.sofa.boot";

public void setSkipJvmReferenceHealthCheck(boolean skipJvmReferenceHealthCheck) {
this.skipJvmReferenceHealthCheck = skipJvmReferenceHealthCheck;
SofaRuntimeProperties.setSkipJvmReferenceHealthCheck(this.getClass().getClassLoader(),
skipJvmReferenceHealthCheck);
}

public void setDisableJvmFirst(boolean disableJvmFirst) {
this.disableJvmFirst = disableJvmFirst;
SofaRuntimeProperties.setDisableJvmFirst(this.getClass().getClassLoader(), disableJvmFirst);
}

public boolean isSkipJvmReferenceHealthCheck() {
return SofaRuntimeProperties
.isSkipJvmReferenceHealthCheck(this.getClass().getClassLoader());
}

public boolean isDisableJvmFirst() {
return SofaRuntimeProperties.isDisableJvmFirst(this.getClass().getClassLoader());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class SofaRuntimePropertiesTest {
Expand All @@ -35,12 +36,35 @@ public void closeContext() {
}

@Test
public void testProperties() {
public void testDisableJvmFirstProperty() {
assertFalse(SofaRuntimeProperties.isDisableJvmFirst(applicationContext.getClassLoader()));

EnvironmentTestUtils.addEnvironment(this.applicationContext,
"com.alipay.sofa.boot.disableJvmFirst=true");
this.applicationContext.register(SofaRuntimeAutoConfiguration.class);
this.applicationContext.refresh();
SofaRuntimeConfigurationProperties configurationProperties = this.applicationContext
.getBean(SofaRuntimeConfigurationProperties.class);

assertTrue(SofaRuntimeProperties.isDisableJvmFirst(applicationContext.getClassLoader()));
assertTrue(configurationProperties.isDisableJvmFirst());
}

@Test
public void testSkipJvmReferenceHealthCheckProperty() {
assertFalse(SofaRuntimeProperties.isSkipJvmReferenceHealthCheck(applicationContext
.getClassLoader()));

EnvironmentTestUtils.addEnvironment(this.applicationContext,
"com.alipay.sofa.boot.skipJvmReferenceHealthCheck=true");
this.applicationContext.register(SofaRuntimeAutoConfiguration.class);
this.applicationContext.refresh();
SofaRuntimeConfigurationProperties configurationProperties = this.applicationContext
.getBean(SofaRuntimeConfigurationProperties.class);

assertTrue(SofaRuntimeProperties.isSkipJvmReferenceHealthCheck(applicationContext
.getClassLoader()));
assertTrue(configurationProperties.isSkipJvmReferenceHealthCheck());
}

}

0 comments on commit e79bb10

Please sign in to comment.