Skip to content

Commit 165314c

Browse files
Revert change to AbstractXContentTestCase
1 parent 82fc4b5 commit 165314c

File tree

2 files changed

+9
-28
lines changed

2 files changed

+9
-28
lines changed

server/src/test/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotStatsTests.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ protected SnapshotStats createTestInstance() {
2828
long incrementalSize = ((long) randomIntBetween(0, Integer.MAX_VALUE)) * 2;
2929
long totalSize = ((long) randomIntBetween(0, Integer.MAX_VALUE)) * 2;
3030
long processedSize = ((long) randomIntBetween(0, Integer.MAX_VALUE)) * 2;
31+
32+
// toXContent() omits the "processed" sub-object if processedFileCount == incrementalFileCount, so here we increase the probability
33+
// of that scenario so we can make sure the processed values are set as expected in fromXContent().
34+
if (randomBoolean()) {
35+
processedFileCount = incrementalFileCount;
36+
processedSize = incrementalSize;
37+
}
38+
3139
return new SnapshotStats(
3240
startTime,
3341
time,
@@ -40,26 +48,6 @@ protected SnapshotStats createTestInstance() {
4048
);
4149
}
4250

43-
public void testXContentSerializationWhenProcessedFileCountEqualsIncrementalFileCount() throws IOException {
44-
final var instance = createTestInstance();
45-
final var incrementalSameAsProcessed = new SnapshotStats(
46-
instance.getStartTime(),
47-
instance.getTime(),
48-
instance.getIncrementalFileCount(),
49-
instance.getTotalFileCount(),
50-
instance.getIncrementalFileCount(), // processedFileCount
51-
instance.getIncrementalSize(),
52-
instance.getTotalSize(),
53-
instance.getIncrementalSize() // processedSize
54-
);
55-
// toXContent() omits the "processed" sub-object in this case, make sure the processed values are set as expected in fromXContent().
56-
testFromXContent(() -> incrementalSameAsProcessed);
57-
}
58-
59-
public void testXContentSerializationForEmptyStats() throws IOException {
60-
testFromXContent(SnapshotStats::new);
61-
}
62-
6351
@Override
6452
protected SnapshotStats doParseInstance(XContentParser parser) throws IOException {
6553
return fromXContent(parser);

test/framework/src/main/java/org/elasticsearch/test/AbstractXContentTestCase.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,9 @@ 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 {
294287
testFromXContent(
295288
NUMBER_OF_TEST_RUNS,
296-
testInstanceSupplier,
289+
this::createTestInstance,
297290
supportsUnknownFields(),
298291
getShuffleFieldsExceptions(),
299292
getRandomFieldsExcludeFilter(),

0 commit comments

Comments
 (0)