Skip to content

Commit

Permalink
Addressing PR review
Browse files Browse the repository at this point in the history
Add FsInfo.Path ctor asserts.

Signed-off-by: Lukáš Vlček <[email protected]>
  • Loading branch information
lukas-vlcek committed Jul 2, 2024
1 parent 2ea3532 commit b0675a9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions server/src/main/java/org/opensearch/monitor/fs/FsInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,20 @@ public static class Path implements Writeable, ToXContentObject {
public Path() {}

/**
* Please notice that this constructor will use value of <code>0</code>
* for <code>fileCacheReserved</code> and <code>fileCacheUtilized</code> variables.
* Please notice that this constructor will set value of <code>0</code>
* to <code>fileCacheReserved</code> and <code>fileCacheUtilized</code> variables.
*
* See {@link #getFileCacheReserved()}, {@link #getFileCacheUtilized()}
*/
public Path(String path, @Nullable String mount, long total, long free, long available) {
new Path(path, mount, total, free, available, 0, 0);
}

/**
* Do not assign negative values to variables <code>total</code>, <code>free</code>, <code>available</code>,
* <code>fileCacheReserved</code> and <code>fileCacheUtilized</code>. The only exception is value <code>-1</code>
* which is interpreted as an uninitialized value.
*/
@InternalApi
public Path(
String path,
Expand All @@ -107,6 +112,12 @@ public Path(
this.available = available;
this.fileCacheReserved = fileCacheReserved;
this.fileCacheUtilized = fileCacheUtilized;

assert (this.total == -1 || this.total >= 0) : "Total value can not be negative";
assert (this.free == -1 || this.free >= 0) : "Free value can not be negative";
assert (this.available == -1 || this.available >= 0) : "Available value can not be negative";
assert (this.fileCacheReserved == -1 || this.fileCacheReserved >= 0) : "File cache reserved value can not be negative";
assert (this.fileCacheUtilized == -1 || this.fileCacheUtilized >= 0) : "File cache utilization value can not be negative";
}

/**
Expand Down

0 comments on commit b0675a9

Please sign in to comment.