File tree Expand file tree Collapse file tree 3 files changed +36
-3
lines changed
main/java/org/elasticsearch/action/admin/cluster/snapshots/status
test/java/org/elasticsearch/action/admin/cluster/snapshots/status
test/framework/src/main/java/org/elasticsearch/test Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -204,10 +204,10 @@ public static SnapshotStats fromXContent(XContentParser parser) throws IOExcepti
204204 long time = 0 ;
205205 int incrementalFileCount = 0 ;
206206 int totalFileCount = 0 ;
207- int processedFileCount = 0 ;
207+ int processedFileCount = Integer . MIN_VALUE ;
208208 long incrementalSize = 0 ;
209209 long totalSize = 0 ;
210- long processedSize = 0 ;
210+ long processedSize = Long . MIN_VALUE ;
211211 while ((token = parser .nextToken ()) != XContentParser .Token .END_OBJECT ) {
212212 XContentParserUtils .ensureExpectedToken (XContentParser .Token .FIELD_NAME , token , parser );
213213 String currentName = parser .currentName ();
@@ -282,6 +282,12 @@ public static SnapshotStats fromXContent(XContentParser parser) throws IOExcepti
282282 }
283283 }
284284 }
285+ // Handle the case where the "processed" sub-object is omitted in toXContent() when processedFileCount == incrementalFileCount.
286+ if (processedFileCount == Integer .MIN_VALUE ) {
287+ assert processedSize == Long .MIN_VALUE ;
288+ processedFileCount = incrementalFileCount ;
289+ processedSize = incrementalSize ;
290+ }
285291 return new SnapshotStats (
286292 startTime ,
287293 time ,
Original file line number Diff line number Diff line change @@ -39,6 +39,26 @@ protected SnapshotStats createTestInstance() {
3939 );
4040 }
4141
42+ public void testXContentSerializationWhenProcessedFileCountEqualsIncrementalFileCount () throws IOException {
43+ final var instance = createTestInstance ();
44+ final var incrementalSameAsProcessed = new SnapshotStats (
45+ instance .getStartTime (),
46+ instance .getTime (),
47+ instance .getIncrementalFileCount (),
48+ instance .getTotalFileCount (),
49+ instance .getIncrementalFileCount (), // processedFileCount
50+ instance .getIncrementalSize (),
51+ instance .getTotalSize (),
52+ instance .getIncrementalSize () // processedSize
53+ );
54+ // toXContent() omits the "processed" sub-object in this case, make sure the processed values are set as expected in fromXContent().
55+ testFromXContent (() -> incrementalSameAsProcessed );
56+ }
57+
58+ public void testXContentSerializationForEmptyStats () throws IOException {
59+ testFromXContent (SnapshotStats ::new );
60+ }
61+
4262 @ Override
4363 protected SnapshotStats doParseInstance (XContentParser parser ) throws IOException {
4464 return SnapshotStats .fromXContent (parser );
Original file line number Diff line number Diff line change @@ -284,9 +284,16 @@ public static <T extends ToXContent> void testFromXContent(
284284 * both for equality and asserts equality on the two queries.
285285 */
286286 public final void testFromXContent () throws IOException {
287+ testFromXContent (this ::createTestInstance );
288+ }
289+
290+ /**
291+ * Generic test that creates a new instance using the given supplier and verifies XContent round trip serialization.
292+ */
293+ public final void testFromXContent (Supplier <T > testInstanceSupplier ) throws IOException {
287294 testFromXContent (
288295 NUMBER_OF_TEST_RUNS ,
289- this :: createTestInstance ,
296+ testInstanceSupplier ,
290297 supportsUnknownFields (),
291298 getShuffleFieldsExceptions (),
292299 getRandomFieldsExcludeFilter (),
You can’t perform that action at this time.
0 commit comments