Skip to content

Commit 16e2d24

Browse files
committed
Fixed precommit failures
Signed-off-by: Sriram Ganesh <[email protected]>
1 parent 1416588 commit 16e2d24

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

server/src/test/java/org/opensearch/index/shard/IndexingStatsTests.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,14 @@ public void testToXContentForIndexingStats() throws IOException {
121121
* This ensures that aggregation (add) always surfaces the maximum value, even across multiple adds and random values.
122122
*/
123123
public void testMaxLastIndexRequestTimestampAggregation() throws Exception {
124-
IndexingStats.Stats stats1 = new IndexingStats.Stats();
125-
IndexingStats.Stats stats2 = new IndexingStats.Stats();
126-
IndexingStats.Stats stats3 = new IndexingStats.Stats();
127-
java.lang.reflect.Field tsField = IndexingStats.Stats.class.getDeclaredField("maxLastIndexRequestTimestamp");
128-
tsField.setAccessible(true);
129-
130-
// Use random values for robustness
124+
// Use explicit values for all fields except the timestamp
125+
IndexingStats.Stats.DocStatusStats docStatusStats = new IndexingStats.Stats.DocStatusStats();
131126
long ts1 = randomLongBetween(0, 1000000);
132127
long ts2 = randomLongBetween(0, 1000000);
133128
long ts3 = randomLongBetween(0, 1000000);
134-
135-
tsField.set(stats1, ts1);
136-
tsField.set(stats2, ts2);
137-
tsField.set(stats3, ts3);
129+
IndexingStats.Stats stats1 = new IndexingStats.Stats(1, 2, 3, 4, 5, 6, 7, 8, false, 9, docStatusStats, ts1);
130+
IndexingStats.Stats stats2 = new IndexingStats.Stats(1, 2, 3, 4, 5, 6, 7, 8, false, 9, docStatusStats, ts2);
131+
IndexingStats.Stats stats3 = new IndexingStats.Stats(1, 2, 3, 4, 5, 6, 7, 8, false, 9, docStatusStats, ts3);
138132

139133
// Aggregate stats1 + stats2
140134
stats1.add(stats2);
@@ -145,15 +139,14 @@ public void testMaxLastIndexRequestTimestampAggregation() throws Exception {
145139
assertEquals(Math.max(Math.max(ts1, ts2), ts3), stats1.getMaxLastIndexRequestTimestamp());
146140

147141
// Test with zero and negative values
148-
tsField.set(stats1, 0L);
149-
tsField.set(stats2, -100L);
150-
stats1.add(stats2);
151-
assertEquals(0L, stats1.getMaxLastIndexRequestTimestamp());
152-
153-
tsField.set(stats1, -50L);
154-
tsField.set(stats2, -100L);
155-
stats1.add(stats2);
156-
assertEquals(-50L, stats1.getMaxLastIndexRequestTimestamp());
142+
IndexingStats.Stats statsZero = new IndexingStats.Stats(1, 2, 3, 4, 5, 6, 7, 8, false, 9, docStatusStats, 0L);
143+
IndexingStats.Stats statsNeg = new IndexingStats.Stats(1, 2, 3, 4, 5, 6, 7, 8, false, 9, docStatusStats, -100L);
144+
statsZero.add(statsNeg);
145+
assertEquals(0L, statsZero.getMaxLastIndexRequestTimestamp());
146+
147+
IndexingStats.Stats statsNeg2 = new IndexingStats.Stats(1, 2, 3, 4, 5, 6, 7, 8, false, 9, docStatusStats, -50L);
148+
statsNeg.add(statsNeg2);
149+
assertEquals(-50L, statsNeg.getMaxLastIndexRequestTimestamp());
157150
}
158151

159152
private IndexingStats createTestInstance() {

0 commit comments

Comments
 (0)