Skip to content

Commit

Permalink
adding boolean check if model stats exists
Browse files Browse the repository at this point in the history
Signed-off-by: Dhrubo Saha <[email protected]>
  • Loading branch information
dhrubo-os committed Oct 4, 2023
1 parent f99a063 commit 4abc1d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public class MLModelStats implements ToXContentFragment, Writeable {
private Map<ActionName, MLActionStats> modelStats;

public MLModelStats(StreamInput in) throws IOException {
this.modelStats = in.readMap(stream -> stream.readEnum(ActionName.class), MLActionStats::new);
if (in.readBoolean()) {
this.modelStats = in.readMap(stream -> stream.readEnum(ActionName.class), MLActionStats::new);
}
}

public MLModelStats(Map<ActionName, MLActionStats> modelStats) {
Expand All @@ -37,7 +39,10 @@ public MLModelStats(Map<ActionName, MLActionStats> modelStats) {
@Override
public void writeTo(StreamOutput out) throws IOException {
if (modelStats != null && modelStats.size() > 0) {
out.writeBoolean(true);
out.writeMap(modelStats, (stream, v) -> stream.writeEnum(v), (stream, stats) -> stats.writeTo(stream));
} else {
out.writeBoolean(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ public void testEmptySerializationDeserialization() throws IOException {
MLModelStats mlModelEmptyStats = new MLModelStats(modelStats);
BytesStreamOutput output = new BytesStreamOutput();
mlModelEmptyStats.writeTo(output);
assertEquals(0, output.bytes().length());
MLModelStats parsedMLModelStats = new MLModelStats(output.bytes().streamInput());
MLActionStats parsedMLActionStats = parsedMLModelStats.getActionStats(ActionName.PREDICT);
assertNull(parsedMLActionStats);
// assertEquals(0, output.bytes().length());
}

public void testToXContent() throws IOException {
Expand Down

0 comments on commit 4abc1d1

Please sign in to comment.