Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
f238812c
Commit
f238812c
authored
Mar 31, 2020
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Improve handling of non-existent path in disk space health check"
See gh-20580
parent
db565cfc
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
130 deletions
+17
-130
DiskSpaceHealthIndicatorProperties.java
...oconfigure/system/DiskSpaceHealthIndicatorProperties.java
+1
-1
DiskSpaceHealthContributorAutoConfigurationTests.java
...tem/DiskSpaceHealthContributorAutoConfigurationTests.java
+3
-6
DiskSpaceHealthIndicator.java
...amework/boot/actuate/system/DiskSpaceHealthIndicator.java
+3
-7
DiskSpaceHealthIndicatorPathTests.java
...oot/actuate/system/DiskSpaceHealthIndicatorPathTests.java
+0
-106
DiskSpaceHealthIndicatorTests.java
...rk/boot/actuate/system/DiskSpaceHealthIndicatorTests.java
+10
-10
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/system/DiskSpaceHealthIndicatorProperties.java
View file @
f238812c
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/system/DiskSpaceHealthContributorAutoConfigurationTests.java
View file @
f238812c
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -16,8 +16,6 @@
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
system
;
import
java.util.UUID
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration
;
...
...
@@ -61,9 +59,8 @@ class DiskSpaceHealthContributorAutoConfigurationTests {
}
@Test
void
pathIsNotRequiredToExist
()
{
String
randomPath
=
"IDoNOTeXiST"
+
UUID
.
randomUUID
().
toString
();
this
.
contextRunner
.
withPropertyValues
(
"management.health.diskspace.path="
+
randomPath
)
void
runWhenPathDoesNotExistShouldCreateIndicator
()
{
this
.
contextRunner
.
withPropertyValues
(
"management.health.diskspace.path=does/not/exist"
)
.
run
((
context
)
->
assertThat
(
context
).
hasSingleBean
(
DiskSpaceHealthIndicator
.
class
));
}
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicator.java
View file @
f238812c
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -59,9 +59,7 @@ public class DiskSpaceHealthIndicator extends AbstractHealthIndicator {
@Override
protected
void
doHealthCheck
(
Health
.
Builder
builder
)
throws
Exception
{
long
diskFreeInBytes
=
this
.
path
.
getUsableSpace
();
// return value of 0L means "the abstract pathname does not name a
// partition" which for our purposes means it's not usable i.e DOWN
if
(
diskFreeInBytes
>=
this
.
threshold
.
toBytes
()
&&
diskFreeInBytes
!=
0L
)
{
if
(
diskFreeInBytes
>=
this
.
threshold
.
toBytes
())
{
builder
.
up
();
}
else
{
...
...
@@ -70,9 +68,7 @@ public class DiskSpaceHealthIndicator extends AbstractHealthIndicator {
builder
.
down
();
}
builder
.
withDetail
(
"total"
,
this
.
path
.
getTotalSpace
()).
withDetail
(
"free"
,
diskFreeInBytes
)
.
withDetail
(
"threshold"
,
this
.
threshold
.
toBytes
()).
withDetail
(
"exists"
,
this
.
path
.
exists
())
.
withDetail
(
"canRead"
,
this
.
path
.
canRead
()).
withDetail
(
"canWrite"
,
this
.
path
.
canWrite
())
.
withDetail
(
"canExecute"
,
this
.
path
.
canExecute
());
.
withDetail
(
"threshold"
,
this
.
threshold
.
toBytes
()).
withDetail
(
"exists"
,
this
.
path
.
exists
());
}
}
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicatorPathTests.java
deleted
100644 → 0
View file @
db565cfc
/*
* Copyright 2012-2019 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
*
* https://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
.
actuate
.
system
;
import
java.io.File
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.boot.actuate.health.HealthIndicator
;
import
org.springframework.boot.actuate.health.Status
;
import
org.springframework.util.unit.DataSize
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
/**
* Tests for the {@link DiskSpaceHealthIndicator} {@code path} parameter.
*
* @author Andreas Born
*/
class
DiskSpaceHealthIndicatorPathTests
{
private
static
final
DataSize
THRESHOLD
=
DataSize
.
ofKilobytes
(
1
);
private
static
final
DataSize
ZERO_THRESHOLD
=
DataSize
.
ofBytes
(
0
);
private
static
final
DataSize
TOTAL_SPACE
=
DataSize
.
ofKilobytes
(
10
);
@Mock
private
File
fileMock
;
private
HealthIndicator
healthIndicator
;
@BeforeEach
void
setUp
()
{
MockitoAnnotations
.
initMocks
(
this
);
given
(
this
.
fileMock
.
exists
()).
willReturn
(
false
);
given
(
this
.
fileMock
.
canRead
()).
willReturn
(
false
);
given
(
this
.
fileMock
.
canWrite
()).
willReturn
(
false
);
given
(
this
.
fileMock
.
canExecute
()).
willReturn
(
false
);
this
.
healthIndicator
=
new
DiskSpaceHealthIndicator
(
this
.
fileMock
,
THRESHOLD
);
}
@Test
void
diskSpaceIsDown
()
{
Health
health
=
this
.
healthIndicator
.
health
();
assertThat
(
health
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
assertThat
(
health
.
getDetails
().
get
(
"threshold"
)).
isEqualTo
(
THRESHOLD
.
toBytes
());
assertThat
(
health
.
getDetails
().
get
(
"free"
)).
isEqualTo
(
0L
);
assertThat
(
health
.
getDetails
().
get
(
"total"
)).
isEqualTo
(
0L
);
assertThat
(
health
.
getDetails
().
get
(
"exists"
)).
isEqualTo
(
false
);
assertThat
(
health
.
getDetails
().
get
(
"canRead"
)).
isEqualTo
(
false
);
assertThat
(
health
.
getDetails
().
get
(
"canWrite"
)).
isEqualTo
(
false
);
assertThat
(
health
.
getDetails
().
get
(
"canExecute"
)).
isEqualTo
(
false
);
}
@Test
void
diskSpaceIsDownWhenThresholdIsZero
()
{
this
.
healthIndicator
=
new
DiskSpaceHealthIndicator
(
this
.
fileMock
,
ZERO_THRESHOLD
);
Health
health
=
this
.
healthIndicator
.
health
();
assertThat
(
health
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
assertThat
(
health
.
getDetails
().
get
(
"threshold"
)).
isEqualTo
(
ZERO_THRESHOLD
.
toBytes
());
assertThat
(
health
.
getDetails
().
get
(
"free"
)).
isEqualTo
(
0L
);
assertThat
(
health
.
getDetails
().
get
(
"total"
)).
isEqualTo
(
0L
);
assertThat
(
health
.
getDetails
().
get
(
"exists"
)).
isEqualTo
(
false
);
assertThat
(
health
.
getDetails
().
get
(
"canRead"
)).
isEqualTo
(
false
);
assertThat
(
health
.
getDetails
().
get
(
"canWrite"
)).
isEqualTo
(
false
);
assertThat
(
health
.
getDetails
().
get
(
"canExecute"
)).
isEqualTo
(
false
);
}
@Test
void
diskSpaceIsUpWhenPathOnlyExists
()
{
long
freeSpace
=
THRESHOLD
.
toBytes
()
+
10
;
given
(
this
.
fileMock
.
getUsableSpace
()).
willReturn
(
freeSpace
);
given
(
this
.
fileMock
.
getTotalSpace
()).
willReturn
(
TOTAL_SPACE
.
toBytes
());
given
(
this
.
fileMock
.
exists
()).
willReturn
(
true
);
Health
health
=
this
.
healthIndicator
.
health
();
assertThat
(
health
.
getStatus
()).
isEqualTo
(
Status
.
UP
);
assertThat
(
health
.
getDetails
().
get
(
"threshold"
)).
isEqualTo
(
THRESHOLD
.
toBytes
());
assertThat
(
health
.
getDetails
().
get
(
"free"
)).
isEqualTo
(
freeSpace
);
assertThat
(
health
.
getDetails
().
get
(
"total"
)).
isEqualTo
(
TOTAL_SPACE
.
toBytes
());
assertThat
(
health
.
getDetails
().
get
(
"exists"
)).
isEqualTo
(
true
);
assertThat
(
health
.
getDetails
().
get
(
"canRead"
)).
isEqualTo
(
false
);
assertThat
(
health
.
getDetails
().
get
(
"canWrite"
)).
isEqualTo
(
false
);
assertThat
(
health
.
getDetails
().
get
(
"canExecute"
)).
isEqualTo
(
false
);
}
}
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicatorTests.java
View file @
f238812c
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -52,9 +52,6 @@ class DiskSpaceHealthIndicatorTests {
void
setUp
()
{
MockitoAnnotations
.
initMocks
(
this
);
given
(
this
.
fileMock
.
exists
()).
willReturn
(
true
);
given
(
this
.
fileMock
.
canRead
()).
willReturn
(
true
);
given
(
this
.
fileMock
.
canWrite
()).
willReturn
(
true
);
given
(
this
.
fileMock
.
canExecute
()).
willReturn
(
true
);
this
.
healthIndicator
=
new
DiskSpaceHealthIndicator
(
this
.
fileMock
,
THRESHOLD
);
}
...
...
@@ -69,9 +66,6 @@ class DiskSpaceHealthIndicatorTests {
assertThat
(
health
.
getDetails
().
get
(
"free"
)).
isEqualTo
(
freeSpace
);
assertThat
(
health
.
getDetails
().
get
(
"total"
)).
isEqualTo
(
TOTAL_SPACE
.
toBytes
());
assertThat
(
health
.
getDetails
().
get
(
"exists"
)).
isEqualTo
(
true
);
assertThat
(
health
.
getDetails
().
get
(
"canRead"
)).
isEqualTo
(
true
);
assertThat
(
health
.
getDetails
().
get
(
"canWrite"
)).
isEqualTo
(
true
);
assertThat
(
health
.
getDetails
().
get
(
"canExecute"
)).
isEqualTo
(
true
);
}
@Test
...
...
@@ -85,9 +79,15 @@ class DiskSpaceHealthIndicatorTests {
assertThat
(
health
.
getDetails
().
get
(
"free"
)).
isEqualTo
(
freeSpace
);
assertThat
(
health
.
getDetails
().
get
(
"total"
)).
isEqualTo
(
TOTAL_SPACE
.
toBytes
());
assertThat
(
health
.
getDetails
().
get
(
"exists"
)).
isEqualTo
(
true
);
assertThat
(
health
.
getDetails
().
get
(
"canRead"
)).
isEqualTo
(
true
);
assertThat
(
health
.
getDetails
().
get
(
"canWrite"
)).
isEqualTo
(
true
);
assertThat
(
health
.
getDetails
().
get
(
"canExecute"
)).
isEqualTo
(
true
);
}
@Test
void
whenPathDoesNotExistDiskSpaceIsDown
()
{
Health
health
=
new
DiskSpaceHealthIndicator
(
new
File
(
"does/not/exist"
),
THRESHOLD
).
health
();
assertThat
(
health
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
assertThat
(
health
.
getDetails
().
get
(
"free"
)).
isEqualTo
(
0L
);
assertThat
(
health
.
getDetails
().
get
(
"total"
)).
isEqualTo
(
0L
);
assertThat
(
health
.
getDetails
().
get
(
"exists"
)).
isEqualTo
(
false
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment