Skip to content

Commit 4d7d64d

Browse files
author
Peter Alfonsi
committed
Addressed andrross's comment
Signed-off-by: Peter Alfonsi <[email protected]>
1 parent 5cb11af commit 4d7d64d

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

modules/cache-common/src/internalClusterTest/java/org/opensearch/cache/common/tier/TieredSpilloverCacheStatsIT.java

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ public void testIndicesLevelAggregation() throws Exception {
104104
);
105105

106106
for (ImmutableCacheStatsHolder statsHolder : List.of(allLevelsStatsHolder, indicesOnlyStatsHolder)) {
107-
assertStatsEqual(index1ExpectedStats, statsHolder.getStatsForDimensionValues(List.of(index1Name)));
108-
assertStatsEqual(index2ExpectedStats, statsHolder.getStatsForDimensionValues(List.of(index2Name)));
107+
assertEquals(index1ExpectedStats, statsHolder.getStatsForDimensionValues(List.of(index1Name)));
108+
assertEquals(index2ExpectedStats, statsHolder.getStatsForDimensionValues(List.of(index2Name)));
109109
}
110110
}
111111

@@ -141,7 +141,7 @@ public void testIndicesAndTierLevelAggregation() throws Exception {
141141
values.get("itemsOnHeapIndex1AfterTest")
142142
)
143143
);
144-
assertStatsEqual(
144+
assertEquals(
145145
index1HeapExpectedStats,
146146
allLevelsStatsHolder.getStatsForDimensionValues(List.of(index1Name, TIER_DIMENSION_VALUE_ON_HEAP))
147147
);
@@ -155,7 +155,7 @@ public void testIndicesAndTierLevelAggregation() throws Exception {
155155
values.get("itemsOnHeapIndex2AfterTest")
156156
)
157157
);
158-
assertStatsEqual(
158+
assertEquals(
159159
index2HeapExpectedStats,
160160
allLevelsStatsHolder.getStatsForDimensionValues(List.of(index2Name, TIER_DIMENSION_VALUE_ON_HEAP))
161161
);
@@ -169,7 +169,7 @@ public void testIndicesAndTierLevelAggregation() throws Exception {
169169
values.get("itemsOnDiskIndex1AfterTest")
170170
)
171171
);
172-
assertStatsEqual(
172+
assertEquals(
173173
index1DiskExpectedStats,
174174
allLevelsStatsHolder.getStatsForDimensionValues(List.of(index1Name, TIER_DIMENSION_VALUE_DISK))
175175
);
@@ -183,7 +183,7 @@ public void testIndicesAndTierLevelAggregation() throws Exception {
183183
values.get("itemsOnDiskIndex2AfterTest")
184184
)
185185
);
186-
assertStatsEqual(
186+
assertEquals(
187187
index2DiskExpectedStats,
188188
allLevelsStatsHolder.getStatsForDimensionValues(List.of(index2Name, TIER_DIMENSION_VALUE_DISK))
189189
);
@@ -220,7 +220,7 @@ public void testTierLevelAggregation() throws Exception {
220220
)
221221
);
222222
ImmutableCacheStats heapStats = tiersOnlyStatsHolder.getStatsForDimensionValues(List.of(TIER_DIMENSION_VALUE_ON_HEAP));
223-
assertStatsEqual(totalHeapExpectedStats, heapStats);
223+
assertEquals(totalHeapExpectedStats, heapStats);
224224
ImmutableCacheStats totalDiskExpectedStats = returnNullIfAllZero(
225225
new ImmutableCacheStats(
226226
values.get("hitsOnDiskIndex1") + values.get("hitsOnDiskIndex2"),
@@ -231,7 +231,7 @@ public void testTierLevelAggregation() throws Exception {
231231
)
232232
);
233233
ImmutableCacheStats diskStats = tiersOnlyStatsHolder.getStatsForDimensionValues(List.of(TIER_DIMENSION_VALUE_DISK));
234-
assertStatsEqual(totalDiskExpectedStats, diskStats);
234+
assertEquals(totalDiskExpectedStats, diskStats);
235235
}
236236

237237
public void testInvalidLevelsAreIgnored() throws Exception {
@@ -324,7 +324,7 @@ public void testStatsMatchOldApi() throws Exception {
324324
ImmutableCacheStats totalStats = getNodeCacheStatsResult(client, List.of()).getTotalStats();
325325

326326
// Check the new stats API values are as expected
327-
assertStatsEqual(
327+
assertEquals(
328328
new ImmutableCacheStats(expectedHits, expectedMisses, 0, expectedEntries * singleSearchSize, expectedEntries),
329329
totalStats
330330
);
@@ -504,16 +504,4 @@ private static ImmutableCacheStatsHolder getNodeCacheStatsResult(Client client,
504504
NodeCacheStats ncs = nodeStatsResponse.getNodes().get(0).getNodeCacheStats();
505505
return ncs.getStatsByCache(CacheType.INDICES_REQUEST_CACHE);
506506
}
507-
508-
// Check each stat separately for more transparency if there's a failure
509-
private void assertStatsEqual(ImmutableCacheStats expected, ImmutableCacheStats actual) {
510-
if (expected == null && actual == null) {
511-
return;
512-
}
513-
assertEquals(expected.getHits(), actual.getHits());
514-
assertEquals(expected.getMisses(), actual.getMisses());
515-
assertEquals(expected.getEvictions(), actual.getEvictions());
516-
assertEquals(expected.getSizeInBytes(), actual.getSizeInBytes());
517-
assertEquals(expected.getItems(), actual.getItems());
518-
}
519507
}

server/src/main/java/org/opensearch/common/cache/stats/ImmutableCacheStats.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,23 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
115115
return builder;
116116
}
117117

118+
@Override
119+
public String toString() {
120+
return String.format(
121+
"%s=%d, %s=%d, %s=%d, %s=%d, %s=%d",
122+
Fields.HIT_COUNT,
123+
hits,
124+
Fields.MISS_COUNT,
125+
misses,
126+
Fields.EVICTIONS,
127+
evictions,
128+
Fields.SIZE_IN_BYTES,
129+
sizeInBytes,
130+
Fields.ITEM_COUNT,
131+
items
132+
);
133+
}
134+
118135
/**
119136
* Field names used to write the values in this object to XContent.
120137
*/

0 commit comments

Comments
 (0)