Skip to content

Commit

Permalink
Fix test logic
Browse files Browse the repository at this point in the history
Signed-off-by: Pranshu Shukla <[email protected]>
  • Loading branch information
Pranshu-S committed Jul 12, 2024
1 parent 9876c13 commit 61bf2e0
Showing 1 changed file with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,6 @@ public void testNodeIndicesStatsOptimizedResponse() {
NodeIndicesStats.Fields.SHARDS,
"unknown"
);
String testToXContentLevel = randomFrom(
NodeIndicesStats.Fields.NODE,
NodeIndicesStats.Fields.INDICES,
NodeIndicesStats.Fields.SHARDS
);
internalCluster().startNode();
ensureGreen();
String indexName = "test1";
Expand All @@ -373,9 +368,10 @@ public void testNodeIndicesStatsOptimizedResponse() {
response.getNodes().forEach(nodeStats -> {
try {
XContentBuilder builder = XContentFactory.jsonBuilder();

builder.startObject();
builder = nodeStats.getIndices()
.toXContent(builder, new ToXContent.MapParams(Collections.singletonMap("level", testToXContentLevel)));
.toXContent(builder, new ToXContent.MapParams(Collections.singletonMap("level", NodeIndicesStats.Fields.SHARDS)));
builder.endObject();

Map<String, Object> xContentMap = xContentBuilderToMap(builder);
Expand All @@ -384,18 +380,43 @@ public void testNodeIndicesStatsOptimizedResponse() {
LinkedHashMap shardStats = (LinkedHashMap) indicesStatsMap.get(NodeIndicesStats.Fields.SHARDS);
switch (testLevel) {
case NodeIndicesStats.Fields.SHARDS:
assertFalse(shardStats == null || shardStats.isEmpty());
assertFalse(indicesStats == null || indicesStats.isEmpty());
assertFalse(shardStats.isEmpty());
assertNull(indicesStats);
break;
case NodeIndicesStats.Fields.INDICES:
assertTrue(shardStats.isEmpty());
assertNull(indicesStats);
break;
case NodeIndicesStats.Fields.NODE:
case "null":
case "unknown":
assertNull(shardStats);
assertNull(indicesStats);
break;
}

builder = XContentFactory.jsonBuilder();

builder.startObject();
builder = nodeStats.getIndices()
.toXContent(builder, new ToXContent.MapParams(Collections.singletonMap("level", NodeIndicesStats.Fields.INDICES)));
builder.endObject();

xContentMap = xContentBuilderToMap(builder);
indicesStatsMap = (LinkedHashMap) xContentMap.get(NodeIndicesStats.Fields.INDICES);
indicesStats = (LinkedHashMap) indicesStatsMap.get(NodeIndicesStats.Fields.INDICES);
shardStats = (LinkedHashMap) indicesStatsMap.get(NodeIndicesStats.Fields.SHARDS);
switch (testLevel) {
case NodeIndicesStats.Fields.SHARDS:
case NodeIndicesStats.Fields.INDICES:
assertTrue(shardStats == null || shardStats.isEmpty());
assertFalse(indicesStats == null || indicesStats.isEmpty());
assertNull(shardStats);
assertFalse(indicesStats.isEmpty());
break;
case NodeIndicesStats.Fields.NODE:
case "null":
case "unknown":
assertTrue(shardStats == null || shardStats.isEmpty());
assertTrue(indicesStats == null || indicesStats.isEmpty());
assertNull(shardStats);
assertNull(indicesStats);
break;
}
} catch (IOException e) {
Expand Down

0 comments on commit 61bf2e0

Please sign in to comment.