mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish
This commit is contained in:
parent
7287c66d88
commit
4c51aa8e28
@ -275,6 +275,7 @@ public class HealthIndicatorAutoConfiguration {
|
||||
public DiskSpaceHealthIndicatorProperties diskSpaceHealthIndicatorProperties() {
|
||||
return new DiskSpaceHealthIndicatorProperties();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,19 +37,12 @@ public class DiskSpaceHealthIndicatorProperties {
|
||||
}
|
||||
|
||||
public void setPath(File path) {
|
||||
if (!path.exists()) {
|
||||
throw new IllegalArgumentException(String.format("Path '%s' does not exist",
|
||||
path));
|
||||
}
|
||||
if (!path.canRead()) {
|
||||
throw new IllegalStateException(String.format("Path '%s' cannot be read",
|
||||
path));
|
||||
}
|
||||
Assert.isTrue(path.exists(), "Path '" + path + "' does not exist");
|
||||
Assert.isTrue(path.canRead(), "Path '" + path + "' cannot be read");
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public long getThreshold() {
|
||||
|
||||
return this.threshold;
|
||||
}
|
||||
|
||||
@ -57,4 +50,5 @@ public class DiskSpaceHealthIndicatorProperties {
|
||||
Assert.isTrue(threshold >= 0, "threshold must be greater than 0");
|
||||
this.threshold = threshold;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
/**
|
||||
* Tests for {@link DiskSpaceHealthIndicator}.
|
||||
@ -43,22 +43,21 @@ public class DiskSpaceHealthIndicatorTests {
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
File fileMock;
|
||||
private File fileMock;
|
||||
|
||||
HealthIndicator healthIndicator;
|
||||
private HealthIndicator healthIndicator;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
when(this.fileMock.exists()).thenReturn(true);
|
||||
when(this.fileMock.canRead()).thenReturn(true);
|
||||
given(this.fileMock.exists()).willReturn(true);
|
||||
given(this.fileMock.canRead()).willReturn(true);
|
||||
this.healthIndicator = new DiskSpaceHealthIndicator(createProperties(
|
||||
this.fileMock, THRESHOLD_BYTES));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void diskSpaceIsUp() throws Exception {
|
||||
when(this.fileMock.getFreeSpace()).thenReturn(THRESHOLD_BYTES + 10);
|
||||
|
||||
given(this.fileMock.getFreeSpace()).willReturn(THRESHOLD_BYTES + 10);
|
||||
Health health = this.healthIndicator.health();
|
||||
assertEquals(Status.UP, health.getStatus());
|
||||
assertEquals(THRESHOLD_BYTES, health.getDetails().get("threshold"));
|
||||
@ -67,8 +66,7 @@ public class DiskSpaceHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
public void diskSpaceIsDown() throws Exception {
|
||||
when(this.fileMock.getFreeSpace()).thenReturn(THRESHOLD_BYTES - 10);
|
||||
|
||||
given(this.fileMock.getFreeSpace()).willReturn(THRESHOLD_BYTES - 10);
|
||||
Health health = this.healthIndicator.health();
|
||||
assertEquals(Status.DOWN, health.getStatus());
|
||||
assertEquals(THRESHOLD_BYTES, health.getDetails().get("threshold"));
|
||||
@ -81,4 +79,5 @@ public class DiskSpaceHealthIndicatorTests {
|
||||
properties.setThreshold(threshold);
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -38,7 +38,7 @@ public abstract class LoggingSystem {
|
||||
systems.put("org.apache.log4j.PropertyConfigurator", pkg
|
||||
+ ".log4j.Log4JLoggingSystem");
|
||||
systems.put("org.apache.logging.log4j.LogManager", pkg
|
||||
+ ".log4j2.Log4J2LoggingSystem");
|
||||
+ ".log4j2.Log4J2LoggingSystem");
|
||||
systems.put("java.util.logging.LogManager", pkg + ".java.JavaLoggingSystem");
|
||||
SYSTEMS = Collections.unmodifiableMap(systems);
|
||||
}
|
||||
|
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.logging.log4j2;
|
||||
|
||||
import java.net.URL;
|
||||
@ -47,22 +63,22 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem {
|
||||
public void initialize(String configLocation) {
|
||||
Assert.notNull(configLocation, "ConfigLocation must not be null");
|
||||
String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(configLocation);
|
||||
|
||||
try {
|
||||
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
|
||||
URL url = ResourceUtils.getURL(resolvedLocation);
|
||||
ConfigurationSource configSource = new ConfigurationSource(url.openStream(),
|
||||
url);
|
||||
Configuration config = ConfigurationFactory.getInstance().getConfiguration(
|
||||
configSource);
|
||||
ctx.start(config);
|
||||
|
||||
initializeAndStart(resolvedLocation);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Could not initialize logging from "
|
||||
+ configLocation, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeAndStart(String resolvedLocation) throws Exception {
|
||||
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
|
||||
URL url = ResourceUtils.getURL(resolvedLocation);
|
||||
ConfigurationSource configSource = new ConfigurationSource(url.openStream(), url);
|
||||
Configuration config = ConfigurationFactory.getInstance().getConfiguration(
|
||||
configSource);
|
||||
ctx.start(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -71,4 +87,5 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem {
|
||||
ctx.getConfiguration().getLoggerConfig(loggerName).setLevel(LEVELS.get(level));
|
||||
ctx.updateLoggers();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user