Merge branch 'disk'
This commit is contained in:
commit
cb4cdf4d9a
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.health;
|
package org.springframework.boot.actuate.health;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
@ -45,7 +47,8 @@ public class DiskSpaceHealthIndicator extends AbstractHealthIndicator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||||
long diskFreeInBytes = this.properties.getPath().getFreeSpace();
|
File path = this.properties.getPath();
|
||||||
|
long diskFreeInBytes = path.getFreeSpace();
|
||||||
if (diskFreeInBytes >= this.properties.getThreshold()) {
|
if (diskFreeInBytes >= this.properties.getThreshold()) {
|
||||||
builder.up();
|
builder.up();
|
||||||
}
|
}
|
||||||
|
|
@ -55,7 +58,8 @@ public class DiskSpaceHealthIndicator extends AbstractHealthIndicator {
|
||||||
this.properties.getThreshold()));
|
this.properties.getThreshold()));
|
||||||
builder.down();
|
builder.down();
|
||||||
}
|
}
|
||||||
builder.withDetail("free", diskFreeInBytes).withDetail("threshold",
|
builder.withDetail("total", path.getTotalSpace())
|
||||||
this.properties.getThreshold());
|
.withDetail("free", diskFreeInBytes)
|
||||||
|
.withDetail("threshold", this.properties.getThreshold());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,19 +58,23 @@ public class DiskSpaceHealthIndicatorTests {
|
||||||
@Test
|
@Test
|
||||||
public void diskSpaceIsUp() throws Exception {
|
public void diskSpaceIsUp() throws Exception {
|
||||||
given(this.fileMock.getFreeSpace()).willReturn(THRESHOLD_BYTES + 10);
|
given(this.fileMock.getFreeSpace()).willReturn(THRESHOLD_BYTES + 10);
|
||||||
|
given(this.fileMock.getTotalSpace()).willReturn(THRESHOLD_BYTES * 10);
|
||||||
Health health = this.healthIndicator.health();
|
Health health = this.healthIndicator.health();
|
||||||
assertEquals(Status.UP, health.getStatus());
|
assertEquals(Status.UP, health.getStatus());
|
||||||
assertEquals(THRESHOLD_BYTES, health.getDetails().get("threshold"));
|
assertEquals(THRESHOLD_BYTES, health.getDetails().get("threshold"));
|
||||||
assertEquals(THRESHOLD_BYTES + 10, health.getDetails().get("free"));
|
assertEquals(THRESHOLD_BYTES + 10, health.getDetails().get("free"));
|
||||||
|
assertEquals(THRESHOLD_BYTES * 10, health.getDetails().get("total"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void diskSpaceIsDown() throws Exception {
|
public void diskSpaceIsDown() throws Exception {
|
||||||
given(this.fileMock.getFreeSpace()).willReturn(THRESHOLD_BYTES - 10);
|
given(this.fileMock.getFreeSpace()).willReturn(THRESHOLD_BYTES - 10);
|
||||||
|
given(this.fileMock.getTotalSpace()).willReturn(THRESHOLD_BYTES * 10);
|
||||||
Health health = this.healthIndicator.health();
|
Health health = this.healthIndicator.health();
|
||||||
assertEquals(Status.DOWN, health.getStatus());
|
assertEquals(Status.DOWN, health.getStatus());
|
||||||
assertEquals(THRESHOLD_BYTES, health.getDetails().get("threshold"));
|
assertEquals(THRESHOLD_BYTES, health.getDetails().get("threshold"));
|
||||||
assertEquals(THRESHOLD_BYTES - 10, health.getDetails().get("free"));
|
assertEquals(THRESHOLD_BYTES - 10, health.getDetails().get("free"));
|
||||||
|
assertEquals(THRESHOLD_BYTES * 10, health.getDetails().get("total"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private DiskSpaceHealthIndicatorProperties createProperties(File path, long threshold) {
|
private DiskSpaceHealthIndicatorProperties createProperties(File path, long threshold) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue